Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] per-event input/output

Date2007-12-16 23:33
From"Michael Gogins"
SubjectRe: [Cs-dev] per-event input/output
You can use the channel API to get and set values from global variables in 
the orchestra -- would this do? The variables would not be unique to each 
instance of an instrument though, do you need that?

Regards,
Mike

----- Original Message ----- 
From: "Jonatan Liljedahl" 
To: 
Sent: Sunday, December 16, 2007 5:26 PM
Subject: [Cs-dev] per-event input/output


> Trying to resend this since it haven't reached the list for several
> hours... sorry if it shows up 2 times.
> ...
>
> Hi all,
> I'm developing a graphical environment for algorithmic composition
> called AlgoScore (http://kymatica.com/algoscore) which also functions as
> a CSound frontend using the API.
>
> All events are sent to CSound with csoundScoreEvent() and then
> csoundPerformKsmps() are called in a loop to produce output until a
> specified length.
>
> Now, I would like to get output for graphical representation from an
> instrument, specifically to show the resulting graph of a k-rate variable.
>
> Doing a "display k1, p3" inside an instrument produces a graph sent to
> my application, one for each event of that instrument. But I can find no
> way for my app to know *which* event the graph is coming from, all
> identification I get is the caption, saying something like "instr 1, k1".
>
> Same problems arise with f-table events, if I have more than one f-table
> event at different times, I don't know which graph sent to my app that
> belongs to which event.
>
> Is there anyway to solve this? It would be so nice to have graphical
> representation in the score of a single events amplitude envelope and so
> on...
>
> It would be simple if csoundScoreEvent() returned an ID or pointer to
> the actual event, and that this ID could be sent along a graph or some
> other data from csound to my app.
>
> I'm also interested in doing it the other way around, to have my app
> send k-rate data to specific events and not only specific instruments
> (through software busses). Is there a way to dynamically allocate
> software busses and bind them to certain events?
>
> -- 
> /Jonatan         [ http://kymatica.com ]
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services
> for just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel 


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 00:47
Frommatt ingalls
SubjectRe: [Cs-dev] per-event input/output
AttachmentsNone  None  
or maybe easier to use is  'outvalue' opcode and setting a callback
with csoundSetOutputValueCallback


On Dec 16, 2007, at 3:33 PM, Michael Gogins wrote:

You can use the channel API to get and set values from global variables in 
the orchestra -- would this do? The variables would not be unique to each 
instance of an instrument though, do you need that?

Regards,
Mike

----- Original Message ----- 
From: "Jonatan Liljedahl" <lijon@kymatica.com>
Sent: Sunday, December 16, 2007 5:26 PM
Subject: [Cs-dev] per-event input/output


Trying to resend this since it haven't reached the list for several
hours... sorry if it shows up 2 times.
...

Hi all,
I'm developing a graphical environment for algorithmic composition
called AlgoScore (http://kymatica.com/algoscore) which also functions as
a CSound frontend using the API.

All events are sent to CSound with csoundScoreEvent() and then
csoundPerformKsmps() are called in a loop to produce output until a
specified length.

Now, I would like to get output for graphical representation from an
instrument, specifically to show the resulting graph of a k-rate variable.

Doing a "display k1, p3" inside an instrument produces a graph sent to
my application, one for each event of that instrument. But I can find no
way for my app to know *which* event the graph is coming from, all
identification I get is the caption, saying something like "instr 1, k1".

Same problems arise with f-table events, if I have more than one f-table
event at different times, I don't know which graph sent to my app that
belongs to which event.

Is there anyway to solve this? It would be so nice to have graphical
representation in the score of a single events amplitude envelope and so
on...

It would be simple if csoundScoreEvent() returned an ID or pointer to
the actual event, and that this ID could be sent along a graph or some
other data from csound to my app.

I'm also interested in doing it the other way around, to have my app
send k-rate data to specific events and not only specific instruments
(through software busses). Is there a way to dynamically allocate
software busses and bind them to certain events?

-- 
/Jonatan         [ http://kymatica.com ]


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
_______________________________________________
Csound-devel mailing list


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
_______________________________________________
Csound-devel mailing list


matt ingalls




Date2007-12-17 01:26
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
Yes, what I need is exactly that, a means of getting values out and know
which instance (event) of an instrument it comes from. I already support
the channel API, but I can only use it for instrument-wide control.

Michael Gogins wrote:
> You can use the channel API to get and set values from global variables in 
> the orchestra -- would this do? The variables would not be unique to each 
> instance of an instrument though, do you need that?

...

>> Now, I would like to get output for graphical representation from an
>> instrument, specifically to show the resulting graph of a k-rate variable.
>>
>> Doing a "display k1, p3" inside an instrument produces a graph sent to
>> my application, one for each event of that instrument. But I can find no
>> way for my app to know *which* event the graph is coming from, all
>> identification I get is the caption, saying something like "instr 1, k1".

-- 
/Jonatan         [ http://kymatica.com ]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 01:50
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
This looks interresting, do I understand it correctly that the
channelname argument to 'outvalue' doesn't need to be an already defined
channel but can be any string?

then all I need is a way for an instrument to set this channelname to
something unique for that instance of the instrument, and for my host
application to know which event this belongs too. But how would this be
possible? Even if I create my own opcode in a plugin to call the
outvalue-callback with some instance-id in the channelname... I'd still
need csoundScoreEvent() to return the same id so I can match them...

And, I don't know how the instrument allocation works, but what I want
is actually not an ID for each instance but for each event..

Maybe the only way is to generate unique event-ID's from my hostapp and
send them as a pfield argument to each event, and then use this ID to
create a channelname for 'outvalue'? It's a bit boring to handle this ID
explicitly, but it's better than nothing. :) Something like this:

k1 ... something ...
Schn sprintf "%d k1", p10
outvalue Schn, k1

where p10 is the number tag to identify the event. Would it work?

matt ingalls wrote:
> or maybe easier to use is  'outvalue' opcode and setting a callback
> with csoundSetOutputValueCallback
> 
> 
> On Dec 16, 2007, at 3:33 PM, Michael Gogins wrote:
> 
>> You can use the channel API to get and set values from global
>> variables in 
>> the orchestra -- would this do? The variables would not be unique to each 
>> instance of an instrument though, do you need that?
>>
>> Regards,
>> Mike
>>
>> ----- Original Message ----- 
>> From: "Jonatan Liljedahl" >
>> To: > >
>> Sent: Sunday, December 16, 2007 5:26 PM
>> Subject: [Cs-dev] per-event input/output
>>
>>
>>> Trying to resend this since it haven't reached the list for several
>>> hours... sorry if it shows up 2 times.
>>> ...
>>>
>>> Hi all,
>>> I'm developing a graphical environment for algorithmic composition
>>> called AlgoScore (http://kymatica.com/algoscore) which also functions as
>>> a CSound frontend using the API.
>>>
>>> All events are sent to CSound with csoundScoreEvent() and then
>>> csoundPerformKsmps() are called in a loop to produce output until a
>>> specified length.
>>>
>>> Now, I would like to get output for graphical representation from an
>>> instrument, specifically to show the resulting graph of a k-rate
>>> variable.
>>>
>>> Doing a "display k1, p3" inside an instrument produces a graph sent to
>>> my application, one for each event of that instrument. But I can find no
>>> way for my app to know *which* event the graph is coming from, all
>>> identification I get is the caption, saying something like "instr 1, k1".
>>>
>>> Same problems arise with f-table events, if I have more than one f-table
>>> event at different times, I don't know which graph sent to my app that
>>> belongs to which event.
>>>
>>> Is there anyway to solve this? It would be so nice to have graphical
>>> representation in the score of a single events amplitude envelope and so
>>> on...
>>>
>>> It would be simple if csoundScoreEvent() returned an ID or pointer to
>>> the actual event, and that this ID could be sent along a graph or some
>>> other data from csound to my app.
>>>
>>> I'm also interested in doing it the other way around, to have my app
>>> send k-rate data to specific events and not only specific instruments
>>> (through software busses). Is there a way to dynamically allocate
>>> software busses and bind them to certain events?
>>>
>>> -- 
>>> /Jonatan         [ http://kymatica.com ]
>>>
>>>
>>> -------------------------------------------------------------------------
>>> SF.Net email is sponsored by:
>>> Check out the new SourceForge.net Marketplace.
>>> It's the best place to buy or sell services
>>> for just about anything Open Source.
>>> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> 
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel 
>>
>>
>> -------------------------------------------------------------------------
>> SF.Net email is sponsored by:
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services
>> for just about anything Open Source.
>> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> 
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
> 
> matt ingalls
> development@gvox.com 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services
> for just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


-- 
/Jonatan         [ http://kymatica.com ]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 03:35
Frommatt ingalls
SubjectRe: [Cs-dev] per-event input/output
AttachmentsNone  None  

This looks interresting, do I understand it correctly that the
channelname argument to 'outvalue' doesn't need to be an already defined

correct.  all the channel name handling is left to the host application to deal with.
if you don't want to deal with that, use the channel bus.

channel but can be any string?

or a number


And, I don't know how the instrument allocation works, but what I want
is actually not an ID for each instance but for each event..

k1 ... something ...
Schn sprintf "%d k1", p10
outvalue Schn, k1

where p10 is the number tag to identify the event. Would it work?

that sounds like it would - however you could just use 2 'outvalues' -- 
as i think running instrument instances do their entire k-pass in series,
and since your callback is called for every 'invalue', you could just cache
one value and when the other value comes in, safely assume the other
value is for that instance.

btw, i have used "fractional" i statements for this kind of thing before:

i 2.3847 0 10 .
i 2.3848 +
i 2.3849 +

instr 2
   outvalue "id", p1
   k1 ...something
   outvalue "value", k1
endif


if i am not missing something, 
i don't think you could use the software bus to do something like this!!

matt ingalls




Date2007-12-17 14:20
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
matt ingalls wrote:
> 
>> This looks interresting, do I understand it correctly that the
>> channelname argument to 'outvalue' doesn't need to be an already defined
> 
> correct.  all the channel name handling is left to the host application
> to deal with.
> if you don't want to deal with that, use the channel bus.

Ok, it's a bit confusing that there's so many different ways of doing
I/O between a host app and csound. busses, outvalue/invalue, spout,
graphs, direct access to ftab's, etc... But I guess there's a good case
for each of them.

>> k1 ... something ...
>> Schn sprintf "%d k1", p10
>> outvalue Schn, k1
> 
>> where p10 is the number tag to identify the event. Would it work?
> 
> that sounds like it would - however you could just use 2 'outvalues' -- 
> as i think running instrument instances do their entire k-pass in series,
> and since your callback is called for every 'invalue', you could just cache
> one value and when the other value comes in, safely assume the other
> value is for that instance.
>
> btw, i have used "fractional" i statements for this kind of thing before:
> 
> i 2.3847 0 10 .
> i 2.3848 +
> i 2.3849 +
> 
> instr 2
>    outvalue "id", p1
>    k1 ...something
>    outvalue "value", k1
> endif
> 
> 
> if i am not missing something, 
> i don't think you could use the software bus to do something like this!!

Yes, you're right, that's even simpler.
I was thinking that I might save the use of fractional p1's for full
support of tied notes in my app, but perhaps it could be used for both.
Could there be any problems with rounding errors (float precision) when
using lots of decimals in the fractional part? Is it different when
using csoundScoreEvent() than parsing a textual score file, or does the
score parser use csoundScoreEvent() too?

-- 
/Jonatan         [ http://kymatica.com ]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 14:47
FromRory Walsh
SubjectRe: [Cs-dev] per-event input/output
> Ok, it's a bit confusing that there's so many different ways of doing
> I/O between a host app and csound. busses, outvalue/invalue, spout,
> graphs, direct access to ftab's, etc... But I guess there's a good case
> for each of them.

I'm not so sure why there are busses AND invalue/outvalue. Correct me if 
I'm wrong but don't they do the same thing apart from some low-level 
allocations? It would be nice if these mechanisms were compatible.

Rory.


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 16:22
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
Rory Walsh wrote:
>> Ok, it's a bit confusing that there's so many different ways of doing
>> I/O between a host app and csound. busses, outvalue/invalue, spout,
>> graphs, direct access to ftab's, etc... But I guess there's a good case
>> for each of them.
> 
> I'm not so sure why there are busses AND invalue/outvalue. Correct me if 
> I'm wrong but don't they do the same thing apart from some low-level 
> allocations? It would be nice if these mechanisms were compatible.

The difference is that invalue/outvalue is callback-based, when busses
needs to be read/written through channel pointers in each k-pass by the
host app.

Also, the host app can get a list of available busses from csound, which
can be very nice, but on the other hand this needs busses to be declared
by the orchestra before instrument performance, which isn't needed in
the case of invalue/outvalue.

-- 
/Jonatan         [ http://kymatica.com ]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-12-17 18:03
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
Attachmentsev_graph_test.pdf  None  None  
matt ingalls wrote:
...
> btw, i have used "fractional" i statements for this kind of thing before:
> 
> i 2.3847 0 10 .
> i 2.3848 +
> i 2.3849 +
> 
> instr 2
>    outvalue "id", p1
>    k1 ...something
>    outvalue "value", k1
> endif
> 
> 
> if i am not missing something, 
> i don't think you could use the software bus to do something like this!!

It worked fine! Here's an example of a graphical score with amplitude
envelope plotting for each event. (attached PDF)

Thanks for your help.
-- 
/Jonatan         [ http://kymatica.com ]

Date2007-12-17 18:12
Frommatt ingalls
SubjectRe: [Cs-dev] per-event input/output
AttachmentsNone  None  
Also, the host app can get a list of available busses from csound, which
can be very nice, but on the other hand this needs busses to be declared
by the orchestra before instrument performance, which isn't needed in
the case of invalue/outvalue.

i've only used invalue/outvalue 
-- but
here is something i've been wondering about:

it seems that you can create a channel on the software bus by calling

csoundGetChannelPtr

and the comment in the header file seems to imply you can do this
before calling csoundCompile (for i and k rate channels) and presumably
the values are not cleared once you do call csoundCompile

has anybody tried this?  if it works, then it might be possible to
consolidate invalue/outvalue and the software bus?

matt ingalls




Date2007-12-17 19:31
FromJonatan Liljedahl
SubjectRe: [Cs-dev] per-event input/output
Jonatan Liljedahl wrote:
> matt ingalls wrote:
> ...
>> btw, i have used "fractional" i statements for this kind of thing before:
>>
>> i 2.3847 0 10 .
>> i 2.3848 +
>> i 2.3849 +
>>
>> instr 2
>>    outvalue "id", p1
>>    k1 ...something
>>    outvalue "value", k1
>> endif
>>
>>
>> if i am not missing something, 
>> i don't think you could use the software bus to do something like this!!
> 
> It worked fine! Here's an example of a graphical score with amplitude
> envelope plotting for each event. (attached PDF)
> 
> Thanks for your help.

There's still one problem... Instrument tags is encoded as the
fractional part of p1, but since it's a simple 32-bit float there's a
lot of problems with rounding errors, see this example:

int main(void) {
    float f;
    int last = 9999;
    for(f=1;f<2;f+=0.0001) {
        int i = 0.5 + f * 10000;
        printf("%d %g %f ",i,f,f);
        if(i!=last+1) printf("ERROR!\n");
        else printf("OK\n");
        last=i;
    }
}

$ foo | grep -B 1 ERROR
13013 1.30135 1.301350 OK
13015 1.30145 1.301450 ERROR!
--
19040 1.90405 1.904050 OK
19042 1.90415 1.904150 ERROR!

Which means that with tags from .0001 to .9999 there's two numbers that
can't be represented? And then one can only have 9998 tagged events,
increasing it to one more decimal gives 136 errors.

Is there a way to tag instrument with strings instead? is there a way to
send string p-args with csoundScoreEvent()?

-- 
/Jonatan         [ http://kymatica.com ]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net