Csound Csound-dev Csound-tekno Search About

[Cs-dev] API: string channels...

Date2006-08-28 12:15
From"Rory Walsh"
Subject[Cs-dev] API: string channels...
I'm trying to work with string channels but I'm getting stuck. I've
attached a full command line version of my problem below, pay particular
attention to my SetValueInChannelStr() function. The Csound code I'm using
is also attached below. Before Istvan left the list he mentioned that I
would have to use csoundGetStrVarMaxLen(cs), can anyone provide any
example code for me, I'm desperate to get this working. Cheers,
Rory.

P.S. The code below does not cause anything to be printed to the screen so
I'm guessing that I am not assigning my string to pvalue correctly?

/*************** test.csd ****************/


-odevaudio1


sr = 44100
kr = 44100
ksmps = 1
nchnls = 1

gSval chnexport "pitch", 1

instr 1
klen strlenk gSval
if(klen!=0) then
printks gSval, 1
endif
endin



f1 0 1024 10 1
i1 0 50




/********************** main.cpp *************************/
#include 
#include "csound.hpp"

using namespace std;
void SetValueInChannelStr(CSOUND *cs, char *name, char* string);
uintptr_t csThread(void *clientData);

struct userData {
int result;
CSOUND* csound;
bool PERF_STATUS;
};

//----------main------------------
int main(int argc, char *argv[])
{
void* ThreadID;
userData* ud;
MYFLT* pvalue;
int trigger=0;
ud = (userData *)malloc(sizeof(userData));
ud->csound=csoundCreate(NULL);
csoundInitialize(&argc, &argv, 0);
ud->result=csoundCompile(ud->csound,argc,argv);
if(!ud->result)
  {
  ud->PERF_STATUS=1;
  ThreadID = csoundCreateThread(csThread, (void*)ud);
  }

while(1)
     {
     scanf("%d", &trigger);
     if(trigger<1)
       {
       ud->PERF_STATUS=0;
       break;
       }
     else if(trigger>0){
          SetValueInChannelStr(ud->csound, "pitch", "testing");
          printf("print_test");
          }
     trigger=0;
     }
csoundDestroy(ud->csound);
return ud->result;
}
//--------------------------------------------------------------
uintptr_t csThread(void *data)
{
userData* udata = (userData*)data;
     if(!udata->result)
       {
             while((csoundPerformKsmps(udata->csound) ==
0)&&(udata->PERF_STATUS==1));
       }
     udata->PERF_STATUS=0;
     printf("thread finsihed");
     return 1;
}
//--------------------------------------------------------------
void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
{
  MYFLT   *pvalue_tmp;
  int result;
  result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
  CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
  char *pvalue = reinterpret_cast(pvalue_tmp);
  if (!result)strcpy(pvalue, "test string");
}




-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 13:10
FromVictor Lazzarini
SubjectRe: [Cs-dev] API: string channels...
The 'string' argument does not get passed to csoundGetChannelPtr(), so
csound never gets it.


>}
>//--------------------------------------------------------------
>void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
>{
>   MYFLT   *pvalue_tmp;
>   int result;
>   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
>   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>   char *pvalue = reinterpret_cast(pvalue_tmp);
>   if (!result)strcpy(pvalue, "test string");
>}
>
>
>
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 13:25
FromVictor Lazzarini
SubjectRe: [Cs-dev] API: string channels...
and here's a simple example that works:

int main(int argc, char **argv)
{
     CSOUND  *csound;
     char    *fname = NULL;
     int     i, result;
     char *string;

     /* initialise Csound library */
     csoundInitialize(&argc, &argv, 0);

     /*  Create Csound. */
     csound = csoundCreate(NULL);

     string = malloc(csoundGetStrVarMaxLen(csound));
     /*  One complete performance cycle. */
     result = csoundCompile(csound, argc, argv);
     result = csoundGetChannelPtr(csound, (MYFLT **)&string, "pitch",
     CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
      strcpy(string, "hello\n");

     while (!result){
       result = csoundPerformKsmps(csound);
     }
     /* delete Csound instance */
     csoundDestroy(csound);
     free(string);
     return (result >= 0 ? 0 : result);
}




At 13:10 28/08/2006, you wrote:
>The 'string' argument does not get passed to csoundGetChannelPtr(), so
>csound never gets it.
>
>
> >}
> >//--------------------------------------------------------------
> >void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
> >{
> >   MYFLT   *pvalue_tmp;
> >   int result;
> >   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
> >   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
> >   char *pvalue = reinterpret_cast(pvalue_tmp);
> >   if (!result)strcpy(pvalue, "test string");
> >}
> >
> >
> >
> >
> >-------------------------------------------------------------------------
> >Using Tomcat but need to do more? Need to support web services, security?
> >Get stuff done quickly with pre-integrated technology to make your job 
> easier
> >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> >_______________________________________________
> >Csound-devel mailing list
> >Csound-devel@lists.sourceforge.net
> >https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>Victor Lazzarini
>Music Technology Laboratory
>Music Department
>National University of Ireland, Maynooth
>
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 13:30
FromRory Walsh
SubjectRe: [Cs-dev] API: string channels...
Sweet. I was just half way through a rather long-winded mail in response 
to your last mail, basically I was confused about the reinterpret_cast 
operator. I will try out your code. Thanks again.

Rory.


Victor Lazzarini wrote:
> and here's a simple example that works:
> 
> int main(int argc, char **argv)
> {
>      CSOUND  *csound;
>      char    *fname = NULL;
>      int     i, result;
>      char *string;
> 
>      /* initialise Csound library */
>      csoundInitialize(&argc, &argv, 0);
> 
>      /*  Create Csound. */
>      csound = csoundCreate(NULL);
> 
>      string = malloc(csoundGetStrVarMaxLen(csound));
>      /*  One complete performance cycle. */
>      result = csoundCompile(csound, argc, argv);
>      result = csoundGetChannelPtr(csound, (MYFLT **)&string, "pitch",
>      CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>       strcpy(string, "hello\n");
> 
>      while (!result){
>        result = csoundPerformKsmps(csound);
>      }
>      /* delete Csound instance */
>      csoundDestroy(csound);
>      free(string);
>      return (result >= 0 ? 0 : result);
> }
> 
> 
> 
> 
> At 13:10 28/08/2006, you wrote:
>> The 'string' argument does not get passed to csoundGetChannelPtr(), so
>> csound never gets it.
>>
>>
>>> }
>>> //--------------------------------------------------------------
>>> void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
>>> {
>>>   MYFLT   *pvalue_tmp;
>>>   int result;
>>>   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
>>>   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>>>   char *pvalue = reinterpret_cast(pvalue_tmp);
>>>   if (!result)strcpy(pvalue, "test string");
>>> }
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Using Tomcat but need to do more? Need to support web services, security?
>>> Get stuff done quickly with pre-integrated technology to make your job 
>> easier
>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> Victor Lazzarini
>> Music Technology Laboratory
>> Music Department
>> National University of Ireland, Maynooth
>>
>>
>> -------------------------------------------------------------------------
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 
> Victor Lazzarini
> Music Technology Laboratory
> Music Department
> National University of Ireland, Maynooth 
> 
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 15:11
FromRory Walsh
SubjectRe: [Cs-dev] API: string channels...
Hi Victor, I've just tried your code which as you said works. I did have 
to cast the result of malloc to a char*, maybe this is because we are 
using different compilers? Anyway I then tried it out in a GUI 
application. I basically modified my previous function to look like this:

void SetValueInChannelStr(CSOUND *cs, char *name, AnsiString string){
            char *my_string;
            my_string = (char*)malloc(csoundGetStrVarMaxLen(cs));
            int result;
            result = csoundGetChannelPtr(cs, (MYFLT **)&my_string, name,
            CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
            //change 'hello' to AnsiString string once it works...
            if (!result)strcpy(my_string, "hello");
           }

I have it set up so that SetValueInChannelStr() is called when I press a 
button. The problem is that when I run my test instead of "hello" being 
printed to the screen I get rubbish characters. Any idea why this might 
be happening?

Rory.


Victor Lazzarini wrote:
> and here's a simple example that works:
> 
> int main(int argc, char **argv)
> {
>      CSOUND  *csound;
>      char    *fname = NULL;
>      int     i, result;
>      char *string;
> 
>      /* initialise Csound library */
>      csoundInitialize(&argc, &argv, 0);
> 
>      /*  Create Csound. */
>      csound = csoundCreate(NULL);
> 
>      string = malloc(csoundGetStrVarMaxLen(csound));
>      /*  One complete performance cycle. */
>      result = csoundCompile(csound, argc, argv);
>      result = csoundGetChannelPtr(csound, (MYFLT **)&string, "pitch",
>      CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>       strcpy(string, "hello\n");
> 
>      while (!result){
>        result = csoundPerformKsmps(csound);
>      }
>      /* delete Csound instance */
>      csoundDestroy(csound);
>      free(string);
>      return (result >= 0 ? 0 : result);
> }
> 
> 
> 
> 
> At 13:10 28/08/2006, you wrote:
>> The 'string' argument does not get passed to csoundGetChannelPtr(), so
>> csound never gets it.
>>
>>
>>> }
>>> //--------------------------------------------------------------
>>> void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
>>> {
>>>   MYFLT   *pvalue_tmp;
>>>   int result;
>>>   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
>>>   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>>>   char *pvalue = reinterpret_cast(pvalue_tmp);
>>>   if (!result)strcpy(pvalue, "test string");
>>> }
>>>
>>>
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Using Tomcat but need to do more? Need to support web services, security?
>>> Get stuff done quickly with pre-integrated technology to make your job 
>> easier
>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>> Victor Lazzarini
>> Music Technology Laboratory
>> Music Department
>> National University of Ireland, Maynooth
>>
>>
>> -------------------------------------------------------------------------
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 
> Victor Lazzarini
> Music Technology Laboratory
> Music Department
> National University of Ireland, Maynooth 
> 
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 15:26
FromVictor Lazzarini
SubjectRe: [Cs-dev] API: string channels...
Try to create my_string outside your Set... function, passing it
to it as a parameter.  In fact you can do the csoundGetCh... call
outside and then just copy the string in your function.

What the csoundGet.... is doing is linking a channel with the
string location you created.  Anything written into that location
will appear on the channel.

At 15:11 28/08/2006, you wrote:
>Hi Victor, I've just tried your code which as you said works. I did have
>to cast the result of malloc to a char*, maybe this is because we are
>using different compilers? Anyway I then tried it out in a GUI
>application. I basically modified my previous function to look like this:
>
>void SetValueInChannelStr(CSOUND *cs, char *name, AnsiString string){
>             char *my_string;
>             my_string = (char*)malloc(csoundGetStrVarMaxLen(cs));
>             int result;
>             result = csoundGetChannelPtr(cs, (MYFLT **)&my_string, name,
>             CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>             //change 'hello' to AnsiString string once it works...
>             if (!result)strcpy(my_string, "hello");
>            }
>
>I have it set up so that SetValueInChannelStr() is called when I press a
>button. The problem is that when I run my test instead of "hello" being
>printed to the screen I get rubbish characters. Any idea why this might
>be happening?
>
>Rory.
>
>
>Victor Lazzarini wrote:
> > and here's a simple example that works:
> >
> > int main(int argc, char **argv)
> > {
> >      CSOUND  *csound;
> >      char    *fname = NULL;
> >      int     i, result;
> >      char *string;
> >
> >      /* initialise Csound library */
> >      csoundInitialize(&argc, &argv, 0);
> >
> >      /*  Create Csound. */
> >      csound = csoundCreate(NULL);
> >
> >      string = malloc(csoundGetStrVarMaxLen(csound));
> >      /*  One complete performance cycle. */
> >      result = csoundCompile(csound, argc, argv);
> >      result = csoundGetChannelPtr(csound, (MYFLT **)&string, "pitch",
> >      CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
> >       strcpy(string, "hello\n");
> >
> >      while (!result){
> >        result = csoundPerformKsmps(csound);
> >      }
> >      /* delete Csound instance */
> >      csoundDestroy(csound);
> >      free(string);
> >      return (result >= 0 ? 0 : result);
> > }
> >
> >
> >
> >
> > At 13:10 28/08/2006, you wrote:
> >> The 'string' argument does not get passed to csoundGetChannelPtr(), so
> >> csound never gets it.
> >>
> >>
> >>> }
> >>> //--------------------------------------------------------------
> >>> void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
> >>> {
> >>>   MYFLT   *pvalue_tmp;
> >>>   int result;
> >>>   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
> >>>   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
> >>>   char *pvalue = reinterpret_cast(pvalue_tmp);
> >>>   if (!result)strcpy(pvalue, "test string");
> >>> }
> >>>
> >>>
> >>>
> >>>
> >>> -------------------------------------------------------------------------
> >>> Using Tomcat but need to do more? Need to support web services, security?
> >>> Get stuff done quickly with pre-integrated technology to make your job
> >> easier
> >>> Download IBM WebSphere Application Server v.1.0.1 based on Apache 
> Geronimo
> >>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> >>> _______________________________________________
> >>> Csound-devel mailing list
> >>> Csound-devel@lists.sourceforge.net
> >>> https://lists.sourceforge.net/lists/listinfo/csound-devel
> >> Victor Lazzarini
> >> Music Technology Laboratory
> >> Music Department
> >> National University of Ireland, Maynooth
> >>
> >>
> >> -------------------------------------------------------------------------
> >> Using Tomcat but need to do more? Need to support web services, security?
> >> Get stuff done quickly with pre-integrated technology to make your job 
> easier
> >> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> >> _______________________________________________
> >> Csound-devel mailing list
> >> Csound-devel@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/csound-devel
> >
> > Victor Lazzarini
> > Music Technology Laboratory
> > Music Department
> > National University of Ireland, Maynooth
> >
> >
> > -------------------------------------------------------------------------
> > Using Tomcat but need to do more? Need to support web services, security?
> > Get stuff done quickly with pre-integrated technology to make your job 
> easier
> > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > _______________________________________________
> > Csound-devel mailing list
> > Csound-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/csound-devel
> >
>
>-------------------------------------------------------------------------
>Using Tomcat but need to do more? Need to support web services, security?
>Get stuff done quickly with pre-integrated technology to make your job easier
>Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2006-08-28 17:32
FromRory Walsh
SubjectRe: [Cs-dev] API: string channels...
I just tried to call csoundGetCha.. directly from my button function. I 
create and allocate space for my_string in my main class constructor but 
I still only see rubbish characters? My OnButtonClick function looks 
like this

void __fastcall TForm1::OnButtonClick(TObject *Sender)
{
csoundGetChannelPtr(pd->instance, (MYFLT **)&my_string, "menu1",
CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
strcpy(my_string, "hello\n");
}

There must be something being assigned to the channel as the rubbish 
characters only appear once I press my button. If they're was nothing be 
sent to the channel Csound would not be printing anything at all, right?

Rory.


Victor Lazzarini wrote:
> Try to create my_string outside your Set... function, passing it
> to it as a parameter.  In fact you can do the csoundGetCh... call
> outside and then just copy the string in your function.
> 
> What the csoundGet.... is doing is linking a channel with the
> string location you created.  Anything written into that location
> will appear on the channel.
> 
> At 15:11 28/08/2006, you wrote:
>> Hi Victor, I've just tried your code which as you said works. I did have
>> to cast the result of malloc to a char*, maybe this is because we are
>> using different compilers? Anyway I then tried it out in a GUI
>> application. I basically modified my previous function to look like this:
>>
>> void SetValueInChannelStr(CSOUND *cs, char *name, AnsiString string){
>>             char *my_string;
>>             my_string = (char*)malloc(csoundGetStrVarMaxLen(cs));
>>             int result;
>>             result = csoundGetChannelPtr(cs, (MYFLT **)&my_string, name,
>>             CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>>             //change 'hello' to AnsiString string once it works...
>>             if (!result)strcpy(my_string, "hello");
>>            }
>>
>> I have it set up so that SetValueInChannelStr() is called when I press a
>> button. The problem is that when I run my test instead of "hello" being
>> printed to the screen I get rubbish characters. Any idea why this might
>> be happening?
>>
>> Rory.
>>
>>
>> Victor Lazzarini wrote:
>>> and here's a simple example that works:
>>>
>>> int main(int argc, char **argv)
>>> {
>>>      CSOUND  *csound;
>>>      char    *fname = NULL;
>>>      int     i, result;
>>>      char *string;
>>>
>>>      /* initialise Csound library */
>>>      csoundInitialize(&argc, &argv, 0);
>>>
>>>      /*  Create Csound. */
>>>      csound = csoundCreate(NULL);
>>>
>>>      string = malloc(csoundGetStrVarMaxLen(csound));
>>>      /*  One complete performance cycle. */
>>>      result = csoundCompile(csound, argc, argv);
>>>      result = csoundGetChannelPtr(csound, (MYFLT **)&string, "pitch",
>>>      CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>>>       strcpy(string, "hello\n");
>>>
>>>      while (!result){
>>>        result = csoundPerformKsmps(csound);
>>>      }
>>>      /* delete Csound instance */
>>>      csoundDestroy(csound);
>>>      free(string);
>>>      return (result >= 0 ? 0 : result);
>>> }
>>>
>>>
>>>
>>>
>>> At 13:10 28/08/2006, you wrote:
>>>> The 'string' argument does not get passed to csoundGetChannelPtr(), so
>>>> csound never gets it.
>>>>
>>>>
>>>>> }
>>>>> //--------------------------------------------------------------
>>>>> void SetValueInChannelStr(CSOUND *cs, char *name, char* string)
>>>>> {
>>>>>   MYFLT   *pvalue_tmp;
>>>>>   int result;
>>>>>   result = csoundGetChannelPtr(cs, &pvalue_tmp, name,
>>>>>   CSOUND_INPUT_CHANNEL | CSOUND_STRING_CHANNEL);
>>>>>   char *pvalue = reinterpret_cast(pvalue_tmp);
>>>>>   if (!result)strcpy(pvalue, "test string");
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------
>>>>> Using Tomcat but need to do more? Need to support web services, security?
>>>>> Get stuff done quickly with pre-integrated technology to make your job
>>>> easier
>>>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache 
>> Geronimo
>>>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>>>> _______________________________________________
>>>>> Csound-devel mailing list
>>>>> Csound-devel@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>> Victor Lazzarini
>>>> Music Technology Laboratory
>>>> Music Department
>>>> National University of Ireland, Maynooth
>>>>
>>>>
>>>> -------------------------------------------------------------------------
>>>> Using Tomcat but need to do more? Need to support web services, security?
>>>> Get stuff done quickly with pre-integrated technology to make your job 
>> easier
>>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>>> _______________________________________________
>>>> Csound-devel mailing list
>>>> Csound-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>> Victor Lazzarini
>>> Music Technology Laboratory
>>> Music Department
>>> National University of Ireland, Maynooth
>>>
>>>
>>> -------------------------------------------------------------------------
>>> Using Tomcat but need to do more? Need to support web services, security?
>>> Get stuff done quickly with pre-integrated technology to make your job 
>> easier
>>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>
>> -------------------------------------------------------------------------
>> Using Tomcat but need to do more? Need to support web services, security?
>> Get stuff done quickly with pre-integrated technology to make your job easier
>> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
>> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 
> Victor Lazzarini
> Music Technology Laboratory
> Music Department
> National University of Ireland, Maynooth 
> 
> 
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel
> 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net