Cabbage Logo
Back to Cabbage Site

Understandig how Cabbage/Csound works

Hi,

working on a new project, (realtime/NON realtime) I realized that I did not clear a few things about Cabbage and Csound. In the figure below, I drew a diagram on how I imagine working Cabbage\Csound.
But I have a lot of confusion about it:

  • the MIDI informations are routed into Cabbage and it re-routed them into “flag” section for their activation-deactivation. If I don’t write the -M flag, the realtime MIDI is deactivated. It’s right?

  • But if I don’t write the --midi-key-cps=4 flag, the cps for ALL my instruments are lost? Or?

  • If I don’t write the --midi-velocity-amp=5, the amplitude for ALL my instruments are equal to 0? In this situation I think I have to write 1 in the amplitude argument for oscili?

  • who activates or deactivates my instruments? If I write i1 0 3600 in the score, Cabbage turned on the instrument1, but what happens if you do not write anything? The MIDI informtions (-M and so on is write in the CsOptions), is routed into my instrument (perhaps using massign opcodes…), but who turn on the instrument? How this works?

  • when to use the opcodes that get MIDI informations for my instrument (bender, notnum, veloc, ecc…) since p4 p5 are already assigned by Cabbage? It makes sense to use them?

  • how Cabbage/Csound handles the switching on and off of the instruments without the use of the score?

  • they are read and sent GUI values?

I don’t understand these things…

Can someone help me?

Many thanks again for all…

R

Nice diagram! I’ll attempt to answer one by one.

MIDI is intercepted by Cabbage and then sent to Csound. We use -+rtmidi=null -M0 to tell Csound NOT to use its own MIDI interface, and listen for MIDI messages on all ports. It’s important that Csound doesn’t use its own MIDI interface as this would lead to two applications trying to access MIDI at the same time.

Not at all. This is just a useful way of passing MIDI information to a p-field in your instrument. Check out http://csound.github.io/docs/manual/MidiInput.html for a list of useful MIDI opcodes. Also, take a look at some of Iain’s synths. He rarely uses the –midi-key-cps flag. He simply uses the notnum opcode to retrieve the incoming MIDI
notes.

Same as above. Again, many people use the veloc opcode to get this information.

If you write i1 0 3600 in your score your instrument will be activated as soon as it is loaded. When loaded a plugin, it will start running as soon as you place it on a track and hit play. f0 score statement instructs Csound to wait for realtime events before triggering an instrument. So in the context of a synth, we often trigger an instrument to play ONLY when MIDI triggers it. But you can also have a synth that is running all the time, and simply waits for incoming MIDI message before it actually does anything. The choice is yours.

These opcodes can be used any time. If you have an instrument that uses veloc that is always on, your velocity will be 0 when no keys are pressed, so you can test this yourself within the instrument while it is performing.

In the case of MIDI it’s pretty straightforward. Incoming MIDI messages will trigger particular instruments. By default, messages on channel one will trigger instrument 1, channel 2, instrument 2 and so on. You can use massign to set up custom associations between channels and instruments. If you wish to trigger an instrument from a widget in Cabbage, ergo, without a MIDI message you can do using an event opcode. For example, let’s assume you have a button in your plugin window, and an instrument number 99 defined in your Csound orchestra. You can use code like the following to turn it on for a second.

k1 chnget "but1"
if changed(k1)==1 then
   event "i", 99, 0, 1
endif   

You can also turn instruments off using turnoff and turnoff2. Looks at some of Iain’s file play instruments. He uses similar mechanism to start and stop instruments that record audio. The same can be achieved using the schedkwhen opcode.

If you want to send instrument 99 from above, the value of a slider, you can pass the sliders value as an extra input argument to the event code:

k1 chnget "but1"
kSlider chnget "slider1"
if changed(k1)==1 then
   event "i", 99, 0, 1, kSlider
endif   

I hope this helps. Thanks for asking. These are things I think everyone struggles with at some point or another. I’ve been using the –midi-key flags myself for teaching as I find it easier to explain to students that a MIDI key press triggers an instrument, and p4 and p5 are the MIDI note and velocity. Because they don’t have to worry too much about what’s actually happening behind the scenes they can quickly get to building synths. But ultimately, all of the questions you have just asked come up too. The next time a student asks I can send them to this thread :wink:

2 Likes

Hi,

I have no words to thank you! I now understand many things, (maybe not all), but surely I keep them in mind for future projects…

Thanks Rory; thanks to your Cabbage, I 'm learning also Csound (and a bit of english… :blush: )

Many thanks again!

R

Hi,

I’m so sorry, but can you explain one more thing?

I hack one Iain example code for learn how Csound activate/deactivate the instruments, but I 'm lost…

why if I don’t write anything, Csound works equally?

In the examples you see it seems to me that only the instrument 1 work at “standard mode” but all the other instruments are not activated by your button…

Many thanks! I did not know…

Thanks again, I am going crazy!

Examples.zip (3.2 KB)

R

If your instrument is numbered 1-16 then it may be triggered by incoming midi messages.

Yikes, it’s never a good idea to mix fltk stuff with Cabbage. When I refer to Iain’s examples I’m strictly referring to his Cabbage examples :slight_smile: Here is a simple instrument that will trigger two additional instruments when either button is pressed. Instrument 100 is instructed to start immediately from the score section. If I left that out and added a “f0 z” nothing would happen, even if MIDI was being sent to the instrument.

001.csd (841 Bytes)

1 Like

Hi,

do not ask me why I was convinced that f0 (for example) or i-n statements turning on all the instruments in the orchestra, and that was enough a button on each to turn them on/off at will (turning on for me is also start or restart the envelopes, audio generations and all the code present in each instrument).
So, if I understand correctly, instr1 is turned on from the score, is the “Master” instrument, and all the others instruments become slave (it’s possible to turn on/off them from “Master” instrument because is active…). The “slave” instruments recalculate all the i-time variables every time I turn on/off each… :frowning:
If I will to play instr3, for example, i need to route the MIDI data with the massign opcode, and all the effects instruments, are turned on always with the f0 function…

Many thanks AGAIN Rory; now everything is more clear. I can go with my new project … :blush:

R

1 Like

there are instruments that are always active: they do not need to be turned on/off because you want to make sure that there is always a reverb (for example). But if I want to turn it on/off I must to insert a new button in the “Master” instrument.

:blush:

(PS: sorry for the .csd fltk…I have not thought about them in Cabbage… :sweat_smile:)

Is correct? :cold_sweat:

THANKS AGAIN Rory…

R

Just so ew’re clear,

  • f0 does not start any instruments. It merely tells Csound to wait for events for a set duration. You decide how events are used.
  • If you want an instrument be active you must start it in the score using an i-statement, or from another instrument using one of the event opcodes.
  • I’m pretty sure the MIDI opcodes can be used in any instrument to access incoming MIDI. You could for example start instrument 10 from instrument 1, and use the notnum opcode in instrument 10 to get MIDI notes.
  • Every time an instrument is started, whether from the score or through an event opcode, it will initialise right back from the start.
  • You could also read MIDI data in instrument one and use global variables to pass it to other instruments. If you do this, note that Csound processes each instrument in order of number, staring with the smallest and going to the largest. Instrument 1 will also be processed before instrument 100.