form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
keyboard bounds(8, 158, 381, 95)
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
opcode MorphOsc, a, kkikkkkkkkk
kVol, kFreq, iPhase, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kFine, kNoteTrig xin
/*
kchange changed kFreq,kOct,kSemi,kFine
kfactor = kFreq*octave(kOct)*semitone(kSemi)*cent(kCent)*kFine
aindex phasor kfactor,iPhase
cngoto kNoteTrig==1||kchange==1, SHAPE_ENV2
reinit SHAPE_ENV2
SHAPE_ENV2:
iNote = (i(kFreq))*octave(i(kOct))*semitone(i(kSemi))*cent(i(kCent))*i(kFine)
ifn vco2ift iNote, gitable_bl
ifn1 vco2ift iNote, gitable_bl1
ifn2 vco2ift iNote, gitable_bl2
asig tabmorphak aindex, kMorph, kWave1,kWave2, ifn, ifn1, ifn2
rireturn*/
asig phasor kFreq
xout asig*kVol
endop
opcode SuperOsc, aa, kkikkkkkkikkkk
setksmps 16
kVol, kFreq, iPhase, kWave1, kWave2, kMorph, kDet, kWid, kVoice, iRetrig, kOct, kSemi, kCent, kNoteTrig xin
kVol limit kVol, 0, 1
;gkDT[] fillarray -.15, -.15/2, -.15/4, -.15/8, .15/8, .15/4, .15/2, .15
gkDT[] fillarray -.40/2, -.30/2, -.30/3, -.30/8, .30/8, .30/3, .35/2, .50/2
gkP[] fillarray -.5, .5, .5, -.5, -.5, .5, .5, -.5
kD[] = gkDT*kDet + 1
kW[] = gkP*kWid + 0.5
kWi[] = 1 - kW
kVol1=0
kVol2=0
kVol3=0
kVol4=0
kVol5=0
kVol6=0
kVol7=0
kVol8=0
if(kVoice>=1)then
kVol1=1
endif
if(kVoice>=2)then
kVol2=1
endif
if(kVoice>=3)then
kVol3=1
endif
if(kVoice>=4)then
kVol4=1
endif
if(kVoice>=5)then
kVol5=1
endif
if(kVoice>=6)then
kVol6=1
endif
if(kVoice>=7)then
kVol7=1
endif
if(kVoice>=8)then
kVol8=1
endif
if(iRetrig==0)then
iphase1 random 0.0, 1.0
iphase2 random 0.0, 1.0
iphase3 random 0.0, 1.0
iphase4 random 0.0, 1.0
iphase5 random 0.0, 1.0
iphase6 random 0.0, 1.0
iphase7 random 0.0, 1.0
iphase8 random 0.0, 1.0
else
iphase1=iPhase
iphase2=iPhase
iphase3=iPhase
iphase4=iPhase
iphase5=iPhase
iphase6=iPhase
iphase7=iPhase
iphase8=iPhase
endif
a1 MorphOsc kVol*kVol1, kFreq, iphase1, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[0], kNoteTrig
a2 MorphOsc kVol*kVol2, kFreq, iphase2, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[1], kNoteTrig
a3 MorphOsc kVol*kVol3, kFreq, iphase3, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[2], kNoteTrig
a4 MorphOsc kVol*kVol4, kFreq, iphase4, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[3], kNoteTrig
a5 MorphOsc kVol*kVol5, kFreq, iphase5, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[4], kNoteTrig
a6 MorphOsc kVol*kVol6, kFreq, iphase6, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[5], kNoteTrig
a7 MorphOsc kVol*kVol7, kFreq, iphase7, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[6], kNoteTrig
a8 MorphOsc kVol*kVol8, kFreq, iphase8, kWave1, kWave2, kMorph, kOct, kSemi, kCent, kD[7], kNoteTrig
if(kVoice>1)then
amixL = a1*kW[0] + a2*kW[1] + a3*kW[2] + a4*kW[3] + a5*kW[4] + a6*kW[5] + a7*kW[6] + a8*kW[7]
amixR = a1*kWi[0] + a2*kWi[1] + a3*kWi[2] + a4*kWi[3] + a5*kWi[4] + a6*kWi[5] + a7*kWi[6] + a8*kWi[7]
else
amixL = a1
amixR = a1
endif
kVoiceTot = kVol1+kVol2+kVol3+kVol4+kVol5+kVol6+kVol7+kVol8
if kVoiceTot == 0 then
kVoiceTot = 1
endif
amixL *= (16-kVoiceTot)/16
amixR *= (16-kVoiceTot)/16
;amixL *= 0.125
;amixR *= 0.125
xout amixL*kVol, amixR*kVol
endop
;instrument will be triggered by keyboard widget
instr 1
ioscphase = 0
a1l ,a1r SuperOsc 1, p4, ioscphase, 0, 0, 0, .5, 1, 8, 0, 0, 0, 0, 0
a2l ,a2r SuperOsc 1, p4, ioscphase, 0, 0, 0, .5, 1, 8, 0, 0, 0, 0, 0
a3l ,a3r SuperOsc 1, p4, ioscphase, 0, 0, 0, .5, 1, 8, 0, 0, 0, 0, 0
a4l ,a4r SuperOsc 1, p4, ioscphase, 0, 0, 0, .5, 1, 8, 0, 0, 0, 0, 0
outs a1l+a2l+a3l+a4l, a1r+a2r+a3r+a4r
endin
;causes Csound to run for about 7000 years...
f0 z