Csound Csound-dev Csound-tekno Search About

[Csnd] CsoundCallbackWrapper questions

Date2013-11-29 13:43
FromJacques Leplat
Subject[Csnd] CsoundCallbackWrapper questions
Hello,

I was wondering if someone could point me in the right direction. 

My goal is to implement a type of VU control in Java (Desktop JDK and Android).

In the csd, I can use the max_k opcode to send the max output to a channel on a regular basis:

instr outInstr
	outs	gaoutL, gaoutR
ktrig	metro	1					;refresh 1 times per second
kvalL	max_k	gaoutL, ktrig, 1
kvalR	max_k	gaoutR, ktrig, 1
chnset kvalL, "masterL"
chnset kvalR, "masterR"
printk2 kvalL
printk2 kvalR
gaoutL = 0
gaoutR = 0
endin

In the java code, my feeling is it would be more efficient if I were to implement a callback, rather than use performKsmps() in a loop to get the channel values on every iteration: I do not expected to need the max amplitude values more than every 0.25 seconds.

The CsoundCallbackWrapper class has a callback method to override, which looks like the one I need to override to catch channel messages public void OutputValueCallback(String chnName, double value)

I can’t find any way of setting the callback wrapper in Csound. The CsoundCallbackWrapper has several callback wrapper setters (SetMidiOutputCallback(), SetMidiInputCallback(), SetYieldCallback(), SetMessageCallback) but none seem to be there for setting channel callbacks.

Any advice on how I should proceed is more than welcome: how can I register a channel callback wrapper with Csound? Alternatively, should I not worry about polling in a performKsmps() loop?

All the best,

Jacques





Date2013-11-30 22:31
FromSteven Yi
SubjectRe: [Csnd] CsoundCallbackWrapper questions
Hi Jacques,

There are some options.  The CsoundCallbackWrapper class is generally
used by subclassing it and overriding implementations of things like
MessageCallback, then calling SetMessageCallback to get it to register
with Csound.  That wrapper is found in csound6/interfaces/cs_glue.hpp
and hasn't really been touched in a very long time.  We could always
add things to it if there is something missing.

That said, if you only want to read values from a channel once in a
while, you could always just use a CsoundMYFLTArray to wrap the
channel, then use GetValue method to read "the current value at this
time".  If you did that from a thread that's animating some UI, it
would seem to me to be accurate enough.  I don't know the exact
operation you need though or the exact accuracy you're looking for,
but the above at least would be relatively efficient and simple.

steven

On Fri, Nov 29, 2013 at 8:43 AM, Jacques Leplat  wrote:
> Hello,
>
> I was wondering if someone could point me in the right direction.
>
> My goal is to implement a type of VU control in Java (Desktop JDK and Android).
>
> In the csd, I can use the max_k opcode to send the max output to a channel on a regular basis:
>
> instr outInstr
>         outs    gaoutL, gaoutR
> ktrig   metro   1                                       ;refresh 1 times per second
> kvalL   max_k   gaoutL, ktrig, 1
> kvalR   max_k   gaoutR, ktrig, 1
> chnset kvalL, "masterL"
> chnset kvalR, "masterR"
> printk2 kvalL
> printk2 kvalR
> gaoutL = 0
> gaoutR = 0
> endin
>
> In the java code, my feeling is it would be more efficient if I were to implement a callback, rather than use performKsmps() in a loop to get the channel values on every iteration: I do not expected to need the max amplitude values more than every 0.25 seconds.
>
> The CsoundCallbackWrapper class has a callback method to override, which looks like the one I need to override to catch channel messages public void OutputValueCallback(String chnName, double value)
>
> I can’t find any way of setting the callback wrapper in Csound. The CsoundCallbackWrapper has several callback wrapper setters (SetMidiOutputCallback(), SetMidiInputCallback(), SetYieldCallback(), SetMessageCallback) but none seem to be there for setting channel callbacks.
>
> Any advice on how I should proceed is more than welcome: how can I register a channel callback wrapper with Csound? Alternatively, should I not worry about polling in a performKsmps() loop?
>
> All the best,
>
> Jacques
>
>
>
>
>
> Send bugs reports to the Sourceforge bug trackers
> csound6:
>             https://sourceforge.net/p/csound/tickets/
> csound5:
>             https://sourceforge.net/p/csound/bugs/
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>
>


Date2013-12-02 15:03
FromJacques Leplat
SubjectRe: [Csnd] CsoundCallbackWrapper questions
Hello Steven,

Thanks for your reply.

For VU meter functionality I think your suggestion of having a thread periodically read a named channel should work. Though it would be nice to have a callback mechanism (in java) that can be used to listen to CSound whenever a channel value is set.

The background for my queries is that I am writing an app that lets users select instruments, set volumes and balance. On playback, some instruments can cause samples out of range. 

It looks to me like this not something that can easily be avoided using behind the scenes code alone, but if the app can display the output using a custom lcd like widget, the user can turn the volume down, or up. 

Ideally I do want to be able to get notified if the performance has any samples out of range, so that a warning can be displayed by the app. 

Without some form of callback mechanism, the app needs to poll CSound slightly faster than the trigger value given to max_k, not 100% neat, but workable.


All the best,

Jacques

On 30 Nov 2013, at 22:31, Steven Yi wrote:

> Hi Jacques,
> 
> There are some options.  The CsoundCallbackWrapper class is generally
> used by subclassing it and overriding implementations of things like
> MessageCallback, then calling SetMessageCallback to get it to register
> with Csound.  That wrapper is found in csound6/interfaces/cs_glue.hpp
> and hasn't really been touched in a very long time.  We could always
> add things to it if there is something missing.
> 
> That said, if you only want to read values from a channel once in a
> while, you could always just use a CsoundMYFLTArray to wrap the
> channel, then use GetValue method to read "the current value at this
> time".  If you did that from a thread that's animating some UI, it
> would seem to me to be accurate enough.  I don't know the exact
> operation you need though or the exact accuracy you're looking for,
> but the above at least would be relatively efficient and simple.
> 
> steven
> 
> 



Date2013-12-02 15:24
FromVictor Lazzarini
SubjectRe: [Csnd] CsoundCallbackWrapper questions
By the way, the shapes.py example in the sources has a VU meter that works on a time scheduler, it seems to work OK.
You can check it out.

Victor
On 2 Dec 2013, at 15:03, Jacques Leplat  wrote:

> Hello Steven,
> 
> Thanks for your reply.
> 
> For VU meter functionality I think your suggestion of having a thread periodically read a named channel should work. Though it would be nice to have a callback mechanism (in java) that can be used to listen to CSound whenever a channel value is set.
> 
> The background for my queries is that I am writing an app that lets users select instruments, set volumes and balance. On playback, some instruments can cause samples out of range. 
> 
> It looks to me like this not something that can easily be avoided using behind the scenes code alone, but if the app can display the output using a custom lcd like widget, the user can turn the volume down, or up. 
> 
> Ideally I do want to be able to get notified if the performance has any samples out of range, so that a warning can be displayed by the app. 
> 
> Without some form of callback mechanism, the app needs to poll CSound slightly faster than the trigger value given to max_k, not 100% neat, but workable.
> 
> 
> All the best,
> 
> Jacques
> 
> On 30 Nov 2013, at 22:31, Steven Yi wrote:
> 
>> Hi Jacques,
>> 
>> There are some options.  The CsoundCallbackWrapper class is generally
>> used by subclassing it and overriding implementations of things like
>> MessageCallback, then calling SetMessageCallback to get it to register
>> with Csound.  That wrapper is found in csound6/interfaces/cs_glue.hpp
>> and hasn't really been touched in a very long time.  We could always
>> add things to it if there is something missing.
>> 
>> That said, if you only want to read values from a channel once in a
>> while, you could always just use a CsoundMYFLTArray to wrap the
>> channel, then use GetValue method to read "the current value at this
>> time".  If you did that from a thread that's animating some UI, it
>> would seem to me to be accurate enough.  I don't know the exact
>> operation you need though or the exact accuracy you're looking for,
>> but the above at least would be relatively efficient and simple.
>> 
>> steven
>> 
>> 
> 
> 
> 
> Send bugs reports to the Sourceforge bug trackers
> csound6:
>            https://sourceforge.net/p/csound/tickets/
> csound5:
>            https://sourceforge.net/p/csound/bugs/
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
> 



Date2013-12-02 21:34
FromJacques Leplat
SubjectRe: [Csnd] CsoundCallbackWrapper questions
Thanks! 

The example is a nice alternative implementation to max_k in the csound reference manual.

All the best,

Jacques

> On 2 Dec 2013, at 15:24, Victor Lazzarini  wrote:
> 
> By the way, the shapes.py example in the sources has a VU meter that works on a time scheduler, it seems to work OK.
> You can check it out.
> 
> Victor
>> On 2 Dec 2013, at 15:03, Jacques Leplat  wrote:
>> 
>> Hello Steven,
>> 
>> Thanks for your reply.
>> 
>> For VU meter functionality I think your suggestion of having a thread periodically read a named channel should work. Though it would be nice to have a callback mechanism (in java) that can be used to listen to CSound whenever a channel value is set.
>> 
>> The background for my queries is that I am writing an app that lets users select instruments, set volumes and balance. On playback, some instruments can cause samples out of range. 
>> 
>> It looks to me like this not something that can easily be avoided using behind the scenes code alone, but if the app can display the output using a custom lcd like widget, the user can turn the volume down, or up. 
>> 
>> Ideally I do want to be able to get notified if the performance has any samples out of range, so that a warning can be displayed by the app. 
>> 
>> Without some form of callback mechanism, the app needs to poll CSound slightly faster than the trigger value given to max_k, not 100% neat, but workable.
>> 
>> 
>> All the best,
>> 
>> Jacques
>> 
>>> On 30 Nov 2013, at 22:31, Steven Yi wrote:
>>> 
>>> Hi Jacques,
>>> 
>>> There are some options.  The CsoundCallbackWrapper class is generally
>>> used by subclassing it and overriding implementations of things like
>>> MessageCallback, then calling SetMessageCallback to get it to register
>>> with Csound.  That wrapper is found in csound6/interfaces/cs_glue.hpp
>>> and hasn't really been touched in a very long time.  We could always
>>> add things to it if there is something missing.
>>> 
>>> That said, if you only want to read values from a channel once in a
>>> while, you could always just use a CsoundMYFLTArray to wrap the
>>> channel, then use GetValue method to read "the current value at this
>>> time".  If you did that from a thread that's animating some UI, it
>>> would seem to me to be accurate enough.  I don't know the exact
>>> operation you need though or the exact accuracy you're looking for,
>>> but the above at least would be relatively efficient and simple.
>>> 
>>> steven
>> 
>> 
>> 
>> Send bugs reports to the Sourceforge bug trackers
>> csound6:
>>           https://sourceforge.net/p/csound/tickets/
>> csound5:
>>           https://sourceforge.net/p/csound/bugs/
>> Discussions of bugs and features can be posted here
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
> 
> 
> Send bugs reports to the Sourceforge bug trackers
> csound6:
>            https://sourceforge.net/p/csound/tickets/
> csound5:
>            https://sourceforge.net/p/csound/bugs/
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
> 
>