Cabbage Logo
Back to Cabbage Site

Change image when note on

Hi! Is there any way to switch between images using the note on and off data? When I hit the MIDI keyboard the image will change, and when I leave the keyboard the image will switch back.

Thank you!

Hi @chenliu52, welcome to the forum. You can just toggle the image when a note is played. Then listen for the release segment to disable the image once again. :+1:

<Cabbage>
form caption("Untitled") size(400, 500), guiMode("queue"), pluginId("def1")
image bounds(0, 0, 400, 400), channel("image1"), file("sadFace.png")

keyboard bounds(0, 398, 400, 100) channel("keyboard10001")
</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
    cabbageSet "image1", "file(\"happyFace.png\")"
    cabbageSet changed(release()), "image1", "file(\"sadFace.png\")"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>