Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Signal via API to host

Date2017-05-03 14:02
FromTarmo Johannes
Subject[Csnd-dev] Signal via API to host
Hi,

What is a good way to send a signal about an event from Csound via API to host program?

So far I have used values in channels as flags but there could be better ways so that the host does not need to check value changes in the channels.

Of course OSC messages could do the trick but then I need to set up OSC listener in the host that I try to avoid. I tried also sending UDP message with socksend but it was not received...

Websockets intoduce a new dependency....

One way could be perhaps  to use messageCallback and just do a prints from csound with a meaningful string to catch and parse in the host. But this seems kind of hack I suspect there is a better way.

Hop I was not too vague...

Thanks!
tarmo

Date2017-05-03 14:27
FromMichael Gogins
SubjectRe: [Csnd-dev] Signal via API to host
Did you try csoundSetOutputChannelCallback? It takes a "C" function
pointer that will be called whenever the Csound orchestra executes the
outvalue opcode. But probably this is what you were talking about
regarding "values in channels". Keep in mind, some code somewhere has
to be checking values, so pushing the checking down into Csound will
not save much time though it would simplify the code.

If csoundSetOutputChannelCallback is not sufficient, perhaps we should
add another callback, call it csoundSetGlobalVariablelCallback. This
would be called when and only when the value of a global variable
changes.

Or, which would amount to much the same thing, we could add a variant
of csoundSetOutputChannelCallback that would apply only to one named
channel and only fire when the value of the channel changes.

Best,
Mike

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


On Wed, May 3, 2017 at 9:02 AM, Tarmo Johannes  wrote:
> Hi,
>
> What is a good way to send a signal about an event from Csound via API to
> host program?
>
> So far I have used values in channels as flags but there could be better
> ways so that the host does not need to check value changes in the channels.
>
> Of course OSC messages could do the trick but then I need to set up OSC
> listener in the host that I try to avoid. I tried also sending UDP message
> with socksend but it was not received...
>
> Websockets intoduce a new dependency....
>
> One way could be perhaps  to use messageCallback and just do a prints from
> csound with a meaningful string to catch and parse in the host. But this
> seems kind of hack I suspect there is a better way.
>
> Hop I was not too vague...
>
> Thanks!

Date2017-05-03 16:36
FromTarmo Johannes
SubjectRe: [Csnd-dev] Signal via API to host
Thank you, Mike!

csoundSetOutputChannelCallback and outvalue could do the trick -  I used chnset before and I did not realize that option.

The only small problem is that outvalue is run also on init-time regardless of the k-rate conditions. It is definitely possibl to overcome in the host's code but would be nice to have a way to tell from csound code to host "do something now  ". Maybe there is another way already

My testing instrument:

instr 1

if (metro(1)==1) then

kvalue timeinsts

outvalue "test",kvalue

endif

endin


And ouput from host callback function:


"test" 0 // <--- this is init time

"test" 0.000725624 // <- and this first firing from metro

"test" 1.00136

"test" 2.00127



Similar result with string channels.


Anyway  - good idea and helps further!


tarmo



2017-05-03 16:27 GMT+03:00 Michael Gogins <michael.gogins@gmail.com>:
Did you try csoundSetOutputChannelCallback? It takes a "C" function
pointer that will be called whenever the Csound orchestra executes the
outvalue opcode. But probably this is what you were talking about
regarding "values in channels". Keep in mind, some code somewhere has
to be checking values, so pushing the checking down into Csound will
not save much time though it would simplify the code.

If csoundSetOutputChannelCallback is not sufficient, perhaps we should
add another callback, call it csoundSetGlobalVariablelCallback. This
would be called when and only when the value of a global variable
changes.

Or, which would amount to much the same thing, we could add a variant
of csoundSetOutputChannelCallback that would apply only to one named
channel and only fire when the value of the channel changes.

Best,
Mike

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


On Wed, May 3, 2017 at 9:02 AM, Tarmo Johannes <trmjhnns@gmail.com> wrote:
> Hi,
>
> What is a good way to send a signal about an event from Csound via API to
> host program?
>
> So far I have used values in channels as flags but there could be better
> ways so that the host does not need to check value changes in the channels.
>
> Of course OSC messages could do the trick but then I need to set up OSC
> listener in the host that I try to avoid. I tried also sending UDP message
> with socksend but it was not received...
>
> Websockets intoduce a new dependency....
>
> One way could be perhaps  to use messageCallback and just do a prints from
> csound with a meaningful string to catch and parse in the host. But this
> seems kind of hack I suspect there is a better way.
>
> Hop I was not too vague...
>
> Thanks!
> tarmo