;Written by Iain McCurdy, 2010 ; Modified for QuteCsound by René, January 2011. ; Thanks to Andres CABRERA for the mouse channels names. ; Tested on Ubuntu 10.04 with csound-float 5.13.0 and QuteCsound svn rev 817 with "Widgets are an independent window" ON. /* Mouse Keyboard -------------- This csd was originally written for use by someone who only had the use of a head-mouse for music performance. A graphical keyboard is drawn on the screen. Notes are played by moving the mouse over a particular key. As well as activating that note, dynamic control is possible by moving the mouse vertically up the key. As the user moves the mouse right to the very bottom of the key, a modulation effect is also introduced. No clicking is required enabling better timing in performance. The GUI window needs to be in focus for this to work. The user can change the functioning (or non-functioning) of the left click mouse button using the menu Mode. The user can choose between different stereo wav sounds using the browse button within the GUI. Reverb and ping-pong delay effects are provided, the parameters of which the user can change are in the GUI. The mouse relative position is given by the channels _MouseRelX and _MouseRelY. If the windows need to be resized, for example to accomodate use on a netbook, it is mandatory to manually update the values of boxes dimensions and positions in the csd file. Professional head mouse or iris tracking software can be very expensive and requires practice. iNavigate is a free option for Mac OS 10.5 if the user wants to experiment with this approach. */ ;Notes on modifications from original csd: ; No automatic rescale ; Add control widgets in GUI ; reverse volume, upper position is 0.0, bottom position (of black key) is 1.0 ; Replaced audio file by an audio generator ;my flags on Ubuntu: -odac -b1024 -B2048 -+rtaudio=alsa -+rtmidi=null -m0 sr = 44100 ;SAMPLE RATE ksmps = 32 ;NUMBER OF AUDIO SAMPLES IN EACH CONTROL CYCLE nchnls = 2 ;NUMBER OF CHANNELS (2=STEREO) 0dbfs = 1 ;MAXIMUM AMPLITUDE REGARDLESS OF BIT DEPTH gisine ftgen 0,0,4096,10,1 ;A SINE WAVE ;TABLE TO MAP MOUSE LOCATION ALONG THE Y-AXIS TO VARIOUS CONTROL PARAMETERS giampscale ftgen 0,0,1024,7,0,240,1,1024-240,1 gimodscale ftgen 0,0,1024,7,0,600,0,1024-600,1 giLPFscale ftgen 0,0,1024,7,0,800,1,224,1 giOct_White ftgen 0,0,16,-2,7,7,7,7,7,7,7,8,8,8,8,8,8,8,9 ;OCT TABLE FOR WHITES KEYS giSemis_White ftgen 0,0,16,-2,0,2/12,4/12,5/12,7/12,9/12,11/12,0,2/12,4/12,5/12,7/12,9/12,11/12 ;SEMIS TABLE FOR WHITES KEYS zakinit 2,1 ;INITIALISE ZAK SPACE FOR VARIABLE STORAGE instr 1 ;SENSES MOUSE POSITION AND PLAYS SOUND (ALWAYS ON) ktrig metro 10 if ktrig = 1 then kportamento invalue "Portamento" ;TIME IT TAKES TO SLIDE BETWEEN NOTES. TRY VALUES WITHIN THE RANGE 0 - 0.3 kOctaveTrans invalue "Octave" ;THIS DEFINES THE AMOUNT OF TRANSPOSITION IN OCTAVES, IDEALLY THIS SHOULD BE A WHOLE NUMBER, I.E. '1', '0', '-1' ETC. kClick invalue "Mode" ;Click OPTION: ;0 = NO LEFT CLICK IS REQUIRED TO PLAY A NOTE. A NOTE PLAYS CONTINUOUSLY ;1 = IT IS REQUIRED TO LEFT CLICK TO PLAY A NOTE ;2 = LEFT CLICK STOPS A NOTE PLAYING kampport invalue "AmpPort" ;DEFINE AMPLITUDE PORTAMENTO TIME (SMOOTHING) kmodfrq invalue "ModFrq" ;DEFINE MODULATION FREQUENCY (VIBRATO/TREMOLO) kvibdep invalue "VibDep" ;DEFINE MAXIMUM VIBRATO DEPTH (PITCH MODULATION) ktrmdep invalue "TrmDep" ;DEFINE MAXIMUM TREMOLO DEPTH (AMPLITUDE MODULATION) ;GUI FOR INSTR 2, PING PONG DELAY gkDelayTime invalue "DelayTime" ;DELAY TIME IN SECONDS gkReverbMix invalue "ReverbMix" ;AMOUNT OF REVERB. TRY VALUES WITHIN THE RANGE 0-1. 0=NO REVERB, 1=LOTS OF REVERB! gkDelayMix invalue "DelayMix" ;AMOUNT OF DELAY EFFECT. TRY VALUES WITHIN THE RANGE 0-1. 0=NO DELAY, 1=LOTS OF DELAY! endif ;KEYS WIDGETS SIZES AND POSITIONS iy_all = 100 ix_offset = 2 ;White notes iwidth_W = 60 iheight_W = 300 ;ixN_W = ix_offset + (N-1) * iwidth_W ;Black notes iwidth_B = 40 iheight_B = 200 ix1_B = 36 ;upper left corner coordinates ix2_B = 106 ix3_B = 212 ix4_B = 282 ix5_B = 352 ix6_B = 456 ix7_B = 526 ix8_B = 632 ix9_B = 702 ix10_B = 772 ;MOUSE POSITION IN WIDGET PANEL AND SENSE MOUSE LEFT BUTTON krelx invalue "_MouseRelX" krely invalue "_MouseRelY" kb1 invalue "_MouseBut1" ;MOUSE ON KEYBOARD AREA kon_kbd init 0 if (ix_offset <= krelx && krelx <= ix_offset+15*iwidth_W && iy_all <= krely && krely <= iy_all+iheight_W) then kon_kbd = 1 else kon_kbd = 0 endif ky init 1 ;amplitude init ;MOUSE ON A BLACK KEY kon_Black init 0 #define BLACK_KEY(N) #(ix$N_B <= krelx && krelx <= ix$N_B + iwidth_B)# if (iy_all <= krely && krely <= iy_all+iheight_B) then ky = (krely - iy_all)/iheight_B ;amplitude 0 to 1 if $BLACK_KEY(1) then kon_Black = 1 koctave = 7 ksemis = 1/12 elseif $BLACK_KEY(2) then kon_Black = 1 koctave = 7 ksemis = 3/12 elseif $BLACK_KEY(3) then kon_Black = 1 koctave = 7 ksemis = 6/12 elseif $BLACK_KEY(4) then kon_Black = 1 koctave = 7 ksemis = 8/12 elseif $BLACK_KEY(5) then kon_Black = 1 koctave = 7 ksemis = 10/12 elseif $BLACK_KEY(6) then kon_Black = 1 koctave = 8 ksemis = 1/12 elseif $BLACK_KEY(7) then kon_Black = 1 koctave = 8 ksemis = 3/12 elseif $BLACK_KEY(8) then kon_Black = 1 koctave = 8 ksemis = 6/12 elseif $BLACK_KEY(9) then kon_Black = 1 koctave = 8 ksemis = 8/12 elseif $BLACK_KEY(10) then kon_Black = 1 koctave = 8 ksemis = 10/12 else kon_Black = 0 endif else kon_Black = 0 endif ;MOUSE ON A WHITE KEY kon_White init 0 if (kon_kbd = 1 && kon_Black = 0) then kx = krelx - ix_offset kKey = int(kx/iwidth_W) koctave table kKey, giOct_White ksemis table kKey, giSemis_White kon_White = 1 else kon_White = 0 endif kgate = kon_Black + kon_White ;CHECK TO SEE WHICH LEFT CLICK BUTTON MODE HAS BEEN SELECTED AND IMPLEMENT THE APPROPRIATE BEHAVIOUR if kClick=1 then ;IF 'LEFT CLICK ACTIVATES NOTE' MODE HAS BEEN SELECTED... ky1 = ky * kb1 elseif kClick=2 then ;IF 'LEFT CLICK DE-ACTIVATES NOTE' MODE HAS BEEN SELECTED... ky1 = ky * (1-kb1) else ky1 = ky endif ;END OF CONDITIONAL BRANCHING kamp table ky1, giampscale,1 ;CREATE AN AMPLITUDE VALUE ACCORDING TO Y POSITION (ky) ON KEY AND AMPLITUDE SCALING TABLE (giampscale) kamp portk kamp*kgate, kampport ;SMOOTH AMPLITUDE VARIABLE USING portk OPCODE (A KIND OF LOW PASS FILTER FOR K-RATE SIGNALS) koct portk koctave+ksemis+kOctaveTrans, kportamento ;COMBINE OCTAVE, SEMITONES AND TRANSPOSE VALUES AND APPLY PORTAMENTO SMOOTHING kmoddepth table ky1, gimodscale,1 ;CREATE AN MODULATION DEPTH VALUE ACCORDING TO Y POSITION (ky) ON KEY AND MODULATION DEPTH SCALING TABLE (gimodscale) ; kmoddepth portk kmoddepth, kampport ;APPLY PORTAMENTO SMOOTHING kmod oscili kmoddepth, kmodfrq, gisine ;CREATE AN LFO FOR MODULATION koct = koct + (kmod*kvibdep) ;APPLY VIBRATO ktrm oscili ktrmdep*.5*kmoddepth, kmodfrq, gisine ;CREATE TREMOLO LFO ktrm = ktrm+.5 ;ADD OFFSET kfrq = cpsoct(koct) ;CONVERT PITCH IN OCT FORMAT TO Hz aL vco2 kamp*ktrm, kfrq ;CREATE AUDIO SIGNAL (LEFT CHANNEL) USING vco2 OPCODE aR = aL ;COPY AUDIO SIGNAL (RIGHT CHANNEL) rireturn ;RETURN FROM REINITIALISATION PASS kcfoct table ky1, giLPFscale, 1 ;CREATE AN FILTER CUTOFF VALUE (OCT FORMAT) ACCORDING TO Y POSITION (ky) ON KEY AND FILTER CUTOFF SCALING TABLE (giLPFscale) ; kcfoct = (kcfoct*7)+7 ;RE-RANGE AND OFFSET FILTER CUTOFF VALUE kcf = cpsoct(kcfoct) ;CONVERT FROM OCT TO CPS FORMAT kcf portk kcf, kampport ;APPLY PORTAMENTO SMOOTHING aL butlp aL, kcf ;APPLY LOW-PASS FILTERING (LEFT CHANNEL) aR butlp aR, kcf ;APPLY LOW-PASS FILTERING (RIGHT CHANNEL) zawm aL, 1 ;WRITE TO ZAK VARIABLE WITH MIXING (LEFT CHANNEL) zawm aR, 2 ;WRITE TO ZAK VARIABLE WITH MIXING (RIGHT CHANNEL) endin instr 2 ; PING PONG DELAY idlyFB init 0.3 ;DELAY FEEDBACK AMOUNT (0 - 1) iRoomSize init 0.9 ;REVERB ROOM SIZE (0 - 1) iHFDamp init 0.5 ;REVERB HIGH FREQUENCY DAMPING (0 - 1) ainL zar 1 ;READ ZAK AUDIO VARIABLE LEFT CHANNEL (WRITTEN BY INSTR 1) ainR zar 2 ;READ ZAK AUDIO VARIABLE RIGHT CHANNEL (WRITTEN BY INSTR 1) ;LEFT CHANNEL OFFSETTING DELAY (NO FEEDBACK!) aBuffer delayr 2.5 ;INITIALISE DELAY BUFFER aLeftOffset deltap3 gkDelayTime * 0.5 ;READ AUDIO FROM DELAY TAP delayw ainL ;WRITE AUDIO INTO BUFFER ;LEFT CHANNEL DELAY WITH FEEDBACK aBuffer delayr 5.0 ;INITIALISE DELAY BUFFER aDlySigL deltap3 gkDelayTime ;READ AUDIO FROM DELAY TAP delayw aLeftOffset+(aDlySigL*idlyFB) ;WRITE AUDIO INTO BUFFER ;RIGHT CHANNEL DELAY WITH FEEDBACK aBuffer delayr 5.0 ;INITIALISE DELAY BUFFER aDlySigR deltap3 gkDelayTime ;READ AUDIO FROM DELAY TAP delayw ainR+(aDlySigR * idlyFB) ;WRITE AUDIO INTO BUFFER amixL ntrpol ainL, aDlySigL+aLeftOffset, gkDelayMix ;CREATE DRY/WET MIX FOR PING-PONG DELAY (LEFT CHANNEL) amixR ntrpol ainR, aDlySigR, gkDelayMix ;CREATE DRY/WET MIX FOR PING-PONG DELAY (RIGHT CHANNEL) denorm amixL, amixR ;DENORMALIZE BOTH CHANNELS OF AUDIO SIGNAL arvbL, arvbR freeverb amixL, amixR, iRoomSize, iHFDamp , sr ;CREATE REVERB SIGNAL USING freeverb OPCODE amixL ntrpol amixL, arvbL, gkReverbMix ;CREATE A DRY/WET MIX BETWEEN THE DRY AND THE REVERBERATED SIGNAL amixR ntrpol amixR, arvbR, gkReverbMix ;CREATE A DRY/WET MIX BETWEEN THE DRY AND THE REVERBERATED SIGNAL outs amixL, amixR ;SEND DELAY OUTPUT SIGNALS TO THE SPEAKERS zacl 1,2 ;CLEAR ZAK VARIABLES endin ;INSTR | START | DURATION i 1 0 3600 ;SOUND PRODUCING INSTRUMENT i 2 0 3600 ;PING-PONG DELAY AND REVERB 72 179 400 200 true 206 206 206 4 16 220 51 {8696498c-ea5a-4002-80e2-b73942e10bb0} true 0 0 center Liberation Sans 24 3 0 0 0 255 255 255 noborder 1 1 2 100 60 300 {6aa6f818-c40c-4f0d-9eeb-f1c5651e3d6d} true 0 0 62 100 60 300 {3c683070-f695-4af9-94dc-3d7843d19dc8} true 0 0 122 100 60 300 {a6839b00-9350-4dcd-bfd7-a172629ebcec} true 0 0 182 100 60 300 {bae8c0bb-03d2-4099-ae9a-1763d781d57c} true 0 0 242 100 60 300 {b0854f55-06b9-44a8-a514-5209d08553cb} true 0 0 302 100 60 300 {3a09e244-6262-4741-a925-27e139a46cc6} true 0 0 362 100 60 300 {865a22bd-dce9-41c6-80b1-7f22bfee61f8} true 0 0 36 100 40 200 {61df7d9b-ddbd-4811-8759-61f4639750ac} true 0 0 106 100 40 200 {e890b8d8-a231-41b5-aab5-d9e13a2cebca} true 0 0 212 100 40 200 {190d5200-e15a-4f87-8f0a-a276d53b36da} true 0 0 282 100 40 200 {debe3eff-6c42-43e3-824f-121054ff21d5} true 0 0 352 100 40 200 {a999fbb8-a44a-46be-ac45-9be60705c808} true 0 0 422 100 60 300 {8531d8e1-59ea-4580-90aa-ff141d0ae7a7} true 0 0 482 100 60 300 {c1c7c643-fae0-4890-ae3d-35c3ffc3c5e3} true 0 0 542 100 60 300 {72ee5338-4bea-4b3d-bb3b-5316200c87c1} true 0 0 602 100 60 300 {129baaca-2098-4c12-900e-6ab5df07b404} true 0 0 662 100 60 300 {070504c2-573d-45b3-8731-89f35fbfdcfc} true 0 0 722 100 60 300 {222e95a8-b4e9-4ebb-b91b-cf4f7f459805} true 0 0 782 100 60 300 {221b96c6-196d-498d-bd36-3975e0b37406} true 0 0 456 100 40 200 {30ee3225-575a-44d0-affe-c33ae51af772} true 0 0 526 100 40 200 {e4a7a68e-3801-4b25-a5e3-ba23ad91cb4a} true 0 0 632 100 40 200 {bf581f89-a373-4302-ba59-f85e1b2a5519} true 0 0 702 100 40 200 {2f2ed15f-5881-4f06-87db-9547cef44df6} true 0 0 772 100 40 200 {8e09f51b-38bc-4db5-a4d2-bbe4270d2785} true 0 0 2 103 30 25 {08c8594e-6119-4860-b97b-399dba37bdb8} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 39 103 30 25 {217c1815-d9eb-42bc-9957-8e9488917ba5} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 74 103 30 25 {c2eb661f-2add-40a1-b06f-7ef2f78a8721} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 110 103 30 25 {e128fb16-a520-4aba-b8b1-2e7808b1725a} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 142 103 30 25 {5c468762-a4a4-458d-a81e-83927d9fe589} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 180 103 30 25 {0064bc2c-741b-41a5-baa2-bedad6e05ff5} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 216 103 30 25 {85835b5d-70f5-4b94-a732-d3155412686e} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 250 103 30 25 {0fc10f9e-ef64-4bf3-a8c4-d1b4f9c39b52} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 286 103 30 25 {af2b8459-3659-4754-b64b-ead485847f0b} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 320 103 30 25 {dfbf7db5-a784-4e4c-8ab6-fb3e79edae0e} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 356 103 30 25 {0988a89d-8f56-4d4b-9c02-34e81797acdd} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 390 103 30 25 {80a1b6b9-4101-4ce6-a71a-a0f15f0c1286} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 424 103 30 25 {05345e72-1676-41d9-a2fb-5b2812eb7f21} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 460 103 30 25 {c34956f2-6065-4c87-8890-4285b1bf5dd5} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 494 103 30 25 {52c84820-7240-498b-90d4-adad7e1d5ad3} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 530 103 30 25 {b7e7faa7-a237-4186-b5bb-76f2799a0a59} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 566 103 30 25 {e2ae0fef-453c-48f1-ae30-c55063cfebaf} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 600 103 30 25 {2f1f4221-aaff-407a-b530-a071be4b812d} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 636 103 30 25 {e55f4426-29f2-4489-83b2-2daacaa175b3} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 670 103 30 25 {3960d1a8-1746-4dca-919c-52fb88666aaf} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 706 103 30 25 {4b55970e-c2eb-40c1-98f2-4292ba31b81a} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 740 103 30 25 {a74e4583-8792-4e0b-919c-01c8df951efb} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 776 103 30 25 {c53a96ef-aead-4229-b590-a0a13a2004e2} true 0 0 center Liberation Sans 12 3 255 255 255 255 255 255 noborder 1 1 811 103 30 25 {09393dfb-946d-45b5-bccb-4050cc70266d} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 842 100 60 300 {97fad51f-43d9-402f-9ee9-3719368f4927} true 0 0 856 103 30 25 {af5356c7-c699-460f-8a6d-0f0a7421249b} true 0 0 center Liberation Sans 12 3 0 0 0 255 255 255 noborder 1 1 911 100 175 300 {e83a6502-9e63-4273-bb0d-7f85d4801d4a} true 0 0 DelayTime 936 179 50 50 {114527f2-819d-4396-bb21-880970440765} true 0 0 0.01000000 1.00000000 0.60400000 lin continuous 0.01000000 false 922 227 80 25 {5d9d940e-601f-46dc-9990-b81655c3b365} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 ReverbMix 1008 106 50 50 {a13e6afd-891a-44ba-8f51-1dce848cec59} true 0 0 0.00000000 1.00000000 0.37000000 lin continuous 0.01000000 false 994 154 80 25 {1c31572a-567e-41dd-9654-b27cbf41f25a} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Portamento 936 106 50 50 {df7d823a-3705-4cbd-9e18-e9ff989ed8c0} true 0 0 0.00000000 0.30000000 0.03300000 lin continuous 0.01000000 false 922 154 80 25 {6df782a8-2bda-426f-b932-4fdf6fbdaadc} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 DelayMix 1008 179 50 50 {9c253129-851f-4d01-92e2-8f801e008298} true 0 0 0.00000000 1.00000000 0.08000000 lin continuous 0.01000000 false 994 227 80 25 {58836950-bd2d-43a4-893a-34274c1d6d58} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Octave 574 29 52 30 {055c3420-76d2-4887-8639-8aab364c2a29} true 0 0 center Liberation Sans 16 0 0 0 255 255 255 1.00000000 -2 2 false 0 503 32 68 25 {7d941c8e-e8aa-4692-8a56-4c39d8d95630} true 0 0 right Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 Mode 321 29 180 30 {7434b3ae-588c-4d0b-b9e0-e5449428e485} true 0 0 No Click to Play / Stop 0 Left click to Play 1 Left Click to Stop 2 0 false 255 31 68 25 {580d20d9-8d0f-4d73-aeee-57f4a269e33c} true 0 0 right Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 AmpPort 935 250 50 50 {cbd37737-7bab-4ffd-936a-f74fe2c64694} true 0 0 0.00000000 1.00000000 0.04000000 lin continuous 0.01000000 false 922 298 80 25 {11980cb6-4448-43b1-be68-bd43a137da92} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 ModFrq 1008 250 50 50 {eeca5b1a-786e-40f5-b571-7f374793e8fb} true 0 0 0.00000000 10.00000000 5.00000000 lin continuous 0.01000000 false 994 298 80 25 {4626fcd6-d179-450c-be5f-2fd7c2dee3ed} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 VibDep 936 323 50 50 {769d9e20-1c87-4945-9d16-728abe2209a3} true 0 0 0.00000000 1.00000000 0.02000000 lin continuous 0.01000000 false 922 371 80 25 {dac0dced-1a75-42e7-977d-5ff5a95bb0f1} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1 TrmDep 1008 323 50 50 {49b664f1-8bdf-4356-b278-82f7ae912c4c} true 0 0 0.00000000 1.00000000 0.20000000 lin continuous 0.01000000 false 994 371 80 25 {9606d7a3-3923-47e2-b3ef-d8acbdcccb40} true 0 0 center Liberation Sans 10 3 0 0 0 255 255 255 noborder 1 1