LameMusic¶
A sequencer for LameAudio that allows your games to play music.
music : "LameMusic"
About¶
Call music.Start
once at the beginning of your program to start
the music engine.
Info
LameAudio must be started before LameMusic.
To load a song, call music.Load
using the Addr
function of the
song object as an argument. Only one song can play at a time. Loading a new song
will stop any currently playing one.
music.Load(mycoolsong.Addr)
You can use music.Play
to play a song once, or
music.Loop
to play it forever. Call
music.IsPlaying
to find out if a song is currently playing.
Once you're tired of listening to music, call music.Stop
to end
the song. Playing the song again will start over from the beginning.
Song Format¶
LameStation songs consist of two main sections: pattern and sequence data.
Pattern Data¶
Patterns contain melodies, riffs, harmonies and any musical parts that fit in a measure.
-
Notes per measure (first byte) (
0-255
) - Each pattern must have exactly this many notes. -
Note (
0-127
) - Play note n between 0 and 127. -
Stop note (
$83
) - Stop playing note. -
Do nothing (
$82
) - Do nothing (continue playing or not playing current note).
DAT
pattern_data
byte 4
byte 42, 44, 46, 49
byte 42, $82, $82, $83
Sequence Data¶
The sequence defines how the patterns are arranged in time and across channels. There should be one command, as many times as you want.
-
Pattern (
<ch1>
,<ch2>
,<ch3>
,<ch4>
) - Set next pattern to pattern 1-127 for all four channels. Pattern 0 plays nothing. -
End song (
$80
) - End the song. -
ADSRW (
$A0
,<a>
,<d>
,<s>
,<r>
,<w>
) - Change the sound of channel(s). -
Tempo (
$B0
,0-255
) - Change the tempo of the song. -
Transpose (
$C0
,-128-127
) - Transpose the channel up or down number of notes.
DAT
sequence_data
byte 1, 0, 0, 0
byte $80
Song Interface¶
For LameMusic to access the song object, some extra code is needed. This code provides an address which LameMusic reads to figure out where the song data is.
DAT
song_data
word @pattern_data, @sequence_data
PUB Addr
result.word[1] := @@0
result.word{0} := @song_data
Functions¶
music.Start¶
Initialize the LameMusic library.
music.Start
Call music.Start once at the beginning of your program to start the music engine.
Info
LameAudio must be started before LameMusic.
music.IsPlaying¶
Check if a song is playing. Returns true if song is playing, otherwise false.
music.IsPlaying
music.Load¶
Load a song to play.
music.Load(songAddr)
- songAddr - Addr of the song object to play.
To load a song, call music.Load
using the Addr
function of the song object
as an argument. Only one song can play at a time. Loading a new song will stop
any currently playing one.
music.Load(mycoolsong.Addr)
music.Loop¶
Play the loaded song forever.
music.Loop
music.Play¶
Play the loaded song once.
music.Play
music.Stop¶
Stop the loaded song, if playing.
music.Stop