-odac -m128 nchnls = 2 ksmps = 128 0dbfs = 1 ;Get the ASCII key number ;Example for CsoundQt ;joachim heintz && andrés cabrera mar 2010 / feb 2011 strset 11, "Thank you!" strset 12, "My goodness!" strset 13, "Oh my god!" strset 14, "Why?" strset 15, "You did what you must." strset 21, "is a very meaningful" strset 22, "is a totally senseless" strset 23, "is a deeply religious" strset 24, "is a rather useless" strset 25, "is a somewhat symbolic" strset 26, "is nothing more than a" strset 27, "is obviously a strange" strset 28, "is an enourmously irrational" seed 0 gicount = 0 gimodel ftgen 0, 0, 32, -2, 1,1,0, .7,2,0, .5,3,0, .3,4,0, .1,5,0, .05,6,0, .02,7,0; partial model opcode TypeIn, 0, k ;displays type-in request konoff xin if konoff == 1 then ktrig metro 1 kplease init 0 if ktrig == 1 then kplease = kplease + 1 endif if kplease % 2 == 1 then outvalue "typein1", "TYPE" else outvalue "typein1", "" endif if kplease % 2 == 0 then outvalue "typein2", "NOW!" else outvalue "typein2", "" endif else outvalue "typein1", "" outvalue "typein2", "" endif endop opcode RandInts_i, i, ii ;random integer between ival1 and ival2 (both included) ival1, ival2 xin if ival1 < ival2 then imin = ival1 imax = ival2 else imin = ival2 imax = ival1 endif imin = (imin < 0 ? imin-0.9999 : imin) imax = (imax < 0 ? imax : imax+0.9999) ires random imin, imax xout int(ires) endop opcode TabMkCp_i, i, i ;creates a function table icop which is a copy of isrc, and returns its number isrc xin isrclen = ftlen(isrc) icop ftgen 0, 0, -isrclen, -2, 0 tableicopy icop, isrc xout icop endop opcode ChangeTable, i, iipo ;copies iftin, changes its value randomly in the range +- iperc percent, and returns it as iftout ;ihop = which is the next element (1=next (= default), 2=the second to come, etc) ;istart = at which index to start (default = 0) iftin, iperc, ihop, istart xin iftout TabMkCp_i iftin indx = istart loop: if indx >= ftlen(iftin)-1 igoto end ival tab_i indx, iftout irand random -iperc, iperc inew = ival + (irand/100) * ival tabw_i inew, indx, iftout indx = indx + ihop igoto loop end: xout iftout endop opcode KeyOnce, kk, kkk ;returns '1' just in the k-cycle a certain key has been pressed (kdown) or released (kup) key, kd, kascii xin ;sensekey output and ascii code of the key (e.g. 32 for space) knew changed key kdown = (key == kascii && knew == 1 && kd == 1 ? 1 : 0) kup = (key == kascii && knew == 1 && kd == 0 ? 1 : 0) xout kdown, kup endop instr 1 ;;GET SPEED AND ESTIMATE THE USER'S AGE kspeed invalue "speed" kyears = 20*kspeed*1.8^kspeed kmonths = 10^kspeed % 12 Sage sprintfk "Age estimated from your speed selection:\n%d years, %d months, %d days.", kyears, kmonths, 10^kspeed % 30 outvalue "age", Sage ;;TURN ON TYPE-IN DISPLAY PROMPT konoff init 1 TypeIn konoff kchr, kkeydown sensekey ;;CALL INSTR 10 IF SOMETHING NEW HAS BEEN TYPED kdwn, k0 KeyOnce kchr, kkeydown, kchr if kchr != 0 && kdwn == 1 then konoff = 0 event "i", 10, 0.1, kspeed*24, kchr endif endin instr 2 ;;CLEAR DISPLAYS WHEN NECESSARY outvalue "thanks", "" outvalue "youtyped", "" outvalue "showchar1", "" outvalue "ascii1", "" outvalue "showascii1", "" outvalue "asyouwill", "" outvalue "showchar2", "" outvalue "isavery", "" outvalue "theby", "" outvalue "showascii2", "" outvalue "isatotally", "" outvalue ".", "" outvalue "!", "" turnoff endin instr 10 event_i "i", 2, 0, .1 ;clear display first ;;GENERATE A NOTE ;PITCH AND ENVELOPE ipch RandInts_i 0, 45; 46 steps per octave ioct RandInts_i 0, 2; 3 octaves ifreq = 200 * 2^ioct * 2^(ipch/46); lowest pitch = 200 Hz iupdown RandInts_i 0, 1; 0 = gliss up, 1 = gliss down iglissrel1 RandInts_i 2, 5 iglissrel = 1/iglissrel1; gliss is 1/2, 1/3, 1/4 or 1/5 higher or lower iglissfreq = (iupdown == 0 ? ifreq + ifreq*iglissrel : ifreq - ifreq*iglissrel) idur = p3 * iglissrel * .2; duration of the tone afreq expseg ifreq, idur, iglissfreq; frequency with glissando ivol1 RandInts_i 2, 5 ivol = 0dbfs/ivol1; volume as 1/2, 1/3, 1/4 or 1/5 0dbfs aenv transeg ivol, idur, -iglissrel, 0, p3-idur, 0, 0; envelope ;;FUNCTION TABLE AND REVERB ipercparts = 50; how many percent maximum change of partials in gimodel ipercstrs = 100; how many percent maximum change of strengths in gimodel iftparts ChangeTable gimodel, ipercparts, 3, 1; change the partial values according to ipercparts iftstrngs ChangeTable iftparts, ipercstrs, 3, 0; change the strenghtes of the partials iftsound ftgen 0, 0, 4096, 34, iftstrngs, 7, 1; calculate the resulting function table asound oscili aenv, afreq, iftsound iromsiz random .5, .9; choose random value for freeverb's roomsize aL, aR freeverb asound, asound, iromsiz, .5; apply reverb outs aL, aR ; send sound out ;;GENERATE IMPORTANT INFORMATION FOR THE USER if gicount == 0 then; at the first time use these values ithanks = 11 isavery = 21 isatotally = 23 else ; at following times use random choices ithanks RandInts_i 11, 15 isavery RandInts_i 21, 28 isatotally RandInts_i 21, 28 endif gicount = gicount + 1; for knowing it's now the second time ichr = p4; ascii code for actual character ispeed = p3/36; speed Schar sprintf "%c", ichr; string with the typed character Sascii sprintf "%d", ichr; string with the ascii code Sthanks strget ithanks Sisavery strget isavery Sisavery strcat Sisavery, " character." Sisatotally strget isatotally if isatotally == isavery then Sisatotally strcat Sisatotally, " number, too." else Sisatotally strcat Sisatotally, " number." endif ;;SHOW SEQUENTIAL OUTPUT ishow = ispeed/4 ;speed of progression ;call i 20 at the different starting times S1 sprintf "i 20 %f 1 1 \"%s\"", ishow, Sthanks S2 sprintf "i 20 %f 1 2 \"\"", ishow*10 S3 sprintf "i 20 %f 1 3 \"%s\"", ishow*20, Schar S4 sprintf "i 20 %f 1 4 \"\"", ishow*35 S5 sprintf "i 20 %f 1 5 \"\"", ishow*50 S6 sprintf "i 20 %f 1 6 \"%s\"", ishow*60, Sascii S7 sprintf "i 20 %f 1 7 \"\"", ishow*65 S8 sprintf "i 20 %f 1 8 \"\"", ishow*90 S9 sprintf "i 20 %f 1 9 \"%s\"", ishow*150, Schar S10 sprintf "i 20 %f 1 10 \"%s\"", ishow*160, Sisavery S11 sprintf "i 20 %f 1 11 \"\"", ishow*180 S12 sprintf "i 20 %f 1 12 \"%s\"", ishow*210, Sascii S13 sprintf "i 20 %f 1 13 \"%s\"", ishow*230, Sisatotally scoreline_i S1 scoreline_i S2 scoreline_i S3 scoreline_i S4 scoreline_i S5 scoreline_i S6 scoreline_i S7 scoreline_i S8 scoreline_i S9 scoreline_i S10 scoreline_i S11 scoreline_i S12 scoreline_i S13 endin instr 20 ;send text ichannel = p4 Stext = p5 if ichannel == 1 then outvalue "thanks", Stext elseif ichannel == 2 then outvalue "youtyped", "You typed the character" elseif ichannel == 3 then outvalue "showchar1", Stext elseif ichannel == 4 then outvalue ".", "." elseif ichannel == 5 then outvalue "ascii1", "The ASCII code of this character is" elseif ichannel == 6 then outvalue "showascii1", Stext elseif ichannel == 7 then outvalue "!", "!" elseif ichannel == 8 then outvalue "asyouwill", "As you will certainly have heard by the unique tone which is presented here for the first time as the result of long research from all times and cultures at least on earth" elseif ichannel == 9 then outvalue "showchar2", Stext elseif ichannel == 10 then outvalue "isavery", Stext elseif ichannel == 11 then outvalue "theby", "The number, which for many reasons is specially related to this character, " elseif ichannel == 12 then outvalue "showascii2", Stext elseif ichannel == 13 then outvalue "isatotally", Stext endif turnoff endin i 2 0 1 i 1 0 36000; spend 10 hours in profund research and listen to the voice of the truth e 335 145 821 593 true 170 170 127 showascii1 359 326 49 33 {a55e0ce0-8c52-4047-bf13-0b1ba20e7fab} true 0 -3 left Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 showchar1 359 288 31 30 {8532d68c-d5df-4af5-b42c-112356c3b1c6} true 0 -3 left Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 typein1 119 184 102 49 {46574579-d664-4984-87d8-c253e399baac} true 0 -3 typein2 223 183 103 49 {87b2b136-82f1-40b7-9039-e8e77395e512} true 0 -3 thanks 62 242 394 33 {0752771e-37c3-49e2-b666-f2b41a1c5bcf} true 0 0 center DejaVu Sans 18 3 0 0 0 255 255 255 noborder 1 1 youtyped 79 290 275 30 {69c3c6d8-c4c0-4b64-a861-35735d0fcae0} true 0 -3 right Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 asyouwill 65 374 391 76 {027dd6d8-79fe-4004-a52b-9205a9a8d176} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 ascii1 82 328 275 30 {1b8bc0dc-fc3c-4f85-b5a0-f041d7b5db79} true 0 -3 right Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 showchar2 96 451 38 30 {3dc69a6f-7567-4667-ad9e-c938ae55d612} true 0 -3 isavery 137 453 275 30 {78ff5969-7917-4dba-afe9-507d6124be33} true 0 -3 isatotally 139 546 275 30 {2b58f46d-0510-439e-a835-9fed0d30f81e} true 0 -3 theby 66 492 382 47 {ca22476a-8dc2-4288-912f-4cfa3cf1eb6f} true 0 -3 showascii2 78 544 59 33 {a9301c1b-f6c8-4a21-af60-f8ee6557ada2} true 0 -3 . 375 290 41 30 {43373687-936d-468d-9260-f7396ab1061c} true 0 -3 left Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 ! 393 328 41 30 {81764181-1f22-48a4-9a9a-293419d282b1} true 0 -3 left Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 49 16 721 41 {041fe329-d209-4e3d-ad7a-56e9abf09631} true 0 -3 center Lucida Grande 22 3 0 0 0 255 255 255 noborder 1 1 48 55 722 58 {6a149d69-516e-49ac-8253-16e048b92ceb} true 0 -3 center Lucida Grande 18 3 0 0 0 255 255 255 noborder 1 1 47 112 724 48 {98fcf679-a848-4a34-996b-9ce180492cb6} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 speed 514 222 259 27 {05335d5c-63bc-43c9-80fb-d041d424167b} true 0 0 0.10000000 2.00000000 0.74555985 lin continuous -1.00000000 false 513 192 260 25 {79ee3261-6f9b-4714-9126-bba72b4d5d3b} true 0 -3 center Lucida Grande 12 3 0 0 0 255 255 255 noborder 1 1 age 514 277 259 97 {e0e9bba2-2adf-4981-af08-9bd45d2be198} true 0 -3 center Lucida Grande 14 3 0 0 0 255 255 255 noborder 1 1 _Play 513 373 261 28 {0ad23d88-6832-4d56-8ca4-b3ecac93a75e} true 0 -3 value 1.00000000 Start / i1 0 10 false false