form caption("Simple FM") size(800, 350), pluginid("def1")
keyboard bounds(270, 210, 381, 86)
gentable bounds(11, 208, 217, 88), identchannel("table1"), tablenumber(1.0), , tablecolour:0(255, 255, 0, 255)
//Gen
rslider bounds(12, 10, 50, 50), channel("ifn1"), range(1, 6, 1, 1, 1), text("ifn1") textcolour(255, 255, 255, 255)
rslider bounds(12, 60, 70, 70), channel("ivca1"), range(0, 1, 0.2, 1, 0.01), text("vca1") textcolour(255, 255, 255, 255)
rslider bounds(82, 10, 50, 50), channel("ifn2"), range(1, 6, 1, 1, 1), text("ifn2") textcolour(255, 255, 255, 255)
rslider bounds(82, 60, 70, 70), channel("ivca2"), range(0, 1, 0.2, 1, 0.01), text("vca2") textcolour(255, 255, 255, 255)
rslider bounds(152, 10, 50, 50), channel("ifn3"), range(1, 6, 1, 1, 1), text("ifn3") textcolour(255, 255, 255, 255)
rslider bounds(152, 60, 70, 70), channel("ivca3"), range(0, 1, 0.2, 1, 0.01), text("vca3") textcolour(255, 255, 255, 255)
//mute
checkbox bounds(64, 16, 12, 12), channel("mute1"), value(0), colour("red"), shape("square") colour:1(255, 0, 0, 255)
checkbox bounds(134, 16, 12, 12), channel("mute2"), value(0), colour("red"), shape("square")
checkbox bounds(204, 16, 12, 12), channel("mute3"), value(0), colour("red"), shape("square")
//solo
checkbox bounds(64, 42, 12, 12), channel("solo1"), value(0), colour("yellow"), shape("square")
checkbox bounds(134, 42, 12, 12), channel("solo2"), value(0), colour("yellow"), shape("square")
checkbox bounds(204, 42, 12, 12), channel("solo3"), value(0), colour("yellow"), shape("square")
//str
rslider bounds(12, 130, 50, 70), channel("str1"), text("Str.1"), valuetextbox(1), textbox(1), range(-1, 1, 1, 1, 0.001), colour(100, 100, 250, 200)
rslider bounds(62, 130, 50, 70), channel("str2"), text("Str.2"), valuetextbox(1), textbox(1), range(-1, 1, 0, 1, 0.001), colour(100, 100, 250, 200)
rslider bounds(112, 130, 50, 70), channel("str3"), text("Str.3"), valuetextbox(1), textbox(1), range(-1, 1, 0, 1, 0.001), colour(100, 100, 250, 200)
groupbox bounds(346, 4, 303, 95), text("Mod Env"){
rslider bounds(22, 24, 60, 60) range(0, 1, 0.01, 1, 0.001), text("Att."), channel("modatt")
rslider bounds(92, 24, 60, 60) range(0, 1, 0.5, 1, 0.001), text("Dec."), channel("moddec")
rslider bounds(162, 24, 60, 60) range(0, 1, 0.2, 1, 0.001), text("Sus."), channel("modsus")
rslider bounds(232, 24, 60, 60) range(0, 1, 0.1, 1, 0.001), text("Rel."), channel("modrel")
}
groupbox bounds(346, 112, 303, 95), text("Car Env"){
rslider bounds(22, 24, 60, 60) range(0, 1, 0.001, 1, 0.001), text("Att."), channel("aatt")
rslider bounds(92, 24, 60, 60) range(0, 1, 0.4, 1, 0.001), text("Dec."), channel("adec")
rslider bounds(162, 24, 60, 60) range(0, 1, 0.5, 1, 0.001), text("Sus."), channel("asus")
rslider bounds(232, 24, 60, 60) range(0, 1, 0.5, 1, 0.001), text("Rel."), channel("arel")
}
rslider bounds(272, 138, 68, 68) range(0, 1, 0.4, 1, 0.001), text("Level"), channel("level")
rslider bounds(272, 70, 68, 68) range(0, 10, 1, 1, 0.001), text("Mod Factor"), channel("modfactor")
rslider bounds(272, 2, 68, 68) range(0, 20, 0, 1, 0.001), text("Mod Index"), channel("modindex")
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
gisine ftgen 1, 0, 16384, 10, 1 ;sine wave
gisquare ftgen 2, 0, 16384, 10, 1, 0 , .33, 0, .2 , 0, .14, 0 , .11, 0, .09 ;odd harmonics
gisaw ftgen 3, 0, 16384, 10, 0, .2, 0, .4, 0, .6, 0, .8, 0, 1, 0, .8, 0, .6, 0, .4, 0,.2 ;even harmonics
giAM ftgen 4, 0, 4096, 5, 1, 4096, 0.01 ;AM waveform
giEQ ftgen 5, 0, 1024, 5, 1, 512, 32, 512, 1 ;FM to EQ
gisine ftgen 6, 0, 1024, 10, 1 ;sine wave
massign 0,2 ; send all midi notes to instr 3
; Make sure CsOptions are not ignored in the preferences,
; Otherwise Realtime MIDI input will not work.
instr 1
gkstr1 chnget "str1"
gkstr2 chnget "str2"
gkstr3 chnget "str3"
gkmute1 chnget "mute1"
gkmute2 chnget "mute2"
gkmute3 chnget "mute3"
gksolo1 chnget "solo1"
gksolo2 chnget "solo2"
gksolo3 chnget "solo3"
kSoloSum = gksolo1+gksolo2+gksolo3
#define SOLO_MUTE_STATUS(N)
#
if gksolo$N==1 then ; if solo for this voice is on...
kstatus$N = 1 ; this partial will be active
elseif kSoloSum>0 then ; if any other solo is on...
kstatus$N = 0 ; this partial will be inactive
else ; other wise
kstatus$N = (1-gkmute$N) ; partial will be on if mute is inactive
endif
#
$SOLO_MUTE_STATUS(1) ; expand macro
$SOLO_MUTE_STATUS(2)
$SOLO_MUTE_STATUS(3)
; generate a trigger if any of the input variables changes
ktrig changed gkstr1,gkstr2,gkstr3
if ktrig==1 then
reinit UPDATE
endif
UPDATE:
giwave ftgen 1,0, 4096,10, i(gkstr1)*i(kstatus1), i(gkstr2)*i(kstatus2), i(gkstr3)*i(kstatus3)
rireturn
if ktrig==1 then
chnset "tablenumber(1)", "table1" ; update table display
endif
endin
instr 2
kEnv madsr .3, .2, .3, .4
ifn1 chnget "ifn1"
ivca1 chnget "ivca1"
ifn2 chnget "ifn2"
ivca2 chnget "ivca2"
ifn3 chnget "ifn3"
ivca3 chnget "ivca3"
aosc1 oscil p5, p4, ifn1
aosc11 = aosc1*kEnv*ivca1
aosc2 oscil p5, p4, ifn2
aosc22 = aosc2*kEnv*ivca2
aosc3 oscil p5, p4, ifn3
aosc33 = aosc3*kEnv*ivca3
amix = aosc11 + aosc22 + aosc33
outs amix, amix
endin
instr 3 ; Simple two operator FM synth
ifreq = p4 ; From p4 in the score or cps from MIDI note
kmodfactor chnget "modfactor"
kmodindex chnget "modindex"
; Mod envelope
kmodatt chnget "modatt"
kmoddec chnget "moddec"
kmodsus chnget "modsus"
kmodrel chnget "modrel"
amodenv madsr i(kmodatt), i(kmoddec), i(kmodsus), i(kmodrel)
kmodfreq = kmodfactor*ifreq
; Index = Am * fc/fm
kmodamp = kmodindex*kmodfactor*ifreq
; Modulator 2
amod poscil amodenv*kmodamp, kmodfreq
;Carrier amp envelope
kaatt chnget "aatt"
kadec chnget "adec"
kasus chnget "asus"
karel chnget "arel"
aenv madsr i(kaatt), i(kadec), i(kasus), i(karel)
; Carrier
aout poscil aenv, ifreq+amod
; Output
klevel chnget "level"
outs aout*klevel, aout*klevel
endin
;causes Csound to run for about 7000 years...
f0 z
i 1 0 [3600*24*7]
i 2 0 [3600*24*7]