;
; DENTAKU - an Casio VL-1 clone
;
; see https://syntherjack.net/casio-vl-1-secrets/ 
; and https://www.youtube.com/watch?v=ENUeNejf_C0
; and http://www.polyvalens.com/vl1/download/casio_vl-tone_manual_uk.pdf
;
; WORK IN PROGRESS - NOT USEFUL YET
;
<Cabbage>
form caption("Dentaku") size(400, 270), colour(58, 110, 182), pluginid("def1")
keyboard bounds(10, 54, 381, 95)


nslider bounds(10, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(100) channel("waveform") text("wav") 
nslider bounds(52, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(100) channel("attack") text("att") 
nslider bounds(94, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(1) channel("decay") text("dec") 
nslider bounds(136, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(50) channel("sustain_level") text("suL") 
nslider bounds(178, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(50) channel("sustain_time") text("suT") 
nslider bounds(220, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(50) channel("release") text("rel") 
nslider bounds(264, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(50) channel("vibrato") text("vib") 
nslider bounds(308, 10, 40, 40) range(0, 9, 0, 1, 1) velocity(50) channel("tremolo") text("trem") 
label bounds(98, 156, 252, 16) text("When the technique is primitive,")
label bounds(146, 174, 209, 18) text("everything is beautiful,")
label bounds(72, 196, 273, 16) text("and when the technique is perfected,")
label bounds(146, 214, 199, 16) text("almost everything is ugly.")
label bounds(240, 232, 110, 16) text("Jean Renoir")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1

; TODO:
; - nastavovani ADSR - viz video (zatím přes madsr)
; - nastavovani vlny - vlny zapsané ručně přes GEN02
; - voice stealing
; - vibrato & tremolo

; hlasy:
; 0. piano - pw = 11/16, pf = 1
; 1. fantasy - pw = 1/2, pf = 2
; 2. violin - ft 103, pf = 1
; 3. flute - pw = 1/2, pf = 1
; 4. guitar_1 - ft 101, pf = 1/2
; 5. guitar_2 - ft 102, pf = 1/2
; 6. horn1 - pw = 1/7, pf = 1/2
; 7. electro_1 - Piano waveform (0) with pitch modulation
; 8. electro_2 - Fantasy waveform (1) with pitch modulation
; 9. electro_3 - Violin waveform (0) with pitch modulation
;
; base freq is changeable by "tempo" slider

iWaveform chnget "waveform"
komplex init 0
ift init -1

if iWaveform == 0 then
    kpw = 11/16
    kpf = 1
    komplex = 0
elseif iWaveform == 1 then
    kpw = 1/2
    kpf = 2
    komplex = 0
elseif iWaveform == 2 then
    kpw = 1/2
    kpf = 1
    komplex = 0
elseif iWaveform == 3 then
    komplex = 1
    ift = 103
    kpf = 1/2    
elseif iWaveform == 4 then
    komplex = 1
    ift = 101
    kpf = 1/2
elseif iWaveform == 5 then
    komplex = 1
    ift = 102
    kpf = 1/2
elseif iWaveform == 6 then
    kpw = 1/7
    kpf = 1/2
    komplex = 0
else
    ; piano-like fallback
    kpw = 11/16
    kpf = 1
    komplex = 0
endif


kEnv madsr .1, .2, .6, .4

printks "wav = %d kpw = %5.2f kpf = %5.2f kft = %d komplex = %d\n", 2, iWaveform, kpw, kpf, ift, komplex

if komplex == 1 then
    printks "komplex %d\n", 1, ift
    aOut poscil p5, p4 * kpf, ift
    ;aOut vco2 0, p4 * kpf, 2, kpw
else
    printks "simple\n", 1
    aOut vco2 p5, p4 * kpf, 2, kpw
endif



outs aOut*kEnv, aOut*kEnv
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
; these were manually constructed from osciloscoped waveforms
f 101 0 24 2 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 ; guitar1 
f 102 0 24 2 0 0 0 1 1 0 1 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 1 1 ; guitar2
f 103 0 32 2 1 1 1 0 1 1 0 1 1 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 1 0 1 ; violin – very very rough
f 104 0 24 2 1 0 0 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 ; electro1

i 1 
</CsScore>
</CsoundSynthesizer>
