Cabbage Logo
Back to Cabbage Site

Midi Out to a DAW, it should work... but it doesn't

After bein able to sync my instrument to the host bars / beats, now I’m struggling to send MIDI from it to Reaper.
As a quick check I tried the MIDI Arpeggiator example, which uses the noteondur opcode. It works, but when I use it inside my k-rate trigger nothing is received from Reaper.

In my basic test a just wrote:

if kTrigger==1 then
  noteondur 1, 60, 80, 0.5
endif

The instrument uses the usual score to run for 1 week.

I expect it to send a noteon, followed by a noteoff after 0.5 seconds, on channel 1.

I’ve used the same CsOptions from the Arpeggiator, and I’ve exported the VST as a synth.

Questions:
is there something that should be done to ensure that MIDI out is correctly routed to the DAW?
how to send noteondur to any channel (insteaf of one from 1-16)?

I think the issue here is that noteondur is i-rate. What I would do in this sinstance is spawn a new instrument to handle the MIDI magic:

if kTrigger==1 then
  event "i", "MIDI_MAGIC", 0, 0
endif

I’d then lob the noteondur opcode into the MIDI_MAGIC instrument and hope for the best :rofl:

rigth @rorywalsh. I did a step ahead, and Reaper seems to “sense” the MIDI note but nothing is recorded. Apparently it doesn’t last the expected 0.5 seconds, and probably that’s the reason nothing appears to be recorded.
Isn’t noteondur meant to make a noton for the desidered duration, followed by a noteoff?

I’ve also tried extending the duration of the event, and using noteondur2, but nothing changes…

<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=null -m0d -Q1 --midi-key=4
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 
	kIsPlaying chnget "IS_PLAYING";
	kPPQPosition chnget "HOST_PPQ_POS";
	kTimeSigNum  chnget "TIME_SIG_NUM";
	kTimeSigDenom chnget "TIME_SIG_DENOM";
	kquarterNotesPerBar = kTimeSigNum *4 / kTimeSigDenom;
	klastBarPos = int(kPPQPosition/kquarterNotesPerBar)*kquarterNotesPerBar;
	kTrigger metro 1

	if kIsPlaying==1 && changed:k(klastBarPos)==1 then
		printk 1, klastBarPos;
		event "i", "MIDI_OUT", 0, 0
	endif
endin

instr MIDI_OUT
    ;MIDI note 60, vel 80, 0.5 secs duration on channel 1
	noteondur2 1, 60, 80, 0.5
endin
</CsInstruments>
<CsScore>
f0 z
i1 0 z
</CsScore>
</CsoundSynthesizer>

I’m busy on something else for the next hour or so, but I think I might have come across this problem before. Can you try something like this?

instr	MIDI_OUT	
 noteon	1,p4,p5
 krel release
 if krel==1 then
  event "i",3,0,0,p4,p5
 endif
endin

instr	3	; note off
 prints	"note off\n"
 noteoff	1,p4,p5
endin

I will have time after lunch to look at it myself if you can’t get something working…

I’ve added a print statement for the “note on”. It gets printed, but note off never.
How is the release opcode expected to work in this case? Who’s expected to set the “release” stage of the note?

In any case the behaviour in Reaper is the same as before. The notes arrive but are not recorded.

Are you setting a duration other than 0 for the MIDI_OUT instrument? In the code you posted earlier is has. duration of 0?

Do you mean in my “noteondur2” trial? In that case I’ve tried setting both a duration of 0 or more. From what I read noteondur2 shouldn’t rely on the triggering event duration.
By the way, if I set a duration of, let’s say, 0.5, it looks like a second midi event is received by Reaper, but still with sort of empty duration (not recorded).

Am I the first person trying to write MIDI to a DAW from a Cabbage/Csounds plugin? :slight_smile:

I’ve done this before without too many issues. I will take a look tomorrow, sorry, my hands were full with other things today…

No problem @rorywalsh, it’s not that urgent.
Thanks so much for your support!

I just tried here now. Same as you, my second track is getting the notes, but they are not being recorded. Must be something in Reaper’s settings…?

Got it! Let me know if this helps. I’m using the MIDIOut2 example.

Unfortunately I wasn’t able to reproduce your example.
How did you record the MIDI in the first track? It looks like you were able to simply record the MIDI OUT there (I don’t care of the routing to synth instruments right now).

I even tried the code from Midi_Out2.csd as it is, without modifications, but it’s even worst then my previous attempts. The MIDI signal indicator in Reaper doesn’t blink…

I drew the MIDI in the first track? Are you trying to play live with a keyboard?

Oh, I thought you created it from the plugin MIDI OUT.
I’ve recreated your setup, which works fine if I draw some MIDI notes and disable the Csound plugin.
However nothing is sent to the second track from the plugin when I enable it.

In this example I’m using MIDI_Out2.csd without modifications.

Did you set the output on track one? In my one you can see output is set to MIDI?

I didn’t, but if I set it to OUT it creates a new empty lane, since it’s not receiving anything from the csound plugin.
So the real issue is that nothing is arriving to Reaper from the Midi_Out2 example. Really strange that it works for you and not here…

Here is my project…

https://1drv.ms/u/s!Ah4mHoWvP_GcgbQUkFTKwk6_fJZuhg?e=VTfCSz

Maybe it can help…

Great, thx! Could you share the .csd too? So I can replicate the exact setup.

MIDIOut.csd (594 Bytes)

I raise my hands. Reaper crashes when it tries to load either the exported vst2 or vst3 plugin. Ableton doesn’t crash but no MIDI arrives to it
By the way I don’t undersand how this patch should work. It has only an f0 statement, when should the instrument be instantiated? I thought f0 without any score was only useful for MIDI in…

Sadly, I think I’ll get back to M4L. Moreover I’ve just discovered that you’ve done a maintenance release of csound~ for Max 8. I will give it a try, but only for audio synth in that case, since M4L already gives me everything for MIDI :slight_smile: