Csound Csound-dev Csound-tekno Search About

[Csnd] Create/query global variables with plugin.h

Date2019-08-20 23:44
FromRichard Knight
Subject[Csnd] Create/query global variables with plugin.h

Hi

I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.

thanks
Richard


Date2019-08-21 14:00
FromVictor Lazzarini
SubjectRe: [Csnd] Create/query global variables with plugin.h
Those functions are used if you have a shared resource that many opcodes need to use,
so yes. You could create the resource with these functions and then pass a handle to this resource 
out to other opcodes through a variable.

Note that you can’t pass the pointer out as a variable, because that would not work in float
builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs
8 bytes), so you will need to find some other way to describe the handle.

A typical example is seen in Opcodes/OSC.c:

1. The global resource relating to a port/address is created in OSCinit
2. An integer count identifying this resource in a list is passed out as a handle
3. OSClisten takes that, finds the global resource pointer, and then identifies
the exact object relayed to the relevant port/address selected in OSCinit.

HTH
========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 20 Aug 2019, at 23:44, Richard Knight  wrote:
> 
> Hi
> 
> I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
> Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.
> 
> thanks
> Richard
> 
> 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

Date2019-08-21 16:06
FromSteven Yi
SubjectRe: [Csnd] Create/query global variables with plugin.h
I'm not sure I understand about the pointer size being an issue with
Create/QueryGlobalVariable since you can allocate/use a size of memory
that is user-defined?

For Richard: You can access Create/QueryGlobalVariable through the
CSOUND data structure that is passed in to opcode functions.  You'll
see that in csoundCore.h there are these members of the CSOUND struct:

    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
    int (*DestroyGlobalVariable)(CSOUND *, const char *name);

and in your opcode code, I think you should be able to use:

int opinit(CSOUND* cs, void* data) {
  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
  // check success from above
 someStruct* s = (someStruct*) QueryGlobalVariable(cs,
"uniqueName_variableName");
 s->val = 0.0;
 ... other initialization of data...
}

You should be able to find a number of examples like this in the
Opcodes folder if you grep for "QueryGlobalVariable" there.

On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini  wrote:
>
> Those functions are used if you have a shared resource that many opcodes need to use,
> so yes. You could create the resource with these functions and then pass a handle to this resource
> out to other opcodes through a variable.
>
> Note that you can’t pass the pointer out as a variable, because that would not work in float
> builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs
> 8 bytes), so you will need to find some other way to describe the handle.
>
> A typical example is seen in Opcodes/OSC.c:
>
> 1. The global resource relating to a port/address is created in OSCinit
> 2. An integer count identifying this resource in a list is passed out as a handle
> 3. OSClisten takes that, finds the global resource pointer, and then identifies
> the exact object relayed to the relevant port/address selected in OSCinit.
>
> HTH
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 20 Aug 2019, at 23:44, Richard Knight  wrote:
> >
> > Hi
> >
> > I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
> > Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.
> >
> > thanks
> > Richard
> >
> > 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

Date2019-08-21 16:29
FromVictor Lazzarini
SubjectRe: [Csnd] Create/query global variables with plugin.h
Pointers are 8 bytes in 64bit archs, so if we are using floats csound, where MYLFT is 4 bytes,
therefore you can’t put a pointer in an ivar (or kvar). Say you have allocated a piece of memory
and wants to pass it via a csound variable, that will not work. That’s not an issue because of
Create/QueryGlobalVariable mechanism. I just mentioned because I remember seeing some
code that passed pointers around from the 32bit arch days, and that had to be fixed. 
That was pre-6.0 days.

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 21 Aug 2019, at 16:06, Steven Yi  wrote:
> 
> I'm not sure I understand about the pointer size being an issue with
> Create/QueryGlobalVariable since you can allocate/use a size of memory
> that is user-defined?
> 
> For Richard: You can access Create/QueryGlobalVariable through the
> CSOUND data structure that is passed in to opcode functions.  You'll
> see that in csoundCore.h there are these members of the CSOUND struct:
> 
>    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
>    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
>    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
>    int (*DestroyGlobalVariable)(CSOUND *, const char *name);
> 
> and in your opcode code, I think you should be able to use:
> 
> int opinit(CSOUND* cs, void* data) {
>  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
>  // check success from above
> someStruct* s = (someStruct*) QueryGlobalVariable(cs,
> "uniqueName_variableName");
> s->val = 0.0;
> ... other initialization of data...
> }
> 
> You should be able to find a number of examples like this in the
> Opcodes folder if you grep for "QueryGlobalVariable" there.
> 
> On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini  wrote:
>> 
>> Those functions are used if you have a shared resource that many opcodes need to use,
>> so yes. You could create the resource with these functions and then pass a handle to this resource
>> out to other opcodes through a variable.
>> 
>> Note that you can’t pass the pointer out as a variable, because that would not work in float
>> builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs
>> 8 bytes), so you will need to find some other way to describe the handle.
>> 
>> A typical example is seen in Opcodes/OSC.c:
>> 
>> 1. The global resource relating to a port/address is created in OSCinit
>> 2. An integer count identifying this resource in a list is passed out as a handle
>> 3. OSClisten takes that, finds the global resource pointer, and then identifies
>> the exact object relayed to the relevant port/address selected in OSCinit.
>> 
>> HTH
>> ========================
>> Prof. Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952
>> 
>>> On 20 Aug 2019, at 23:44, Richard Knight  wrote:
>>> 
>>> Hi
>>> 
>>> I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
>>> Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.
>>> 
>>> thanks
>>> Richard
>>> 
>>> 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

Date2019-08-21 20:36
FromSteven Yi
SubjectRe: [Csnd] Create/query global variables with plugin.h
I see, I wasn't clear you were talking about that. Yes, I remember
some code like that in the past and it was not easy to figure out the
issues. ;)

On Wed, Aug 21, 2019 at 11:29 AM Victor Lazzarini
 wrote:
>
> Pointers are 8 bytes in 64bit archs, so if we are using floats csound, where MYLFT is 4 bytes,
> therefore you can’t put a pointer in an ivar (or kvar). Say you have allocated a piece of memory
> and wants to pass it via a csound variable, that will not work. That’s not an issue because of
> Create/QueryGlobalVariable mechanism. I just mentioned because I remember seeing some
> code that passed pointers around from the 32bit arch days, and that had to be fixed.
> That was pre-6.0 days.
>
> ========================
> Prof. Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 21 Aug 2019, at 16:06, Steven Yi  wrote:
> >
> > I'm not sure I understand about the pointer size being an issue with
> > Create/QueryGlobalVariable since you can allocate/use a size of memory
> > that is user-defined?
> >
> > For Richard: You can access Create/QueryGlobalVariable through the
> > CSOUND data structure that is passed in to opcode functions.  You'll
> > see that in csoundCore.h there are these members of the CSOUND struct:
> >
> >    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
> >    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
> >    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
> >    int (*DestroyGlobalVariable)(CSOUND *, const char *name);
> >
> > and in your opcode code, I think you should be able to use:
> >
> > int opinit(CSOUND* cs, void* data) {
> >  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
> >  // check success from above
> > someStruct* s = (someStruct*) QueryGlobalVariable(cs,
> > "uniqueName_variableName");
> > s->val = 0.0;
> > ... other initialization of data...
> > }
> >
> > You should be able to find a number of examples like this in the
> > Opcodes folder if you grep for "QueryGlobalVariable" there.
> >
> > On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini  wrote:
> >>
> >> Those functions are used if you have a shared resource that many opcodes need to use,
> >> so yes. You could create the resource with these functions and then pass a handle to this resource
> >> out to other opcodes through a variable.
> >>
> >> Note that you can’t pass the pointer out as a variable, because that would not work in float
> >> builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs
> >> 8 bytes), so you will need to find some other way to describe the handle.
> >>
> >> A typical example is seen in Opcodes/OSC.c:
> >>
> >> 1. The global resource relating to a port/address is created in OSCinit
> >> 2. An integer count identifying this resource in a list is passed out as a handle
> >> 3. OSClisten takes that, finds the global resource pointer, and then identifies
> >> the exact object relayed to the relevant port/address selected in OSCinit.
> >>
> >> HTH
> >> ========================
> >> Prof. Victor Lazzarini
> >> Dean of Arts, Celtic Studies, and Philosophy,
> >> Maynooth University,
> >> Maynooth, Co Kildare, Ireland
> >> Tel: 00 353 7086936
> >> Fax: 00 353 1 7086952
> >>
> >>> On 20 Aug 2019, at 23:44, Richard Knight  wrote:
> >>>
> >>> Hi
> >>>
> >>> I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
> >>> Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.
> >>>
> >>> thanks
> >>> Richard
> >>>
> >>> 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

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

Date2019-08-21 22:23
FromRichard Knight
SubjectRe: [Csnd] Create/query global variables with plugin.h

Thank you both - I have done this in a C opcode before, and the existing opcodes were indeed really useful to see how this is used elsewhere - but my question was really how/where to go about this with the C++ plugin framework? ie when I try csound->CreateGlobalVariable in my struct which inherits from csnd::Plugin, I get:

error: ‘CSOUND_’ is an inaccessible base of ‘csnd::Csound’

If I hack plugin.h from
    class Csound : CSOUND {
to
    class Csound : public CSOUND {

it does compile and appears to work OK... But is there a recommended way of doing this?

 

On Wed, 21 Aug 2019 11:06:40 -0400, Steven Yi wrote:

I'm not sure I understand about the pointer size being an issue with
Create/QueryGlobalVariable since you can allocate/use a size of memory
that is user-defined?

For Richard: You can access Create/QueryGlobalVariable through the
CSOUND data structure that is passed in to opcode functions.  You'll
see that in csoundCore.h there are these members of the CSOUND struct:

    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
    int (*DestroyGlobalVariable)(CSOUND *, const char *name);

and in your opcode code, I think you should be able to use:

int opinit(CSOUND* cs, void* data) {
  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
  // check success from above
 someStruct* s = (someStruct*) QueryGlobalVariable(cs,
"uniqueName_variableName");
 s->val = 0.0;
 ... other initialization of data...
}

You should be able to find a number of examples like this in the
Opcodes folder if you grep for "QueryGlobalVariable" there.

On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Those functions are used if you have a shared resource that many opcodes need to use, so yes. You could create the resource with these functions and then pass a handle to this resource out to other opcodes through a variable. Note that you can’t pass the pointer out as a variable, because that would not work in float builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs 8 bytes), so you will need to find some other way to describe the handle. A typical example is seen in Opcodes/OSC.c: 1. The global resource relating to a port/address is created in OSCinit 2. An integer count identifying this resource in a list is passed out as a handle 3. OSClisten takes that, finds the global resource pointer, and then identifies the exact object relayed to the relevant port/address selected in OSCinit. HTH ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952
On 20 Aug 2019, at 23:44, Richard Knight <richard@1BPM.NET> wrote: Hi I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes. Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h. thanks Richard 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
-- 


http://rk.1bpm.net/

Date2019-08-21 22:25
FromVictor Lazzarini
SubjectRe: [Csnd] Create/query global variables with plugin.h
Oh, I have not exported this, I can do it in git if it helps.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 21 Aug 2019, at 22:23, Richard Knight <richard@1bpm.net> wrote:

Thank you both - I have done this in a C opcode before, and the existing opcodes were indeed really useful to see how this is used elsewhere - but my question was really how/where to go about this with the C++ plugin framework? ie when I try csound->CreateGlobalVariable in my struct which inherits from csnd::Plugin, I get:

error: ‘CSOUND_’ is an inaccessible base of ‘csnd::Csound’

If I hack plugin.h from
    class Csound : CSOUND {
to
    class Csound : public CSOUND {

it does compile and appears to work OK... But is there a recommended way of doing this?

 

On Wed, 21 Aug 2019 11:06:40 -0400, Steven Yi wrote:

I'm not sure I understand about the pointer size being an issue with
Create/QueryGlobalVariable since you can allocate/use a size of memory
that is user-defined?

For Richard: You can access Create/QueryGlobalVariable through the
CSOUND data structure that is passed in to opcode functions.  You'll
see that in csoundCore.h there are these members of the CSOUND struct:

    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
    int (*DestroyGlobalVariable)(CSOUND *, const char *name);

and in your opcode code, I think you should be able to use:

int opinit(CSOUND* cs, void* data) {
  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
  // check success from above
 someStruct* s = (someStruct*) QueryGlobalVariable(cs,
"uniqueName_variableName");
 s->val = 0.0;
 ... other initialization of data...
}

You should be able to find a number of examples like this in the
Opcodes folder if you grep for "QueryGlobalVariable" there.

On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Those functions are used if you have a shared resource that many opcodes need to use, so yes. You could create the resource with these functions and then pass a handle to this resource out to other opcodes through a variable. Note that you can’t pass the pointer out as a variable, because that would not work in float builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs 8 bytes), so you will need to find some other way to describe the handle. A typical example is seen in Opcodes/OSC.c: 1. The global resource relating to a port/address is created in OSCinit 2. An integer count identifying this resource in a list is passed out as a handle 3. OSClisten takes that, finds the global resource pointer, and then identifies the exact object relayed to the relevant port/address selected in OSCinit. HTH ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952
On 20 Aug 2019, at 23:44, Richard Knight <richard@1BPM.NET> wrote: Hi I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes. Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h. thanks Richard 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

Date2019-08-21 22:28
FromRichard Knight
SubjectRe: [Csnd] Create/query global variables with plugin.h

If it's no considerable trouble and you think may be of wider benefit to other users then that would be great, otherwise happy to work around.

On Wed, 21 Aug 2019 21:25:01 +0000, Victor Lazzarini wrote:

Oh, I have not exported this, I can do it in git if it helps.

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 21 Aug 2019, at 22:23, Richard Knight <richard@1bpm.net> wrote:

Thank you both - I have done this in a C opcode before, and the existing opcodes were indeed really useful to see how this is used elsewhere - but my question was really how/where to go about this with the C++ plugin framework? ie when I try csound->CreateGlobalVariable in my struct which inherits from csnd::Plugin, I get:

error: ‘CSOUND_’ is an inaccessible base of ‘csnd::Csound’

If I hack plugin.h from
    class Csound : CSOUND {
to
    class Csound : public CSOUND {

it does compile and appears to work OK... But is there a recommended way of doing this?

 

On Wed, 21 Aug 2019 11:06:40 -0400, Steven Yi wrote:

I'm not sure I understand about the pointer size being an issue with
Create/QueryGlobalVariable since you can allocate/use a size of memory
that is user-defined?

For Richard: You can access Create/QueryGlobalVariable through the
CSOUND data structure that is passed in to opcode functions.  You'll
see that in csoundCore.h there are these members of the CSOUND struct:

    int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
    void *(*QueryGlobalVariable)(CSOUND *, const char *name);
    void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
    int (*DestroyGlobalVariable)(CSOUND *, const char *name);

and in your opcode code, I think you should be able to use:

int opinit(CSOUND* cs, void* data) {
  cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
  // check success from above
 someStruct* s = (someStruct*) QueryGlobalVariable(cs,
"uniqueName_variableName");
 s->val = 0.0;
 ... other initialization of data...
}

You should be able to find a number of examples like this in the
Opcodes folder if you grep for "QueryGlobalVariable" there.

On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
Those functions are used if you have a shared resource that many opcodes need to use, so yes. You could create the resource with these functions and then pass a handle to this resource out to other opcodes through a variable. Note that you can’t pass the pointer out as a variable, because that would not work in float builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs 8 bytes), so you will need to find some other way to describe the handle. A typical example is seen in Opcodes/OSC.c: 1. The global resource relating to a port/address is created in OSCinit 2. An integer count identifying this resource in a list is passed out as a handle 3. OSClisten takes that, finds the global resource pointer, and then identifies the exact object relayed to the relevant port/address selected in OSCinit. HTH ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952
On 20 Aug 2019, at 23:44, Richard Knight <richard@1BPM.NET> wrote: Hi I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes. Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h. thanks Richard 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

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

-- 


http://rk.1bpm.net/

Date2019-08-21 22:45
FromVictor Lazzarini
SubjectRe: [Csnd] Create/query global variables with plugin.h
yes, it’s there now. They’re 

  /** Creates a global variable in the current Csound object 
  */
  int create_global_variable(const char *name, size_t nbytes)

  /** Retrieves a ptr for an existing named global variable
   */
  void *query_global_variable(const char* name)

  /** Destroy an existing named global variable
   */
  int destroy_global_variable(const char* name)

in the Csound class. I’ve also added a mediated
access to the base object, so other functions of
CSOUND can also be accessed if they’re not
exported through Csound.

  /** Access to the base CSOUND object
   */ 
  CSOUND *get_csound() {
    return this;
  }

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 21 Aug 2019, at 22:28, Richard Knight  wrote:
> 
> If it's no considerable trouble and you think may be of wider benefit to other users then that would be great, otherwise happy to work around.
> 
> On Wed, 21 Aug 2019 21:25:01 +0000, Victor Lazzarini wrote:
> 
>> Oh, I have not exported this, I can do it in git if it helps.
>> 
>> Victor Lazzarini
>> Dean of Arts, Celtic Studies, and Philosophy
>> Maynooth University
>> Ireland
>> 
>> On 21 Aug 2019, at 22:23, Richard Knight  wrote:
>> 
>>> Thank you both - I have done this in a C opcode before, and the existing opcodes were indeed really useful to see how this is used elsewhere - but my question was really how/where to go about this with the C++ plugin framework? ie when I try csound->CreateGlobalVariable in my struct which inherits from csnd::Plugin, I get:
>>> 
>>> error: ‘CSOUND_’ is an inaccessible base of ‘csnd::Csound’
>>> 
>>> 
>>> If I hack plugin.h from
>>>     class Csound : CSOUND {
>>> to
>>>     class Csound : public CSOUND {
>>> 
>>> it does compile and appears to work OK... But is there a recommended way of doing this?
>>> 
>>>  
>>> On Wed, 21 Aug 2019 11:06:40 -0400, Steven Yi wrote:
>>> 
>>> I'm not sure I understand about the pointer size being an issue with
>>> Create/QueryGlobalVariable since you can allocate/use a size of memory
>>> that is user-defined?
>>> 
>>> For Richard: You can access Create/QueryGlobalVariable through the
>>> CSOUND data structure that is passed in to opcode functions.  You'll
>>> see that in csoundCore.h there are these members of the CSOUND struct:
>>> 
>>>     int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
>>>     void *(*QueryGlobalVariable)(CSOUND *, const char *name);
>>>     void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
>>>     int (*DestroyGlobalVariable)(CSOUND *, const char *name);
>>> 
>>> and in your opcode code, I think you should be able to use:
>>> 
>>> int opinit(CSOUND* cs, void* data) {
>>>   cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct));
>>>   // check success from above
>>>  someStruct* s = (someStruct*) QueryGlobalVariable(cs,
>>> "uniqueName_variableName");
>>>  s->val = 0.0;
>>>  ... other initialization of data...
>>> }
>>> 
>>> You should be able to find a number of examples like this in the
>>> Opcodes folder if you grep for "QueryGlobalVariable" there.
>>> 
>>> On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini <
>>> Victor.Lazzarini@mu.ie
>>> > wrote:
>>> 
>>> 
>>> Those functions are used if you have a shared resource that many opcodes need to use,
>>> so yes. You could create the resource with these functions and then pass a handle to this resource
>>> out to other opcodes through a variable.
>>> 
>>> Note that you can’t pass the pointer out as a variable, because that would not work in float
>>> builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs
>>> 8 bytes), so you will need to find some other way to describe the handle.
>>> 
>>> A typical example is seen in Opcodes/OSC.c:
>>> 
>>> 1. The global resource relating to a port/address is created in OSCinit
>>> 2. An integer count identifying this resource in a list is passed out as a handle
>>> 3. OSClisten takes that, finds the global resource pointer, and then identifies
>>> the exact object relayed to the relevant port/address selected in OSCinit.
>>> 
>>> HTH
>>> ========================
>>> Prof. Victor Lazzarini
>>> Dean of Arts, Celtic Studies, and Philosophy,
>>> Maynooth University,
>>> Maynooth, Co Kildare, Ireland
>>> Tel: 00 353 7086936
>>> Fax: 00 353 1 7086952
>>> 
>>> 
>>> On 20 Aug 2019, at 23:44, Richard Knight >> > wrote:
>>> 
>>> Hi
>>> 
>>> I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes.
>>> Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h.
>>> 
>>> thanks
>>> Richard
>>> 
>>> 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
>>> 
>>> -- 
>>> 
>>> 
>>> 
>>> http://rk.1bpm.net/
>>> 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
>> 
> -- 
> 
> 
> http://rk.1bpm.net/
> 
> 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

Date2019-08-21 22:53
FromRichard Knight
SubjectRe: [Csnd] Create/query global variables with plugin.h

That's wonderful, thank you very much!

On Wed, 21 Aug 2019 21:45:31 +0000, Victor Lazzarini wrote:

yes, it’s there now. They’re 

  /** Creates a global variable in the current Csound object 
  */
  int create_global_variable(const char *name, size_t nbytes)

  /** Retrieves a ptr for an existing named global variable
   */
  void *query_global_variable(const char* name)

  /** Destroy an existing named global variable
   */
  int destroy_global_variable(const char* name)

in the Csound class. I’ve also added a mediated
access to the base object, so other functions of
CSOUND can also be accessed if they’re not
exported through Csound.

  /** Access to the base CSOUND object
   */ 
  CSOUND *get_csound() {
    return this;
  }

========================
Prof. Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

On 21 Aug 2019, at 22:28, Richard Knight <richard@1BPM.NET> wrote: If it's no considerable trouble and you think may be of wider benefit to other users then that would be great, otherwise happy to work around. On Wed, 21 Aug 2019 21:25:01 +0000, Victor Lazzarini wrote:
Oh, I have not exported this, I can do it in git if it helps. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland On 21 Aug 2019, at 22:23, Richard Knight <richard@1bpm.net> wrote:
Thank you both - I have done this in a C opcode before, and the existing opcodes were indeed really useful to see how this is used elsewhere - but my question was really how/where to go about this with the C++ plugin framework? ie when I try csound->CreateGlobalVariable in my struct which inherits from csnd::Plugin, I get: error: ‘CSOUND_’ is an inaccessible base of ‘csnd::Csound’ If I hack plugin.h from class Csound : CSOUND { to class Csound : public CSOUND { it does compile and appears to work OK... But is there a recommended way of doing this? On Wed, 21 Aug 2019 11:06:40 -0400, Steven Yi wrote: I'm not sure I understand about the pointer size being an issue with Create/QueryGlobalVariable since you can allocate/use a size of memory that is user-defined? For Richard: You can access Create/QueryGlobalVariable through the CSOUND data structure that is passed in to opcode functions. You'll see that in csoundCore.h there are these members of the CSOUND struct: int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes); void *(*QueryGlobalVariable)(CSOUND *, const char *name); void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name); int (*DestroyGlobalVariable)(CSOUND *, const char *name); and in your opcode code, I think you should be able to use: int opinit(CSOUND* cs, void* data) { cs->CreateGlobalVariable(cs, "uniqueName_variableName", sizeof(someStruct)); // check success from above someStruct* s = (someStruct*) QueryGlobalVariable(cs, "uniqueName_variableName"); s->val = 0.0; ... other initialization of data... } You should be able to find a number of examples like this in the Opcodes folder if you grep for "QueryGlobalVariable" there. On Wed, Aug 21, 2019 at 9:00 AM Victor Lazzarini < Victor.Lazzarini@mu.ie
wrote:
Those functions are used if you have a shared resource that many opcodes need to use, so yes. You could create the resource with these functions and then pass a handle to this resource out to other opcodes through a variable. Note that you can’t pass the pointer out as a variable, because that would not work in float builds of Csound for 64bit architecture (where the variable size is 4 bytes, a pointer needs 8 bytes), so you will need to find some other way to describe the handle. A typical example is seen in Opcodes/OSC.c: 1. The global resource relating to a port/address is created in OSCinit 2. An integer count identifying this resource in a list is passed out as a handle 3. OSClisten takes that, finds the global resource pointer, and then identifies the exact object relayed to the relevant port/address selected in OSCinit. HTH ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 On 20 Aug 2019, at 23:44, Richard Knight <richard@1BPM.NET
wrote:
Hi I am writing some plugin opcode in cpp using plugin.h and would like to pass a handle between the opcodes. Is there any way to use QueryGlobalVariable and CreateGlobalVariable or similar? I may be missing something but can't find how to do this like with csdl.h. thanks Richard 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 -- http://rk.1bpm.net/ 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
-- http://rk.1bpm.net/ 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
-- 


http://rk.1bpm.net/