Csound Csound-dev Csound-tekno Search About

[Csnd-dev] InstrDef names and numbers

Date2026-10-29 12:19
Fromthorin kerr
Subject[Csnd-dev] InstrDef names and numbers
Hi Csound Dev's

I wouldn't presume this is a bug, but I have noticed something unusual about using InstrDef and create, that I wonder if it was intentional.

At the moment, it looks like create() compiles instrument body code into an InstrDef and assigns and binds that instrument to both a name variable, and an Instrument number.

If create() is called again, the same named variable is re-bound to whatever the new instrument definition might be, but the instrument number is incremented/reassigned. This can be mitigated somewhat by using delete, although there's no guarantee the new instrument definion gets the old number it used to have.

Here's a simple example:
<CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr wrapper
  istamp = p4
  iendamp = p5
    defbody:S = sprintf({{
      aenv linseg %f,p3,%f
      aTone poscil p4*aenv, p5
    out aTone
  }},p4,p5)
  tone@global:InstrDef = create(defbody)
  printfi("tone inum = %f\n",1,nstrnum(tone))
  ;; no deletes
endin

schedule(wrapper,0,1,0,1) 
schedule(wrapper,1,1,1,0)

</CsInstruments>
<CsScore>
f0 2

e
</CsScore>
Output is:
tone inum = 2.000000 tone inum = 3.000000

It's different to 'the old' method of using something like compileorc or evalstr to redefine an instrument definition ( in which case the instrument number is retained).  
I suspect this might also cause issues if I'm routing audio signals between instruments and expect the signal path to follow the order of instrument number.
I acknowledge this might be intentional, in which case, your wisdom on correct usage would be much appreciated.
Thorin


Date2026-10-29 12:28
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd-dev] [EXTERNAL] [Csnd-dev] InstrDef names and numbers
yes, every time you call create a new InstrDef is created into a free number slot and so that's expected. 

It's different from other ways of compiling instruments. If you want to replace, you need to compile an instrument using compilestr.

Prof. Victor Lazzarini
Maynooth University
Ireland

On 29 Oct 2026, at 12:20, thorin kerr <thorin.kerr@gmail.com> wrote:



*Warning*

This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.

Hi Csound Dev's

I wouldn't presume this is a bug, but I have noticed something unusual about using InstrDef and create, that I wonder if it was intentional.

At the moment, it looks like create() compiles instrument body code into an InstrDef and assigns and binds that instrument to both a name variable, and an Instrument number.

If create() is called again, the same named variable is re-bound to whatever the new instrument definition might be, but the instrument number is incremented/reassigned. This can be mitigated somewhat by using delete, although there's no guarantee the new instrument definion gets the old number it used to have.

Here's a simple example:
<CsoundSynthesizer>
<CsOptions>
-odac -d
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr wrapper
  istamp = p4
  iendamp = p5
    defbody:S = sprintf({{
      aenv linseg %f,p3,%f
      aTone poscil p4*aenv, p5
    out aTone
  }},p4,p5)
  tone@global:InstrDef = create(defbody)
  printfi("tone inum = %f\n",1,nstrnum(tone))
  ;; no deletes
endin

schedule(wrapper,0,1,0,1) 
schedule(wrapper,1,1,1,0)

</CsInstruments>
<CsScore>
f0 2

e
</CsScore>
Output is:
tone inum = 2.000000 tone inum = 3.000000

It's different to 'the old' method of using something like compileorc or evalstr to redefine an instrument definition ( in which case the instrument number is retained).  
I suspect this might also cause issues if I'm routing audio signals between instruments and expect the signal path to follow the order of instrument number.
I acknowledge this might be intentional, in which case, your wisdom on correct usage would be much appreciated.
Thorin

The information contained in this email may be confidential and privileged. It is intended only for the addressee(s) stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig  dataprotection@mu.ie  agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130