Cabbage Logo
Back to Cabbage Site

Csound : Managing multiple "named" instances

This isn’t a Cabbage specific question but this forum seems more active than the Csound Slack :wink: so maybe someone has a suggestion…

I’m trying to launch named instances of an instrument with ‘schedwhen’ but it seems to keep returning the same ifxsno on each trigger. Shouldn’t they be on fractional or different instr numbers? schedkwhen allows you to define the max number of named instances that can be instanced so how can I locate which instr numbers those are allocated to?

schedkwhen metro(1), 0, 5, gSeffectName, 0, -1 ;launch named instrument
            ifxsno nstrnum gSeffectName  ; get instrument number of named instrument
            print ifxsno

Basically, I have a library of named instrument effect .orcs that I wish to compile “live” with compileorc. Multiple instances of the same file can be instanced but I need to somehow keep track of them to turn individual ones off later.

You’re aware that Csound has its own discord server now? That’s why Slack is so quite these days.

I’m not sure. I thought they would all return the same number unless you specify fractional parts when triggering them. I’m not sure how you would do this with a named instrument. I think you can both name and number instruments. In this case you would trigger them via fractional number. You could also write a UDO that would let you do something like:

schedkwhen metro(1), 0, 5, namedInstr(gSeffectName, iFrac), 0, -1

where namedInstr take an instrument name, and return the instrument number with a fractional part. Either way, you have to manage the fractional parts yourself if I’m not mistaken.

Oh? Nobody told me where the party went? :laughing: Thanks for the tip…

I thought every named instr was actually assigned an instr number. Hmmm… Thanks for the suggestion there - I need a different way of thinking about this b/c I’ve been stuck on it forever… so I’ll try it.

They are. but you don’t know what’s what until you check. But you can do:

instr MyRetirementFund, 1

And then call it by its number with a fractional part?

I see… Do you know if instrument number can be dynamically assigned?

if iAmRetiring < 1 then 

ginum = $100


`instr MyRetirementFund, ginum`

It looks like you are trying to set an i-rate variable at k-rate times… Or am I missing something about the variable name “ifxsno”?

You are right but ifxsno does return a value that’s indicative of the named instrument. Not sure how it gets there though…

I could but it messes up some of the flexibility I was hoping for. Doing it this way means that each .orc has to have a fixed number that I need to keep track of so there aren’t any conflicts. It adds a lot more dependency. Might be my only option though…

I’m not sure, have you tried set p1 when an instrument is started?

It looks like instrument names do not correspond to the number when defined in instr
For instance with instr 100, namedInstrument does not mean that namedInstrument is #100.
You can call one or the other and namedInstrument will get a default instr number if you use that to call it. I did not know this… Anyway, don’t mean to clog up the Cabbage forum with Csound questions… will figure something out here…

Don’t worry about that. I just tried the same here. This seems very odd. The following gives a different number for the named instrument to what pi1 gives?

instr 1
    event_i "i", 100, 0, 1

instr 100, namedInstrument
    print p1
    print nstrnum("namedInstrument")


instr 100:  p1 = 100.000
instr 100:  #i0 = 2.000

Surely this is wrong?

That’s what I always thought but according to the manual this is correct. The names or numbers can be called but they do not correlate. The names instrument will simply take the next available spot.

1 min later…. Wait a minute. Is there a difference between

instr named, 1


instr 1, named


Oh I see now. Ha. Yeah that does not look right.