The labs for unit Lab 3 will introduce Dynamics, MIDI Control messages and MIDI Patch Change messages. You'll also learn some new Excel formulas.
Connect the USB cable between the QX25 MIDI controller and the iMac.
I've written twelve MIDI Tools you can run on the iMacs in the labs. These programs were written in C++ and can be found in the course common folder. They are Mac only and can be installed for home use by following the README instructions.
Four tools are reference only: midiprobe, listGMnames, listGMdrums, debugSMF. The remaining tools produce sound using AU Lab.
debugSMF filename- helps find mistakes in you Standard MIDI File
drums47 - plays each of the 47 General MIDI drums sounds assigned on channel 10 (9 in MIDI)
dur - experiment with durations
listGMdrums - a list of the MIDI note numbers for all drum sounds on channel 10 (9)
listGMnames - a list of the 128 General MIDI instrument names (0-127 in MIDI)
midiin - midi record function can be used to paste data into MIDIDisplay
midiprobe - lists available MIDI input and output ports
non127 - experiment with different MIDI note numbers and durations
pan127 - experiment with stereo pan settings
panic - turn off stuck notes
patch127 - experiment with MIDI Patch Change commands
vel127 - experiment with velocity levels for any instrument
Open Au Lab from the Applications folder. All MIDI tools expect AU Lab. See AU Lab Setup for home use setup instructions. Drag the icon to the Dock for easy access.
Double click the Terminal application. You can find it in the Utilities folder inside the Applications folder (/Applications/Utilities). Drag the icon to the Dock for easy access.
In many ways the Terminal Window is the most powerful program on the Macintosh. Advanced users can write scripts and compile software that can be executed by the Terminal. For example, Terminal scripts automatically associate your email, course folders, your network folder, and your network quota with your login name.
Double click the Terminal icon and the Terminal window will appear.
All utilities are run by typing their name and then pressing Return or Enter. For example:
Type listGMnames followed by enter in the Terminal window.
These 128 General MIDI sounds (0-127) are available for your midterm project on any MIDI channel except the drum channel.
================================================================
List all GM instruments
================================================================
Piano =========================
0: Acoustic Grand Piano
1: Bright Acoustic Piano
2: Electric Grand Piano
3: Honky-tonk Piano
4: Electric Piano 1
5: Electric Piano 2
6: Harpsichord
7: Clavinet
Chromatic Percussion ==========
8: Celesta
9: Glockenspiel
10: Music Box
11: Vibraphone
12: Marimba
13: Xylophone
14: Tubular Bells
15: Dulcimer
Organ =========================
16: Drawbar Organ
17: Percussive Organ
18: Rock Organ
19: Church Organ
20: Reed Organ
21: Accordion
22: Harmonica
23: Tango Accordion
Guitar ========================
24: Acoustic Guitar (nylon)
25: Acoustic Guitar (steel)
26: Electric Guitar (jazz)
27: Electric Guitar (clean)
28: Electric Guitar (muted)
29: Overdriven Guitar
30: Distortion Guitar
31: Guitar harmonics
Bass ==========================
32: Acoustic Bass
33: Electric Bass (finger)
34: Electric Bass (pick)
35: Fretless Bass
36: Slap Bass 1
37: Slap Bass 2
38: Synth Bass 1
39: Synth Bass 2
Strings =======================
40: Violin
41: Viola
42: Cello
43: Contrabass
44: Tremolo Strings
45: Pizzicato Strings
46: Orchestral Harp
47: Timpani
Ensemble ======================
48: String Ensemble 1
49: String Ensemble 2
50: SynthStrings 1
51: SynthStrings 2
52: Choir Aahs
53: Voice Oohs
54: Synth Voice
55: Orchestra Hit
Brass =========================
56: Trumpet
57: Trombone
58: Tuba
59: Muted Trumpet
60: French Horn
61: Brass Section
62: SynthBrass 1
63: SynthBrass 2
Reed ==========================
64: Soprano Sax
65: Alto Sax
66: Tenor Sax
67: Baritone Sax
68: Oboe
69: English Horn
70: Bassoon
71: Clarinet
Pipe ==========================
72: Piccolo
73: Flute
74: Recorder
75: Pan Flute
76: Blown Bottle
77: Shakuhachi
78: Whistle
79: Ocarina
Synth Lead ====================
80: Lead 1 (square)
81: Lead 2 (sawtooth)
82: Lead 3 (calliope)
83: Lead 4 (chiff)
84: Lead 5 (charang)
85: Lead 6 (voice)
86: Lead 7 (fifths)
87: Lead 8 (bass + lead)
Synth Pad =====================
88: Pad 1 (new age)
89: Pad 2 (warm)
90: Pad 3 (polysynth)
91: Pad 4 (choir)
92: Pad 5 (bowed)
93: Pad 6 (metallic)
94: Pad 7 (halo)
95: Pad 8 (sweep)
Synth Effects =================
96: FX 1 (rain)
97: FX 2 (soundtrack)
98: FX 3 (crystal)
99: FX 4 (atmosphere)
100: FX 5 (brightness)
101: FX 6 (goblins)
102: FX 7 (echoes)
103: FX 8 (sci-fi)
Ethnic ========================
104: Sitar
105: Banjo
106: Shamisen
107: Koto
108: Kalimba
109: Bag pipe
110: Fiddle
111: Shanai
Percussive ====================
112: Tinkle Bell
113: Agogo
114: Steel Drums
115: Woodblock
116: Taiko Drum
117: Melodic Tom
118: Synth Drum
119: Reverse Cymbal
Sound Effects =================
120: Guitar Fret Noise
121: Breath Noise
122: Seashore
123: Bird Tweet
124: Telephone Ring
125: Helicopter
126: Applause
127: Gunshot
Type midiprobe followed by enter in the Terminal window.
The DLSMusicDevice is the output of AU Lab. AU Lab is Apple's software General MIDI synthesizer that produces the sounds you hear. You'll be asked to enter the output port number of the DLSMusicDevice in several MIDI tools.
When you encounter a "stuck note," execute the panic command. Occasionally, MIDI notes do not turn off properly and continue to sound when the song is over. The most common reason for stuck notes is failing to match a NON message with a corresponding NOF message. The panic tool it sends a NOF message to all 128 notes on all 16 MIDI channels.
Type Ctrl-C. That's the standard command for stopping a command running in Terminal.
non127 plays single notes. You choose the note number and velocity.
vel127 plays middle C with a range of velocities. You choose the velocity range and the instrument sound. Different instruments may have different velocity curves. This tool will be helpful in your midterm project when deciding on which instruments to use and to map musical dynamics to velocity ranges. Different instruments may have different velocity curves.
Try other instruments and play options.
dur plays middle C four times spaced one second apart. You choose the duration in milliseconds and the instrument sound. This tool will be helpful in your midterm project for making articulation and phrasing decisions.
Do again with duration of 400 and again with duration of 2.
There are 47 drum sounds defined in the General MIDI specification. Drums sounds are played on MIDI drum channel 9, zero based. The MIDI note numbers 35-81 are used as data1 for all NON and NOF messages on the drum channel. Patch change messages are not needed on the drum channel.
listGMdrums - lists the 47 drum sounds and their MIDI note number assignment.
drums47 - plays short rhythm pattern for each drum note
etc.
A MIDI patch change messages changes the instrument sound and used the status byte Cn. There are a total of 128 General MIDI instruments to choose from as shown by listGMnames. The patch change command is not used with the Drum Channel.
Experiment with different options.
You can use midiin to display and record MIDI messages.
Execute midiin
Experiment with piano keys, knobs, wheels, buttons, sliders, and pads on the QX25. Observe the output.
Type Enter to quit.
Type clear to clear the terminal screen. Actually it just moves the prompt to the top of the window.
Execute midiin again. This time play something on the piano keyboard to record a short fragment of music.
Type enter to quit.
Open Excel.
Copy the midiin data from the Terminal and paste it into Excel at cell A1.
Select and copy the MIDI messages in columns A through D and paste them into MIDIDisplay.
Note: Widen the Terminal window for this test.
Back to Terminal. The MIDI Pan Control message places an instrument from left to right on a stereo sound stage. The MIDI Pan message is one of several MIDI control messages you'll use in your midterm project. All MIDI control messages start with status byte Bn. The data1 byte is the type of control, it's 10 for the Pan message. The data2 byte is the left-right pan value. Zero is extreme left, 64 is center, and 127 is extreme right.
Execute pan127. The output format consists of 128 periods with the letter P positioned at the data2 pan value. The numbers in parentheses are the data1 MIDI note number for NON and NOF messages, the data2 stereo pan position, and the data1 patch change instrument number.
This is an advanced example that demonstrates very powerful text processing capabilities available in Excel and TextWrangler.
How would you convert the pan127 data into a format that could be played in MIDIDisplay? You could do it manually but it would be a tedious, error prone, task. You'd need to create four MIDI messages for each line: a patch change message, a pan control message, a NON message and a NOF message. You'd also have to calculate the millisecond time of each message.
Why not have the computer do the work?
Open TextWrangler.
Copy the pan127 data to TextWrangler. Start with the first line of dots containing a P.
Note: Your numbers will be different because of the Random choices made.
We'll use a very powerful text processing tool called Grep that is built into TextWrangler. Grep is available in many other text editors, including Terminal, and is commonly used by programmers and power users.
Choose Find from the Search menu. Enter the following text exactly as shown. Make sure Grep is checked.
Grep is an acronym for General Regular Expression Parser. Entire books have been written about constructing and using "regular expressions", the language of Grep. Here's what the Find and Replace regular expressions mean.
Find:
. | Match a single character |
.* | Match a single character any number of times |
\( | Match a literal opening parenthesis. Parentheses are one of several reserved characters that are part of the Grep language. A backslash tells Grep to treat a reserved character as a literal character. |
(.*) | Match and remember anything inside the Grep language parenthesis. |
\) | Match a literal opening parenthesis. |
The net result of the regular expression for Find is to select one entire line and remember the characters between the opening and closing parentheses.
Replace:
\1
\1 | Anything enclosed within Grep language parentheses is remembered and can be recalled later. Remembered items are designated by \1 \2 \3 etc. in the Grep language. |
The TextWrangler window should now look similar to this. Your numbers will be different because of the Random choices made by pan127.
The TextWrangler data consists of three numbers per line separated by commas. The first number is the MIDI note number (data1 of a NON, NOF message), the second number is the left-right stereo position (data2) of the Pan Control message, and the third number is the patch change instrument number (data1 of a Patch Change message).
Save this TextWrangler document to the Desktop as pan127.txt.
Choose Import from the File menu and choose the pan127.txt file. Make sure the popup menu shows Text Files.
When the Import dialog appears select CSV file and click Import.
Step 1 of the Text Import Wizard dialog will appear. Make these settings and click the Next button.
Step 2 of the Text Import Wizard dialog will appear. Make these settings and click the Next button.
Step 3 of the Text Import Wizard dialog will appear. Make these settings and click the Finish button.
The Import Data dialog will ask you where to start pasting the imported data. Use the existing sheet an start at cell B1. Click OK.
Column should be blank. Columns B, C, and D should contain the data. Your numbers will be different because of the Random choices made.
Enter zero in A1 and select A1.
Use the Fill Series command from the Edit menu to create the millisecond times in column A.
Click OK
Copy Columns A1:D128 and paste into TextWrangler. Your numbers will be different because of the Random choices made.
We want the MIDIDisplay messages to end up looking like this, assuming eighth notes at a tempo of 60. Your numbers will be different because of the Random choices made.
Important: The MIDI messages for Patch Change and Pan Control need to precede the NON and NOF messages they affect.
Choose Find from the search menu. You'll enter these rather scary looking regular expressions. First, read on below to understand how they work.
The Regular Expression for Find:
This one's relatively easy. Each line in TextWrangler consists of four numbers separated by tabs.
(.*) - match any number of characters and remember it for later
\t - match a tab character
Token | Regular Expression Explanation | What gets remembered |
(.*)\t | Select everything up through the first tab. Remember everything up to the first tab, but not including the tab. Recall it later as \1 | \1 time in milliseconds |
(.*)\t | Select everything after the first tab up through the second tab. Recall it later as \2 | \2 is data1 (MIDI note number) for the NON and NOF messages |
(.*)\t | Select everything after the second tab up through the third tab. Recall it later as \3 | \3 is data2 (pan left-right location) for the MIDI Control message for Pan. |
(.*) | Select everything after the third tab to the end of the line. Recall it later as \4 | \4 is data1 (instrument number) for the Patch Change message |
The Regular Expression for Replace:
Let's break it down
\1 |
Recall time in milliseconds |
\tC0 |
Tab followed by status C0 (patch change on channel 0) |
\t |
Tab |
\4 |
Recall Patch change instrument number (data1) |
\t0 |
Tab followed by zero (data2) |
\n |
new line |
\1 |
Recall time in milliseconds |
\tB0 |
Tab followed by status B0 (MIDI Control message on channel 0) |
\t10 |
Control message is Pan (data1) |
\t |
Tab |
\3 |
Recall Pan control left-right value (data2) |
\n |
new line |
\1 |
Recall time in milliseconds |
\t90 |
Tab followed by status 90 (NON on channel 0) |
\t |
Tab |
\2 |
Recall MIDI note number (data1) |
\t100 |
Tab followed by velocity of 100 (data2) |
\n |
new line |
999999 |
Placeholder. We'll use an Excel formula to set the real NOF time later. |
\t80 |
Tab followed by status 80 (NOF on channel 0) |
\t |
Tab |
\2 |
Recall MIDI note number (data1) |
\t0 |
Tab followed by velocity of 0 (data2) |
\n not needed. Grep processing is on a line by line basis and a new line happens automatically. |
Click the Replace All button.
The results should look like this.
Note: Your numbers will be different because of the Random choices made.
Paste the TextWrangler data into Excel.
The last NON time should be 63500 in row 511. The last row should be 512 at time 64000. You may have to edit the last row it by hand to make the NOF message turn off the previous NON.
The duration of each NOF time must be less than or equal to the next NON time. This formula will check to see if the cell in column A equals 999999. If it does it will replace 999999 with the NON time of the cell below. Otherwise, the cell is unchanged.
Enter this formula into cell F1.
=IF ( A1=999999, INDIRECT( ADDRESS( ROW() + 1, COLUMN() ) ), A1)
The logical_test is: A1 = 999999
The value_if_true is
INDIRECT( ADDRESS( ROW() + 1, COLUMN() ) )that replaces A1 with the value of the cell in the row below in the same column.
The value_if_false is
A1
that leaves A1 unchanged.
Copy the formula into cells F2:F512.
Paste Special by Values the new NOF times from column F back into column A.
Copy Excel columns A, B, C, D and paste into MIDIDisplay.
Play.
That's pretty powerful text processing.
Continue with ExcelTips.
Continue with 03Lab1.