[q-lang-cvs] qcalc/examples midiio.qcalc, 1.3, 1.4 midiutil.q, 1.1, 1.2
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-26 02:13:36
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv21930/examples Modified Files: midiio.qcalc midiutil.q Log Message: cosmetic changes Index: midiutil.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/examples/midiutil.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** midiutil.q 25 Nov 2007 15:35:17 -0000 1.1 --- midiutil.q 26 Nov 2007 02:13:31 -0000 1.2 *************** *** 2,17 **** --- 2,37 ---- /* Helper functions used in the midiio.qcalc example. */ + /* Translate MidiShare time in msecs to min:sec:msec format. */ + + public timestr MSECS; + /* Translate MIDI note numbers to note and GM percussion names. */ public note_name N, perc_name N; + /* Use note or percussion names, depending on the channel number. */ + + public xnote_name CH N; + /* Translate GM controller and program numbers. */ public ctrl_name N, prog_name N; + /* Translate pitch wheel value. */ + + public pitch_val LSB MSB; + /* Implementation. */ import dict; + timestr MS = sprintf "%d:%02d:%03d" (M,S,MS) + where S = MS div 1000, MS = MS mod 1000, + M = S div 60, S = S mod 60; + + pitch_val LSB:Int MSB:Int + = MSB*128+LSB-8192 if (LSB>=0) and then (MSB>=0); + pitch_val _ _ = "N/A" otherwise; + def NOTE_NAMES = ("C","C#","D","D#","E","F","F#","G","G#","A","Bb","B"); *************** *** 19,22 **** --- 39,45 ---- note_name _ = "N/A" otherwise; + xnote_name 9 N = perc_name N; + xnote_name CH N = note_name N otherwise; + def GMPROG = dict [(0, "Acoustic Grand Piano"), Index: midiio.qcalc =================================================================== RCS file: /cvsroot/q-lang/qcalc/examples/midiio.qcalc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** midiio.qcalc 25 Nov 2007 15:35:17 -0000 1.3 --- midiio.qcalc 26 Nov 2007 02:13:30 -0000 1.4 *************** *** 1,6 **** ! // 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)")] // [] ! // [(0,126),(1,146),(5,83)] // Start of script. Please do not remove this line. --- 1,6 ---- ! // qcalc 1.0, created Mon Nov 26 03:05:30 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 (-1,15,1,-1,\" \")"),((4,3),"= spinbox (-1,127,1,-1,\" \")"),((4,4),"= spinbox (-1,127,1,-1,\" \")"),((4,5),"= togglebutton (\"Recv\",\"\",true)"),((4,6),"= xnote_name C5 D5"),((5,0),"Note Off"),((5,2),"= spinbox (-1,15,1,-1,\" \")"),((5,3),"= spinbox (-1,127,1,-1,\" \")"),((5,4),"= spinbox (-1,127,1,-1,\" \")"),((5,5),"= togglebutton (\"Recv\",\"\",true)"),((5,6),"= xnote_name C6 D6"),((6,0),"Pitch Wheel"),((6,2),"= spinbox (-1,15,1,-1,\" \")"),((6,3),"= spinbox (-1,127,1,-1,\" \")"),((6,4),"= spinbox (-1,127,1,-1,\" \")"),((6,5),"= togglebutton (\"Recv\",\"\",true)"),((6,6),"= pitch_val D7 E7"),((7,0),"Controller"),((7,2),"= spinbox (-1,15,1,-1,\" \")"),((7,3),"= spinbox (-1,127,1,-1,\" \")"),((7,4),"= spinbox (-1,127,1,-1,\" \")"),((7,5),"= togglebutton (\"Recv\",\"\",true)"),((7,6),"= ctrl_name D8"),((8,0),"Program"),((8,2),"= spinbox (-1,15,1,-1,\" \")"),((8,3),"= spinbox (-1,127,1,-1,\" \")"),((8,5),"= togglebutton (\"Recv\",\"\",true)"),((8,6),"= prog_name D9"),((9,0),"Aftertouch"),((9,2),"= spinbox (-1,15,1,-1,\" \")"),((9,3),"= spinbox (-1,127,1,-1,\" \")"),((9,5),"= togglebutton (\"Recv\",\"\",true)"),((10,0),"Poly Aftertouch"),((10,2),"= spinbox (-1,15,1,-1,\" \")"),((10,3),"= spinbox (-1,127,1,-1,\" \")"),((10,4),"= spinbox (-1,127,1,-1,\" \")"),((10,5),"= togglebutton (\"Recv\",\"\",true)"),((10,6),"= xnote_name C11 D11"),((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,15,1,D$14)"),((16,3),"= spinbox (0,127,1,60)"),((16,4),"= spinbox (0,127,1,64)"),((16,5),"= outsendbutton C$14 (note_on C17 D17 E17)"),((16,6),"= xnote_name C17 D17"),((17,0),"Note Off"),((17,2),"= spinbox (0,15,1,D$14)"),((17,3),"= spinbox (0,127,1,60)"),((17,4),"= spinbox (0,127,1,64)"),((17,5),"= outsendbutton C$14 (note_off C18 D18 E18)"),((17,6),"= xnote_name C18 D18"),((18,0),"Pitch Wheel"),((18,2),"= spinbox (0,15,1,D$14)"),((18,3),"= spinbox (0,127,1,0)"),((18,4),"= spinbox (0,127,1,64)"),((18,5),"= outsendbutton C$14 (pitch_wheel C19 D19 E19)"),((18,6),"= pitch_val D19 E19"),((19,0),"Controller"),((19,2),"= spinbox (0,15,1,D$14)"),((19,3),"= spinbox (0,127,1,0)"),((19,4),"= spinbox (0,127,1,0)"),((19,5),"= outsendbutton C$14 (ctrl_change C20 D20 E20)"),((19,6),"= ctrl_name D20"),((20,0),"Program"),((20,2),"= spinbox (0,15,1,D$14)"),((20,3),"= spinbox (0,127,1,0)"),((20,5),"= outsendbutton C$14 (prog_change C21 D21)"),((20,6),"= prog_name D21"),((21,0),"Aftertouch"),((21,2),"= spinbox (0,15,1,D$14)"),((21,3),"= spinbox (0,127,1,0)"),((21,5),"= outsendbutton C$14 (chan_press C22 D22)"),((22,0),"Poly Aftertouch"),((22,2),"= spinbox (0,15,1,D$14)"),((22,3),"= spinbox (0,127,1,60)"),((22,4),"= spinbox (0,127,1,64)"),((22,5),"= outsendbutton C$14 (key_press C23 D23 E23)"),((22,6),"= xnote_name C23 D23")] // [] ! // [(0,126),(1,146),(5,83),(6,185)] // Start of script. Please do not remove this line. *************** *** 38,43 **** outport_spinbox = spinbox (0,255,1,0); ! inchan_spinbox = spinbox (0,16,1,0,"Any"); ! outchan_spinbox = spinbox (1,16,1,1); /* Translate symbolic port and channel names. */ --- 38,43 ---- outport_spinbox = spinbox (0,255,1,0); ! inchan_spinbox = spinbox (-1,15,1,-1,"Any"); ! outchan_spinbox = spinbox (0,15,1,0); /* Translate symbolic port and channel names. */ *************** *** 46,50 **** portno N:Int = N; ! channo "Any" = 0; channo N:Int = N; --- 46,50 ---- portno N:Int = N; ! channo "Any" = -1; channo N:Int = N; *************** *** 52,56 **** clearbutton = actionbutton "Clear" ! (matrix (row+1,1) [[""," "," "," "] : K in [1..7]] || ()); /* Reset the MIDI output area to defaults. */ --- 52,62 ---- clearbutton = actionbutton "Clear" ! (matrix (row+1,1) [[""," "," "," "], ! [""," "," "," "], ! [""," "," "," "], ! [""," "," "," "], ! [""," "," ",""], ! [""," "," ",""], ! [""," "," "," "]] || ()); /* Reset the MIDI output area to defaults. */ *************** *** 60,66 **** ["",CH,60,64], ["",CH,0,64], ! ["",CH,1,0], ! ["",CH,0," "], ! ["",CH,0," "], ["",CH,60,64]] || ()); --- 66,72 ---- ["",CH,60,64], ["",CH,0,64], ! ["",CH,0,0], ! ["",CH,0,""], ! ["",CH,0,""], ["",CH,60,64]] || ()); *************** *** 80,85 **** where IN:Int = client_ref NAME, NAME:String = midi_client_name IN, ! SEM:Semaphore = task_input, (I,J) = index, ! CHAN = CHAN-1; port_filter PORT --- 86,90 ---- where IN:Int = client_ref NAME, NAME:String = midi_client_name IN, ! SEM:Semaphore = task_input, (I,J) = index; port_filter PORT *************** *** 91,97 **** --- 96,108 ---- midi_accept_chan INREF CHAN true if CHAN >= 0; + def IN_T = ref 0; + + delta T0 T = T-T0 if T>=T0 where T0 = get T0; + = delta T0 (T+0x100000000) otherwise; + inprocess F SEM (I,J) IN PORT H:Thread B:Bool = puts "connecting input\n" || midi_connect IN INREF || + IN_T := midi_time || inprocess F SEM (I,J) IN PORT H (get SEM) if B; *************** *** 110,138 **** CONN = midi_connected IN INREF; inprocess F SEM (I,J) IN PORT H:Thread (TIME,note_on CH N V) ! = rowvect (I+1,J+1) [TIME,CH+1,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!0; inprocess F SEM (I,J) IN PORT H:Thread (TIME,note_off CH N V) ! = rowvect (I+2,J+1) [TIME,CH+1,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!1; inprocess F SEM (I,J) IN PORT H:Thread (TIME,pitch_wheel CH LSB MSB) ! = rowvect (I+3,J+1) [TIME,CH+1,LSB,MSB] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!2; inprocess F SEM (I,J) IN PORT H:Thread (TIME,ctrl_change CH N V) ! = rowvect (I+4,J+1) [TIME,CH+1,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!3; inprocess F SEM (I,J) IN PORT H:Thread (TIME,prog_change CH V) ! = rowvect (I+5,J+1) [TIME,CH+1,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!4; inprocess F SEM (I,J) IN PORT H:Thread (TIME,chan_press CH V) ! = rowvect (I+6,J+1) [TIME,CH+1,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!5; inprocess F SEM (I,J) IN PORT H:Thread (TIME,key_press CH N V) ! = rowvect (I+7,J+1) [TIME,CH+1,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!6; --- 121,149 ---- CONN = midi_connected IN INREF; inprocess F SEM (I,J) IN PORT H:Thread (TIME,note_on CH N V) ! = rowvect (I+1,J+1) [timestr (delta IN_T TIME),CH,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!0; inprocess F SEM (I,J) IN PORT H:Thread (TIME,note_off CH N V) ! = rowvect (I+2,J+1) [timestr (delta IN_T TIME),CH,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!1; inprocess F SEM (I,J) IN PORT H:Thread (TIME,pitch_wheel CH LSB MSB) ! = rowvect (I+3,J+1) [timestr (delta IN_T TIME),CH,LSB,MSB] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!2; inprocess F SEM (I,J) IN PORT H:Thread (TIME,ctrl_change CH N V) ! = rowvect (I+4,J+1) [timestr (delta IN_T TIME),CH,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!3; inprocess F SEM (I,J) IN PORT H:Thread (TIME,prog_change CH V) ! = rowvect (I+5,J+1) [timestr (delta IN_T TIME),CH,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!4; inprocess F SEM (I,J) IN PORT H:Thread (TIME,chan_press CH V) ! = rowvect (I+6,J+1) [timestr (delta IN_T TIME),CH,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!5; inprocess F SEM (I,J) IN PORT H:Thread (TIME,key_press CH N V) ! = rowvect (I+7,J+1) [timestr (delta IN_T TIME),CH,N,V] || inprocess F SEM (I,J) IN PORT H (get SEM) if F!6; *************** *** 162,168 **** --- 173,182 ---- SEM:Semaphore = task_input, (I,J) = index; + def OUT_T = ref 0; + outprocess SEM (I,J) OUT B:Bool = puts "connecting output\n" || midi_connect OUTREF OUT || + OUT_T := midi_time || outprocess SEM (I,J) OUT (get SEM) if B; *************** *** 188,191 **** outsend PORT MSG = //printf "%08d %s\n" (TIME,str MSG) || ! setval (row,1) TIME || midi_send OUTREF PORT MSG where TIME = midi_time; --- 202,206 ---- outsend PORT MSG = //printf "%08d %s\n" (TIME,str MSG) || ! setval (row,1) (timestr (delta OUT_T TIME)) || ! midi_send OUTREF PORT MSG where TIME = midi_time; |