[Csnd] print values if subinstr is active

Dear community,
In the following example, I would like to print the value of iamp, but only if the subinstrument is activated (when a midi key is pressed).

How could I achieve this?


-o dac -Ma


sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 ;master instrument
inumparts = p4 ;number of partials
ibasfreq cpsmidi
ibaseamp ampmidi 1
ipart = 1 ;count variable for loop
;loop for inumparts over the ipart variable
;and trigger inumpartss instanes of the subinstrument
loop:
ifreq = ibasfreq * ipart
iamp = ibaseamp/ipart/inumparts
event_i “i”, 10, 0, p3, ifreq, iamp
loop_le ipart, 1, inumparts, loop
endin

instr 10 ;subinstrument for playing one partial
ifreq = p4 ;frequency of this partial
iamp = p5 ;amplitude of this partial
aenv transeg 0, .01, 0, iamp, p3-0.1, -10, 0
apart poscil aenv, ifreq
outs apart, apart
endin

; number of partials i 1 0 3 10 i 1 3 3 20 i 1 6 3 2 ;Example by joachim heintz

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

hi stefan -
i don't understand this condition: "only if the subinstrument is activated (when a midi key is pressed)".
do you trigger via midi keyboard, or via score, or both?
best -
  joachim

I trigger via midi keyboard instr 1 which triggers instr 10

but then, what is the question?
why not simply print(iamp)?

Sorry, I made a couple of mistakes in the code, I was too hasty again.
With this below quoted code I get, before pressing the first midikey the following messages:
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000
instr 10: iamp = 0.000

-o dac -Ma -m0d sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 alwayson 1 instr 1 ;master instrument inumparts = 10 ;number of partials ibasfreq cpsmidi ibaseamp ampmidi 1 ipart = 1 ;count variable for loop ;loop for inumparts over the ipart variable ;and trigger inumpartss instanes of the subinstrument loop: ifreq = ibasfreq * ipart iamp = ibaseamp/ipart/inumparts event_i "i", 10, 0, p3, ifreq, iamp loop_le ipart, 1, inumparts, loop endin ; number of partials

instr 10 ;subinstrument for playing one partial
ifreq = p4 ;frequency of this partial
iamp = p5 ;amplitude of this partial
print(iamp)
aenv transeg 0, .01, 0, iamp, p3-0.1, -10, 0
apart poscil aenv, ifreq
outs apart, apart
endin

;Example by joachim heintz

Unless I’m reading this wrong, it looks like you are running instr 1 from the score, and instr 1 is invoking instr 10 in a loop. which will happen regardless of MIDI input.

but why do you write "alwayson 1"?
what you want to do is to trrigger your instr 1 via midi keyboard.
this happens, as you say. (otherwise it would be a problem of the midi settings.)
so no need for a score, and no need for any alwayson.
here are more descriptions: The Csound FLOSS Manual

okay, that’s the way. I will try it. Thanks!