Cabbage Logo
Back to Cabbage Site

Passing midi to Effect instrument

add on to my last post, but i felt like this should be a new topic since its a new issue.

Found a way to do the Filters, and now the plugin is functioning the way i originally intended. However, after showing it to some people and getting feedback on its function, i would like to expand its functionality. What i would like to do is be able to is pass midi information to the effect plugin, and make the resonances occur on the keys pressed. This however presents multiple questions.

1- How do i go about passing midi to the effect? how do i make sure this will work with DAWs? Should i need to include controls to change the midi channel and port?
2- How do i assign one frequency to one note? or in other words, make sure every note has one resonance associated with it?
3- How would i make this scalable? would it be best to create an individual opcode that creates a singe resonance, and then make that occur at every note?

I realize this is a complicated topic, with a lot of questions, so i appreciate the effort in answering. :slight_smile:

From my understanding of what you are designing here, the way I normally approach functioning such as this is to have an instrument (instr 1) that is always on to receive audio in and handle any other global and single-instance variables and procedures, and a second instrument (instr 2) that is triggered by MIDI notes and creates instances of signal processing according to however many notes are being played. You should to use massign to ensure the correct instrument is triggered from MIDI. Below is a simple example. Sound is generated in instr 1 and processed in instr 2 by reson. Frequency of reson depends on the MIDI notes played; I think you are aiming for something like this.

form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
keyboard bounds(8, 158, 381, 95)
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

massign 0,2 ;all MIDI notes trigger instr 2

instr 1 ; always on
gaL noise 0.3,0
gaR noise 0.3,0
; gaL,gaR ins ;;use for live audio in

instr 2
icps cpsmidi
aL   reson    gaL,icps,icps*0.1,1
aR   reson    gaR,icps,icps*0.1,1
     outs     aL,aR

;causes Csound to run for about 7000 years...
i 1 0 z
1 Like

This seems to be what im after! thanks for the response! If i wanted to be able to switch from one mode to the other, would i put all the code for that section in instr 1 since its not triggered by midi, then switch between which audio is going out?

You can set up a two-way conditional at the top of the instrument that sets the relevant variables depending on whether the instrument was activated by a MIDI note or by a GUI button. There are a number of opcodes and ways in which you can set up the conditional query, but mididefault might be a good place to start. If you need and example, let me know.