; instruments management instr KillImpl Sinstr = p4 if (nstrnum(Sinstr) > 0) then turnoff2(Sinstr, 0, 0) endif turnoff endin opcode kill, 0, S Sinstr xin schedule("KillImpl", 0, .05, Sinstr) endop opcode refresh, 0, S Sinstr xin if (nstrnum(Sinstr) > 0) then kill(Sinstr) schedule(Sinstr, ksmps / sr, -1) endif endop #define _endin # endin refresh("livecoding") # opcode rint, i, ii imin, imax xin irnd = int(random:i(imin, int(imax) + 0.99)) xout irnd endop opcode rint, k, kk kmin, kmax xin krnd = int(random:k(kmin, int(kmax) + 0.99)) xout krnd endop opcode euclidian, k, kkkk konset, kdiv, kpulses, krot xin kphasor = gkphasor kph = int( ( ( (kphasor + krot) * kdiv) / 1) * kpulses) keucval = int((konset / kpulses) * kph) kold_euc init i(keucval) kold_ph init i(kph) kres = ((kold_euc != keucval) && (kold_ph != kph)) ? 1 : 0 kold_euc = keucval kold_ph = kph xout kres endop // Simple rhythm array opcode array_rhythm, k, k[] karr[] xin kmet = gkbeat kcnt init 0 ilen = lenarray(karr) ktrig = 0 if ( kmet > 0 ) then kval = karr[kcnt] ktrig = kval kcnt = (kcnt + 1) % ilen endif xout ktrig endop opcode trunc, k, k kx xin ky = (kx < 0) ? -(floor(-kx)) : floor(kx) xout ky endop opcode mfmod, k, kk kone, ktwo xin kres = kone - trunc(kone/ktwo) * ktwo xout kres endop opcode phase_trig, k, k kphase xin kold init 1 ktrigger init 0 ktrigger = 0 if (kold > kphase) then ktrigger = 1 endif kold = kphase xout ktrigger endop opcode downprint, 0, kki kprint, kdown, imargin xin kcnt init 0 if (kcnt == 0) then printk2(kprint, imargin) endif kcnt = (kcnt + 1) % kdown endop opcode phasor_fqmult, k, kk kphase, kmult xin if (kmult <= 0) then kmult = 1 endif kfphase init 0 if (kmult <= 1) then kfphase = mfmod(gkslowph * (kmult * 100), 1) elseif (kmult > 1) then kfphase = mfmod(gkslowph * (kmult * 100), 1) ;kfphase= mfmod(gkphasor * kmult, 1) endif xout kfphase endop opcode rh_subd, k, k[]P karr[], kpdiv xin ilen = lenarray(karr) if (kpdiv <= 0) then kpdiv = ilen endif kdiv = kpdiv kph = phasor_fqmult(gkphasor, kdiv ) ktr = phase_trig(kph) kidx init 0 ktrigger = 0 if (ktr == 1) then ktrigger = karr[kidx] kidx = (kidx+1) % ilen endif xout ktrigger endop opcode rhythm, k, k[]P karr[], kpdiv xin ilen = lenarray(karr) if (kpdiv <= 0) then kpdiv = ilen endif kdiv = kpdiv kph = phasor_fqmult(gkphasor, kdiv) ktr = phase_trig(kph) kidx init 0 ktrigger = 0 if (ktr == 1) then ktrigger = karr[kidx] kidx = (kidx+1) % ilen endif xout ktrigger endop opcode beat, k, k kmult xin kmult = limit:k(kmult, 0.001, 1000) km = rhythm(array(1), kmult) ;kph = phasor:k(kmult * gktempo) ;km = phase_trig(kph) xout km endop opcode swing, k, kk kspeed, ksw xin ktrig init 0 kold init 0 kph = phasor_fqmult(gkphasor, kspeed) ktr1 = phase_trig(kph) ktr2 = 0 if (kold < ksw && kph >= ksw) then ktr2 = 0.6 endif kold = kph ktrig = limit:k(ktr1 + ktr2, 0, 1) xout ktrig endop opcode drunk, k, kk kspeed, kdrunk xin kold init 0 kspeed = limit:k(kspeed, 0.001, 1000) knoi = random:k(0, kdrunk) kph = phasor_fqmult(gkphasor, kspeed) ;kph = phase_incr_mod(gkphasor, 1/ kspeed) ktrig = limit:k(phase_trig(kph) + ((kold < knoi && kph > knoi) ? 1 : 0), 0, 1) kold = kph xout ktrig endop opcode filter_first_trig, k, k ktrig xin ksub init 1 ktrig -= ksub ksub = 0 xout ktrig endop opcode check_trig, k, k ktrig xin kf = filter_first_trig(ktrig) kres = (changed:k(kf) > 0 && kf > 0) ? 1 : 0 xout kres endop opcode to_tempo_dur, k, k kdur xin ktdur = kdur / gktempo xout ktdur endop opcode chance, k, kk kmin, kmax xin kres = random:k(kmin, kmax) xout kres endop opcode alternate, k, kkkO kone, ktwo, kspeed, kduty xin if (kduty == 0) then kduty = 0.5 endif if (kspeed <= 0) then kspeed = 1 endif kspeed = limit:k(to_tempo_dur(kspeed), 0.0001, 1000) kph = phasor_fqmult(gkphasor, kspeed) kres init i(kone) if (kph < kduty) then kres = kone else kres = ktwo endif xout kres endop opcode trajectory, k, kkk kfrom, kdur, kto xin kdur = to_tempo_dur(kdur) kres = linseg:k( i(kfrom), i(kdur), i(kto) ) xout kres endop opcode oscillation, k, kkk kmin, kmax, kspeed xin if (kmin > kmax) then ktmp = kmin kmin = kmax kmax = ktmp endif kspeed = limit:k(gktempo / kspeed, 0.001, 1000) kfq = kspeed ; / gktempo iphs init i(gkphasor) kosc = oscili(0.5, kfq, -1, iphs) + 0.5 kres = kosc * (kmax - kmin) + kmin xout kres endop opcode sequence, k, k[]P karr[], kpdiv xin ilen = lenarray(karr) if (kpdiv <= 0) then kpdiv = ilen endif kdiv = kpdiv kph = phasor_fqmult(gkphasor, kdiv ) ktr = phase_trig(kph) kidx init 0 if (ktr == 1) then kidx = (kidx+1) % ilen endif ktrigger = karr[kidx] xout ktrigger endop opcode random_array_int, i[], iii isize, imin, imax xin iarr[] init isize icnt init 0 while icnt < isize do iarr[icnt] = int(random:i(imin, imax+0.99)) icnt += 1 od xout iarr endop opcode random_array_int, k[], iii isize, imin, imax xin kArr[] init isize icnt init 0 iArr[] = random_array_int(isize, imin, imax) while icnt < isize do kArr[icnt] = iArr[icnt] icnt += 1 od xout kArr endop #define arr #fillarray(# ; kind of random based savage opcode savage_1, k, 0 k1 = gkmirlorenz_x k2 = abs(oscili:k(1, gkmirlorenz_y * 6 + 0.01)) k3 = rspline:k(0, gkmirlorenz_z, 1, 5) kfq = gkmirlorenz_x * rspline:k(1, 3, 1, 5) + 0.001 kmod = beat(kfq) ;lfo:k(1, kfq, 3) ksel init 0 ksel_sig init 0 if (trigger:k(kmod, 0.5, 0) == 1) then ksel = rint:k(0, 2) endif if (ksel == 0) then ksel_sig = k1 elseif (ksel == 1) then ksel_sig = k2 elseif (ksel == 2) then ksel_sig = k3 endif kres = (kmod > 0) ? ksel_sig : 0 xout kres endop ; direct lorenz savage mode opcode savage_2, k, 0 kmult = pow(abs(lfo:k(1, rspline:k(0, gklorenz_x, 0.1, 3), 1)),3) kmod = abs(poscil:k( pow(gkmirlorenz_z, 3) * kmult, gkmirlorenz_x * gkmirlorenz_y * 40)) xout kmod endop ; pwm based savage mode opcode savage_3, k, 0 kduty = gkmirlorenz_y kph = phasor:k(gkmirlorenz_x * 5 ) kres init 0 if (kph < kduty) then kres = 1 else kres = 0 endif kmult = mirror:k(gklorenz_z, 0, 1) kres *= kmult xout kres endop opcode savage_4, k, 0 iarr[] = fillarray(random:i(0, 1), random:i(0, 1), random:i(0, 1), random:i(0, 1)) kchange init 1 kchange = changed:k(round(abs(gklorenz_x ))) kmod init 1 if (kchange == 1) then iarr[0] = random:i(0, 1) iarr[1] = random:i(0, 1) iarr[2] = random:i(0, 1) iarr[3] = random:i(0, 1) endif ksel = int(abs(gklorenz_x) * 4.99) % 4 kres = limit:k (lineto(iarr[ksel], mirror:k(abs(gklorenz_y), 0, 1) ), 0, 1) xout kres endop opcode savage_5, k, 0 kamp = pow(abs(gklorenz_x), 2) kfq = 8 - (0.01 + abs(gklorenz_y) * 8) kmod = oscili:k(kamp, kfq) xout kmod endop opcode chaos_rhythm, k, kk kchoice, kthresh xin kthresh = limit:k(kthresh, 0, 1) kchoice = int(limit:k(kchoice, 1, 3.99)) kval init 0 if (kchoice == 1) then kval = gkmirlorenz_x elseif (kchoice == 2) then kval = gkmirlorenz_y elseif (kchoice == 3) then kval = gkmirlorenz_z endif kres = trigger:k(kval, kthresh, 2) xout kres endop opcode chaos_control, k, kkk kchoice, kmin, kmax xin kmax = max:k(kmin, kmax) kmin = min:k(kmin, kmax) kchoice = int(limit:k(kchoice, 1, 3.99)) kval init 0 if (kchoice == 1) then kval = gkmirlorenz_x elseif (kchoice == 2) then kval = gkmirlorenz_y elseif (kchoice == 3) then kval = gkmirlorenz_z endif kdiff = kmax - kmin kres = kval * kdiff + kmin xout kres endop