Cabbage Logo
Back to Cabbage Site

Sample player and Kswitch

I am trying to make a simple plugin that play 3 different samples (with diffrent pitches mapped to each key) with a Kswitch but i cant quite figure out how to do that.

Can you what you’ve got so far?

sure

form caption(“Tari”) size(600, 400), colour(58, 110, 182), pluginid(“def1”)
image bounds(0, 0, 600, 400) file(“Tari plugin bg.png”)
keyboard bounds(4, 298, 328, 95)
soundfiler bounds(4, 222, 108, 73) file(“Fem Aa.wav”) channel(“Ah”) colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(224, 222, 108, 73) file(“Fem Oh.wav”) channel(“Oh”) colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(114, 222, 108, 73) file(“Fem Eh.wav”) channel(“Eh”) colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)

label bounds(4, 192, 108, 29) text(“Ah: c1”) fontcolour(255, 0, 202, 255)
label bounds(114, 192, 108, 29) text(“Oh: c#1”) fontcolour(255, 0, 202, 255)
label bounds(224, 192, 108, 29) text(“Eh: D1”) fontcolour(255, 0, 202, 255)
label bounds(42, 148, 261, 43) text(“Kswitches”) fontcolour(255, 0, 43, 255)



-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5


; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr Ah
a1, a2 diskin2 “Fem Aa.wav”, 1, 0, 1
outs a1, a2
endin

instr Oh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOutkEnv, aOutkEnv
endin

instr Eh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOutkEnv, aOutkEnv
endin


;causes Csound to run for about 7000 years…
f0 z

Can you format your code…? Sorry, but it’s pretty hard to read like this. You need to select the code and press the code format button ‘</>’

here sorry that it took so long

<Cabbage>
form caption("Tari") size(600, 400), colour(58, 110, 182), pluginid("def1")
image bounds(0, 0, 600, 400) file("Tari plugin bg.png")
keyboard bounds(4, 298, 328, 95)
soundfiler bounds(4, 222, 108, 73) file("Fem Aa.wav") channel("Ah") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(224, 222, 108, 73) file("Fem Oh.wav") channel("Oh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(114, 222, 108, 73) file("Fem Eh.wav") channel("Eh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)

label bounds(4, 192, 108, 29) text("Ah: c1") fontcolour(255, 0, 202, 255)
label bounds(114, 192, 108, 29) text("Oh: c#1") fontcolour(255, 0, 202, 255)
label bounds(224, 192, 108, 29) text("Eh: D1") fontcolour(255, 0, 202, 255)
label bounds(42, 148, 261, 43) text("Kswitches") fontcolour(255, 0, 43, 255)
</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 Ah
a1, a2 diskin2 "Fem Aa.wav", 1, 0, 1
outs a1, a2
endin

instr Oh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin

instr Eh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>

There are lots of ways to do this. The simplest way is to check what note is pressed, and then react accordingly. To do this, first change the CsOptions in order to get the MIDI note number:

-n -d -+rtmidi=NULL -M0 -m0d --midi-key=4 --midi-velocity-amp=5

instr 1 check which note was pressed:

instr 1
    if p4 == 60 then
        a1, a2 diskin2 "Fem Aa.wav", 1, 0, 1
        outs a1, a2
    elseif p4 == 61
        //do something if user presses C#
    endif
endin

eh its not working for me

Maybe if you can just turn your computer monitor around slightly I can reposition my remote satellite to get a look at your code :rofl: Otherwise there is not much I can do with a statement like ‘it’s not working:man_shrugging:

p.s. in case my sarcasm is lost on you, please post the code that is not working…

ok lmao

<Cabbage>
form caption("Tari") size(600, 400), colour(58, 110, 182), pluginid("def1")
image bounds(0, 12, 600, 400) file("Tari plugin bg.png")
keyboard bounds(4, 298, 328, 95) whitenotecolour(63, 0, 255, 255) blacknotecolour(164, 0, 255, 255) arrowbackgroundcolour(255, 255, 255, 255) 
soundfiler bounds(4, 222, 108, 73) file("Fem Aa.wav") channel("Ah") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(224, 222, 108, 73) file("Fem Oh.wav") channel("Oh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(114, 222, 108, 73) file("Fem Eh.wav") channel("Eh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)

label bounds(4, 192, 108, 29) text("Ah: c1") fontcolour(255, 0, 202, 255)
label bounds(114, 192, 108, 29) text("Oh: c#1") fontcolour(255, 0, 202, 255)
label bounds(224, 192, 108, 29) text("Eh: D1") fontcolour(255, 0, 202, 255)
label bounds(-26, 148, 261, 43) text("Kswitches") fontcolour(255, 0, 43, 255)
label bounds(0, 0, 600, 14) text("=Tari art by rainder -- bg art by skylindraws -- vst plugin and sound design by HACKY=") colour(0, 0, 0, 255) fontcolour(255, 255, 255, 255)



vmeter bounds(336, 192, 19, 201) channel("out")   text("Volume") metercolour:0(255, 0, 217, 255) metercolour:1(120, 0, 255, 255) metercolour:2(34, 0, 255, 255) value(1)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=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 Ah
    if p4 == 60 then
        a1, a2 diskin2 "Fem Aa.wav", 1, 0, 1
        outs a1, a2
    elseif p4 == 61
        //do something if user presses C#
    endif
endin

instr Oh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin

instr Eh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>

There was a typo in my code I was missing the then at the end of this line:

elseif p4 == 61 then

this might be my fault idk but its still not working for me:

<Cabbage>
form caption("Tari") size(600, 400), colour(58, 110, 182), pluginid("def1")
image bounds(0, 12, 600, 400) file("Tari plugin bg.png")
keyboard bounds(4, 298, 328, 95) whitenotecolour(63, 0, 255, 255) blacknotecolour(164, 0, 255, 255) arrowbackgroundcolour(255, 255, 255, 255) 
soundfiler bounds(4, 222, 108, 73) file("Fem Aa.wav") channel("Ah") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(224, 222, 108, 73) file("Fem Oh.wav") channel("Oh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)
soundfiler bounds(114, 222, 108, 73) file("Fem Eh.wav") channel("Eh") colour(0, 96, 255, 255) tablebackgroundcolour(255, 0, 144, 104)

label bounds(4, 192, 108, 29) text("Ah: c1") fontcolour(255, 0, 202, 255)
label bounds(114, 192, 108, 29) text("Oh: c#1") fontcolour(255, 0, 202, 255)
label bounds(224, 192, 108, 29) text("Eh: D1") fontcolour(255, 0, 202, 255)
label bounds(-26, 148, 261, 43) text("Kswitches") fontcolour(255, 0, 43, 255)
label bounds(0, 0, 600, 14) text("=Tari art by rainder -- bg art by skylindraws -- vst plugin and sound design by HACKY=") colour(0, 0, 0, 255) fontcolour(255, 255, 255, 255)



vmeter bounds(336, 192, 19, 201) channel("out")   text("Volume") metercolour:0(255, 0, 217, 255) metercolour:1(120, 0, 255, 255) metercolour:2(34, 0, 255, 255) value(1)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key=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 Ah
    if p4 == 60 then
        a1, a2 diskin2 "Fem Aa.wav", 1, 0, 1
        outs a1, a2
    elseif p4 == 61 then
        //do something if user presses C#
    endif
endin

instr Oh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin

instr Eh
kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>

What do you mean when you say it’s not working? Of course you have to finish writing the code, I merely gave you enough to get going. Right now when I press C3 I get an error telling me it can’t find the Fem sample, which is expected considering I don’t have that sample here. But it also tells me that the code is working fine, at least the code that is there.

Finally the forums are back up!!

Anyway i should have been more clear about what i was trying to do.
I am trying to make a vst specially for an fnf mod (ya know that game no one can escape from) and its purpose is basicly to play samples like a soundfont with k switches to switch between vowels.

finally i remembered the word TRANSPOSE thats what i am trying to do

well this doesnt work lol

instr Ah
ktrans linseg 1, 5, 2, 10, -2
a1, a2 diskin2 "Fem Aa.wav", ktrans, 0, 1, 0, 32
outs a1, a2
endin

Perhaps you want to use an enveloper with a release state. Swap out linseg with linsegr and update accordingly. Anyhow, in what way does it not work?

It sounds like a siren
Thats not what its supposed to do

That’s because you are changing the frequency with an envelop? If you want to re-pitch the sample based on the current not, you need to know what pitch the actual sample is, and then transpose it accordingly based on interval ratios of the tuning system you wish to use.

Ok ill figure out what pitch my samples are and comeback here

I dont really get what u mean with the pitch of my sample all i want to do is this but with the samples preloaded into the synth:

https://drive.google.com/file/d/1EQmtuNOkDgXbGUb6Oz0uCWCypU6kCT02/view?usp=sharing

Are you using samples of actuals notes?