Csound Csound-dev Csound-tekno Search About

Open Sound Control (OSC) n00b question

Date2016-08-12 22:45
Fromphil jones
SubjectOpen Sound Control (OSC) n00b question
Hi everyone.

I'm new to CSOUND and just trying it out, especially the OSC functionality.

I want to use CSOUND to make several instruments that are controlled
via a Processing sketch using OSC.

Based on the example on
http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
simple instrument :

instr 1001  ; this instrument receives OSC-values
    k1 init 0.0
    kFreq init 0.0
    kAmp init 0.0
    kReverbAmp init 0.0
    k5 init 0.0
    k6 init 0.0

    ihandle OSCinit 9006
    kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
kAmp, kReverbAmp, k5, k6
    printk2 kAction
    if (kAction == 1) then
        printk2 kFreq
        printk2 kAmp
     endif

    aSine poscil3 0.5, kFreq, 1

    ; reverb
    aInVerb = aSine*1
    aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
outs aWetL+aSine, aWetR+aSine
endin


Which seems to work as expected.

However, I now want to add two more instruments, listening to the same
port number but different OSC paths ie. "/channel1" and "/channel2".

If I just copy and paste this instrument a second time, changing the
path string, CSOUND blows up with a segmentation fault. Presumably
because there are things in this instrument definition that shouldn't
be repeated.

So what's the issue?  Are the "variables" in an instrument local to
it? Or actually global? Should I rename all the kAmp etc. in each
separate instrument definition?

Or are there only specific things?

I tried giving everything different names in a second instrument, and
CSOUND still complained that it couldn't open the OSCinit because the
port was blocked.

Does that mean that I can only call OSCinit once per port number? If
so, where do I put the call to it, and what's the scope of ihandle?
Can it be outside an instrument?

Or must I put everything that listens to the same port inside the same
instrument?

If I want three identical voices, each listening to a different path
on the same OSC port, is there a way of creating a reusable component,
like a PureData abstraction, which can be reused for each of them,
parameterized by path? And if so, where / how do I define it?

many thanks

Phil

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-08-12 23:08
Fromjoachim heintz
SubjectRe: Open Sound Control (OSC) n00b question
hi phil -

yes i think you got the point.  try
   gihandle OSCinit 9006
outside any instrument, before the first one (= "instrument 0").

this should work.  best -
	joachim


On 12/08/16 23:45, phil jones wrote:
> Hi everyone.
>
> I'm new to CSOUND and just trying it out, especially the OSC functionality.
>
> I want to use CSOUND to make several instruments that are controlled
> via a Processing sketch using OSC.
>
> Based on the example on
> http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
> simple instrument :
>
> instr 1001  ; this instrument receives OSC-values
>      k1 init 0.0
>      kFreq init 0.0
>      kAmp init 0.0
>      kReverbAmp init 0.0
>      k5 init 0.0
>      k6 init 0.0
>
>      ihandle OSCinit 9006
>      kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
> kAmp, kReverbAmp, k5, k6
>      printk2 kAction
>      if (kAction == 1) then
>          printk2 kFreq
>          printk2 kAmp
>       endif
>
>      aSine poscil3 0.5, kFreq, 1
>
>      ; reverb
>      aInVerb = aSine*1
>      aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
> outs aWetL+aSine, aWetR+aSine
> endin
>
>
> Which seems to work as expected.
>
> However, I now want to add two more instruments, listening to the same
> port number but different OSC paths ie. "/channel1" and "/channel2".
>
> If I just copy and paste this instrument a second time, changing the
> path string, CSOUND blows up with a segmentation fault. Presumably
> because there are things in this instrument definition that shouldn't
> be repeated.
>
> So what's the issue?  Are the "variables" in an instrument local to
> it? Or actually global? Should I rename all the kAmp etc. in each
> separate instrument definition?
>
> Or are there only specific things?
>
> I tried giving everything different names in a second instrument, and
> CSOUND still complained that it couldn't open the OSCinit because the
> port was blocked.
>
> Does that mean that I can only call OSCinit once per port number? If
> so, where do I put the call to it, and what's the scope of ihandle?
> Can it be outside an instrument?
>
> Or must I put everything that listens to the same port inside the same
> instrument?
>
> If I want three identical voices, each listening to a different path
> on the same OSC port, is there a way of creating a reusable component,
> like a PureData abstraction, which can be reused for each of them,
> parameterized by path? And if so, where / how do I define it?
>
> many thanks
>
> Phil
>
> 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-08-13 16:02
FromRory Walsh
SubjectRe: Open Sound Control (OSC) n00b question

You could also try csoundo which will let you call Csound directly within Processing. I find this to be a more streamlined approach.


On 13 Aug 2016 00:07, "joachim heintz" <jh@joachimheintz.de> wrote:
hi phil -

yes i think you got the point.  try
  gihandle OSCinit 9006
outside any instrument, before the first one (= "instrument 0").

this should work.  best -
        joachim


On 12/08/16 23:45, phil jones wrote:
Hi everyone.

I'm new to CSOUND and just trying it out, especially the OSC functionality.

I want to use CSOUND to make several instruments that are controlled
via a Processing sketch using OSC.

Based on the example on
http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
simple instrument :

instr 1001  ; this instrument receives OSC-values
     k1 init 0.0
     kFreq init 0.0
     kAmp init 0.0
     kReverbAmp init 0.0
     k5 init 0.0
     k6 init 0.0

     ihandle OSCinit 9006
     kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
kAmp, kReverbAmp, k5, k6
     printk2 kAction
     if (kAction == 1) then
         printk2 kFreq
         printk2 kAmp
      endif

     aSine poscil3 0.5, kFreq, 1

     ; reverb
     aInVerb = aSine*1
     aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
outs aWetL+aSine, aWetR+aSine
endin


Which seems to work as expected.

However, I now want to add two more instruments, listening to the same
port number but different OSC paths ie. "/channel1" and "/channel2".

If I just copy and paste this instrument a second time, changing the
path string, CSOUND blows up with a segmentation fault. Presumably
because there are things in this instrument definition that shouldn't
be repeated.

So what's the issue?  Are the "variables" in an instrument local to
it? Or actually global? Should I rename all the kAmp etc. in each
separate instrument definition?

Or are there only specific things?

I tried giving everything different names in a second instrument, and
CSOUND still complained that it couldn't open the OSCinit because the
port was blocked.

Does that mean that I can only call OSCinit once per port number? If
so, where do I put the call to it, and what's the scope of ihandle?
Can it be outside an instrument?

Or must I put everything that listens to the same port inside the same
instrument?

If I want three identical voices, each listening to a different path
on the same OSC port, is there a way of creating a reusable component,
like a PureData abstraction, which can be reused for each of them,
parameterized by path? And if so, where / how do I define it?

many thanks

Phil

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-08-13 16:27
FromJohn
SubjectRe: Open Sound Control (OSC) n00b question

But we ought to fix the segfault as well

Sent from TypeApp

On 13 Aug 2016, at 16:03, Rory Walsh <rorywalsh@EAR.IE> wrote:

You could also try csoundo which will let you call Csound directly within Processing. I find this to be a more streamlined approach.


On 13 Aug 2016 00:07, "joachim heintz" <jh@joachimheintz.de> wrote:
hi phil -

yes i think you got the point.  try
  gihandle OSCinit 9006
outside any instrument, before the first one (= "instrument 0").

this should work.  best -
        joachim


On 12/08/16 23:45, phil jones wrote:
Hi everyone.

I'm new to CSOUND and just trying it out, especially the OSC functionality.

I want to use CSOUND to make several instruments that are controlled
via a Processing sketch using OSC.

Based on the example on
http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
simple instrument :

instr 1001  ; this instrument receives OSC-values
     k1 init 0.0
     kFreq init 0.0
     kAmp init 0.0
     kReverbAmp init 0.0
     k5 init 0.0
     k6 init 0.0

     ihandle OSCinit 9006
     kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
kAmp, kReverbAmp, k5, k6
     printk2 kAction
     if (kAction == 1) then
         printk2 kFreq
         printk2 kAmp
      endif

     aSine poscil3 0.5, kFreq, 1

     ; reverb
     aInVerb = aSine*1
     aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
outs aWetL+aSine, aWetR+aSine
endin


Which seems to work as expected.

However, I now want to add two more instruments, listening to the same
port number but different OSC paths ie. "/channel1" and "/channel2".

If I just copy and paste this instrument a second time, changing the
path string, CSOUND blows up with a segmentation fault. Presumably
because there are things in this instrument definition that shouldn't
be repeated.

So what's the issue?  Are the "variables" in an instrument local to
it? Or actually global? Should I rename all the kAmp etc. in each
separate instrument definition?

Or are there only specific things?

I tried giving everything different names in a second instrument, and
CSOUND still complained that it couldn't open the OSCinit because the
port was blocked.

Does that mean that I can only call OSCinit once per port number? If
so, where do I put the call to it, and what's the scope of ihandle?
Can it be outside an instrument?

Or must I put everything that listens to the same port inside the same
instrument?

If I want three identical voices, each listening to a different path
on the same OSC port, is there a way of creating a reusable component,
like a PureData abstraction, which can be reused for each of them,
parameterized by path? And if so, where / how do I define it?

many thanks

Phil

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-08-13 16:41
FromSteven Yi
SubjectRe: Open Sound Control (OSC) n00b question
Hi Phil,

Just a guess, but I would try doing the OSCinit once and sharing it.
If you check the manual:

http://csound.github.io/docs/manual/OSCinit.html

You'll see how to do the OSCinit once in the "instrument 0" space that
exists outside of instruments.  The value is assigned to the gihandle
variable, a global I-time variable that can be accessed by any
instrument.  Using that outside of the instrument definition, you
would modify your OSClisten code to use gihandle and remove any
OSCinit calls within the instrument.

If you want to reuse the same instrument definition but have the
various instances of the instrument listen on different paths, you
could pass the path as a p-field. You would use something like:

instr 1
Sosc_path = p4
...
    kAction  OSClisten    giihandle, Sosc_path, "dddddd", k1, kFreq,...
...
endin

and start the multiple instances using instrument 0 code with event_i,
or use a Score using something like:

i1 0 1000000 "/channel0"
i1 0 1000000 "/channel1"
i1 0 1000000 "/channel2"

Hope that helps!
steven

On Fri, Aug 12, 2016 at 5:45 PM, phil jones  wrote:
> Hi everyone.
>
> I'm new to CSOUND and just trying it out, especially the OSC functionality.
>
> I want to use CSOUND to make several instruments that are controlled
> via a Processing sketch using OSC.
>
> Based on the example on
> http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
> simple instrument :
>
> instr 1001  ; this instrument receives OSC-values
>     k1 init 0.0
>     kFreq init 0.0
>     kAmp init 0.0
>     kReverbAmp init 0.0
>     k5 init 0.0
>     k6 init 0.0
>
>     ihandle OSCinit 9006
>     kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
> kAmp, kReverbAmp, k5, k6
>     printk2 kAction
>     if (kAction == 1) then
>         printk2 kFreq
>         printk2 kAmp
>      endif
>
>     aSine poscil3 0.5, kFreq, 1
>
>     ; reverb
>     aInVerb = aSine*1
>     aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
> outs aWetL+aSine, aWetR+aSine
> endin
>
>
> Which seems to work as expected.
>
> However, I now want to add two more instruments, listening to the same
> port number but different OSC paths ie. "/channel1" and "/channel2".
>
> If I just copy and paste this instrument a second time, changing the
> path string, CSOUND blows up with a segmentation fault. Presumably
> because there are things in this instrument definition that shouldn't
> be repeated.
>
> So what's the issue?  Are the "variables" in an instrument local to
> it? Or actually global? Should I rename all the kAmp etc. in each
> separate instrument definition?
>
> Or are there only specific things?
>
> I tried giving everything different names in a second instrument, and
> CSOUND still complained that it couldn't open the OSCinit because the
> port was blocked.
>
> Does that mean that I can only call OSCinit once per port number? If
> so, where do I put the call to it, and what's the scope of ihandle?
> Can it be outside an instrument?
>
> Or must I put everything that listens to the same port inside the same
> instrument?
>
> If I want three identical voices, each listening to a different path
> on the same OSC port, is there a way of creating a reusable component,
> like a PureData abstraction, which can be reused for each of them,
> parameterized by path? And if so, where / how do I define it?
>
> many thanks
>
> Phil
>
> 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-08-14 15:52
Fromphil jones
SubjectRe: Open Sound Control (OSC) n00b question
Thanks everyone for the advice ... it's been very useful helping me
understand this.

so far, I've managed to get this working :

gihandle OSCinit 9006

opcode SimpleVoice, aa, kkk
    setksmps 1
    kFreq, kAmp, kReverb xin ; arguments are the handle on the OSC
port and the channel string

    aSig poscil3 0.5, kFreq, 1
    aInVerb = aSig*1
    aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
    xout aWetL+aSig, aWetR+aSig
endop


turnon 1001  ; starts instrument 1001 immediately

instr 1001  ; this instrument receives OSC-values
    k1, k1Freq, k1Amp, k1Reverb, k1a, k1b init 0.0
    k1Act OSClisten gihandle, "/channel0", "dddddd", k1, k1Freq,
k1Amp, k1Reverb, k1a, k1b
    ac1l, ac1r SimpleVoice k1Freq, k1Amp, k1Reverb

    k2, k2Freq, k2Amp, k2Reverb, k2a, k2b init 0.0
    k2Act OSClisten gihandle, "/channel1", "dddddd", k2, k2Freq,
k2Amp, k2Reverb, k2a, k2b
    ac2l, ac2r SimpleVoice k2Freq, k2Amp, k2Reverb

    k3, k3Freq, k3Amp, k3Reverb, k3a, k3b  init 0.0
    k3Act OSClisten gihandle, "/channel2", "dddddd", k3, k3Freq,
k3Amp, k3Reverb, k3a, k3b
    ac3l, ac3r SimpleVoice k3Freq, k3Amp, k3Reverb


outs (ac1l+ac2l+ac3l)/3, (ac1r+ac2r+ac3r)/3

endin

I still wish I could refactor out the multiple instances of
OSClisten, at the moment there's a proliferation of variables (I
presume they're passed by reference)

Next I'll try Stephen Yi's suggestion of making multiple instruments
parameterized by channel.

cheers

Phil


On 13 August 2016 at 12:41, Steven Yi  wrote:
> Hi Phil,
>
> Just a guess, but I would try doing the OSCinit once and sharing it.
> If you check the manual:
>
> http://csound.github.io/docs/manual/OSCinit.html
>
> You'll see how to do the OSCinit once in the "instrument 0" space that
> exists outside of instruments.  The value is assigned to the gihandle
> variable, a global I-time variable that can be accessed by any
> instrument.  Using that outside of the instrument definition, you
> would modify your OSClisten code to use gihandle and remove any
> OSCinit calls within the instrument.
>
> If you want to reuse the same instrument definition but have the
> various instances of the instrument listen on different paths, you
> could pass the path as a p-field. You would use something like:
>
> instr 1
> Sosc_path = p4
> ...
>     kAction  OSClisten    giihandle, Sosc_path, "dddddd", k1, kFreq,...
> ...
> endin
>
> and start the multiple instances using instrument 0 code with event_i,
> or use a Score using something like:
>
> i1 0 1000000 "/channel0"
> i1 0 1000000 "/channel1"
> i1 0 1000000 "/channel2"
>
> Hope that helps!
> steven
>
> On Fri, Aug 12, 2016 at 5:45 PM, phil jones  wrote:
>> Hi everyone.
>>
>> I'm new to CSOUND and just trying it out, especially the OSC functionality.
>>
>> I want to use CSOUND to make several instruments that are controlled
>> via a Processing sketch using OSC.
>>
>> Based on the example on
>> http://write.flossmanuals.net/csound/a-open-sound-control/ I have a
>> simple instrument :
>>
>> instr 1001  ; this instrument receives OSC-values
>>     k1 init 0.0
>>     kFreq init 0.0
>>     kAmp init 0.0
>>     kReverbAmp init 0.0
>>     k5 init 0.0
>>     k6 init 0.0
>>
>>     ihandle OSCinit 9006
>>     kAction  OSClisten    ihandle, "/channel0", "dddddd", k1, kFreq,
>> kAmp, kReverbAmp, k5, k6
>>     printk2 kAction
>>     if (kAction == 1) then
>>         printk2 kFreq
>>         printk2 kAmp
>>      endif
>>
>>     aSine poscil3 0.5, kFreq, 1
>>
>>     ; reverb
>>     aInVerb = aSine*1
>>     aWetL, aWetR freeverb aInVerb, aInVerb, 0.4, 0.8
>> outs aWetL+aSine, aWetR+aSine
>> endin
>>
>>
>> Which seems to work as expected.
>>
>> However, I now want to add two more instruments, listening to the same
>> port number but different OSC paths ie. "/channel1" and "/channel2".
>>
>> If I just copy and paste this instrument a second time, changing the
>> path string, CSOUND blows up with a segmentation fault. Presumably
>> because there are things in this instrument definition that shouldn't
>> be repeated.
>>
>> So what's the issue?  Are the "variables" in an instrument local to
>> it? Or actually global? Should I rename all the kAmp etc. in each
>> separate instrument definition?
>>
>> Or are there only specific things?
>>
>> I tried giving everything different names in a second instrument, and
>> CSOUND still complained that it couldn't open the OSCinit because the
>> port was blocked.
>>
>> Does that mean that I can only call OSCinit once per port number? If
>> so, where do I put the call to it, and what's the scope of ihandle?
>> Can it be outside an instrument?
>>
>> Or must I put everything that listens to the same port inside the same
>> instrument?
>>
>> If I want three identical voices, each listening to a different path
>> on the same OSC port, is there a way of creating a reusable component,
>> like a PureData abstraction, which can be reused for each of them,
>> parameterized by path? And if so, where / how do I define it?
>>
>> many thanks
>>
>> Phil
>>
>> 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