[Csnd] MIDI activated instruments: passing on note-off

Hey hey,
I have a MIDI activated instrument, by using realtime MIDI events (-+rtmidi=...). Inside that instrument I need to call other instruments. Or possibly activate one instrument several times by one MIDI event. Her's the basic outline:

massign 1, "Player" ; Assign MIDI channel 1 to Player

instr Oscillator
   ; Play some sound using p4 and p5 MIDI note and velocity
endin

instr Player
   ; start several Oscillator instruments
   ; and stop them, when the MIDI note ends
endin

Of course, the Oscillator instrument is something quite complex that would require a lot of code to duplicate and thus be open to typos, huge code redundancy and very awkward maintenance. Any kind of loop, like while or loop_lt would not work either. Think of it like a string section made up of individual instruments.

Is there any tried and tested solution? Or perhaps a good opcode which I have overlooked that is made for this purpose?

Best wishes and thanks,

Jeanette

The way I would do this is to send events with fractional p1 and p3=-1 and then check for the release flag, then send corresponding negative p1s to stop the events.

Prof. Victor Lazzarini
Maynooth University
Ireland

Hi Victor,
thanks for the feedback. This sounds quite viable and clean.

Best wishes,

Jeanette

Sep 18 2024, Victor Lazzarini has written: