Open AU Lab
Open MIDIDisplay
Test Sound
0 90 60 127 1000 80 60 0
When sound is working download 05SMFClassDemo.zip.
Double click to create 05SMFClassDemo.xls.
Copy 05SMFClassDemo.xls. to the desktop.
Copy the all data from the MIDIDisplay tab and paste it into the scratch tab. Then paste it into MIDIDisplay. This is the same example used in "04 Standard MIDI Files".
Next we'll turn this song into a Standard MIDI File (SMF).
These notes outline the steps you'll use to create your midterm SMF.
I've created an Excel template that represents the structure of a Standard MIDI File. After you've filled in the template data you can copy paste into MIDIDisplay and convert that data into a Standard MIDI File that can be played on any computer.
The flute is on channel 0 and the bassoon is on channel 1.
Sort by Status Ascending to separate the channels.
Copy the sorted messages into both the flute and bassoon tabs.
Keep all 80 and 90 status rows and delete the others.
Sort by time (smallest to largest) and status (smallest to largest) into MIDIDisplay chronological time order.
Keep all 81 and 91 status rows and delete the others.
Sort by time (smallest to largest) and status (smallest to largest) into MIDIDisplay chronological time order.
Make sure each instrument plays correctly.
Insert a blank column B to the right of the Ms time column A.
Important: Always keep the millisecond data in column A and your converted PPQ times in column B. A worksheet with only PPQ times is difficult to sort back into ms times. Use a PPQ of 480.
Enter this formula in B2 to calculate the first PPQ time:
=A2 * 480 / 1000
Enter this formula in B3 to calculate the second PPQ time:
=(A3 - A2) * 480 / 1000
All remaining PPQ times can be found by copying and pasting the above formula.
Copy the PPQ-Status-Data1-Data2 data into MIDIDisplay. Configure MIDIDisplay to play at 480 PPQ's. Make sure each instrument plays correctly.
Switch to the SMFTemplate tab.
Copy all cells from the SMFTemplate and paste them into the SMF tab.
Save.
Important: Keep the SMFTemplate in its own tab with no changes. Work in the SMF tab on the copied template.
The first chunk in every SMF is called the header track. They are rows 10-11 in the SMFTemplate. Row 10 begins with a semicolon and is a comment. It provides a consise description of the MThd format. Line 10 indicates that the SMF header has five componenets:
The values of these five items will be entered in row 11. The ID, Length, and SMF Type are prefilled with the correct values.
You'll need to fill in the two remaining yellow cells in row 11.
The ( h ) and ( d ) directly above the yellow cells in row 10 indicate whether the number format is Hex or Decimal.
There can be a maximum of 17 MTrk tracks that follow the track header. All 17 tracks begin with MTrk followed by the length. Use a length of 0 in the SMF template and MIDIDisplay will calculate the correct number of bytes for you.
Track 1 is sometimes called the Tempo Track and it contains special meta events that provide additional information about the song. It does not contain NON or NOF data for instruments. At a minimum, track 1 should contain meta events for the time signature, the key signature and the tempo.
The remaining 16 tracks contain the MIDI message data similar to that used in MIDIDisplay. The convention is to use one MIDI channel per track.
indicate the length of the data to follow. Track 1 is a special track often called the Tempo Track or Conductor Track and uses meta events to provide general song information.
Track 1 begins with the four byte' MTrk' header followed by a four byte length that indicates the number of bytes to follow.
PPQ | Symbol | Bytes | Data Hex | Notes |
not used | MTrk | 4D 54 72 6B | A marker that indicates the start of a track | |
not used | Length of data | <length> | The number of bytes that follow. |
The MIDI Manufacturer's Association defined a series of events called meta events to represent information like time signature, key signature, tempo, copyright, instrument track names, text, etc.
All meta events follow this format: FF cc nn dd
You'll be always use these four Meta Events in Track 1.
Important: A Delta Time (PPQ value) precedes every meta event and MIDI message. Delta times are in column A.
Lines 18-19 are paired together. Line 18 begins with a semicolon and is a comment. It provides a consise description of the key signature meta event format. You must fill in every yellow cell in line 19.
The format for the Key Signature meta event is:
The two data bytes are documented as sf and mi.
sf represents the number of sharps and flats in the key signature as shown in the following table. Sharps are numbered from 1 - 7, while flats are numbered negative 1 - 7. A standard convention in computer counting is that negative numbers count backwards from FF.
Number Sharps Flats | Hex Code |
7 sharps | 7 |
6 sharps | 6 |
5 sharps | 5 |
4 sharps | 4 |
3 sharps | 3 |
2 sharps | 2 |
1 sharp | 1 |
0 sharps or flats | 0 |
1 flat | FF |
2 flats | FE |
3 flats | FD |
4 flats | FC |
5 flats | FB |
6 flats | FA |
7 flats | F9 |
mi indicates whether the song is in a major or minor key. Use one for a minor key and zero for a major key.
This key signature has 2 sharps and is in the key of D major.
PPQ |
FF Type Length |
Data |
Interpretation |
0 or 1 | FF 59 02 |
sf mi |
sf = number of sharps or flats in the key signature mi = 1 is minor key, 0 is major key |
Lines 21-22 are paired together. Line 21 begins with a semicolon and is a comment. It provides a consise description of the time signature meta event format. You must fill in every yellow cell in line 22.
The format for the Time Signature meta event is:
nn the upper number of the time signature.
dd the lower number of the key signature expressed as a power of two.
cc the number of MIDI clocks ($F8) per quarter note. MIDI clocks were an early attempt to synchronize multiple MIDI synthesizers. It is not that accurate. Better synchronization methods are used today. However, the SMF still requires an entry. The cc value in simple time is $18 (24 decimal). In compound time it is $24 (36 decimal).
bb the number of notated thirty second notes in a quarter note (8 is the standard value).
This example is in four four time.
PPQ |
FF Type Length |
Data |
Interpretation |
0 or 1 | FF 58 04 |
nn dd cc bb |
nn = numerator of time signature dd = denominator of time signature expressed cc = MIDI clocks per metronome click, bb =number of notated thirty second notes per quarter note |
Lines 24-25 are paired together. Line 24 begins with a semicolon and is a comment. It provides a consise description of the tempo meta event format. You must fill in every yellow cell in line 25.
The Tempo meta event is:
The microsecond duration of one quarter note at a tempo of 100 bpm is 60,000,000/100 = 600,00 μs. Convert 600,000 to hex.
Try this Excel formula in an empty cell: =DEC2HEX(1000000*60/100). If the DEC2HEX function is installed you'll get 927C0.
PPQ |
FF Type Length |
Data |
Interpretation |
0 or 1 | FF 51 03 |
tt tt tt |
tt tt tt = time in microseconds per quarter note microseconds formula tempo formula Our converted tempo is 1000000*60/100 = 600000 Use tt tt tt = 9 27 C0 |
NOTE: If there are tempo changes in your song, they go in track 1 at the appropriate PPQ offset from the previous tempo change.
Here's the track 1 data filled.
Every MTrk track ends with an End of Track meta event:FF 2F 0. Use a PPQ of 1.
Up to 16 additional tracks can follow Track 1. These tracks contain the same MIDI messages you've been using in MIDIDisplay. Our example uses two instruments. Track 2 will be the flute and track 3 will be the bassoon.
All instrument tracks should begin with the following MIDI messages :
Important: Make sure every status message for the flute part is on MIDI channel zero.
Paste this after the last MIDI message. You can copy it from the SMFTemplate page.
Here's the completed Track 3 section. The MIDI channel for every status byte has been changed to channel 1.
Every track ends with the End of Track meta event.
The Reference page for Unit 5 provides additional documentation on SMF documentation and MIDI programming libraries.
Copy and Paste Into all data in columns A:H into MIDIDisplay.
Choose Export Standard MIDI File from the Options menu.
If there's an error, a message will point you to the Excel row number.
On a Mac, select the SMF icon and press the space bar.
The Reference page for Unit 5 provides additional documentation on SMF documentation and MIDI programming libraries.
Revised John Ellinger, January - September 2013