Cabbage Logo
Back to Cabbage Site

Problems With TrigExpSeg/LinExpSeg

Hey again!

I am trying to employ a tape stop style effect using a triggered envelope to modulate the time and pitch of a temposcal object using trigexpseg. I believe I have everything set up properly but whenever I operate the trigger to begin the tape stop, the effect is not occurring.

Any and all help solving this would be greatly appreciated!

Best,
Mitch

<Cabbage> bounds(0, 0, 0, 0)
form caption("TapeStopTest") size(300, 300), pluginId("def1"), bundle("Resources"), guiMode("queue")

button bounds(16, 12, 69, 56) channel("PlayStop") colour:1(42, 74, 255, 255) colour:0(55, 106, 132, 255) text("Off", "On")
combobox bounds(16, 66, 68, 22) channel("FFTattributes") text("128", "256", "512", "1024", "2048", "4096", "8192", "16384", "") value(5)

rslider bounds(94, 54, 60, 60) channel("TimeStretch") range(0, 2, 1, 1, 0.001) text("TimeStretch")
rslider bounds(154, 54, 60, 60) channel("PitchStretch") range(0, 2, 1, 1, 0.001) text("PitchStretch")
button bounds(118, 8, 80, 40) channel("Link") colour:0(255, 13, 13, 255) colour:1(4, 224, 0, 255) text("Unlinked", "Linked")
button bounds(116, 122, 80, 40) channel("TapeStop") colour:0(255, 13, 13, 255) colour:1(4, 224, 0, 255) text("TapeStop", "TapeStop") alpha(0.99)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -+rtmidi=NULL -M0
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1

;=====INIT VARS===========
giSamp1		ftgen 21, 0, 0, 1, "Resources/dh-DRUMS.wav", 0, 0, 1
giamp = 1

;====FFT TABLE DATA=============
giFFTattributes0	ftgen	1, 0, 4, -2, 128, 64, 256, 1
giFFTattributes1	ftgen	2, 0, 4, -2, 256, 128, 512, 1
giFFTattributes2	ftgen	3, 0, 4, -2, 512, 256, 1024, 1
giFFTattributes3	ftgen	4, 0, 4, -2, 1024, 256, 1024, 1
giFFTattributes4	ftgen	5, 0, 4, -2, 2048, 256, 2048, 1
giFFTattributes5	ftgen	6, 0, 4, -2, 4096, 256, 4096, 1
giFFTattributes6	ftgen	7, 0, 4, -2, 8192, 256, 8192, 1
giFFTattributes7	ftgen	8, 0, 4, -2, 16384, 256, 16384, 1

;====PROCESSING=====
instr 1
gkFFTattributes    chnget    "FFTattributes"
gkFFTattributes-=1

    kSwitch		changed		gkFFTattributes							
    if	kSwitch=1	then													
        reinit	UPDATE												
        endif															
        UPDATE:	

gkPlayStop chnget "PlayStop"
 if gkPlayStop==0 then
turnoff
 endif
 
giFFTsize	table	0, i(gkFFTattributes)+1			
gioverlap	table	1, i(gkFFTattributes)+1								
giwinsize	table	2, i(gkFFTattributes)+1								
giwintype	table	3, i(gkFFTattributes)+1								

//============Tape-Stop==================
//======================================
//======================================

kLink chnget "Link"
kTapeStop chnget "TapeStop"
printk2 kTapeStop

if kLink = 1 && kTapeStop = 0 then
ktimescal chnget "TimeStretch"
kpitch chnget "TimeStretch"

elseif kLink = 0 && kTapeStop = 0 then
ktimescal chnget "TimeStretch"
kpitch chnget "PitchStretch"

elseif kTapeStop = 1 then
ktimescal trigExpseg kTapeStop, 1, 5, 2.0 
kpitch trigExpseg kTapeStop, 1, 5, 2.0
endif
//======================================
//======================================
//======================================


aIn1 temposcal ktimescal, giamp, kpitch, giSamp1, 1, giFFTsize
outs aIn1, aIn1

endin


//SAMPLE-TRIGGER
//======================================
instr 99

gkPlayStop chnget "PlayStop"
ktrig    trigger    gkPlayStop,0.5,0      
schedkwhen    ktrig,0,0,1,0,-1

endin

</CsInstruments>
<CsScore>

f0 z

i 99 0 100000


</CsScore>
</CsoundSynthesizer>

You’r if statement all use an assignment operator (=) rather than an equal operator (==). If you do something like this is should work:

elseif kTapeStop == 1 then
    ktimescal trigExpseg changed:k(kTapeStop), 1, 5, 2.0, 1, 0.2

Not that I use a changed() opcode here to provide the trigger signal for the envs. :+1: