MUSC 108. Introduction to Music Technology - Fall 2013

Unit 4 Lecture

[Overview] [Syllabus]

Create A Standard MIDI File (SMF)

This is a short example written in Sibelius 7 and exported as a SMF.

04 Class Example Score

04ClassExampleSib7.mid

Unable to play MP3

The Sibelius and Standard MIDI File versions of this file are in the course common folder.

Format of a Standard MIDI File (SMF)

SMF structure

Hex View Of 04Classexample

Use TextWrangler's Hex Dump command in the File menu

HexView 3a

Legend

MThd is SMF Header Marker

MTrk is Track Header Marker

Number of bytes to follow

FF2F00 is End of Track Marker

Use the hexdump tool in Terminal

Copy the 04ClassExamople60bpm.mid file from the Course Common folder to the iMac desktop.

Execute these commands in the terminal.

hexdump commands

Hold down the Option key and select the data shown in grey.

hexdump tool

Paste back into a new TextWrangler window.

4. Organize into track events.

MThd header chunk

MTrk chunk1

MTrk track2

MTrk track4

5. Convert Spaces to Tabs

Use grep to convert a space to a tab.

Spaces to tabs

6. Paste into Excel

SMF pasted into Excel

7. Change delta times to PPQ values

These are the delta times used in the MIDI file.

Delta Times PPQ
81 70 240
83 60 480
87 40 960

Optional:

Here's how to figure out what 81 70 means. This example is specific to two byte delta times.

Aren't you glad you don't have to do this!
Delta time
81
70
Get the first hex byte (8 bits)
81
Convert to Binary
1000 0001
Bit And 81 with 0111 1111 (7F)
0000 0001
Bit Shift result left by 7 bits
1000 0000
Add second hex byte (70) to this value
1000 0000
+
0111 0000  
Equals =
1111 0000  
Convert to hex. This is PPQ in hex.
F0
PPQ in decimal is 240

Here's how to figure out what 83 60 means. This example is specific to two byte delta times.

Delta time
83
60
Get the first hex byte (8 bits)
83
Convert to Binary
1000 0011
Bit And 83 with 0111 1111 (7F)
0000 0011
Bit Shift result left by 7 bits
0001 1000 0000
Add second hex byte (60) to this value
0001 1000 0000
+
0110 0000  
Equals =
0001 1110 0000  
Convert to hex. This is PPQ in hex.
1E0
PPQ in decimal is 480

Here's how to figure out what 87 40 means. This example is specific to two byte delta times.

Delta time
87
40
Get the first hex byte (8 bits)
87
Convert to Binary
1000 0111
Bit And 87 with 0111 1111 (7F)
0000 0111
Bit Shift result left by 7 bits
0011 1000 0000
Add second hex byte (70) to this value
0011 1000 0000
+
0100 0000  
Equals =
0011 1100 0000  
Convert to hex. This is PPQ in hex.
3C0
PPQ in decimal is 960

7. Play in Track 2 in MIDIDisplay

Track two should be in this form.

SMF track 2

Delete rows 14, 15, 22, and 41.

Track 2 after delete

Use the Excel DEC2HEX command to convert all hexadecimal numbers in data1 and data2 columns to decimal.

HEX2DEC Excel command

Left column used this Excel formula: =HEX2DEC( C14 )

Right column used this Excel formula: =HEX2DEC( D14 )

Paste Special by Values to replace data1 and data2 hex values with decimal values.

Copy data into MIDIDisplay. Set the Time Base to PPQ. Set the PPQ value to 480.

Play.

SMF data in MIDIDisplay

The debugSMF Tool

debugSMF is a MIDI tool I wrote to help you find errors in your standard MIDI file.

Execute this command in Terminal.

debugSMF tool

Formatted with tabs for display in Excel: 
Header: 
  Format:   1
  Tracks:   3
  PPQ Division: 480


Start of Track 1
Time signature: 4/2/24/8
Key signature: 2, 0
Tempo: f4240 1000000 [M.M. = 60]
End of Track FF 2F 00


Start of Track 2
MTrk 00 00 00 6e [Length = 110]
PPQ	Status	 Data1	Data2
0	PrgC	73	OK
0	Ctrl	121	OK
0	Ctrl	64	OK
0	Ctrl	91	OK
0	Ctrl	10	OK
0	Ctrl	7	OK
;Text: 3	 
0	NON 	62	OK
240	NOF	62	0
0	NON 	64	OK
240	NOF	64	0
0	NON 	66	OK
240	NOF	66	0
0	NON 	67	OK
240	NOF	67	0
0	NON 	69	OK
240	NOF	69	0
0	NON 	71	OK
240	NOF	71	0
0	NON 	73	OK
240	NOF	73	0
0	NON 	69	OK
240	NOF	69	0
0	NON 	74	OK
960	NOF	74	0
End of Track FF 2F 00


Start of Track 3
MTrk 00 00 00 4a [Length = 74]
PPQ	Status	 Data1	Data2
0	PrgC	70	OK
0	Ctrl	121	OK
0	Ctrl	64	OK
0	Ctrl	91	OK
0	Ctrl	10	OK
0	Ctrl	7	OK
;Text: 3	 
0	NON 	54	OK
480	NOF	54	0
0	NON 	50	OK
480	NOF	50	0
0	NON 	49	OK
480	NOF	49	0
0	NON 	45	OK
480	NOF	45	0
0	NON 	50	OK
960	NOF	50	0
End of Track FF 2F 00

Modifying A SMF using a Hex Editor

Hex View Of 04Classexample

HexEdit on the Mac (Applications Folder)

See Reference page, Unit4, for free Hex editor downloads for Mac and Windows.

Address
Hex Data
ASCII data
Hex view 1

1. Change Instruments - Patch Change message Cn data1

Hex view 1

2. Change Pan values - Control message Bn 10 data2

Hex view 1

3. Change Volume - Control message Bn 7 data2

Hex view 1

3. Change Tempo - Track 1 Meta Event FF 51 03 tt tt tt

Hex view 1

[Overview] [Syllabus]

Revised John Ellinger, January - September 2013