MUSC 108. Introduction to Music Technology - Fall 2013

05 Lecture Notes

[Overview] [Syllabus]

Take Home Quiz 1 will be available Thursday Oct. 3 and due Tuesday Oct. 8.

Setup

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.

Open 05SMFClassDemo in Excel

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".

Play in MIDIDisplay

Next we'll turn this song into a Standard MIDI File (SMF).

Excel Standard MIDI File Template Demo

These notes outline the steps you'll use to create your midterm SMF.

class example song

SMF Structure

SMF structure

SMFTemplate Demo

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.

Separate The MIDIDisplay Data Into Separate Instruments

The flute is on channel 0 and the bassoon is on channel 1.

Sort by Status Ascending to separate the channels.

Sort by status

Flute and Bassoon

Copy the sorted messages into both the flute and bassoon tabs.

Flute tab

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.

flute sorted

Bassoon tab

Keep all 81 and 91 status rows and delete the others.

basson

Sort by time (smallest to largest) and status (smallest to largest) into MIDIDisplay chronological time order.

bassoon sorted

Play The Flute and Bassoon Parts in MIDIDisplay

Make sure each instrument plays correctly.

Convert The Flute Millisecond Times To PPQ

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.

Play The Flute In MIDIDisplay Using PPQ Time

Copy the PPQ-Status-Data1-Data2 data into MIDIDisplay. Configure MIDIDisplay to play at 480 PPQ's. Make sure each instrument plays correctly.

PPQ times for flute in MIDIDisplay

Do the Same for the Bassoon

bassoon in PPQ in MIDIDisplay

Convert The MIDIDisplay Data To A Standard MIDI File

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.

Excel SMF Template Rules

  1. ALL cells in yellow Yellow bullet must be filled in by you.
  2. Cells in green green bullet are already pre-filled. Leave them alone.
  3. There can be no empty rows. Every row must contain data in column A, or begin with a semi-colon.
  4. Comment lines begin with a semi-colon.
  5. No commas allowed in any cell.
  6. An ( h ) above a cell indicates data that must be entered as hex.
  7. A ( d ) above a cell indicates data that must be entered as decimal.

SMF Track Header (MThd)

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:

  1. ID
  2. Length
  3. SMF Type (h)
  4. NumTracks (h)
  5. PPQ (d)

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.

x

SMF MTrk Tracks

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.

Track 1, the Tempo Track (MTrk)

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.

track 1 header

PPQ Symbol Bytes Data Hex Notes
not used MTrk
4
4D 54 72 6B A marker that indicates the start of a track
not used Length of data
4
<length>

The number of bytes that follow.
Use zero in the SMF Excel template.

Meta Events

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.

  1. Key Signature
  2. Time Signature
  3. Tempo
  4. End of track

Important: A Delta Time (PPQ value) precedes every meta event and MIDI message. Delta times are in column A.

Key Signature Meta Event

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.

track 1 meta event for key signature

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
1-7 for sharps; FF-F9 for flats (FF = -1, F9 = -7)
Use sf = 2.

mi = 1 is minor key, 0 is major key
Use mi=0

Time Signature Meta Event

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.

track 1 meta event for time signature

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
Use nn = 4

dd = denominator of time signature expressed
as a power of 2.
Our time signature denominator is four
Use dd = 2

cc = MIDI clocks per metronome click,
Use cc = 18 (hex, decimal is 24)

bb =number of notated thirty second notes per quarter note
Use bb = 8

Tempo Meta Event

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.

track 1 meta event for tempo

The Tempo meta event is:

Tempo Formulas

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.

Hex Conversion Methods

Try this Excel formula in an empty cell: =DEC2HEX(1000000*60/100). If the DEC2HEX function is installed you'll get 927C0.

The tempo of this example is 60 beats per minute.

PPQ

FF Type Length
Data
Interpretation
0 or 1
FF 51 03

tt tt tt

tt tt tt = time in microseconds per quarter note
converted to three hex digits

microseconds formula
= 1,000,000 * 60 / tempo

tempo formula
= 1,000,000*60 / microseconds

Our converted tempo is 1000000*60/100 = 600000
= DEC2HEX(600000)

Use tt tt tt = 9 27 C0

Split the hex number into three parts 9 27 c0. This is the information you need to fill in:

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.

x

End of Track Meta Event

Every MTrk track ends with an End of Track meta event:FF 2F 0. Use a PPQ of 1.

End of track message

Fill in Track 2 - The Flute Part on Channel 0

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 :

  1. Reset All Controllers message (Bn 121 0)
  2. Volume Control Message (Bn 7 data2)
  3. Pan Control message (Bn 10 data2)
  4. Patch Change command (Cn data1) -- Important: only one data byte
  5. The remaining MIDI messages you've used in MIDIDisplay

Copy and paste the MIDIDisplay data for the flute

Important: Make sure every status message for the flute part is on MIDI channel zero.

SMF Template Track 2

All Instrument tracks end with a Reset All controllers message and an End of Track meta event

Paste this after the last MIDI message. You can copy it from the SMFTemplate page.

End of track meta event

Fill in Track 3 - The Bassoon Part on Channel 1

Copy and paste the MIDIDisplay data for the Bassoon

Here's the completed Track 3 section. The MIDI channel for every status byte has been changed to channel 1.

x

Every track ends with the End of Track meta event.

x

The Reference page for Unit 5 provides additional documentation on SMF documentation and MIDI programming libraries.

MIDIDisplay

Copy and Paste Into all data in columns A:H into MIDIDisplay.

Choose Export Standard MIDI File from the Options menu.

MIDIDisplay export menu

If there's an error, a message will point you to the Excel row number.

MIDIDisplay error

Play It On Your Computer

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.

[Overview] [Syllabus]

Revised John Ellinger, January - September 2013