Cabbage Logo
Back to Cabbage Site

Why to build a Midi Connection between two CSound Instruments

I have two Scripts, which I will run at the same time. In both Scripts are Instruments defined. First Script have three Instruments. Instrument one triggers Instrument 2 and 3. Instrument 1 gives events with a random Variable in Integers to Instrument 2 and 3. Instrument 2 generates Midi-Note-On Messages. Instrument 3 generates Midi-Off Messages. Both Instruments are so triggered taht 0.5 Seconds would be between both Messages. Both Instruments should be terminated when Message are created. And I knew both Instruments are needed because of the I Arguments on noteon and noteoff Opcodes.

Here the full script which is Source:

<Cabbage>
form caption("Sender") size(400, 300), colour(58, 110, 182), pluginid("def1")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
kZahl init 0
kTrig metro 4
if kTrig == 1 then
if kZahl == 0 then
kran random 20, 100
kran = int(kran)
event "i", 2,  0, 1, kran
kZahl = 1
else
event "i", 3,  0, 1, kran
printk 0, 777
kZahl = 0
endif
endif
endin

instr 2
iNumb = p4
noteon 1, iNumb, 64
turnoff
endin

instr 3
iNumb = p4
noteoff 1, iNumb, 64
turnoff
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>

And this are the Destination Script:

<Cabbage>
form caption("Empfang") size(400, 300), colour(58, 110, 182), pluginid("def1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
kstatus, kchan, kdata1, kdata2 midiin
if kstatus == 128 then 
printks "NoteOff mit Note = \n", 0, kdata1
elseif kstatus == 144 then
printks "NoteOn mit Note = \n", 0, kdata1
endif
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i1 0 z
</CsScore>
</CsoundSynthesizer>

In my mind is that anything with the comandline-Flags / Options-Section is wron

Ok, the CSound Manual are still stupid. Can nobody write a better Help for the Command Line Flags.
I have to insert -Q1 in the Options Section.:dizzy_face::disappointed: :smiling_imp:

But new I have a second Problem. Why I can get back the Note Number. Firstly from the Note-On Mesages.

So it wolud get a Opcode which is called midinoteoncps. But he has nothing Chanel select. And it would be better there is a way to make a Chanel Select.

Ok. I have had any problems with the midiin Opcode. It would work and not work. I not understand the circumstances when it work and when not. But I think I will be manage The Problem.:innocent::flushed::dizzy_face:

Try these instruments, one sends MIDI arpeggios to another instrument when you press the keyboard, the other one randomly generates MIDI values without any input from the user or keyboard.

BTW: I’ve moved this posts to the Cabbage Stew section which is where we discuss most things to do with Cabbage :wink:

I think I have a bigger problem then I think. I have start my Code today after one day rest, and I not in the circumstances that I can run my Code. And I think I have nothing change.:scream::disappointed:

So I have to make clearer my Problem. I will receive Note-On and Note-Off Messages. But I’m nothing can find the right way to get the Number of the Key. So I would build a Synthesizer which can make noise, but not a Synthesizer who will build Music.

I forgot to attach the instruments I wrote. They are on my work PC but let me see if I can’t quickly write up another…

Try these.
MidiOutSimple.csd (611 Bytes)
SimpleSynth.csd (432 Bytes)
You’ll need to connect them together in the Cabbage patcher.

Ok, In the last days I have many work Sections. So I come only just to this Thread back. So I have tested now your Scripts. And all will get best, but your code are not the right what I needed. Pleace, can you write again “SimpleSynth.csd”. The different what I want is: Can you write it so, it will select the Midi-Channell-

Thank you
Mungo1981 :innocent: :grin::sleeping:

You want it to report which channel the information is arriving on?

Yes this is what I need. I’m happy to can use midi. But this is the last Information of my midi Instruments to needed. Because it becomes strong Connections between my Instruments and effects, So that it would be better could I have this information.

Can you simply add the following lines:

kstatus, kchan, kdata1, kdata2 midiin

kchan will be the MIDI channel.

ok, this I have already done.
But when I’m not blind I have only a recommended output of the Keyboard in the GUI of this special Instrument. And not on the Generator Script.

Ok. I’m blind. It is more a problem to chose the right metro Values.
I’m so stupid.
:blush: :smirk: :sweat: