h6. [[Programmer's Reference Manuals]] h6(. » [[File Formats]] h6((. » MusicFile The MusicFile filetype is primarily used by the [[Software information: Maestro|Maestro]] application. MusicFiles allow music to be played by the 8-bit sound system, and are limited to 8 channels. h3. Header block |*Size*|*Description*| |8|'Maestro', followed by linefeed character (@&0A@)| |1|2 (Type 2 MusicFile)| The Header block is followed by zero or more of the following blocks. The original spec claimed they could appear in any order, but in fact Maestro will expect blocks 1-6 before any others. Note that block types 7, 8 and 9 are not currently implemented by Maestro. h3. 1. Music data |*Size*|*Description*| |1|1| |5|Number of bytes in the Gates array[1]| |5x8|Number of bytes in the queue of notes and rests for each of the 8 channels[1]| |_n_|Gate data (see below)| |_q1...q8_|Data for all notes and rests in channels 1-8| fn1. Stored as a BASIC integer: @&40@ followed by 4 bytes of data, most significant first. h3. 2. Stave data |*Size*|*Description*| |1|2| |1|Number of staves (0-3)| |1|Number of percussion staves (0-1)| The staves value is incremented by one to create a range of 1-4 staves, whereas the percussion value controls whether a single percussion stave is added. Earlier versions of Maestro permitted more than one percussion stave. In Maestro, the distribution of channels to staves is as follows: table(bordered). |_<^{width:9}. Music staves|_<^{width:9}. Percussion staves|_<^{width:9}. Stave 1|_<^{width:9}. Stave 2|_<^{width:9}. Stave 3|_<^{width:9}. Stave 4|_<^{width:9}. Percussion| |1|0|1-8||||| |1|1|1-7||||8| |2|0|1-4|5-8|||| |2|1|1-4|5-7|||8| |3|0|1|2-5|6-8||| |3|1|1|2-5|6-7||8| |4|0|1-2|3-4|5-6|7-8|| |4|1|1-2|3-4|5-6|7|8| h3. 3. Instrument data Instrument names are not recorded, only channel numbers. |*Size*|*Description*| |1|3| This is followed by 8 blocks: |*Size*|*Description*| |1|Channel number (1-8, consecutive)| |1|Voice number (0=none attached)| h3. 4. Volume data |*Size*|*Description*| |1|4| |1x8|Volume of channel (0-7)| h3. 5. Stereo position data |*Size*|*Description*| |1|5| |1x8|Stereo position of channel (0-6, left to right)| h3. 6. Tempo data |*Size*|*Description*| |1|6| |1x8|Tempo value (0-14)| Tempo values correspond to the following beats per minute: 40, 50, 60, 65, 70, 80, 90, 100, 115, 130, 145, 160, 175, 190 and 210. To convert to values suitable for use with [[Sound_QTempo]], use the formula: Sound_QTempo value = beats per minute * 128 * 4096 / 6000 h3. 7. Title string |*Size*|*Description*| |1|7| |_n_|Null-terminated string of _n_ characters length| h3. 8. Instrument names |*Size*|*Description*| |1|8| |_n1...n8_|8 null-terminated strings for each Voice number used in ascending order, corresponding to data in block type 3, above| h3. 9. MIDI channels |*Size*|*Description*| |1|9| |1x8|MIDI channel for Instrument (1-16, or 0 for not MIDI)| h3. Gates A Gate is a point in the music where something is interpreted: a note, time signature, key signature, bar line or clef, for example. A note or a rest takes up 1 byte, whereas all other attributes, such as key signatures, etc, take up 2 bytes, where the first byte is 0 and the second contains data on the attribute. h4. Note/Rest |*Bits*|*Description*| |0-7|Gate mask: bit _n_ set => gate 1 note/rest from queue _n_.| h4. Time signature |*Byte 2 bits*|*Description*| |0|@%1@| |1-4|Beats per bar (0-15)| |5-7|Beat type (0-7, breve to hemidemisemiquaver)| h4. Key signature |*Byte 2 bits*|*Description*| |0-1|@%10@| |2|Accidental type (0=sharp, 1=flat)| |3-5|Number of accidentals (0-7)| |6-7| Reserved (must be 0)| h4. Clef |*Byte 2 bits*|*Description*| |0-2|@%100@| |3-4|0=treble, 1=alto, 2=tenor, 3=bass| |5| Reserved (must be 0)| |6-7| Stave (0-3)| Maestro currently only implements treble and bass clefs. h4. Slur |*Byte 2 bits*|*Description*| |0-3|@%1000@| |4|1=on, 0=off| |5|Reserved (must be 0)| |6-7| Stave (0-3)| h4. Octave shift |*Byte 2 bits*|*Description*| |0-4|@%10000@| |5|0=up, 1=down| |6-7| Stave (0-3)| h4. Barline |*Byte 2 bits*|*Description*| |0-5|@%100000@| |6|0=single barline, 1=double barline| |7| Reserved (must be 0)| Double barlines implemented in Maestro 2.11. Earlier versions will ignore double barlines in MusicFiles, and display single barlines instead. h4. Reserved Bits 6 and 7 of the attribute byte are reserved for future expansion. Maestro currently does not implement types 4 and 5 (slurs and octave shifts). h3. Notes/Rests Notes/rests are stored in 2-byte blocks. h4. Notes |*Bits*|*Description*| |0|Stem orientation (0=up, 1=down)| |1|Tie orientation (0=over note, 1=under note)[2]| |2|Tie (0=no tie, 1=tie to next note)| |3-7|Stave line position (1-31; 16=centre)| |8-10|Accidental (0-7)[3]| |11-12|Number of dots (0-3)| |13-15|Type (0-7, breve to hemidemisemiquaver)| fn2. Tie orientation was implemented in version 2.14 of Maestro. In earlier versions of the file specification, this bit was described as being used to mark the note as having a beam connected to the next note. However, this was never implemented in Maestro, and so has been repurposed. fn3. Accidental values: 0=None 1=Natural 2=Sharp 3=Flat 4=Double-sharp 5=Double-flat 6=Natural sharp 7=Natural flat h4. Rests |*Bits*|*Description*| |0-7|Reserved (must be 0)| |8-10|Stave line position (0-7)[4]| |11-12|Number of dots (0-3)| |13-15|Type (0-7, breve to hemidemisemiquaver)| fn4. Stave line positions for rests were introduced in Maestro 2.13. Previously, these bits were all unset. In order to maintain compatibility with older versions, a value of 0 for the stave line position is interpreted as the centre stave line. Values 1, 2 and 3 are below the centre line in ascending height order (ie, 1 is furthest from the centre line), and 5, 6 and 7 are above, also in ascending order. The 'resolution' is doubled, so that a rest line position of 5 is equivalent to a note line position of 18, 6 is equivalent to 20, 7 to 22, etc. If a rest coincides with a note, its position is determined by the following note on the same channel.