[q-lang-cvs] qcalc/examples midiutil.q, NONE, 1.1 midiio.qcalc, 1.2, 1.3
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-25 15:35:36
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21118/examples Modified Files: midiio.qcalc Added Files: midiutil.q Log Message: moved helper functions to separate module, added helper functions to translate GM percussion, programs and controllers --- NEW FILE: midiutil.q --- /* Helper functions used in the midiio.qcalc example. */ /* Translate MIDI note numbers to note and GM percussion names. */ public note_name N, perc_name N; /* Translate GM controller and program numbers. */ public ctrl_name N, prog_name N; /* Implementation. */ import dict; def NOTE_NAMES = ("C","C#","D","D#","E","F","F#","G","G#","A","Bb","B"); note_name N:Int = sprintf "%s%d" (NOTE_NAMES!(N mod 12),N div 12) if N>=0; note_name _ = "N/A" otherwise; def GMPROG = dict [(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"), (8, "Celesta"), (9, "Glockenspiel"), (10, "Music Box"), (11, "Vibraphone"), (12, "Marimba"), (13, "Xylophone"), (14, "Tubular Bells"), (15, "Dulcimer"), (16, "Drawbar Organ"), (17, "Percussive Organ"), (18, "Rock Organ"), (19, "Church Organ"), (20, "Reed Organ"), (21, "Accordion"), (22, "Harmonica"), (23, "Tango Accordian"), (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"), (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"), (40, "Violin"), (41, "Viola"), (42, "Cello"), (43, "Contrabass"), (44, "Tremolo Strings"), (45, "Pizzicato Strings"), (46, "Orchestral Strings"), (47, "Timpani"), (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"), (56, "Trumpet"), (57, "Trombone"), (58, "Tuba"), (59, "Muted Trumpet"), (60, "French Horn"), (61, "Brass Section"), (62, "SynthBrass 1"), (63, "SynthBrass 2"), (64, "Soprano Sax"), (65, "Alto Sax"), (66, "Tenor Sax"), (67, "Baritone Sax"), (68, "Oboe"), (69, "English Horn"), (70, "Bassoon"), (71, "Clarinet"), (72, "Piccolo"), (73, "Flute"), (74, "Recorder"), (75, "Pan Flute"), (76, "Blown Bottle"), (77, "Shakuhachi"), (78, "Whistle"), (79, "Ocarina"), (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)"), (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)"), (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)"), (104, "Sitar"), (105, "Banjo"), (106, "Shamisen"), (107, "Koto"), (108, "Kalimba"), (109, "Bagpipe"), (110, "Fiddle"), (111, "Shanai"), (112, "Tinkle Bell"), (113, "Agogo"), (114, "Steel Drums"), (115, "Woodblock"), (116, "Taiko Drum"), (117, "Melodic Tom"), (118, "Synth Drum"), (119, "Reverse Cymbal"), (120, "Guitar Fret Noise"), (121, "Breath Noise"), (122, "Seashore"), (123, "Bird Tweet"), (124, "Telephone Ring"), (125, "Helicopter"), (126, "Applause"), (127, "Gunshot")], GMPERC = dict [(35, "Acoustic Bass Drum"), (36, "Bass Drum 1"), (37, "Side Stick"), (38, "Acoustic Snare"), (39, "Hand Clap"), (40, "Electric Snare"), (41, "Low Floor Tom"), (42, "Closed Hi-Hat"), (43, "High Floor Tom"), (44, "Pedal Hi-Hat"), (45, "Low Tom"), (46, "Open Hi-Hat"), (47, "Low-Mid Tom"), (48, "Hi-Mid Tom"), (49, "Crash Cymbal 1"), (50, "High Tom"), (51, "Ride Cymbal 1"), (52, "Chinese Cymbal"), (53, "Ride Bell"), (54, "Tambourine"), (55, "Splash Cymbal"), (56, "Cowbell"), (57, "Crash Cymbal 2"), (58, "Vibraslap"), (59, "Ride Cymbal 2"), (60, "Hi Bongo"), (61, "Low Bongo"), (62, "Mute Hi Conga"), (63, "Open Hi Conga"), (64, "Low Conga"), (65, "High Timbale"), (66, "Low Timbale"), (67, "High Agogo"), (68, "Low Agogo"), (69, "Cabasa"), (70, "Maracas"), (71, "Short Whistle"), (72, "Long Whistle"), (73, "Short Guiro"), (74, "Long Guiro"), (75, "Claves"), (76, "Hi Wood Block"), (77, "Low Wood Block"), (78, "Mute Cuica"), (79, "Open Cuica"), (80, "Mute Triangle"), (81, "Open Triangle")], GMCTRL = dict [(0, "Bank Select"), (1, "Modulation Wheel (coarse)"), (2, "Breath controller (coarse)"), (4, "Foot Pedal (coarse)"), (5, "Portamento Time (coarse)"), (6, "Data Entry (coarse)"), (7, "Volume (coarse)"), (8, "Balance (coarse)"), (10, "Pan position (coarse)"), (11, "Expression (coarse)"), (12, "Effect Control 1 (coarse)"), (13, "Effect Control 2 (coarse)"), (16, "General Purpose Slider 1"), (17, "General Purpose Slider 2"), (18, "General Purpose Slider 3"), (19, "General Purpose Slider 4"), (32, "Bank Select (fine)"), (33, "Modulation Wheel (fine)"), (34, "Breath controller (fine)"), (36, "Foot Pedal (fine)"), (37, "Portamento Time (fine)"), (38, "Data Entry (fine)"), (39, "Volume (fine)"), (40, "Balance (fine)"), (42, "Pan position (fine)"), (43, "Expression (fine)"), (44, "Effect Control 1 (fine)"), (45, "Effect Control 2 (fine)"), (64, "Hold Pedal (on/off)"), (65, "Portamento (on/off)"), (66, "Sustenuto Pedal (on/off)"), (67, "Soft Pedal (on/off)"), (68, "Legato Pedal (on/off)"), (69, "Hold 2 Pedal (on/off)"), (70, "Sound Variation"), (71, "Sound Timbre"), (72, "Sound Release Time"), (73, "Sound Attack Time"), (74, "Sound Brightness"), (75, "Sound Control 6"), (76, "Sound Control 7"), (77, "Sound Control 8"), (78, "Sound Control 9"), (79, "Sound Control 10"), (80, "General Purpose Button 1 (on/off)"), (81, "General Purpose Button 2 (on/off)"), (82, "General Purpose Button 3 (on/off)"), (83, "General Purpose Button 4 (on/off)"), (91, "Effects Level"), (92, "Tremulo Level"), (93, "Chorus Level"), (94, "Celeste Level"), (95, "Phaser Level"), (96, "Data Button increment"), (97, "Data Button decrement"), (98, "Non-registered Parameter (fine)"), (99, "Non-registered Parameter (coarse)"), (100, "Registered Parameter (fine)"), (101, "Registered Parameter (coarse)"), (120, "All Sound Off"), (121, "All Controllers Off"), (122, "Local Keyboard (on/off)"), (123, "All Notes Off"), (124, "Omni Mode Off"), (125, "Omni Mode On"), (126, "Mono Operation"), (127, "Poly Operation")]; perc_name N:Int = S where S:String = GMPERC!N; perc_name _ = "N/A" otherwise; ctrl_name N:Int = S where S:String = GMCTRL!N; ctrl_name _ = "N/A" otherwise; prog_name N:Int = S where S:String = GMPROG!N; prog_name _ = "N/A" otherwise; Index: midiio.qcalc =================================================================== RCS file: /cvsroot/q-lang/qcalc/examples/midiio.qcalc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** midiio.qcalc 25 Nov 2007 15:06:17 -0000 1.2 --- midiio.qcalc 25 Nov 2007 15:35:17 -0000 1.3 *************** *** 1,3 **** ! // qcalc 1.0, created Sun Nov 25 16:10:11 2007 -*-Q-*- -*- coding: UTF-8 -*- // [((0,1),"MidiShare Client"),((0,2),"Port"),((0,3),"Channel"),((1,0),">>> Input:"),((1,1),"= inclient_combobox"),((1,2),"= inport_spinbox"),((1,3),"= inchan_spinbox"),((3,0),"= intaskbutton B2 C2 D2 F5:F11"),((3,1),"Time"),((3,2),"Channel"),((3,3),"Data #1"),((3,4),"Data #2"),((3,5),"= clearbutton"),((4,0),"Note On"),((4,2),"= spinbox (0,16,1,0,\" \")"),((4,3),"= spinbox (-1,127,1,-1,\" \")"),((4,4),"= spinbox (-1,127,1,-1,\" \")"),((4,5),"= togglebutton (\"Recv\",\"\",true)"),((4,6),"= note_name D5"),((5,0),"Note Off"),((5,2),"= spinbox (0,16,1,0,\" \")"),((5,3),"= spinbox (-1,127,1,-1,\" \")"),((5,4),"= spinbox (-1,127,1,-1,\" \")"),((5,5),"= togglebutton (\"Recv\",\"\",true)"),((5,6),"= note_name D6"),((6,0),"Pitch Wheel"),((6,2),"= spinbox (0,16,1,0,\" \")"),((6,3),"= spinbox (-1,127,1,-1,\" \")"),((6,4),"= spinbox (-1,127,1,-1,\" \")"),((6,5),"= togglebutton (\"Recv\",\"\",true)"),((7,0),"Controller"),((7,2),"= spinbox (0,16,1,0,\" \")"),((7,3),"= spinbox (-1,127,1,-1,\" \")"),((7,4),"= spinbox (-1,127,1,-1,\" \")"),((7,5),"= togglebutton (\"Recv\",\"\",true)"),((8,0),"Program"),((8,2),"= spinbox (0,16,1,0,\" \")"),((8,3),"= spinbox (-1,127,1,-1,\" \")"),((8,4),"= spinbox (-1,127,1,-1,\" \")"),((8,5),"= togglebutton (\"Recv\",\"\",true)"),((9,0),"Aftertouch"),((9,2),"= spinbox (0,16,1,0,\" \")"),((9,3),"= spinbox (-1,127,1,-1,\" \")"),((9,4),"= spinbox (-1,127,1,-1,\" \")"),((9,5),"= togglebutton (\"Recv\",\"\",true)"),((10,0),"Poly Aftertouch"),((10,2),"= spinbox (0,16,1,0,\" \")"),((10,3),"= spinbox (-1,127,1,-1,\" \")"),((10,4),"= spinbox (-1,127,1,-1,\" \")"),((10,5),"= togglebutton (\"Recv\",\"\",true)"),((12,1),"MidiShare Client"),((12,2),"Port"),((12,3),"Channel"),((13,0),">>> Output:"),((13,1),"= outclient_combobox"),((13,2),"= outport_spinbox"),((13,3),"= outchan_spinbox"),((15,0),"= outtaskbutton B14"),((15,1),"Time"),((15,2),"Channel"),((15,3),"Data #1"),((15,4),"Data #2"),((15,5),"= resetbutton D14"),((16,0),"Note On"),((16,2),"= spinbox (0,16,1,D$14,\" \")"),((16,3),"= spinbox (-1,127,1,60,\" \")"),((16,4),"= spinbox (-1,127,1,64,\" \")"),((16,5),"= outsendbutton C$14 (note_on (C17-1) D17 E17)"),((16,6),"= note_name D17"),((17,0),"Note Off"),((17,2),"= spinbox (0,16,1,D$14,\" \")"),((17,3),"= spinbox (-1,127,1,60,\" \")"),((17,4),"= spinbox (-1,127,1,64,\" \")"),((17,5),"= outsendbutton C$14 (note_off (C18-1) D18 E18)"),((17,6),"= note_name D18"),((18,0),"Pitch Wheel"),((18,2),"= spinbox (0,16,1,D$14,\" \")"),((18,3),"= spinbox (-1,127,1,0,\" \")"),((18,4),"= spinbox (-1,127,1,64,\" \")"),((18,5),"= outsendbutton C$14 (pitch_wheel (C19-1) D19 E19)"),((19,0),"Controller"),((19,2),"= spinbox (0,16,1,D$14,\" \")"),((19,3),"= spinbox (-1,127,1,1,\" \")"),((19,4),"= spinbox (-1,127,1,0,\" \")"),((19,5),"= outsendbutton C$14 (ctrl_change (C20-1) D20 E20)"),((20,0),"Program"),((20,2),"= spinbox (0,16,1,D$14,\" \")"),((20,3),"= spinbox (-1,127,1,0,\" \")"),((20,4),"= spinbox (-1,127,1,-1,\" \")"),((20,5),"= outsendbutton C$14 (prog_change (C21-1) D21)"),((21,0),"Aftertouch"),((21,2),"= spinbox (0,16,1,D$14,\" \")"),((21,3),"= spinbox (-1,127,1,0,\" \")"),((21,4),"= spinbox (-1,127,1,-1,\" \")"),((21,5),"= outsendbutton C$14 (chan_press (C22-1) D22)"),((22,0),"Poly Aftertouch"),((22,2),"= spinbox (0,16,1,D$14,\" \")"),((22,3),"= spinbox (-1,127,1,60,\" \")"),((22,4),"= spinbox (-1,127,1,64,\" \")"),((22,5),"= outsendbutton C$14 (key_press (C23-1) D23 E23)")] // [] --- 1,3 ---- ! // qcalc 1.0, created Sun Nov 25 16:12:11 2007 -*-Q-*- -*- coding: UTF-8 -*- // [((0,1),"MidiShare Client"),((0,2),"Port"),((0,3),"Channel"),((1,0),">>> Input:"),((1,1),"= inclient_combobox"),((1,2),"= inport_spinbox"),((1,3),"= inchan_spinbox"),((3,0),"= intaskbutton B2 C2 D2 F5:F11"),((3,1),"Time"),((3,2),"Channel"),((3,3),"Data #1"),((3,4),"Data #2"),((3,5),"= clearbutton"),((4,0),"Note On"),((4,2),"= spinbox (0,16,1,0,\" \")"),((4,3),"= spinbox (-1,127,1,-1,\" \")"),((4,4),"= spinbox (-1,127,1,-1,\" \")"),((4,5),"= togglebutton (\"Recv\",\"\",true)"),((4,6),"= note_name D5"),((5,0),"Note Off"),((5,2),"= spinbox (0,16,1,0,\" \")"),((5,3),"= spinbox (-1,127,1,-1,\" \")"),((5,4),"= spinbox (-1,127,1,-1,\" \")"),((5,5),"= togglebutton (\"Recv\",\"\",true)"),((5,6),"= note_name D6"),((6,0),"Pitch Wheel"),((6,2),"= spinbox (0,16,1,0,\" \")"),((6,3),"= spinbox (-1,127,1,-1,\" \")"),((6,4),"= spinbox (-1,127,1,-1,\" \")"),((6,5),"= togglebutton (\"Recv\",\"\",true)"),((7,0),"Controller"),((7,2),"= spinbox (0,16,1,0,\" \")"),((7,3),"= spinbox (-1,127,1,-1,\" \")"),((7,4),"= spinbox (-1,127,1,-1,\" \")"),((7,5),"= togglebutton (\"Recv\",\"\",true)"),((8,0),"Program"),((8,2),"= spinbox (0,16,1,0,\" \")"),((8,3),"= spinbox (-1,127,1,-1,\" \")"),((8,4),"= spinbox (-1,127,1,-1,\" \")"),((8,5),"= togglebutton (\"Recv\",\"\",true)"),((9,0),"Aftertouch"),((9,2),"= spinbox (0,16,1,0,\" \")"),((9,3),"= spinbox (-1,127,1,-1,\" \")"),((9,4),"= spinbox (-1,127,1,-1,\" \")"),((9,5),"= togglebutton (\"Recv\",\"\",true)"),((10,0),"Poly Aftertouch"),((10,2),"= spinbox (0,16,1,0,\" \")"),((10,3),"= spinbox (-1,127,1,-1,\" \")"),((10,4),"= spinbox (-1,127,1,-1,\" \")"),((10,5),"= togglebutton (\"Recv\",\"\",true)"),((12,1),"MidiShare Client"),((12,2),"Port"),((12,3),"Channel"),((13,0),">>> Output:"),((13,1),"= outclient_combobox"),((13,2),"= outport_spinbox"),((13,3),"= outchan_spinbox"),((15,0),"= outtaskbutton B14"),((15,1),"Time"),((15,2),"Channel"),((15,3),"Data #1"),((15,4),"Data #2"),((15,5),"= resetbutton D14"),((16,0),"Note On"),((16,2),"= spinbox (0,16,1,D$14,\" \")"),((16,3),"= spinbox (-1,127,1,60,\" \")"),((16,4),"= spinbox (-1,127,1,64,\" \")"),((16,5),"= outsendbutton C$14 (note_on (C17-1) D17 E17)"),((16,6),"= note_name D17"),((17,0),"Note Off"),((17,2),"= spinbox (0,16,1,D$14,\" \")"),((17,3),"= spinbox (-1,127,1,60,\" \")"),((17,4),"= spinbox (-1,127,1,64,\" \")"),((17,5),"= outsendbutton C$14 (note_off (C18-1) D18 E18)"),((17,6),"= note_name D18"),((18,0),"Pitch Wheel"),((18,2),"= spinbox (0,16,1,D$14,\" \")"),((18,3),"= spinbox (-1,127,1,0,\" \")"),((18,4),"= spinbox (-1,127,1,64,\" \")"),((18,5),"= outsendbutton C$14 (pitch_wheel (C19-1) D19 E19)"),((19,0),"Controller"),((19,2),"= spinbox (0,16,1,D$14,\" \")"),((19,3),"= spinbox (-1,127,1,1,\" \")"),((19,4),"= spinbox (-1,127,1,0,\" \")"),((19,5),"= outsendbutton C$14 (ctrl_change (C20-1) D20 E20)"),((20,0),"Program"),((20,2),"= spinbox (0,16,1,D$14,\" \")"),((20,3),"= spinbox (-1,127,1,0,\" \")"),((20,4),"= spinbox (-1,127,1,-1,\" \")"),((20,5),"= outsendbutton C$14 (prog_change (C21-1) D21)"),((21,0),"Aftertouch"),((21,2),"= spinbox (0,16,1,D$14,\" \")"),((21,3),"= spinbox (-1,127,1,0,\" \")"),((21,4),"= spinbox (-1,127,1,-1,\" \")"),((21,5),"= outsendbutton C$14 (chan_press (C22-1) D22)"),((22,0),"Poly Aftertouch"),((22,2),"= spinbox (0,16,1,D$14,\" \")"),((22,3),"= spinbox (-1,127,1,60,\" \")"),((22,4),"= spinbox (-1,127,1,64,\" \")"),((22,5),"= outsendbutton C$14 (key_press (C23-1) D23 E23)")] // [] *************** *** 8,12 **** in qcalc. */ ! import calclib, midi; /* Open MidiShare clients. */ --- 8,12 ---- in qcalc. */ ! import calclib, midi, midiutil; /* Open MidiShare clients. */ *************** *** 16,26 **** _ = midi_connect INREF INREF; - /* Helper function to translate MIDI note numbers to note names. */ - - def NOTE_NAMES = ("C","C#","D","D#","E","F","F#","G","G#","A","Bb","B"); - - note_name N:Int = sprintf "%s%d" (NOTE_NAMES!(N mod 12),N div 12) if N>=0; - note_name _ = "N/A" otherwise; - /* Create and parse numbered client names, to resolve ambiguities. */ --- 16,19 ---- |