Music sequence

From SM64Decomp Wiki
(Redirected from Sequence)
Jump to navigation Jump to search

dasdasdasdMusic in Super Mario 64 is controlled by sequence files. They are in .m64 format, which is similar to MIDI. A sequence file has a sequence script, that can spawn channels, which have channel scripts, that can spawn layers (also known as tracks), which have layer scripts that can play notes. Each note is performed using an instrument from a sound bank. A sequence file can use multiple banks. The mapping from sequences to sound banks is described in sound/sequences.json. Channels can switch between banks using a command. However, in practice most sequences limit themselves to a single sound bank. The main exception is sequence 0, which is responsible for sound effects.

A sequence may play up to 16 channels with up to 4 layers per channel. Several notes can be played simultaneously on a single layer.

A sequence is played as long as the sequence script is not ended. A channel (including layers) is active as long as the channel script is not ended.

Note properties

A note can be played by the commands layer_note0, layer_note1 and layer_note2 (only valid if chan_largenoteson has been called on the layer's channel) or layer_smallnote0, layer_smallnote1 and layer_smallnote2 (only valid if chan_largenotesoff has been called on the layer's channel; default state). A note is defined by the following properties:

Pitch

Also known as note. The pitch defines the frequency in which the instrument is to be played. See list of notes below for available pitches.

Play percentage

Also known as timestamp. This defines the note value, such as half or quarter note. This also implies a layer delay of the same amount. See note values below for possible values.

Velocity

This is the volume of the note.

Duration

Also known as gate or gate time. A value of 0 menas the note is heard during the whole percentage, 128 is half of the percentage and 255 almost none.

List of notes

This is a list of notes as used by the layer_note# and layer_smallnote# commands.

Octave Note Decimal Hex (note0) Hex (note1) Hex (note2)
0 A 0 0x00 0x40 0x80
A♯/B♭ 1 0x01 0x41 0x81
B 2 0x02 0x42 0x82
1 C 3 0x03 0x43 0x83
C♯/D♭ 4 0x04 0x44 0x84
D 5 0x05 0x45 0x85
D♯/E♭ 6 0x06 0x46 0x86
E 7 0x07 0x47 0x87
F 8 0x08 0x48 0x88
F♯/G♭ 9 0x09 0x49 0x89
G 10 0x0A 0x4A 0x8A
G♯/A♭ 11 0x0B 0x4B 0x8B
A 12 0x0C 0x4C 0x8C
A♯/B♭ 13 0x0D 0x4D 0x8D
B 14 0x0E 0x4E 0x8E
2 C 15 0x0F 0x4F 0x8F
C♯/D♭ 16 0x10 0x50 0x90
D 17 0x11 0x51 0x91
D♯/E♭ 18 0x12 0x52 0x92
E 19 0x13 0x53 0x93
F 20 0x14 0x54 0x94
F♯/G♭ 21 0x15 0x55 0x95
G 22 0x16 0x56 0x96
G♯/A♭ 23 0x17 0x57 0x97
A 24 0x18 0x58 0x98
A♯/B♭ 25 0x19 0x59 0x99
B 26 0x1A 0x5A 0x9A
3 C 27 0x1B 0x5B 0x9B
C♯/D♭ 28 0x1C 0x5C 0x9C
D 29 0x1D 0x5D 0x9D
D♯/E♭ 30 0x1E 0x5E 0x9E
E 31 0x1F 0x5F 0x9F
F 32 0x20 0x60 0xA0
F♯/G♭ 33 0x21 0x61 0xA1
G 34 0x22 0x62 0xA2
G♯/A♭ 35 0x23 0x63 0xA3
A 36 0x24 0x64 0xA4
A♯/B♭ 37 0x25 0x65 0xA5
B 38 0x26 0x66 0xA6
4 C 39 0x27 0x67 0xA7
C♯/D♭ 40 0x28 0x68 0xA8
D 41 0x29 0x69 0xA9
D♯/E♭ 42 0x2A 0x6A 0xAA
E 43 0x2B 0x6B 0xAB
F 44 0x2C 0x6C 0xAC
F♯/G♭ 45 0x2D 0x6D 0xAD
G 46 0x2E 0x6E 0xAE
G♯/A♭ 47 0x2F 0x6F 0xAF
A 48 0x30 0x70 0xB0
A♯/B♭ 49 0x31 0x71 0xB1
B 50 0x32 0x72 0xB2
5 C 51 0x33 0x73 0xB3
C♯/D♭ 52 0x34 0x74 0xB4
D 53 0x35 0x75 0xB5
D♯/E♭ 54 0x36 0x76 0xB6
E 55 0x37 0x77 0xB7
F 56 0x38 0x78 0xB8
F♯/G♭ 57 0x39 0x79 0xB9
G 58 0x3A 0x7A 0xBA
G♯/A♭ 59 0x3B 0x7B 0xBB
A 60 0x3C 0x7C 0xBC
A♯/B♭ 61 0x3D 0x7D 0xBD
B 62 0x3E 0x7E 0xBE
6 C 63 0x3F 0x7F 0xBF

Note durations

The effective duration of a note and the delay commands is based on the currently set sequence tempo. The duration of a single tick in seconds can be calculated using the following formula: time = 1.25 / tempo.

Note Ticks Duration (120 BPM)
whole 192 2s
half dotted (2nd + 4th) 144 1.5s
half 96 1s
quarter dottet (4th + 8th) 72 0.75s
quarter (4th) 48 0.5s
eighth dottet (8th + 16th) 36 0.375s
quarter tuplet 32 0.333s
eighth (8th) 24 0.25s
sixteenth dottet (16th + 32th) 18 0.1875s
eigthth tuplet 16 0.1666s
sixteenth (16th) 12 0.125s
32th dottet (32th + 64th) 9 0.09375s
sixteenth tuplet (16th) 8 0.08333s
32th 6 0.0625s
32th tuplet 4 0.041666s
64th 3 0.03125s
64th tuplet 2 0.0208333s

Create sequences

There are several ways for creating new sequence files.

Seq64

Seq64 is a GUI program for editing sequence files for Super Mario 64 and other Nintendo games. It also features full MIDI importing and exporting.

https://github.com/sauraen/seq64

Manually

Sequence files can also be created manually in a textual format. Create a new assembly file in the sequences directory, for example sound/sequences/us/23_custom_sequence.s. This file should have the following anatomy:

 1 #include "seq_macros.inc"
 2 .section .rodata
 3 .align 0
 4 
 5 ################################################################################
 6 # This label is required at the beginning of the sequence.
 7 sequence_start:
 8 
 9 # Sequence commands like seq_settempo, seq_initchannels, seq_startchannel here
10 seq_startchannel 0, channel0
11 
12 # If your sequence loops, put this here
13 seq_jump sequence_start
14 
15 # End of sequence script
16 seq_end
17 
18 ################################################################################
19 # Any label you want, so you can refer to this section when starting a channel.
20 channel0:
21 
22 # Channel commands like chan_setvol, chan_setinstr, chan_setlayer here
23 chan_largenoteson
24 chan_setlayer 0, layer_melody
25 
26 # End of channel script
27 chan_end
28 
29 ################################################################################
30 layer_melody:
31 
32 # Layer commands here like layer_note0, layer_note1 etc.
33 
34 # End of layer script
35 layer_end

Next you can write down a series of commands. See include/seq_macros.inc or https://hackmd.io/opEB-OmxRa26P8h8pA-x7w for a list of available commands.

Example melody "Transposition"

The following example script plays a melody of 69 notes and repeats it over at varying transposition (hence the name).

  1 #include "seq_macros.inc"
  2 .section .rodata
  3 .align 0
  4 
  5 .eqv EIGHTH, 24
  6 .eqv SEQ_LEN, EIGHTH * (9 + 11 + 10 + 12 + 12 + 7 + 8)
  7 
  8 # This label is required at the beginning of the sequence.
  9 sequence_start:
 10 
 11 seq_setmutebhv 0x20
 12 seq_settempo 125
 13 seq_setvol 127
 14 
 15 seq_initchannels 0x01
 16 seq_startchannel 0, channel0
 17 
 18 # Note: the maximum delay is 32767 (0x7fff) ticks, so we just do multiple delays.
 19 seq_delay SEQ_LEN * 5
 20 seq_delay SEQ_LEN * 5
 21 seq_delay SEQ_LEN * 5
 22 seq_delay SEQ_LEN * 5
 23 seq_delay SEQ_LEN * 5
 24 seq_jump sequence_start
 25 
 26 seq_end
 27 
 28 channel0:
 29 chan_largenoteson
 30 chan_setvol 127
 31 chan_setinstr 4
 32 chan_setreverb 127
 33 
 34 chan_setlayer 0, layer_melody
 35 chan_delay SEQ_LEN
 36 
 37 chan_transpose -11
 38 chan_setlayer 0, layer_melody
 39 chan_delay SEQ_LEN
 40 
 41 chan_transpose -8
 42 chan_setlayer 0, layer_melody
 43 chan_delay SEQ_LEN
 44 
 45 chan_transpose -2
 46 chan_setlayer 0, layer_melody
 47 chan_delay SEQ_LEN
 48 
 49 chan_transpose -6
 50 chan_setlayer 0, layer_melody
 51 chan_delay SEQ_LEN
 52 
 53 chan_transpose 9
 54 chan_setlayer 0, layer_melody
 55 chan_delay SEQ_LEN
 56 
 57 chan_transpose 1
 58 chan_setlayer 0, layer_melody
 59 chan_delay SEQ_LEN
 60 
 61 chan_transpose -7
 62 chan_setlayer 0, layer_melody
 63 chan_delay SEQ_LEN
 64 
 65 chan_transpose 10
 66 chan_setlayer 0, layer_melody
 67 chan_delay SEQ_LEN
 68 
 69 chan_transpose 12
 70 chan_setlayer 0, layer_melody
 71 chan_delay SEQ_LEN
 72 
 73 chan_transpose 2
 74 chan_setlayer 0, layer_melody
 75 chan_delay SEQ_LEN
 76 
 77 chan_transpose 4
 78 chan_setlayer 0, layer_melody
 79 chan_delay SEQ_LEN
 80 
 81 chan_transpose 5
 82 chan_setlayer 0, layer_melody
 83 chan_delay SEQ_LEN
 84 
 85 chan_transpose 3
 86 chan_setlayer 0, layer_melody
 87 chan_delay SEQ_LEN
 88 
 89 chan_transpose -5
 90 chan_setlayer 0, layer_melody
 91 chan_delay SEQ_LEN
 92 
 93 chan_transpose -12
 94 chan_setlayer 0, layer_melody
 95 chan_delay SEQ_LEN
 96 
 97 chan_transpose -9
 98 chan_setlayer 0, layer_melody
 99 chan_delay SEQ_LEN
100 
101 chan_transpose 7
102 chan_setlayer 0, layer_melody
103 chan_delay SEQ_LEN
104 
105 chan_transpose 6
106 chan_setlayer 0, layer_melody
107 chan_delay SEQ_LEN
108 
109 chan_transpose -10
110 chan_setlayer 0, layer_melody
111 chan_delay SEQ_LEN
112 
113 chan_transpose 11
114 chan_setlayer 0, layer_melody
115 chan_delay SEQ_LEN
116 
117 chan_transpose -4
118 chan_setlayer 0, layer_melody
119 chan_delay SEQ_LEN
120 
121 chan_transpose -1
122 chan_setlayer 0, layer_melody
123 chan_delay SEQ_LEN
124 
125 chan_transpose 8
126 chan_setlayer 0, layer_melody
127 chan_delay SEQ_LEN
128 
129 chan_transpose -3
130 chan_setlayer 0, layer_melody
131 chan_delay SEQ_LEN
132 
133 chan_end
134 
135 layer_melody:
136 layer_note1 40, EIGHTH, 100 # c#4
137 layer_note1 42, EIGHTH, 100 # d#4
138 layer_note1 43, EIGHTH, 100 # e-4
139 layer_note1 35, EIGHTH, 100 # ab3
140 layer_note1 42, EIGHTH, 100 # d#4
141 layer_note1 33, EIGHTH, 100 # gb3
142 layer_note1 31, EIGHTH, 100 # e-3
143 layer_note1 30, EIGHTH, 100 # d#3
144 layer_note1 28, EIGHTH, 100 # c#3
145 
146 layer_note1 35, EIGHTH, 100 # ab3
147 layer_note1 40, EIGHTH, 100 # c#4
148 layer_note1 43, EIGHTH, 100 # e-4
149 layer_note1 42, EIGHTH, 100 # d#4
150 layer_note1 43, EIGHTH, 100 # e-4
151 layer_note1 45, EIGHTH, 100 # gb4
152 layer_note1 35, EIGHTH, 100 # ab3
153 layer_note1 38, EIGHTH, 100 # b-3
154 layer_note1 43, EIGHTH, 100 # e-4
155 layer_note1 42, EIGHTH, 100 # d#4
156 layer_note1 40, EIGHTH, 100 # c#4
157 
158 layer_note1 35, EIGHTH, 100 # ab3
159 layer_note1 40, EIGHTH, 100 # c#4
160 layer_note1 44, EIGHTH, 100 # f-4
161 layer_note1 40, EIGHTH, 100 # c#4
162 layer_note1 45, EIGHTH, 100 # gb4
163 layer_note1 40, EIGHTH, 100 # c#4
164 layer_note1 47, EIGHTH, 100 # ab4
165 layer_note1 40, EIGHTH, 100 # c#4
166 layer_note1 48, EIGHTH, 100 # a-4
167 layer_note1 40, EIGHTH, 100 # c#4
168 
169 layer_note1 42, EIGHTH, 100 # d#4
170 layer_note1 38, EIGHTH, 100 # b-3
171 layer_note1 33, EIGHTH, 100 # gb3
172 layer_note1 38, EIGHTH, 100 # b-3
173 layer_note1 42, EIGHTH, 100 # d#4
174 layer_note1 38, EIGHTH, 100 # b-3
175 layer_note1 43, EIGHTH, 100 # e-4
176 layer_note1 38, EIGHTH, 100 # b-3
177 layer_note1 45, EIGHTH, 100 # gb4
178 layer_note1 38, EIGHTH, 100 # b-3
179 layer_note1 47, EIGHTH, 100 # ab4
180 layer_note1 38, EIGHTH, 100 # b-3
181 
182 layer_note1 40, EIGHTH, 100 # c#4
183 layer_note1 36, EIGHTH, 100 # a-3
184 layer_note1 35, EIGHTH, 100 # ab3
185 layer_note1 36, EIGHTH, 100 # a-3
186 layer_note1 40, EIGHTH, 100 # c#4
187 layer_note1 43, EIGHTH, 100 # e-4
188 layer_note1 38, EIGHTH, 100 # b-3
189 layer_note1 35, EIGHTH, 100 # ab3
190 layer_note1 33, EIGHTH, 100 # gb3
191 layer_note1 35, EIGHTH, 100 # ab3
192 layer_note1 38, EIGHTH, 100 # b-3
193 layer_note1 43, EIGHTH, 100 # e-4
194 
195 layer_note1 33, EIGHTH, 100 # gb3
196 layer_note1 35, EIGHTH, 100 # ab3
197 layer_note1 36, EIGHTH, 100 # a-3
198 layer_note1 31, EIGHTH, 100 # e-3
199 layer_note1 30, EIGHTH, 100 # d#3
200 layer_note1 31, EIGHTH, 100 # e-3
201 layer_note1 33, EIGHTH, 100 # gb3
202 
203 layer_note1 30, EIGHTH, 100 # d#3
204 layer_note1 26, EIGHTH, 100 # b-2
205 layer_note1 24, EIGHTH, 100 # a-2
206 layer_note1 23, EIGHTH, 100 # ab2
207 layer_note1 31, EIGHTH, 100 # e-3
208 layer_note1 24, EIGHTH, 100 # a-2
209 layer_note1 31, EIGHTH, 100 # e-3
210 layer_note1 23, EIGHTH, 100 # ab2
211 
212 layer_end

Commands

Sequence commands

Mnemonic Param 1 Param 2 Bytecode (US) Description
seq_end 0xff End of script, loop or function
seq_delay1 0xfe Delay for 1 tick
seq_delay ticks 0xfd, var Delay for X ticks
seq_call address 0xfc, addr Call a function
seq_jump address 0xfb, addr Jump to a point in the sequence script
seq_beqz address 0xfa, addr Jump if Q == 0, where Q is an s8 used to hold temporary sequence script state
seq_bltz address 0xf9, addr Jump if Q < 0
seq_loop iterations 0xf8, u8 Repeat until loopend for X iterations (256 if X = 0)
seq_loopend 0xf7 Loop end marker
seq_bgez address 0xf5, addr Jump if Q >= 0
seq_reservenotes numNotes 0xf2, u8 Reserve X notes for exclusive use by this sequence (dropping earlier reservations). A limited number of notes can be played at once (configurable per level, usually 16); if more than that are played, an existing one will be stopped and reused. This command can prevent that from happening across sequences.
seq_unreservenotes 0xf1 Drop all earlier reservations made by this sequence.
seq_transpose semitones 0xdf, s8 Set transposition in semitones.
seq_transposerel semitones 0xde, s8 Change transposition by some delta.
seq_settempo tempo 0xdd, u8 Set tempo in BPM.
seq_addtempo tempo 0xdc, s8 Change tempo by some delta.
seq_setvol volume 0xdb, u8 Set volume scale (0…255 = none to twice normal).
seq_changevol volume 0xda, s8 Change volume scale by some delta.
seq_initchannels channelMask 0xd7, u16 Initialize channels (bitmask). This copies mute behavior and note allocation policy.
seq_disablechannels channelMask 0xd6, u16 Uninitialize channels (bitmask).
seq_setmutescale mulitplier 0xd5, s8 Set volume multiplier for muted mode (0…127).
seq_mute 0xd4 Set sequence to muted mode. Depending on what behavior has been set this will do different things; from lowering volume to not running scripts.
seq_setmutebhv bitmask 0xd3, u8 Set mute behavior (bitmask). Bit 0x20 lowers volume, bit 0x40 does something to layers, and bit 0x80 pauses the sequence script. Default mute behavior is to have all of those bits set.
seq_setshortnotevelocitytable address 0xd2, addr Set velocity table for short notes (see further down). Target should be an array of bytes in the sequence data of length 16.
seq_setshortnotedurationtable address 0xd1, addr Set duration table for short notes (see further down). Target should be an array of bytes in the sequence data of length 16.
seq_setnoteallocationpolicy policyMask 0xd0, u8 Set note allocation policy (bitmask). If bit 0x1 is set, it will try to steal notes back from what was previously played on the same layer. If bit 0x2 is set, notes will be allocated exclusively from the channel’s reserved notes, else if 0x4 is set, from the channel’s or sequence’s reserved notes, else if 0x8 is set, from unreserved notes, otherwise from all sources. Not used by the game.
seq_setval value 0xcc, u8 Set Q to a constant.
seq_bitand value 0xc9, u8 Bitand Q by a constant.
seq_subtract value 0xc8, u8 Subtract a constant from Q.
seq_startchannel channel address 0x90-0x9f, addr Start channel N, with a given channel script.
seq_getvariation 0x80-0x8f Set Q to the variation bit, which is initially either 0 or 0x80 (i.e. -128, since Q is s8). This bit comes from the sequence load command. For instance, to play the Koopa shell music, the game plays sequence 0x8E, which is the same as sequence 0xE but with the variation bit set.
seq_setvariation 0x70-0x7f Set the variation bit to Q.
seq_subvariation 0x50-0x5f Subtract the variation bit from Q.
seq_testchdisabled channel 0x00-0x0f Set Q to 1 or 0, depending on whether channel N has been disabled by channel script.

Channel commands

Mnemonic Param 1 Param 2 Param 3 Bytecode (US) Description
chan_end 0xff End of script, loop or function
chan_delay1 0xfe Delay for 1 tick
chan_delay ticks 0xfd, var Delay for X ticks
chan_call address 0xfc, addr Call a function
chan_jump address 0xfb, addr Jump to a point in the channel script
chan_beqz address 0xfa, addr Jump if Q == 0, where Q is an s8 used to hold temporary channel script state
chan_bltz address 0xf9, addr Jump if Q < 0
chan_loop iterations 0xf8, u8 Repeat until loopend for X iterations (256 if X = 0)
chan_loopend 0xf7 Loop end marker
chan_break 0xf6 Decrease loop/function stack depth by 1. Combine with a jump to break out of a loop.
chan_bgez address 0xf5, addr Jump if Q >= 0
chan_hang 0xf3 Infinite delay.
chan_reservenotes numNotes 0xf2, u8 Reserve X notes for exclusive use by this channel (dropping earlier reservations).
chan_unreservenotes numNotes 0xf1 Drop all earlier reservations made by this channel.
chan_dyncall 0xe4 If Q != -1, make a function call to position dyntable[Q], where dyntable is a channel-specific u16 array which can set by setdyntable/dynsetdyntable.
chan_setvibratodelay 0xe3, u8 Set delay until vibrato starts for each note.
chan_setvibratoextentlinear 0xe2, u8, u8, u8 Set vibrato extent for each note as a function that starts at X, goes up linearly to Y over a time span given by Z, then stays there.
chan_setvibratoratelinear 0xe1, u8, u8, u8 Like above except for vibrato rate.
chan_setvolscale volume 0xe0, u8 Set scale factor for volume (0…255 = none to twice normal).
chan_setvol volume 0xdf, u8 Set scale factor #2 for volume (0…255 = none to twice normal). The two scale factors are separately controlled by outer audio logic, e.g. when changing between rooms, when playing sound effects, etc. The game almost exclusively uses setvol, so that should probably be preferred, but setvolscale shows up in a few locations in the sound effect sequence.
chan_freqscale value 0xde, u16 Pitch bend using a raw frequency multiplier X/2^15.
chan_setpan pan 0xdd, u8 Set the pan for this channel (0…128)
chan_setpanchanweight 0xdc, u8 The pan for each note will be computed as W * channel pan + (1 - W) * note pan. This sets W (0…128 maps to 0…1). W defaults to 1.0.
chan_transpose semitones 0xdb, s8 Set transposition in semitones.
chan_setenvelope address 0xda, addr Set ADSR envelope. See below for format.
chan_setdecayrelease rate 0xd9, u8 Set ADSR decay/release rate.
chan_setvibratoextent extent 0xd8, u8 Set vibrato extent.
chan_setvibratorate rate 0xd7, u8 Set vibrato rate.
chan_setupdatesperframe 0xd6, u8 Seems like it was meant to set the number of updates per frame? But it doesn’t actually do anything.
chan_setreverb reverb 0xd4, u8 Set amount of reverb (or “dry/wet mix”?).
chan_pitchbend bend 0xd3, s8 Pitch bend by <= 1 octave in either direction (-127…127).
chan_setsustain volume 0xd2, u8 Set ADSR sustain volume.
chan_setnoteallocationpolicy policyMask 0xd1, u8 Set note allocation policy for channel. See the description for sequence scripts.
chan_stereoheadseteffects enable 0xd0, u8 Enable (1) or disable (0) some pan/volume effects related to stereo/headset. I don’t know which ones precisely – pan is still taken into account even with this disabled. With this disabled, stereo/headset gets the same output.
chan_setval value 0xcc, u8 Set Q to a constant.
chan_readseq address 0xcb, addr Set Q to sequenceData[X + Q].
chan_setmutebhv 0xca, u8 Set mute behavior for this channel.
chan_bitand value 0xc9, u8 Bitand Q by a constant.
chan_subtract value 0xc8, u8 Subtract a constant from Q.
chan_writeseq address 0xc7, u8, addr Overwrite the byte at the given position in the sequence script by (Q + X).
chan_setbank bank 0xc6, u8 Switch bank within instrument bank sets, to the X’th bank, 0-indexed, counting from the end.
chan_dynsetdyntable 0xc5 If Q != -1, set dyntable to point to position dyntable[Q] in the sequence data.
chan_largenoteson 0xc4 Set notes for this channel to use “large notes” format. SM64 does this for all channels. (See note vs. shortnote in the layer section below.)
chan_largenotesoff 0xc3 Set notes for this channel to use “short notes” format.
chan_setdyntable address 0xc2, addr Set dyntable to point to a given u16 array from the sequence data.
chan_setinstr instrument 0xc1, u8 Set instrument (program?) within bank. 0x80-0x83 set raw waves (sawtooth, triangle, sine, square), 0x7f is special, otherwise 0-indexed.
chan_dynsetlayer 0xb0-0xbf If Q != -1, start layer N, with layer script given by dyntable[Q].
chan_freelayer layer 0xa0-0xaf Stop layer N.
chan_setlayer layer address 0x90-0x9f, addr Start layer N, with layer script starting at address X.
chan_ioreadval 0x80-0x8f Set Q to IO[N], where IO is an array of bytes that can be read/written by both the game and the channel script. If N < 4, IO[N] is then set to -1.
chan_iowriteval 0x70-0x7f Set IO[N] to Q.
chan_setnotepriority 0x60-0x6f Set note priority for later notes played on this channel to N. When the game wants to play a note and there aren’t any free notes available, a note with smaller or equal priority is discarded. Should be >= 2; 0 and 1 have internal meaning. Defaults to 3.
chan_ioreadvalsub 0x50-0x5f Decrease Q by IO[N].
chan_ioreadval2 0x40-0x4f, u8 Set Q to IO2[X], where IO2 is the IO array for channel N.
chan_iowriteval2 0x30-0x3f, u8 Set IO2[X] to Q, where IO2 is the IO array for channel N.
chan_disablechannel channel 0x20-0x2f Disable channel N for the parent sequence.
chan_startchannel channel address 0x10-0x1f, addr Start channel N for the parent sequence, with channel script starting at address X.
chan_testlayerfinished layer 0x00-0x0f Set Q to 1 or 0, depending on whether layer N has been disabled (either forcibly or by finishing its script).

Layer commands

Mnemonic Param 1 Param 2 Param 3 Param 4 Bytecode (US) Description
layer_end 0xff End of script, loop or function
layer_call address 0xfc, addr Call a function
layer_jump address 0xfb, addr Jump to a point in the layer script
layer_loop iterations 0xf8, u8 Repeat until loopend for X iterations (256 if X = 0)
layer_loopend 0xf7 Loop end marker
layer_setshortnotedurationfromtable 0xe0-0xef Set the duration for future short notes to table[N], where table defaults to {229, 203, 177, 151, 139, 126, 113, 100, 87, 74, 61, 48, 36, 23, 10, 0} and can be set by setshortnotedurationtable.
layer_setshortnotevelocityfromtable 0xd0-0xdf Set the velocity for future short notes to table[N], where table defaults to {12, 25, 38, 51, 57, 64, 71, 76, 83, 89, 96, 102, 109, 115, 121, 127} and can be set by setshortnotevelocitytable.
layer_setpan pan 0xca, u8 Set the pan for this layer (0…128).
layer_setshortnoteduration duration 0xc9, u8 Set the duration for future short notes.
layer_disableportamento 0xc8 Disable portamento for later notes.
layer_portamento 0xc7, u8, u8, u8/var Enable portamento (aka glissando; continuously sliding pitch). X describes the mode of operation somehow using its 0x80 bit and a value 0-5 in its lower-order bits. Y describes the target pitch. Z gives the duration, and is a u8 if the 0x80 bit is set, otherwise a var.
layer_setinstr instrument 0xc6, u8 Set instrument/program. Similar to the channel command, except arguments 0x7f and above are not supported.
layer_somethingoff 0xc5 Turn off some bool related to how notes decay somehow? (This is the default.)
layer_somethingon 0xc4 Turn on the same thing.
layer_setshortnotedefaultplaypercentage percentage 0xc3, var Set the default play percentage for short notes (see below).
layer_transpose semitones 0xc2, u8 Set transposition in semitones.
layer_setshortnotevelocity velocity 0xc1, u8 Set velocity for future short notes.
layer_delay ticks 0xc0, var Delay for N ticks
layer_note0 pitch percentage velocity duration 0x00-0x3f, var, u8, u8 Play note with specified pitch, percentage, velocity and duration. Only valid if channel is set to “large notes”.
layer_note1 pitch percentage velocity 0x40-0x7f, var, u8 Play note with specified pitch, percentage and velocity and duration of 0. Only valid if channel is set to “large notes”.
layer_note2 pitch velocity duration 0x80-0xbf, u8, u8 Play note with specified pitch, velocity and duration. Only valid if channel is set to “large notes”.
layer_smallnote0 pitch percentage 0x00-0x3f, var Play note with specified pitch and percentage and velocity and duration set with layer_setshortnotevelocity and layer_setshortnoteduration. Only valid if channel is set to “small notes”.
layer_smallnote1 pitch 0x40-0x7f Play note with specified pitch and the default play percentage, as set by layer_setshortnotedefaultplaypercentage (there is no built-in default; using it without that command will read uninitialized memory). Velocity and duration is set like in layer_smallnote0. Only valid if channel is set to “small notes”.
layer_smallnote2 pitch 0x80-0xbf Play note with specified pitch and the previous play percentage. Velocity and duration is set like in layer_smallnote0. Only valid if channel is set to “small notes”.

See also