API MIDI question
Date | 2016-05-27 00:09 |
From | Forrest Curo |
Subject | API MIDI question |
If I run an instance of Csound via the API in a C program, it should be catching & responding to the available MIDI note messages... as readily as if I'd started it up via the command line but I haven't (so far) found a good C library for digesting these within the calling C program itself. |
Date | 2016-05-27 06:37 |
From | Victor Lazzarini |
Subject | Re: API MIDI question |
MIDI io is handled by a plugin, which will use either portmidi or the system libraries directly (depending on the plugin). You can bypass this by supplying your own MIDI handlers via the API. Unless there is a special reason not to do it, you should keep using the plugins that come with Csound. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
Date | 2016-05-27 13:48 |
From | Forrest Curo |
Subject | Re: API MIDI question |
Yes, I want to keep using the built-in plugin -- but also access the information from that to put rt sequencer/looper information out to the calling program. ? On Thu, May 26, 2016 at 10:37 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
|
Date | 2016-05-27 16:10 |
From | Michael Gogins |
Subject | Re: API MIDI question |
You have to send both a MIDI ON an a MIDI OFF channel message to Csound's MIDI OUT port for each Csound note. Something like this: In order to receive MIDI events from Csound in regular instrument pfields run with: --midi-key-number=pN --midi-velocity=pM (N and M being the numbers of the pfields you use; I use p4 and p5). instr MyInstr ; Use pN and pM as normal, e.g. for MIDI key number and velocity. ; Immediately send the "NOTE ON" message to the MIDI out port. midiout 144, p1, pN, pM ; Schedule the "NOTE OFF" message to be sent to the MIDI out port. ; p1 instrument, p2 time, p3 duration, p4 channel, p5 key, p6 velocity ;schedule "SendMidiOff", 0, .1, p1, pN, pM ; Now do the regular synthesis stuff. i_hz midinn pN i_amplitude ampdb pM a_signal vco2 i_amplitude, i_hz ; Use a releasing envelope. a_envelope madsr .005, .5, .25, 1.5 out a_signal * a_envelope endin ; Must come after all instruments that schedule this instrument! instr SendMidiOff midiout 128, p4, p5, p6 endin Hope this helps, Mike ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Fri, May 27, 2016 at 8:48 AM, Forrest Curo |
Date | 2016-05-27 16:12 |
From | Michael Gogins |
Subject | Re: API MIDI question |
Oops, that should be (to account for duration of note to schedule NOTE OFF MIDI channel message): ; Schedule the "NOTE OFF" message to be sent to the MIDI out port. ; p1 instrument, p2 time, p3 duration, p4 channel, p5 key, p6 velocity schedule "SendMidiOff", p3, .1, p1, pN, pM On 5/27/16, Michael Gogins |
Date | 2016-05-27 17:22 |
From | Forrest Curo |
Subject | Re: API MIDI question |
Anyway, to send noteoff when csound's note gets its release -- given that we don't know the duration until then. Thanks! ------------ Or if I use the midi thru port, wouldn't everything listening on the system pick that up directly, the plug in as well? Is there a good C function for that? On Fri, May 27, 2016 at 8:12 AM, Michael Gogins <michael.gogins@gmail.com> wrote: Oops, that should be (to account for duration of note to schedule NOTE |
Date | 2016-05-27 17:31 |
From | Victor Lazzarini |
Subject | Re: API MIDI question |
I suppose what you need to do is this: 1) figure out what MIDI lib you will use; that will depend on your platform 2) Write three callbacks: to open the midi device; to read midi in; to close the device 3) Register these callbacks with Csound via the relevant API functions Then if you run Csound with -+rtmidi=null, Csound will pick up your callbacks and use them to respond to MIDI. The obvious examples for this are in the Csound sources under InOut/ where you can find the code for all plugins. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
Date | 2016-05-27 23:02 |
From | Forrest Curo |
Subject | Re: API MIDI question |
In case you might be interested in yet another approach, I just tried this & find that it works... [where 'example1' is example1.py from the Csound API python examples, copied into /usr/lib/python2.7 ]julia> using PyCall julia> @pyimport example1 On Fri, May 27, 2016 at 9:31 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
|
Date | 2016-05-27 23:41 |
From | Forrest Curo |
Subject | Re: API MIDI question |
If I rewrite Steven Yi's python example1.py to: I then can reuse this as a julia function:import csnd6 def playit(): c = csnd6.Csound() # Create an instance of the Csound object c.Compile('Kung-Xanadu.csd') # Compile a pre-defined test1.csd file c.Perform() # This call runs Csound to completion c.Stop() # At this point, Csound is already stopped, but this call is here using PyCall @pyimport mido On Fri, May 27, 2016 at 3:02 PM, Forrest Curo <treegestalt@gmail.com> wrote:
|
Date | 2016-06-05 02:24 |
From | Forrest Curo |
Subject | Re: API MIDI question |
Without threading, translating Steven Yi's python example 5 to julia -- and befnurgling it to put the 'ReadScore(sco2)' line into the performance loop: j= 0 while (c[:PerformKsmps]() == 0) if(j ==0) c[:ReadScore](sco2) # Read in Score from loop-generated String j= 1 end end added ~.001 second of timing inaccuracy: rtevent: T 1.001 TT 1.001 M: 0.00000 0.00000 rtevent: T 1.251 TT 1.251 M: 0.31839 0.31839 rtevent: T 1.501 TT 1.501 M: 0.49385 0.49385 rtevent: T 1.751 TT 1.751 M: 0.65381 0.65381 ----- which remains the same even if I add 1000 notes and calculate them all in that first loop: if(j ==0) sco2 = "" for i = 0:1000 sco2 *= "i1 $(0.25*i +1) 1 0.5 $(7+ 0.02*(i%12)) " end c[:ReadScore](sco2) # Read in Score from loop-generated String j= 1 end So: even without threading there isn't significant overhead unless someone (like me) is dumb enough to put a sleep() into the loop. On Fri, May 27, 2016 at 3:41 PM, Forrest Curo <treegestalt@gmail.com> wrote:
|
Date | 2016-06-05 12:15 |
From | Forrest Curo |
Subject | Re: API MIDI question |
The error vanished with ksmps=8... It wasn't a timing error from time spent in the loop, but an artifact of the 32-sample delay before starting the first pass. To put those first 32-samples at the end of the loop in julia takes some perverse syntax, but likewise eliminates the error.On Sat, Jun 4, 2016 at 6:24 PM, Forrest Curo <treegestalt@gmail.com> wrote:
|