Cabbage Logo
Back to Cabbage Site

Key trigger

Hi, was wondering if you can trigger samples by using the keys on my laptop rather than a midi controller?

Thanks.

The Cabbage keyboard component can be triggered with keys. Bring the plugin window into focus (in the Cabbage IDE) and try hitting ā€˜aā€™ for example. This will not work in all hosts. Most host handle keystrokes themselves.

Thanks Rory, unfortunately im not sure what the IDE window is lol

IDE is the instrument window? how do I bring the plugin window into focus?

Thanks

I just mean the plugin instrument window when you run it in Cabbage. If it doesnā€™t have focus, the keystrokes will end up passing to the text editor instead. :+1:

Ok thanks. Iā€™ll just let you know my idea for thisā€¦my plan is to have an interface that when you play numbers 1-7 on the keyboard a sample will play containing a chordā€¦I also want to trigger samples that are just midi notes triggered by letters on the keyboard that I would like specifically assign (n,j,i,m,k,o,l,p). and hopefully later assign knobs and sliders that will have effects that will affect the midi note samples(reverb, chorus etc.) is this possible do you think?

Cabbage doesnā€™t currently allow custom mapping of key strokes, so Iā€™m not sure how far you will get with that. :thinking: Do you need a GUI? If not you could just do this with plain old Csound from the command line.

Oh, you could also use the texteditor widget, which you can then parse for keystrokes. That might be the best actuallyā€¦

I tried using the text editor example on the page but it crashes for meā€¦its for an assignment for which im basing off an old p5 coding assignmentā€¦but I seem to having issues with going about itā€¦I think I might just try get a new idea altogether thoughā€¦thanks for your replies Rory.

Donā€™t give up so easy Chris! Try this instrument. Itā€™s only set up to trigger notes with 1 and 2, but it should get you started. You have to hit enter after you type the number into the text editor.

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
texteditor bounds(60, 16, 248, 27) channel("textEditor1"), text("")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
    SKey, kTrig cabbageGetValue "textEditor1"
    cabbageSet kTrig, "textEditor1", strcpyk("text(\"\")")

    if kTrig == 1 && strcmpk(SKey, "1") == 0 then
        event "i", 2, 0, 4, 60
    elseif kTrig == 1 && strcmpk(SKey, "2") == 0 then
        event "i", 2, 0, 4, 62
    endif
endin

instr 2
    a1 expon 1, p3, 0.01
    a2 oscili 1, cpsmidinn(p4)
    outs a2, a2
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Thank you Rory, Iā€™ve decided im going to try use the keyboard as standard. I now have a sample playing from the keyboard when I press a, s, d etcā€¦but all text keys are assigned to the 1 sampleā€¦how do i assign seperate keys to seperate samples?
Thanks

Iā€™m not sure I follow. I think you might need to post your .csd?

3.csd (3.1 KB)

Ok i think its uploadedā€¦each button needs to be able to trigger a sample, preferably using the keys(which are indicated by the small letters on the button). Each button will be a sample midi note corresponding to the pitchā€¦does that make sense?

Sorry, I fail to see what youā€™re doing here, and the .csd file wonā€™t compile.

Iā€™m not sure what you meant by this.

I canā€™t see how that is in the .csd you posted? Maybe you posted the wrong one?

I have changed from this idea with the keyboardā€¦i now have an array of clickable buttons in the ā€œ3.csdā€ I sent? C-D-E-F-G-A-B-C will be the pitch of the samplesā€¦the smaller letters are the buttons of my text keyboard that will trigger them.

3.csd (2.2 KB)

Ok, there are a lot of issues here. Have you gone over the video tutorials. It seems that you might need to do a slight crash course on Csound and Cabbage?

There was one that seemed fitting where you used double bass samples, and i was going to base it off that but the files just wouldnt play for meā€¦ill have another look though.
Thanks Rory

Let me know which ones donā€™t work for you, or post them here so I can take a look.

Ok this is the update, small bit stripped back :grimacing:

3.csd (3.0 KB)

Of all the languages in the world, Iā€™d say Csound is the hardest one to copy code for if you donā€™t have a good grounding in Csound. In this instrument I was being clever in using a single instrument, and starting it 8 times, but for the beginner this is rather complex. If you just want a button to trigger a sample, just do something like this:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
button bounds(10, 10, 100, 50), channel("play1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
  kButton1, kTrig1 cabbageGetValue "play1"
  if kTrig1 == 1 then
    event "i", 2, 0, 2
  endif
endin

instr 2
    a1 diskin "mySample.wav", 1, 0, 0
    outs a1, a1
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Thatā€™s about as simple as it gets, but I think you would best served starting with something simple.

ok thank you that worked :grinning:
is it now possible to trigger that sample with the letter a for example??