[q-lang-cvs] qcalc/examples midiio.qcalc,NONE,1.1
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-22 09:30:21
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv16375/examples Added Files: midiio.qcalc Log Message: added midiio example --- NEW FILE: midiio.qcalc --- // qcalc 1.0, created Thu Nov 22 10:31:16 2007 -*-Q-*- -*- coding: UTF-8 -*- // [((0,1),"MidiShare Client"),((0,2),"Port"),((0,3),"Channel"),((1,0),"Input:"),((1,1),"= client_combobox"),((1,2),"= port_spinbox"),((1,3),"= chan_spinbox"),((3,0),"= midiin_taskbutton B2 C2 D2 F5:F11"),((3,1),"Time"),((3,2),"Channel"),((3,3),"Data #1"),((3,4),"Data #2"),((3,5),"= midiin_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)"),((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)")] // [] // [(0,126),(1,146),(5,83)] // Start of script. Please do not remove this line. import calclib, midi; def MYNAME = "QCalc MIDI I/O", REF = midi_open MYNAME, _ = midi_connect REF REF; 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; make_client_name N = sprintf "%d %s" (N,midi_client_name N); client_ref S = N where N:Int = sscanf S "%d"; client_name S = S where N:Int = sscanf S "%d", S:String = midi_client_name N; client_combobox = combobox $ filter ((<>MYNAME).client_name) $ map make_client_name midi_clients; port_spinbox = spinbox (-1,255,1,-1,"Any"); chan_spinbox = spinbox (0,16,1,0,"Any"); portno "Any" = -1; portno N:Int = N; channo "Any" = 0; channo N:Int = N; midiin_clearbutton = actionbutton "Clear" (matrix (row+1,1) [[""," "," "," "] : K in [1..7]] || ()); midiin_taskbutton NAME:String PORT CHAN F:List = taskbutton "Connect" $ midiin_task NAME (portno PORT) (channo CHAN) (tuple F); midiin_task NAME:String PORT:Int CHAN:Int F:Tuple = printf "opening client #%d %s (port %d, channel %d)\n" (IN,NAME,PORT,CHAN) || midi_connect IN REF || port_filter PORT || chan_filter CHAN || midiin_process F SEM (I,J) IN PORT (thread $ midiin_loop SEM (midi_get REF)) (get SEM) 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 = do (flip (midi_accept_port REF) false) [0..255] || midi_accept_port REF PORT true if PORT >= 0; chan_filter CHAN = do (flip (midi_accept_chan REF) false) [0..15] || midi_accept_chan REF CHAN true if CHAN >= 0; midiin_process F SEM (I,J) IN PORT H:Thread B:Bool = puts "connecting\n" || midi_connect IN REF || midiin_process F SEM (I,J) IN PORT H (get SEM) if B; = puts "disconnecting\n" || midi_disconnect IN REF || midiin_process F SEM (I,J) IN PORT H (get SEM) otherwise; midiin_process F SEM (I,J) IN PORT H:Thread 'X = puts "closing\n" || midi_send REF PORT stop || cancel H || midi_accept_all REF || midi_disconnect IN REF || taskbutton ("Connect",CONN) $ midiin_task NAME (portno PORT) (channo CHAN) F where (_,_,NAME,PORT,CHAN,F) = task_params 'X, CONN = midi_connected IN REF; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,note_on CH N V) = rowvect (I+1,J+1) [TIME,CH+1,N,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!0; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,note_off CH N V) = rowvect (I+2,J+1) [TIME,CH+1,N,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!1; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,pitch_wheel CH LSB MSB) = rowvect (I+3,J+1) [TIME,CH+1,LSB,MSB] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!2; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,ctrl_change CH N V) = rowvect (I+4,J+1) [TIME,CH+1,N,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!3; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,prog_change CH V) = rowvect (I+5,J+1) [TIME,CH+1,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!4; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,key_press CH N V) = rowvect (I+6,J+1) [TIME,CH+1,N,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!5; midiin_process F SEM (I,J) IN PORT H:Thread (TIME,chan_press CH V) = rowvect (I+7,J+1) [TIME,CH+1,V] || midiin_process F SEM (I,J) IN PORT H (get SEM) if F!6; midiin_process F SEM (I,J) IN PORT H:Thread _ = midiin_process F SEM (I,J) IN PORT H (get SEM) otherwise; midiin_loop SEM (_,_,TIME,MSG) = post SEM (TIME,MSG) || //printf "%08d %s\n" (TIME,str MSG) || midiin_loop SEM (midi_get REF); |