Ok, I see an issue with my code, it seems that you can’t assign two different Csound instruments to the same MIDI channel. I always thought this was possible. Anyway, I think you’re better off putting everything into the same instrument. Otherwise you’ll have to manage the starting and stopping of the other instruments manually. See below, Btw, this code is a bit of a mess - but should get you set up.
<Cabbage>
form caption("Drum-synth") size(400, 300), guiMode("queue"), pluginId("def1")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key=4 --midi-velocity-amp=5 -b128 -B256
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
massign 1, 1
instr 1
;Henter notenummer
iNote notnum
iVel = p5
; Declare a variable to hold the file name
Sfile = ""
; ; Choose the sample file based on the MIDI note number
if (iNote == 60) then
Sfile = "1 - Hi-Hat.wav"
elseif (iNote == 61) then
Sfile = "2 - Crash.wav"
elseif (iNote == 62) then
Sfile = "3 - Rimshot.wav"
endif
iLen filelen Sfile
xtratim iLen
; Play the selected sample without looping
a1, a2 diskin2 Sfile, 1, 0, 0
; Output the audio
outs a1, a2
; Midi-note input
if (iNote == 63) then
; Bass drum synthesis code
kFreq expon 400, 0.1, 5
kAmp expon 1, 0.7, 0.00001
aSin oscil kAmp, kFreq
kNoiseAmp expon 1, 0.1, 0.00001
aNoise rand kNoiseAmp * 0.2
aOut = aSin + aNoise
; Output the audio
outs aOut, aOut
endif
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f 0 z
</CsScore>
</CsoundSynthesizer>