--midi-key=4 --midi-velocity-amp=5 -m128 --env:SSDIR+=../../SourceMaterials /***Imitative Additive Synthesis***/ ;example for CsoundQt ;joachim heintz mar 2011 sr = 44100 ksmps = 128 nchnls = 1 0dbfs = 1 ;============================================================================; ;============================================================================; ; GENERAL VALUES FOR FOURIER TRANSFORMATION ; ;============================================================================; ;============================================================================; gifftsiz = 1024 ;fft size giovlap = gifftsiz / 4 ;overlap giwinsiz = gifftsiz * 2 ;window size giwintyp = 1 ;von hann window giamps ftgen 0, 0, gifftsiz/2+1, 2, 0 ;table for bin amps giampcpy ftgen 0, 0, gifftsiz/2+1, 2, 0 ;needed for the TabIndxNMax_k opcode gifreqs ftgen 0, 0, gifftsiz/2+1, 2, 0 ;table for bin freqs gimaxindc ftgen 0, 0, gifftsiz/2+1, 2, 0 ;indices for temporal maxima of giamps gisine ftgen 0, 0, 2^10, 10, 1 massign 0, 10 ;send all midi key events to instr 10 chn_S "_MBrowse", 1 ;declare string channel ;============================================================================; ;============================================================================; ; FUNCTIONS (USER DEFINED OPCODES) ; ;============================================================================; ;============================================================================; ;OPCODES FOR USING STRINGS AS ARRAYS ;(see http://www.csounds.com/journal/issue13/StringsAsArrays.html) opcode StrayGetEl, ii, Sijj ;returns the startindex and the endindex (= the first space after the element) for ielindex in String. if startindex returns -1, the element has not been found Stray, ielindx, isepA, isepB xin ;DEFINE THE SEPARATORS isep1 = (isepA == -1 ? 32 : isepA) isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB)) Sep1 sprintf "%c", isep1 Sep2 sprintf "%c", isep2 ;INITIALIZE SOME PARAMETERS ilen strlen Stray istartsel = -1; startindex for searched element iendsel = -1; endindex for searched element iel = 0; actual number of element while searching iwarleer = 1 indx = 0 if ilen == 0 igoto end ;don't go into the loop if Stray is empty loop: Snext strsub Stray, indx, indx+1; next sign isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1 isep2p strcmp Snext, Sep2; 0 if Snext is sep2 ;NEXT SIGN IS NOT SEP1 NOR SEP2 if isep1p != 0 && isep2p != 0 then if iwarleer == 1 then; first character after a separator if iel == ielindx then; if searched element index istartsel = indx; set it iwarleer = 0 else ;if not searched element index iel = iel+1; increase it iwarleer = 0; log that it's not a separator endif endif ;NEXT SIGN IS SEP1 OR SEP2 else if istartsel > -1 then; if this is first selector after searched element iendsel = indx; set iendsel igoto end ;break else iwarleer = 1 endif endif loop_lt indx, 1, ilen, loop end: xout istartsel, iendsel endop opcode StrayLen, i, Sjj ;returns the number of elements in Stray. elements are defined by two separators as ASCII coded characters: isep1 defaults to 32 (= space), isep2 defaults to 9 (= tab). if just one separator is used, isep2 equals isep1 Stray, isepA, isepB xin ;DEFINE THE SEPARATORS isep1 = (isepA == -1 ? 32 : isepA) isep2 = (isepA == -1 && isepB == -1 ? 9 : (isepB == -1 ? isep1 : isepB)) Sep1 sprintf "%c", isep1 Sep2 sprintf "%c", isep2 ;INITIALIZE SOME PARAMETERS ilen strlen Stray icount = 0; number of elements iwarsep = 1 indx = 0 if ilen == 0 igoto end ;don't go into the loop if String is empty loop: Snext strsub Stray, indx, indx+1; next sign isep1p strcmp Snext, Sep1; returns 0 if Snext is sep1 isep2p strcmp Snext, Sep2; 0 if Snext is sep2 if isep1p == 0 || isep2p == 0 then; if sep1 or sep2 iwarsep = 1; tell the log so else ; if not if iwarsep == 1 then ; and has been sep1 or sep2 before icount = icount + 1; increase counter iwarsep = 0; and tell you are ot sep1 nor sep2 endif endif loop_lt indx, 1, ilen, loop end: xout icount endop ;OPCODES FOR TABLE OPERATIONS opcode TabMinVal_k, k, ii ift, iftlen xin kminval tab 0, ift kndx = 1 loop: kval tab kndx, ift kmaxval = (kval < kminval ? kval : kminval) loop_lt kndx, 1, iftlen, loop xout kminval endop opcode TabMaxValIndx_k, kk, iikk ;returns the maximum value of a function table and its index ift, iftlen, kstrt, kshft xin; ftable, length, startindex, how many values to shift for the next value kndx = kstrt kresultindx = kstrt kresultval tab kstrt, ift; first value in the table as comparision loop: kval tab kndx, ift if kval > kresultval then kresultindx = kndx kresultval = kval endif loop_lt kndx, kshft, iftlen, loop xout kresultval, kresultindx endop opcode TabIndxNMax_k, 0, iiiik ;returns the indices of the first khowmany largest values in iftsrc and writes them in iftdest ;bin 0 is omitted (shift value in TabMaxValIndx_k) iftsrc, isrclen, iftcpy, iftdest, khowmany xin tablecopy iftcpy, iftsrc ;leave iftsrc (= amp table) untouched kmin TabMinVal_k iftcpy, isrclen; smallest value in iftsrc kwritindx = 0 loop: kval, kndx TabMaxValIndx_k iftcpy, isrclen, 1, 1; gets index for maximum tabw kmin-1, kndx, iftcpy ;replace this maximum by kmin-1 tabw kndx, kwritindx, iftdest ;write the index to index table loop_lt kwritindx, 1, khowmany, loop endop ;MISCELLANEOUS opcode BufPlay1, a, ii ifn, iskip xin icps = 1 / (ftlen(ifn) / ftsr(ifn)) iphs = iskip / (ftlen(ifn) / ftsr(ifn)) asig poscil3 1, icps, ifn, iphs xout asig endop opcode Stayed, k, kk ;outputs 1 if kin has not changed since ksec seconds, otherwise outputs 0 kin, ksec xin kout init 0 knumk = ksec * kr ;number of control cycles for ksec kinit init 1 kcount init 0 if kinit == 1 then ;just once, at the beginning kprevious = kin kinit = 0 endif if kin == kprevious then kcount = kcount + 1 else kcount = 0 kprevious = kin endif if kcount > knumk then kout = 1 else kout = 0 endif xout kout endop opcode ShowLED_a, 0, Sakkk ;Shows an audio signal in an outvalue channel. You can choose to show the value in dB or in raw amplitudes. ;Soutchan: string with the name of the outvalue channel ;asig: audio signal which is to displayed ;kdispfreq: refresh frequency (Hz) ;kdb: 1 = show in dB, 0 = show in raw amplitudes (both in the range 0-1) ;kdbrange: if idb=1: how many db-steps are shown (e.g. if 36 you will not see anything from a signal below -36 dB) Soutchan, asig, kdispfreq, kdb, kdbrange xin kdispval max_k asig, kdispfreq, 1 if kdb != 0 then kdb = dbfsamp(kdispval) kval = (kdbrange + kdb) / kdbrange else kval = kdispval endif outvalue Soutchan, kval endop opcode ShowOver_a, 0, Sakk ;Shows if the incoming audio signal was more than 1 and stays there for some time ;Soutchan: string with the name of the outvalue channel ;asig: audio signal which is to displayed ;kdispfreq: refresh frequency (Hz) ;khold: time in seconds to "hold the red light" Soutchan, asig, kdispfreq, khold xin kon init 0 ktim times kstart init 0 kend init 0 khold = (khold < .01 ? .01 : khold) ;avoiding too short hold times kmax max_k asig/0dbfs, kdispfreq, 1 if kon == 0 && kmax > 1 then kstart = ktim kend = kstart + khold outvalue Soutchan, kmax kon = 1 endif if kon == 1 && ktim > kend then outvalue Soutchan, 0 kon = 0 endif endop ;============================================================================; ;============================================================================; ; INSTRUMENT BLOCKS ; ;============================================================================; ;============================================================================; instr 1 ;always on turnon 999 ;monitoring the audio output ;============================================================================; ; RECEIVING USER INPUT FROM THE WIDGET PANEL ; ;============================================================================; ;INPUT TO BE ANALYZED Sfiles chnget "_MBrowse" ;selection of sound files kinch invalue "inch" ;number of live input channel kgain invalue "gain" ;live input gain (dB) kselsamp invalue "sample" ;1 = select sample input gksampnr invalue "sampnr" ;1, 2, ... for selecting a sample from the sf bank keysel invalue "keysel" ;1=enable selection of sample by computer number keys ksellive invalue "live" ;1 = select live input kdolive invalue "dolive" ;when button pressed, live input to be analyzed ;ANALYSIS PARAMETERS kpos invalue "pos" ;position in buffer (0-1) kfast invalue "fast" ;how fast to react to position changes (sec) kpartsana invalue "numpartsana" ;number of strongest partials to analyze kmanpos invalue "manpos" ;manually selected position krandpos invalue "randpos" ;random position selected krndpos1 invalue "rndpos1" ;lower limit for random pointer (0-1) krndpos2 invalue "rndpos2" ;upper limit for random pointer (0-1) khopmove invalue "hopmove" ;hop move selected khopmvsiz invalue "hopmovsiz" ;size of hopping in fractions of the table ;PLAYBACK PARAMETERS gkvol invalue "vol" ;overall volume (dB) gkmaxdur invalue "maxdur" ;maximum duration of a note in seconds gkhowmany invalue "numpartspl" ;how many partials to be played back gkshiftpl invalue "shiftpl" ;number of strongest partials to skip for playback gkrefpch invalue "refpch" ;midi note number for playing at original pitch gkstcent invalue "stcent" ;how many cents to transpose for adjacent semitones on the midi keyboard gkrndfqdv invalue "rndfqdv" ;maximal partial random frequency deviation (cent) gkrdampdv invalue "rndampdv" ;maximal partial random amplitude deviation (dB) gkrddurdv invalue "rnddurdv" ;maximal partial random duration deviation (%) gkatt invalue "att" ;attack time (sec) gkdec invalue "dec" ;decay time (sec) gksus invalue "sus" ;sustain level (0-1) gkrel invalue "rel" ;release time (sec) ;PRINT AND EXPORT kprint invalue "print" ;1 = print current values kexp1 invalue "exp1" ;export printout gSfexp1 invalue "_Browse1" ;file for printout export kexp2 invalue "exp2" ;export amp-freq gSfexp2 invalue "_Browse2" ;file for amp-freq export kexp3 invalue "exp3" ;export as tables with multipliers gSfexp3 invalue "_Browse3" ;file for table multiplier export ;REGULATING THE SWITCH BETWEEN CERTAIN BUTTONS ;analysis source ksllivnew changed ksellive kslsmpnew changed kselsamp if kslsmpnew == 1 && kselsamp == 1 then outvalue "live", 0 elseif ksllivnew == 1 && ksellive == 1 then outvalue "sample", 0 endif ;pointer method kmnposnew changed kmanpos krdposnew changed krandpos khopmvnew changed khopmove if kmnposnew == 1 && kmanpos == 1 then outvalue "randpos", 0 outvalue "hopmove", 0 elseif krdposnew == 1 && krandpos == 1 then outvalue "manpos", 0 outvalue "hopmove", 0 knewrdpos = 1 elseif khopmvnew == 1 && khopmove == 1 then outvalue "manpos", 0 outvalue "randpos", 0 knewhpmv = 1 endif ;CALCULATING A NEW POSITION IF RANDOM OR HOPMOVE SELECTED ;if note-on message has been received kst,k0,k0,k0 midiin if kst == 144 then ;calculate new random position if selected if krandpos == 1 then kpos random krndpos1, krndpos2 outvalue "pos", kpos knewrdpos = 1 ;calculate new hop position if selected elseif khopmove == 1 then kpos = frac(kpos+khopmvsiz) kpos = (kpos < 0 ? 1-kpos : kpos) outvalue "pos", kpos knewhpmv = 1 endif endif ;ENABLE COMPUTER KEYS FOR SWITCHING if keysel == 1 then key,k0 sensekey keychange changed key if keychange == 1 && k0 == 1 then ;new key down if key > 47 && key < 58 then ;number keys 0-9 event "i", 3, 0, .1, key elseif key == 112 || key == 114 || key == 104 then ;p/r/h event "i", 4, 0, .1, key elseif key == 115 || key == 108 then ;s/l event "i", 5, 0, .1, key endif endif endif ;============================================================================; ; SETTING SOME BASIC VALUES ; ;============================================================================; iftdatlen = ftlen(giamps) ;length of amp/freq tables iftmaxlen = ftlen(gimaxindc) ;length of maxima table kwritten init 0 ;1 = having written new values in giamps/gifreqs kwritliv init 0 ;write the fft-analysis of the live signal ... kwritsmp init 0 ;... or of the selected sample position to the tables ;============================================================================; ; LOADING INPUT FILES AND CALCULATING POINTER POSITION ; ;============================================================================; ;LOADING THE SELECTED FILES IN FUNCTION TABLES 1, 2, ... AND STORING SF LENGTHS inumfils StrayLen Sfiles, 124 ;how many files (separated by '|') to load giftsflns ftgen 0, 0, -inumfils, -2, 0 ;empty table for sound file lenghths iload = 0 load: ist, ien StrayGetEl Sfiles, iload, 124 Sfil strsub Sfiles, ist, ien inoth ftgen iload+1, 0, 0, 1, Sfil, 0, 0, 1 ;storing sf data in table 1, 2, ... ilen filelen Sfil tabw_i ilen, iload, giftsflns ;storing sf lenghts in table giftsflns loop_lt iload, 1, inumfils, load ;CALCULATING AND SHOWING THE POSITION OF THE POINTER kthissamp = (gksampnr > inumfils ? inumfils : gksampnr) kfilen tab kthissamp-1, giftsflns kpossec = kpos * kfilen ;position in sec outvalue "position", kpossec ;SHOWING WHENEVER A NEW SAMPLE HAS BEEN SELECTED newfile: itable = i(kthissamp) ist, ien StrayGetEl Sfiles, itable-1, 124 Sfil strsub Sfiles, ist, ien ilslash strrindex Sfil, "/" Sname strsub Sfil, ilslash+1 Showname sprintf "File selected:\n'%s'", Sname rireturn knewtable changed kthissamp if knewtable == 1 then reinit newfile outvalue "showname", Showname outvalue "showtab", -kthissamp endif ;============================================================================; ; RECEIVING LIVE INPUT ; ;============================================================================; ain inch kinch ain = ain*ampdb(kgain) kdisp metro 10 ShowLED_a "livein", ain, kdisp, 1, 50 ShowOver_a "livein_over", ain, kdisp, 1 ;============================================================================; ; CONTINUOUSLY STREAMING FFT SIGNALS FROM LIVE AND FROM THE SELECTED SAMPLE ; ;============================================================================; ;STREAMING THE FFT LIVE SIGNAL flive pvsanal ain, gifftsiz, giovlap, giwinsiz, giwintyp ;STREAMING THE FFT SIGNAL FROM THE SELECTED SAMPLE WHENEVER A NEW POSITION IS GIVEN knewpos changed kpos, kthissamp, kslsmpnew, kmnposnew, krdposnew, khopmvnew if knewpos == 1 then reinit readsampnew endif readsampnew: fsamp pvstanal 0, 1, 1, kthissamp, 0, 0, i(kpossec), gifftsiz, giovlap, 0 rireturn ;============================================================================; ; SELECT INPUT AND SET VARIABLES FOR WRITING THE TABLES ; ;============================================================================; ;SET kwritliv=1 IN THE k-CYCLE THE "dolive" BUTTON HAS BEEN PRESSED if ksellive == 1 then ;live source must be selected klivenew changed kdolive if klivenew == 1 && kdolive == 1 then kwritliv = 1 endif ;SET writesamp=1 IF A NEW POINTER POSITION HAS BEEN SET, ;SELECTOR HAS CHANGED OR BUTTON HAS BEEN SWITCHED elseif kselsamp == 1 then ;sample source selected ;manual position if kmanpos == 1 then kpstayed Stayed kpos, kfast ;returns 1 if pos has not changed for kfast seconds knewpos changed kpstayed if (knewpos == 1 && kpstayed == 1) || knewtable == 1 || kslsmpnew == 1 then kwritsmp = 1 endif ;random position elseif knewrdpos == 1 then kwritsmp = 1 ;hop position elseif knewhpmv == 1 then kwritsmp = 1 endif endif ;============================================================================; ; FILL THE TABLES WITH THE CURRENT AMPLTITUDE/FREQUENCY VALUES ; ;============================================================================; ;INITIALIZE COUNTERS ksmpcnt init 0 klivcnt init 0 ;LIVE INPUT SELECTED if kwritliv == 1 then kwritten pvsftw flive, giamps, gifreqs if kwritten == 1 then klivcnt = klivcnt + 1 printks " New live values written! (%d)\n", 0, klivcnt kwritliv = 0 endif ;SOUND FILE INPUT SELECTED elseif kwritsmp == 1 then kwritten pvsftw fsamp, giamps, gifreqs if kwritten == 1 then ksmpcnt = ksmpcnt + 1 printks " New sample values written (%d)!\n", 0, ksmpcnt kwritsmp = 0 knewrdpos = 0 knewhpmv = 0 endif endif ;================================================================================; ;ANALYZE BIN AMPLITUDES AND FILL INDEX-TABLE IF AMP/FREQ-TABLES HAVE BEEN UPDATED; ;================================================================================; if kwritten == 1 then ;writing via pvsftw has been finished TabIndxNMax_k giamps, iftdatlen, giampcpy, gimaxindc, kpartsana gkthsnman = kpartsana ;number of partials in this analysis ;============================================================================; ; PRINT VALUES IF DESIRED AND IF NEW VALUES AVAILABLE ; ;============================================================================; if kprint == 1 && kwritten == 1 then kprntndx = 0 if kselsamp == 1 then Sprint sprintfk "File '%s' at position %f seconds:\n", Sname, kpossec elseif ksellive == 1 then Sprint sprintfk "%s\n", "Live input:" else Sprint = "" endif printout: ktabindx tab kprntndx, gimaxindc kamp tab ktabindx, giamps kfreq tab ktabindx, gifreqs Snew sprintfk "%s%.2d) amp = %f, freq = %f, bin = %d\n", Sprint, kprntndx+1, kamp, kfreq, ktabindx Sprint strcpyk Snew loop_lt kprntndx, 1, kpartsana, printout outvalue "values", Sprint gSexpt1 strcpyk Sprint else outvalue "values", "" endif endif ;============================================================================; ; EXPORT VALUES IF DESIRED ; ;============================================================================; kexp1new changed kexp1 kexp2new changed kexp2 kexp3new changed kexp3 ;EXPORT IN THE SAME FORMAT AS IN THE WIDGET PANEL if kexp1new == 1 && kexp1 == 1 then event "i", 6, 0, .1 ;EXPORT AS RAW AMP-FREQ PAIR PER LINE elseif kexp2new == 1 && kexp2 == 1 then kexpt2ndx = 0 if kselsamp == 1 then gSexpt2 sprintfk "Amp-Freq values for file '%s' at position %f seconds:\n", Sname, kpossec elseif ksellive == 1 then gSexpt2 sprintfk "%s\n", "Amp-Freq values for live input:" endif expt2: ktabindx tab kexpt2ndx, gimaxindc kamp tab ktabindx, giamps kfreq tab ktabindx, gifreqs Snew sprintfk "%s%f %f\n", gSexpt2, kamp, kfreq gSexpt2 strcpyk Snew loop_lt kexpt2ndx, 1, kpartsana, expt2 event "i", 7, 0, .1 ;EXPORT AS MULTIPLIERS IN FUNCTION TABLES elseif kexp3new == 1 && kexp3 == 1 then kexpt3cnt init 0 ;counter kexpt3cnt = kexpt3cnt+1 ;get reference frequency for frequency multiplier = 1 ktabindx tab 0, gimaxindc kfreq0 tab ktabindx, gifreqs ;frequency corresponding to strongest amplitude if kselsamp == 1 then Sexpt3 sprintfk "Amp-Freq multiplier for file '%s' at position %f seconds.\nPitch at frequency multiplier 1 was %f Hz.\n", Sname, kpossec, kfreq0 elseif ksellive == 1 then Sexpt3 sprintfk "Amp-Freq multiplier for live input.\nPitch at frequency multiplier 1 was %f Hz.\n", kfreq0 endif Samptab sprintfk "giAmp%d ftgen 0, 0, -%d, -2", kexpt3cnt, kpartsana Sfreqtab sprintfk "giFreq%d ftgen 0, 0, -%d, -2", kexpt3cnt, kpartsana kexpt3ndx = 0 expt3: ktabindx tab kexpt3ndx, gimaxindc kamp tab ktabindx, giamps kfreq tab ktabindx, gifreqs kfmult = kfreq/kfreq0 Snewamp sprintfk "%s, %f", Samptab, kamp Snewfreq sprintfk "%s, %f", Sfreqtab, kfmult Samptab strcpyk Snewamp Sfreqtab strcpyk Snewfreq loop_lt kexpt3ndx, 1, kpartsana, expt3 gSexpt3 sprintfk "%s%s\n%s\n\n", Sexpt3, Samptab, Sfreqtab event "i", 8, 0, .1 endif kwritten = 0 ;reset kwritten at the end of each k-cycle endin ;============================================================================; ; SUBINSTRUMENT FOR LISTENING TO THE SELECTED SAMPLE ; ;============================================================================; instr 2 itab = i(gksampnr) ;number of ftable (1, 2, ...) idur tab_i itab-1, giftsflns ;get length of sample p3 = idur aout poscil3 1, 1/p3, itab out aout*ampdb(gkvol) endin ;============================================================================; ; SUBINSTRUMENTS FOR PERFORMING ACTIONS BY COMPUTER KEYBOARD SHORTCUTS ; ;============================================================================; ;MAKE LIVE SNAPSHOT AND CHANGE THE SAMPLE NUMBER instr 3 ikey = p4 ;48-57 kcyc timeinstk if ikey == 48 then outvalue "dolive", 1 else outvalue "sampnr", ikey-48 endif if kcyc == 2 then outvalue "dolive", 0 turnoff endif endin ;CHANGE THE POINTER MODE instr 4 ikey = p4 if ikey == 112 then ;p = manual pointer outvalue "manpos", 1 elseif ikey == 114 then ;r = random pointer outvalue "randpos", 1 elseif ikey == 104 then ;h = hop move outvalue "hopmove", 1 endif turnoff endin ;SWITCH BETWEEN SAMPLE/LIVE MODE instr 5 ikey = p4 if ikey == 115 then ;s = sample as input outvalue "sample", 1 elseif ikey == 108 then ;l = live input outvalue "live", 1 endif turnoff endin ;============================================================================; ; SUBINSTRUMENTS FOR WRITING VALUES TO THE EXPORT TEXTFILE ; ;============================================================================; ;ADD VALUES IN THE SAME FORMAT AS IN THE WIDGET PANEL TO THE APPROPRIATE FILE instr 6 fprints gSfexp1, gSexpt1 fprints gSfexp1, "%n" printf_i "Values written to file '%s'\n", 1, gSfexp1 turnoff endin ;ADD VALUES AS RAW AMP-FREQ PAIRS TO THE APPROPRIATE FILE instr 7 fprints gSfexp2, gSexpt2 fprints gSfexp2, "%n" printf_i "Values written to file '%s'\n", 1, gSfexp2 turnoff endin ;ADD VALUES AS AMP-FREQ MULTIPLIERS TO THE APPROPRIATE FILE instr 8 fprints gSfexp3, gSexpt3 printf_i "Values written to file '%s'\n", 1, gSfexp3 turnoff endin ;============================================================================; ; SUBINSTRUMENTS FOR TERMINATING THE SAMPLE LISTENING ; ;============================================================================; instr 9 turnoff2 2, 0, 0 endin ;============================================================================; ;============================================================================; ; MIDI-TRIGGERED INSTRUMENT FOR THE ADDITIVE SYNTHESIS ; ;============================================================================; ;============================================================================; instr 10 ;============================================================================; ; RECEIVING BASIC VALUES ; ;============================================================================; inote = p4 ;midi note number imidamp = p5 ;midi velocity (0-1) insnum = 100 + (inote/100) ;fractional number to differentiate keys irefpch = i(gkrefpch) istcent = i(gkstcent) ;cent difference for each semitone icentdif = (inote-irefpch) * istcent ihowmany = i(gkhowmany) ishift = i(gkshiftpl) imax = i(gkthsnman) ;number of partials analyzed ihowmany = (ihowmany+ishift > imax ? imax-ishift : ihowmany) imaxdur = i(gkmaxdur) ;maximum duration for one note (sec) irndampdv = i(gkrdampdv) ;max amp deviation (dB) irndfqdv = i(gkrndfqdv) ;max freq deviation (cent) irnddurdv = i(gkrddurdv) ;max dur deviation (%) ivol = i(gkvol) ;overall volume (dB) idur = i(gkmaxdur) ;duration of each note (without random deviations) idur = (idur < 0.1) ? 0.1 : idur ;make sure there will not be zero duration ;============================================================================; ; GETTING THE SUM OF ALL SELECTED AMPLITUDES FOR SCALING ; ;============================================================================; indx = ishift iampsum = 0 loop1: itabindx tab_i indx, gimaxindc ;bekommt index für stärkste, zweitstärkste usw amp aus gimaxindc iamp tab_i itabindx, giamps ;get 1., 2., etc strongest amps iampsum = iampsum + iamp loop_lt indx, 1, ihowmany+ishift, loop1 indx = ishift ;============================================================================; ; TRIGGERING THE INSTANCES OF THE SUBINSTRUMENT FOR PLAYING THE PARTIALS ; ;============================================================================; loop2: ;AMPLITUDES itabindx tab_i indx, gimaxindc ;get index for ordered amps from gimaxindc iptamp tab_i itabindx, giamps ;get 1., 2., etc strongest amps iptamp = iptamp * imidamp ;following midi velocity iptdbvar rnd31 irndampdv, 0 ;dB deviation iptamp = ampdb(ivol) * iptamp * ampdb(iptdbvar) ;resulting amp ;FREQUENCIES iptfq tab_i itabindx, gifreqs ;get related freq to selected amp iptfq = cent(icentdif) * iptfq ;transposed depending on key pressed iptfqvar rnd31 irndfqdv, 0 ;cent deviation iptfq = iptfq * cent(iptfqvar) ;DURATIONS iptdurvar rnd31 irnddurdv, 0 ;percent of duration deviation (100=twice,-100=half as long) iptdur = idur * 2^(iptdurvar/100) event_i "i", insnum, 0, iptdur, iptamp, iptfq, iampsum ;call instr 100.nn loop_lt indx, 1, ihowmany+ishift, loop2 ;============================================================================; ; STOPPING THE INSTANCES OF THE SUBINSTRUMENT IF MIDI-KEY HAS BEEN RAISED ; ;============================================================================; krel release if krel == 1 then turnoff2 insnum, 4, 1 endif endin ;============================================================================; ; SUBINSTRUMENT FOR PLAYING ONE PARTIAL ; ;============================================================================; instr 100 ;GET VALUES FROM INSTR 10 AND FROM WIDGETS iamp = p4 ifreq = p5 iampsum = p6 iatt = i(gkatt) idec = i(gkdec) isus = i(gksus) irel = i(gkrel) ;PLAY A SINE WITH ADSR ENVELOPE apart poscil iamp, ifreq, gisine aenv madsr iatt, idec, isus, irel out apart*aenv/iampsum endin ;============================================================================; ; COLLECTING ALL OUTGOING AUDIO AND SENDING IT TO THE METER DISPLAY ; ;============================================================================; instr 999 ktrigdisp metro 10 aout monitor ShowLED_a "out", aout, ktrigdisp, 1, 48 ShowOver_a "out_over", aout, ktrigdisp, 2 endin i 1 0 36000 15 69 1350 659 true 170 170 127 button1 874 591 100 30 {202c13fc-5d88-4826-a232-0e263bb5b119} true 0 0 event 1.00000000 play! / i 10 0 5 60 .5 false false false 10 734 71 247 262 {fe6e4eec-d24b-4130-ac47-0509d6087482} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 268 335 247 171 {ef6762d2-df69-49d4-b2de-79768f36a0e9} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 522 335 228 291 {3cfa2bba-4cba-4506-8dd0-a2cf8cba83cc} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 756 335 225 147 {cd6f814b-6ee2-4dae-aca2-e003f0930179} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 769 584 107 42 {651e302b-ea78-4453-8d18-a8df59faf558} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 268 508 247 118 {ad09a76a-5d31-4cc9-a269-5668506ed9cb} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 756 485 225 99 {732add43-b213-4020-acb2-56175ca913dc} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 9 13 1299 49 {9705422d-67f5-4b92-b66a-cdadf1801e9f} true 0 0 center top Arial 40 3 0 0 0 255 255 255 noborder 1 0 10 221 255 405 {d56a8527-e63b-4d47-9cfc-2f4d90bdcb24} true 0 0 left top Liberation Sans 10 3 0 0 0 255 255 255 true 1 1 values 995 119 312 502 {104a6eb1-9c4e-4dc2-85c7-a27518fe09b3} true 0 0 left top Arial 12 3 0 0 0 255 255 255 noborder 1 0 990 70 319 556 {404b0422-2cbd-4c4a-9433-a4e9c805789c} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 livein 861 180 92 20 {aea96bd2-66c8-46ed-ba64-42a9b473cfbc} true 0 0 livein 0.00000000 1.00000000 0.00000000 1.00000000 0.25549939 0.25549939 fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true livein_over 947 180 20 20 {714f538d-b15d-450f-8243-f731e47cec08} true 0 0 livein_over 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 fill 1 0.00000000 jump noborder #00FF00 255 0 0 false 0 0 0 true gain 861 205 80 20 {a2a3113b-ea7c-4113-8aa5-22318f22d899} true 0 0 -12.00000000 12.00000000 1.58490566 lin continuous -1.00000000 false dolive 861 230 106 41 {dacdf18f-bde4-4a64-8973-9285e8c73e68} true 0 0 value 1.00000000 Get Live Snapshot! / i1 0 10 false false false 10 941 201 39 24 {5db562b3-eb02-48d2-9792-3c725a677612} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 sample 738 114 104 30 {c2700f76-0407-44bb-9c6a-6440205a419f} true 0 0 value 1.00000000 Sample / true false true 10 live 863 115 104 30 {4f1cac68-9cfe-4663-8847-2319835a203e} true 0 0 value 1.00000000 Live / i1 0 10 true false false 10 862 149 62 26 {e8dc513b-db58-4aaf-97ba-50df3ef532da} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 inch 927 148 40 27 {fd2c2663-b818-4bc2-9e3c-933480540979} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 1.00000000 1 1e+12 false 1 740 148 57 24 {0ee3a50b-51d8-4bc9-813e-f0d565c01f96} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 sampnr 801 147 40 27 {ccb65c55-41fe-46ef-a983-94752dc3b1d5} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 1.00000000 1 1e+12 false 2 740 178 56 25 {216588f6-fc24-4a02-8159-df22c0689436} true 0 0 event 1.00000000 Play it / i 2 0 1 false false false 10 740 225 104 102 {96551f1f-2888-4e8b-92a5-fe5f40650b1b} true 0 0 left top Arial 10 3 0 0 0 255 255 255 noborder 1 0 keysel 740 205 104 21 {c546d668-bca5-4c14-a13d-d18c5b844efe} true 0 0 value 1.00000000 Enable Keys / i 2 0 1 true false false 10 797 178 47 25 {1d2f4673-864c-4aa6-a813-6f4b73fe536e} true 0 0 event 1.00000000 Stop / i 9 0 .1 false false false 10 267 71 458 262 {8cbb0d66-be77-44fb-9fea-1c2d42f85655} true 0 0 center top Arial 20 3 0 0 0 255 255 255 border 1 1 _MBrowse 275 75 343 29 {fe1e66fe-4105-4aed-9c04-e06ef3c95aa2} true 0 0 left Arial 12 3 0 0 0 239 239 239 nobackground _MBrowse 620 75 100 30 {7e9d3773-29f5-4906-91f7-3e35e562dfa6} true 0 0 value 1.00000000 fox.wav|bell.aiff|BratscheMono.wav|Wood.wav Select Files / false false false 10 pos 273 242 449 40 {a8250334-53f7-4e66-aa18-2b9be5ff9466} true 0 0 pos 0.00000000 1.00000000 0.00000000 1.00000000 0.05345212 0.05345212 line 1 0.00000000 jump noborder #00FF00 255 255 255 false 0 0 0 true 591 280 104 25 {47aae0f0-46ca-4f1b-a3ba-5923cc3fb761} true 0 0 center top Arial 14 3 0 0 0 255 255 255 noborder 1 0 position 612 302 55 26 {87aa8561-e21a-4634-9693-ad2680b9d547} true 0 0 right top Arial 14 3 0 0 0 255 255 255 noborder 1 0 showtab 272 109 450 138 {193d6210-1914-4ba1-b1b3-6f813a1eecbb} true 0 0 7 1.00000000 1.00000000 1.00000000 1.00000000 lin lin true true true true true true true showname 274 282 172 50 {b7f9aafe-e4c4-4837-aacf-13c309c3899d} true 0 0 left top Arial 14 3 255 255 0 0 0 0 noborder 1 0 756 365 137 27 {e05fc469-2f58-410b-9806-dc9cb7655d4b} true 0 -3 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 756 392 132 28 {2a973632-d5ee-4246-ae9f-4db7349afc29} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 _Browse1 887 393 48 26 {7b71257f-6fef-494d-a260-98647d7ffc68} true 0 0 value 1.00000000 /home/linux/Desktop/Presentation/test/export1.txt To... / i1 0 10 false false false 10 756 419 132 28 {c453cf7a-dbdd-4bc9-9c96-37d7e39c3a30} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 _Browse2 886 419 48 26 {5bbf7fad-0c36-4780-a07d-a60f81d40d90} true 0 0 value 1.00000000 /home/linux/Desktop/Presentation/test/export2.txt To... / i1 0 10 false false false 10 756 446 132 27 {d574f198-bfad-40b6-b163-c4046e3878bf} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 _Browse3 886 447 48 25 {709af31e-5c0e-483f-a8e6-d0a51351680e} true 0 0 value 1.00000000 /home/linux/Desktop/Presentation/test/export3.txt To... / i1 0 10 false false false 10 print 892 366 83 25 {33968315-e837-4af4-bdf2-98480bf44c91} true 0 0 value 1.00000000 Print / i1 0 10 true false true 10 exp1 930 393 51 26 {109e08e0-b1c7-4c4f-a2a2-18469fd6a4bb} true 0 0 value 1.00000000 Now! / i1 0 10 false false false 10 exp2 929 420 52 25 {6d4111e8-cd9f-4140-9d7f-8dfb008c6564} true 0 0 value 1.00000000 Now! / i1 0 10 false false false 10 exp3 929 447 52 25 {7980b3f7-f6bc-4798-8a65-f58642700fb3} true 0 0 value 1.00000000 Now! / i1 0 10 false false false 10 out 767 516 172 28 {dfa0444b-a225-47a5-a1db-3ac7e63f8034} true 0 0 out 0.00000000 1.00000000 0.00000000 1.00000000 -inf -inf fill 1 0.00000000 jump noborder #00FF00 0 234 0 false 0 0 0 true out_over 937 516 28 28 {02c1d76c-5c5d-4a11-93b4-21dc54706c90} true 0 0 out_over 0.00000000 1.00000000 0.00000000 1.00000000 0.00000000 0.00000000 fill 1 0.00000000 jump noborder #00FF00 255 0 0 false 0 0 0 true vol 768 551 149 21 {d0dd7c29-31c8-4847-bb6c-7707ff1f3570} true 0 0 -12.00000000 12.00000000 -1.53020134 lin continuous -1.00000000 false 948 548 30 28 {2918f563-dce4-45c5-96e8-07df0b671f27} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 275 370 189 27 {b609249e-e278-4c26-9182-01086a1f20e3} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 fast 458 404 50 25 {22a49672-685f-4628-8c6f-6fe2e09a6a9c} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 0.10000000 0.1 1 false 0 354 403 102 27 {599be8ec-f1b9-434a-b229-1f693270447d} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 numpartsana 462 371 46 26 {caec7ed3-498b-4458-ac4e-57fac52c4df9} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 1 64 false 32 hopmove 275 435 90 28 {38e30cb8-9e88-4dc9-8d09-b30f75c2e0c4} true 0 0 value 1.00000000 Hop Move / i1 0 10 true false false 10 380 435 68 27 {5da20281-4647-40b9-8499-ee43eff43519} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 hopmovsiz 450 437 58 26 {f7598ae6-c54e-438f-94c2-b29d932ee539} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 0.01000000 -1 1 false 0 manpos 275 403 71 28 {f8579654-8952-4866-a7cf-c0d757108732} true 0 0 value 1.00000000 Pointer / i1 0 10 true false true 10 numpartspl 695 369 50 25 {19be0852-85d9-4ae7-8506-e9b0d40d6dda} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 1 32 false 32 refpch 695 432 50 25 {68269bfd-79e9-4749-a934-2187c48d3734} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 127 false 60 529 432 139 27 {05fccea2-ecb7-4fdc-ae15-062016397ad8} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 stcent 695 464 50 25 {b16b9f6e-73f5-4c22-83a7-c47d8f0a68da} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 200 false 100 528 463 156 27 {e35d6aaa-3dcb-4e83-882d-0d51db0d867e} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 528 369 167 27 {c4d885cd-a6ac-413a-b148-b8c7c11d3537} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 shiftpl 695 400 50 25 {5b84e7d0-0c82-45e2-aca9-f2d1f982970a} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 31 false 0 528 399 149 27 {b4cef0ea-2ef0-4c9d-ade1-702aea738fd8} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 rndfqdv 695 528 50 25 {d09928e9-5e05-4ba0-bd7d-94f92a0630d4} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 200 false 0 527 518 167 40 {8b426732-b781-4659-a813-de60b04656ac} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 rndampdv 695 560 50 25 {34535596-8d50-43f6-908c-58a524740c90} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 200 false 0 527 552 162 39 {32f46896-8772-4e3c-b3d6-730806ad9ca4} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 rnddurdv 695 592 50 25 {f20eb136-d9d2-4559-9fbc-6c44e6864afa} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 1.00000000 0 200 false 0 527 586 158 41 {40a78d4c-b76c-4fa9-a75a-8baa76abcea9} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 maxdur 695 496 50 25 {10a57f16-265b-4774-a0d6-26c3c629bf77} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 0.10000000 0.1 2000 false 0 527 495 156 27 {ffe891f4-df20-436c-b300-6ab71182168d} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 att 290 540 176 17 {c00e9cc5-61b3-4190-ab37-a0227e181716} true 0 0 att 0.01000000 0.20000000 0.01000000 0.20000000 0.01755682 0.01755682 fill 1 0.00000000 jump noborder #00ff00 255 170 0 false 42 46 50 true dec 290 559 176 17 {a2de8382-412c-4b27-a075-1ae824b85ff3} true 0 0 dec 0.00000000 1.00000000 0.00000000 1.00000000 0.27840909 0.27840909 fill 1 0.00000000 jump noborder #00ff00 255 170 0 false 42 46 50 true sus 290 578 176 17 {fb32d182-7973-4205-aa3e-eca37b202fc7} true 0 0 sus 0.00000000 1.00000000 0.00000000 1.00000000 0.51136364 0.51136364 fill 1 0.00000000 jump noborder #00ff00 255 170 0 false 42 46 50 true rel 291 598 176 17 {d1e99338-5f53-426a-8a8f-9124b39a69b9} true 0 0 rel 0.00000000 1.00000000 0.00000000 1.00000000 0.73863636 0.73863636 fill 1 0.00000000 jump noborder #00ff00 255 170 0 false 42 46 50 true att 463 536 50 21 {f887d4bf-9249-4736-84e6-71ae3883aae4} true 0 0 left top Arial 12 3 0 0 0 255 255 255 noborder 1 0 dec 463 556 50 21 {406da2a0-8ba4-40c0-91a4-09184aba8654} true 0 0 left top Arial 12 3 0 0 0 255 255 255 noborder 1 0 sus 463 576 50 21 {0b43ed62-96ca-47f4-8056-a8459f7e4ece} true 0 0 left top Arial 12 3 0 0 0 255 255 255 noborder 1 0 rel 463 595 50 21 {5439df97-f182-4a18-ac2e-60995d097127} true 0 0 left top Arial 12 3 0 0 0 255 255 255 noborder 1 0 272 537 19 24 {da37e1dc-1232-49cb-a919-4218bd97460a} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 272 556 19 24 {e3ad5e24-3b8f-4013-a0d8-a1fac6cb0133} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 272 575 19 24 {4364c297-c8a3-472b-a4f8-14dbc6c5d226} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 272 593 19 24 {f3d92b16-98c4-4c99-98f2-483a79a2314f} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 350 470 60 28 {6fdc67be-6b4e-4f62-99ab-fa4ed69aff12} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 randpos 275 467 77 28 {79f6ce72-902a-4ba6-a0df-fd33b6169a3f} true 0 0 value 1.00000000 Random / i1 0 10 true false false 10 rndpos1 410 471 50 25 {ddedf240-0604-49f7-9f8c-880d31f26d17} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 0.10000000 0 0.99 false 0 rndpos2 458 471 50 25 {b73dfa9b-7dfb-488c-ab7f-be3d165a31b4} true 0 0 right Liberation Sans 14 0 0 0 255 255 255 0.10000000 0.1 0.99 false 0 vol 916 548 33 29 {e4f92c35-0043-4eea-9560-7c55018f479e} true 0 0 left top Arial 14 3 0 0 0 255 255 255 noborder 1 0 pos 460 305 92 25 {de3cf7d9-8cc9-47f9-a205-ef243a143424} true 0 0 left Liberation Sans 14 0 0 0 255 255 255 0.00000100 0 1 false 0.0534521 453 280 104 25 {141519e4-0af6-4486-895a-b8cc5e5e0462} true 0 0 center top Arial 14 3 0 0 0 255 255 255 noborder 1 0 10 71 255 150 {b8f46405-6cc4-4b7d-a2da-13890ad2864c} true 0 -3 center top Liberation Sans 30 3 0 0 0 255 255 255 false 1 0 10 111 255 110 {998837f8-1449-4aa2-b0c7-66677e5ba65b} true 0 -3 left top Liberation Sans 16 3 0 0 0 255 255 255 false 1 0