Csound Csound-dev Csound-tekno Search About

API MIDI question

Date2016-05-27 00:09
FromForrest Curo
SubjectAPI 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.

I see there are functions in the API for accessing MIDI messages, but it's not clear to me how to use them -- and I wouldn't want to interfere with Csound's normal handling of MIDI, except to give the calling program a copy of the notes (for echoing them later.)

I could open a channel out & have each triggered instrument send its data out when the noteoff arrives...

but what way would be simplest? 
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 06:37
FromVictor Lazzarini
SubjectRe: 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

On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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.

I see there are functions in the API for accessing MIDI messages, but it's not clear to me how to use them -- and I wouldn't want to interfere with Csound's normal handling of MIDI, except to give the calling program a copy of the notes (for echoing them later.)

I could open a channel out & have each triggered instrument send its data out when the noteoff arrives...

but what way would be simplest? 
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 13:48
FromForrest Curo
SubjectRe: 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:
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

On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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.

I see there are functions in the API for accessing MIDI messages, but it's not clear to me how to use them -- and I wouldn't want to interfere with Csound's normal handling of MIDI, except to give the calling program a copy of the notes (for echoing them later.)

I could open a channel out & have each triggered instrument send its data out when the noteoff arrives...

but what way would be simplest? 
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 16:10
FromMichael Gogins
SubjectRe: 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  wrote:
> 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
>  wrote:
>>
>> 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
>>
>> On 27 May 2016, at 00:09, Forrest Curo  wrote:
>>
>> 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.
>>
>> I see there are functions in the API for accessing MIDI messages, but it's
>> not clear to me how to use them -- and I wouldn't want to interfere with
>> Csound's normal handling of MIDI, except to give the calling program a copy
>> of the notes (for echoing them later.)
>>
>> I could open a channel out & have each triggered instrument send its data
>> out when the noteoff arrives...
>>
>> but what way would be simplest?
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features can
>> be posted here
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features can
>> be posted here
>
>
> Csound mailing list Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2016-05-27 16:12
FromMichael Gogins
SubjectRe: 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  wrote:
> 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 
> wrote:
>> 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
>>  wrote:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo  wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>

Date2016-05-27 17:22
FromForrest Curo
SubjectRe: 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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 17:31
FromVictor Lazzarini
SubjectRe: 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

On 27 May 2016, at 17:22, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 23:02
FromForrest Curo
SubjectRe: API MIDI question
In case you might be interested in yet another approach, I just tried this & find that it works...

julia> using PyCall

julia> @pyimport example1

[where 'example1' is example1.py from the Csound API python examples, copied into /usr/lib/python2.7 ]

Julia makes for fairly straightforward use of quite a few libraries, including python ones, for MIDI or graphics or whatever. (It looks like I'd be using Python API functions to make those usable from julia, but hey!)



On Fri, May 27, 2016 at 9:31 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
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

On 27 May 2016, at 17:22, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-05-27 23:41
FromForrest Curo
SubjectRe: API MIDI question
If I rewrite Steven Yi's python example1.py to:
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

I then can reuse this as a julia function:
example1.playit() -- & similarly with anything else from there.

I can route MIDI both to julia & Csound via a combination of aconnectgui and:
using PyCall
@pyimport mido


On Fri, May 27, 2016 at 3:02 PM, Forrest Curo <treegestalt@gmail.com> wrote:
In case you might be interested in yet another approach, I just tried this & find that it works...

julia> using PyCall

julia> @pyimport example1

[where 'example1' is example1.py from the Csound API python examples, copied into /usr/lib/python2.7 ]

Julia makes for fairly straightforward use of quite a few libraries, including python ones, for MIDI or graphics or whatever. (It looks like I'd be using Python API functions to make those usable from julia, but hey!)



On Fri, May 27, 2016 at 9:31 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
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

On 27 May 2016, at 17:22, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-06-05 02:24
FromForrest Curo
SubjectRe: 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:
If I rewrite Steven Yi's python example1.py to:
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

I then can reuse this as a julia function:
example1.playit() -- & similarly with anything else from there.

I can route MIDI both to julia & Csound via a combination of aconnectgui and:
using PyCall
@pyimport mido


On Fri, May 27, 2016 at 3:02 PM, Forrest Curo <treegestalt@gmail.com> wrote:
In case you might be interested in yet another approach, I just tried this & find that it works...

julia> using PyCall

julia> @pyimport example1

[where 'example1' is example1.py from the Csound API python examples, copied into /usr/lib/python2.7 ]

Julia makes for fairly straightforward use of quite a few libraries, including python ones, for MIDI or graphics or whatever. (It looks like I'd be using Python API functions to make those usable from julia, but hey!)



On Fri, May 27, 2016 at 9:31 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
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

On 27 May 2016, at 17:22, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here



Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2016-06-05 12:15
FromForrest Curo
SubjectRe: 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:
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:
If I rewrite Steven Yi's python example1.py to:
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

I then can reuse this as a julia function:
example1.playit() -- & similarly with anything else from there.

I can route MIDI both to julia & Csound via a combination of aconnectgui and:
using PyCall
@pyimport mido


On Fri, May 27, 2016 at 3:02 PM, Forrest Curo <treegestalt@gmail.com> wrote:
In case you might be interested in yet another approach, I just tried this & find that it works...

julia> using PyCall

julia> @pyimport example1

[where 'example1' is example1.py from the Csound API python examples, copied into /usr/lib/python2.7 ]

Julia makes for fairly straightforward use of quite a few libraries, including python ones, for MIDI or graphics or whatever. (It looks like I'd be using Python API functions to make those usable from julia, but hey!)



On Fri, May 27, 2016 at 9:31 AM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
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

On 27 May 2016, at 17:22, Forrest Curo <treegestalt@GMAIL.COM> wrote:

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
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 <michael.gogins@gmail.com> wrote:
> 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 <treegestalt@gmail.com>
> wrote:
>> 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:
>>>
>>> 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
>>>
>>> On 27 May 2016, at 00:09, Forrest Curo <treegestalt@GMAIL.COM> wrote:
>>>
>>> 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.
>>>
>>> I see there are functions in the API for accessing MIDI messages, but
>>> it's
>>> not clear to me how to use them -- and I wouldn't want to interfere with
>>> Csound's normal handling of MIDI, except to give the calling program a
>>> copy
>>> of the notes (for echoing them later.)
>>>
>>> I could open a channel out & have each triggered instrument send its
>>> data
>>> out when the noteoff arrives...
>>>
>>> but what way would be simplest?
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>>
>>> Csound mailing list Csound@listserv.heanet.ie
>>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>>> https://github.com/csound/csound/issues Discussions of bugs and features
>>> can
>>> be posted here
>>
>>
>> Csound mailing list Csound@listserv.heanet.ie
>> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
>> https://github.com/csound/csound/issues Discussions of bugs and features
>> can
>> be posted here
>


--

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here




Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here