Cabbage Logo
Back to Cabbage Site

Learning about midiin opcode

Hi all,

i would like to understand about midiin opcode but I have problems with it; (this opcode is very simply but… :sweat: )
I would like to print 144 (=NoteOn) when I press a Note, and 128 (=NoteOff) when released… Simply… but…
It happens that the values ​​are printed together only to the release of the note (Or If I hold the note, only 128 is printed :disappointed: ) …

what I wrong?

; detecting MIDI information: 128 (note off) - 144 (note on)
kstatus, kchan, kdata1, kdata2 midiin
ktrig changed kstatus
if (ktrig==1 && kstatus==144) then {
printk2 kstatus
}
elseif (ktrig==1 && kstatus==128) then {
printk2 kstatus
}
endif

Thanks, R

Seems to work for me, but it seems to be missing some message. This may be Cabbage and not Csound. I’m seeing some issues in the output console lately. Anyhow, try this:

instr 100
; detecting MIDI information: 128 (note off) - 144 (note on)
kstatus, kchan, kdata1, kdata2 midiin
ktrig changed kstatus

if (ktrig==1 && kstatus==144) then
printks “Note on:%d”, 1, kstatus
elseif (ktrig==1 && kstatus==128) then
printks “Note off:%d”, 1, kstatus
endif

endin

Note that Csound doesn’t need {}'s around an if statement. It looks quite odd having them in there. Although it causes no problem now, the language is constantly growing. In the future these types of brackets could potentially mean something and your code would break.

Hi Rory,

very thank’s for your reply and sorry because I often ask for help… All the documents about Csound are in english and frequently I don’t understand many things…

I tried your code but the problem still exists. And sound several notes that are not reported.
I must point out that often the midi bus crashes and the instrument continues to play indefinitely. I have to restart cabbage or the Instrument (Reload Instrument) to turnoff the sound…

Thanks for {} info, I’ll be more careful.

R

Feel free to continue asking here. That’s fine. Can you try this one, it runs Ok for me?

testMIDI.csd (610 Bytes)

works much better, it happens that loses some info (Note OFF)…

but, thanks! :blush:

R

As I said, I think some Csound messages might not be getting through. If I get a chance later I’ll try it outside of Cabbage and see if it it is a Cabbage issue of messages not being printed to the screen. But I’m pretty sure MIDI is working as it should.