; ported to the Csound list by Thorin Kerr. 
; ported to Cabbage on the 18th of March, 2016 by Rory Walsh
; updated by Severak in 2019
; presets by Codesound / Ruben
<Cabbage>
#define RSLIDER colour("black"), trackercolour("orange"), 
form caption("Thorin Bass") size(422, 440), colour(0, 0, 0), pluginID("def1")

image bounds(106, 88, 216, 186), colour(60,60,60)
image bounds(110, 88, 208, 183), colour(10, 10, 10)
image bounds(15, 15, 393, 80), colour(10, 10, 10)
image bounds(15, 115, 393, 80), colour(10, 10, 10)
rslider bounds(24, 20, 72, 72), channel("distortionSlider"), range(0, 8, 2.3, .5, 0.001), text("Distortion"), $RSLIDER
rslider bounds(328, 20, 72, 72), channel("harmonicsSlider1"), range(1, 10, 8, 1, 1), text("Hrms.1"), $RSLIDER

keyboard bounds(24, 288, 381, 95), value(24), keywidth(18)
rslider bounds(112, 216, 52, 52), channel("attackSlider"), outlinecolour(0, 0, 0, 0), range(0.01, 1, 0.01), text("Att."), $RSLIDER
rslider bounds(160, 216, 52, 52), channel("decaySlider"), outlinecolour(0, 0, 0, 0), range(0.01, 1, 0.2), text("Dec"), $RSLIDER
rslider bounds(208, 216, 52, 52), channel("sustainSlider"), outlinecolour(0, 0, 0, 0), range(0.01, 1, 0.6), text("Sus."), $RSLIDER
rslider bounds(256, 216, 52, 52), channel("releaseSlider"), outlinecolour(0, 0, 0, 0), range(0.01, 2, 0.01), text("Rel."), $RSLIDER


rslider bounds(328, 122, 72, 72), channel("harmonicsSlider2"), range(1, 10, 8, 1, 1), text("Hrms.2"), $RSLIDER
rslider bounds(24, 122, 72, 72), channel("tuningSlider"), range(0, 2, 1, 1, .1), text("Tuning"), $RSLIDER

rslider bounds(328, 208, 69, 62), channel("wobbleTableSlider"), range(1, 10, 1, 1, 1), text("Shape"), $RSLIDER  

rslider bounds(32, 208, 62, 62), channel("gainSlider"), range(0, 2, 1), text("Gain"), $RSLIDER

xypad bounds(96, 8, 232, 200), channel("xchan0", "ychan0"), rangex(0, 20, 0), rangey(0, 5, 1), text("Amount Freq"), colour("orange"), fontcolour("orange"), textcolour("orange")
label bounds(220, 182, 70, 14), text("Wobble"), fontstyle("bold"), fontcolour("orange")
combobox bounds(136, 392, 116, 24), populate("*.snaps")

filebutton bounds(24, 392, 111, 25), channel("but1"), text("Save Preset"), mode("snapshot")
</Cabbage>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 1
nchnls = 2
0dbfs = 1



gi_cubicb ftgen 0, 0, 512, 8, 0, 128, 1, 128, 0, 256, 0
gi_cosine ftgen 0,0,16384,11,1,1
giFilterEnv	ftgen	98, 0, 1024, 27, 0, 0, 100, 1, 500, .5, 800, .5, 1024, 0 
gkActivateRMS init 0

instr 1
gkActivateRMS = 1
kWobble chnget "ychan0"

kWobbleAmp chnget "xchan0"
kwobbler = oscil3(kWobbleAmp, kWobble, chnget:i("wobbleTableSlider")) + 0.5

ares1      gbuzz     p5, p4 + (jspline:k(1.7, 0.2, 7.7)*chnget:k("tuningSlider")), chnget:k("harmonicsSlider1"), 1, kwobbler, gi_cosine
ares2      gbuzz     p5, (p4/2) + (jspline:k(1.5, 2.5, 3)*chnget:k("tuningSlider")), chnget:k("harmonicsSlider2"), 2, kwobbler, gi_cosine

ares3 distort ares1, (kwobbler + 0.1) * chnget:k("distortionSlider"), gi_cubicb

ares = ((ares1 + (ares2 * 2) + ares3))/3

;adeclick linseg 0, 0.002, 1, p3-0.005, 1, 0.003, 0
;ares = ares * adeclick

kEnv madsr chnget:i("attackSlider"), chnget:i("decaySlider"), chnget:i("sustainSlider"), chnget:i("releaseSlider")

ares = ares*chnget:k("gainSlider")
outs ares*kEnv, ares*kEnv

kRel release
gkActivateRMS = kRel==1 ? 0 : 1


endin


</CsInstruments>
<CsScore>
f99 0 2 2 -80 1
f1 0 4096 10 1 
f2 0 4096 10 1 .4 .5
f3 0 4096 10 0 1 1 1 1 .4 .5
f4 0 4096 10 1 .5
f5 0 4096 5 0.01 1 1 4095 0.01 
f6 0 4096 10 1
f7 0 4096 7 0 2040 .2 20 1 1024 .4 100 0
f8 0 4096 10 1 .1 .1 1 .4 .5
f9 0 4096 10 1 1 1 1 .4 .5 1 .4 .5
f10 0 4096 10 1 1 1 1 1 .4 .5 .4 .5
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>
