Cabbage Logo
Back to Cabbage Site

Turning on and off instruments (turnon / turnoff-opcodes)

hi all,

first post :slight_smile: I’m only into cabbage for ~2 weeks and into csound maybe ~4, so I’m not at all surprised that almost nothing I try to achieve works out :joy: I could be posting a 1000 questions already but I’ll try to keep it to a minimum.

I read on another thread that the turnon / turnoff-opcodes don’t work on windows (I’m on windows 10). (which I read because as soon as I tried launching a csd-file with one them it crashed cabbage instantly. Cabbage just shut down, no error-messages. It took me some time to find out what the issue was and I’m hyper-glad that cabbage restores unsaved changes after the crash! :cowboy_hat_face: )

In that other thread it said that one should use a score event instead of the turnon opcode, like event "i", "inst_name", 0, 1 which sounds good.
But
1) How can you turn the instrument on indefinitely? From the score section you can:
i99 0 z to play intrument 99 forever, but from in the instrument section I can’t send that “z”. Should I just pass a duration of several days? But then
2) How can I turn the instrument off again with a score event? I googled and looked through the examples but found nothing so far.

Thanks for any thoughts and hints!

Kind regards,
Stefan

Hi @Stefan_Mayer, welcome to the forum!

  1. i1 0 -1 will start instr 1 with infinite duration
  2. i-1 0 -1 will stop instr 1 (the third param can be any number instead of -1)
1 Like

Hi @giovannibedetti, thanks for the welcome! I’m enjoying the atmosphere of this forum a lot.

Thank you for your answer!
Reading it I realized that I did of course read that in the floss manual at some point, but it totally slipped my mind.
With a little twisting I got it working as an event from the instrument section as well:

turn on:
event "i", "MIDI_seq", 0, -1 (-1 duration for indefinite playback)
turn off:
event "i", "MIDI_seq", 0, 0 (0 duration for “off”)

Just in case anyone else ever stumbles upon this with a similar question.

This brings me one significant step closer to syncing my metro opcode with the host beat!

1 Like

Spoiler alert!

bpmTest.csd (678 Bytes)

In this one I turn off each instrument before I start a new one.

if metro(kBPM/60) == 1 then
        event "i", "Pulse", 0, 0
        event "i", "Pulse", 0, -1
endif

If you know how long each MIDI_Seq is going to be, then you can simply set the desired duration on each event.

1 Like

:laughing:
breaking news: csound now let’s you turn off an istrument! hehe

I didn’t mean to sound like I invented the method, it’s really trivial once you know how to do it. But on the other hand, it’s really not self-explanatory either and, due the lacking csound keyword in the syntax, somewhat hard to search (also in the examples). Thought it would be nice to leave it here for someone who possibly has the same line of thought as I -> preferring triggering instruments from the instrument section, therefore ignoring most of the reading on the score section (mistake), thinking all of it can be done with turnon/turnoff-opcodes, only to realize they just ever so bluntly crash cabbage and seem not to be working on windows at all :wink:

@rorywalsh where is that bpmTest.csd from? I’m pretty sure it did not come with my cabbage installation. I read about some other examples here already that I failed to spot in the cabbage examples. Is there a second go-to resource?

I just threw it together for you earlier :+1: