Csound Csound-dev Csound-tekno Search About

Re: API - message callback

Date2007-07-31 19:48
FromVictor Lazzarini
SubjectRe: API - message callback
Use vsnprintf(...).

This is an example callback from csoundapi_tilde.c:

static void message_callback(CSOUND *csound,
  			     int attr, const char *format,va_list valist){
     int i;
     t_csoundapi *x = (t_csoundapi *)
csoundGetHostData(csound);

     if(x->csmess != NULL)
     vsnprintf(x->csmess, MAXMESSTRING, format, valist);
     for(i=0;icsmess != NULL && x->csmess[i] == '\0'){
         x->csmess[i-1]= ' ';
         break;
       }
    if(x->csmess != NULL && x->messon) post(x->csmess);
  }


>
>
> I'm using the message callback because I want to pass the
> message   elsewhere (file, network, etc..):
>
> Here is my function:
>
> void csoundMessageHandler(CSOUND *csound, int attr, const
> char   *format, va_list valist) {
>     char messageData[256];
>      vsprintf(messageData, format, valist);
>      va_end(valist);
>
>     printf("messageData: %s\n", messageData);
> }
>
> Here is how I register it:
>      csoundSetMessageCallback(csound,
> csoundMessageHandler);
>
>
> Here is some of the output:
> messageData: rtaudio: PortAudio module enabled ...
> messageData: using callback interface
>
> messageData: rtmidi: PortMIDI module enabled
>
> messageData: orch compiler:
>
> messageData: 17 lines read
>
> messageData:
> messageData: instr
> messageData: 1
> messageData:
>
> messageData: error:
> messageData: input arg 'aOsc' used before defined
> messageData: , line 15:
>
> messageData:
> messageData: o
> messageData: u
> messageData: t
> messageData: s
> messageData:
> messageData: a
> messageData: O
> messageData: s
> messageData: c
> messageData: ,
> messageData:
> messageData: a
> messageData: O
> messageData: s
> messageData: c
> messageData:
>
> messageData: error:
> messageData: input arg 'aOsc' used before defined
> messageData: , line 15:
>
> messageData:
> messageData: o
> messageData: u
> messageData: t
> messageData: s
> messageData:
> messageData: a
> messageData: O
> messageData: s
> messageData: c
> messageData: ,
> messageData:
> messageData: a
> messageData: O
> messageData: s
> messageData: c
> messageData:
>
> messageData: 2 syntax errors in orchestra.  compilation
> invalid messageData:
>
>
> It only seems to happen on errors (which are the most
> important   messages).   Is there a way to avoid these
> newlines so it can be   readable?
>
> thanks
> greg
>
>

Date2007-07-31 21:08
FromGreg Thompson
SubjectRe: API - message callback
i understand using that using vsnprintf would allow me to get it to  
work .. few questions though:


if i == 0 and csmess[i] == '\0'
	wouldn't  x->csmess[i - 1] = ' '  be illegal?


I haven't analyzed the stream .. but is it just that 0's are being  
written into it and this just replaces the character before it with a  
space?  Why are some strings formatted correctly in the first place?   
Why is any of this buffer manipulation necessary in the first place?

greg


On Jul 31, 2007, at 2:48 PM, Victor Lazzarini wrote:

> Use vsnprintf(...).
>
> This is an example callback from csoundapi_tilde.c:
>
> static void message_callback(CSOUND *csound,
>   			     int attr, const char *format,va_list valist){
>      int i;
>      t_csoundapi *x = (t_csoundapi *)
> csoundGetHostData(csound);
>
>      if(x->csmess != NULL)
>      vsnprintf(x->csmess, MAXMESSTRING, format, valist);
>      for(i=0;i        if(x->csmess != NULL && x->csmess[i] == '\0'){
>          x->csmess[i-1]= ' ';
>          break;
>        }
>     if(x->csmess != NULL && x->messon) post(x->csmess);
>   }
>
>
>>
>>
>> I'm using the message callback because I want to pass the
>> message   elsewhere (file, network, etc..):
>>
>> Here is my function:
>>
>> void csoundMessageHandler(CSOUND *csound, int attr, const
>> char   *format, va_list valist) {
>>     char messageData[256];
>>      vsprintf(messageData, format, valist);
>>      va_end(valist);
>>
>>     printf("messageData: %s\n", messageData);
>> }
>>
>> Here is how I register it:
>>      csoundSetMessageCallback(csound,
>> csoundMessageHandler);
>>
>>
>> Here is some of the output:
>> messageData: rtaudio: PortAudio module enabled ...
>> messageData: using callback interface
>>
>> messageData: rtmidi: PortMIDI module enabled
>>
>> messageData: orch compiler:
>>
>> messageData: 17 lines read
>>
>> messageData:
>> messageData: instr
>> messageData: 1
>> messageData:
>>
>> messageData: error:
>> messageData: input arg 'aOsc' used before defined
>> messageData: , line 15:
>>
>> messageData:
>> messageData: o
>> messageData: u
>> messageData: t
>> messageData: s
>> messageData:
>> messageData: a
>> messageData: O
>> messageData: s
>> messageData: c
>> messageData: ,
>> messageData:
>> messageData: a
>> messageData: O
>> messageData: s
>> messageData: c
>> messageData:
>>
>> messageData: error:
>> messageData: input arg 'aOsc' used before defined
>> messageData: , line 15:
>>
>> messageData:
>> messageData: o
>> messageData: u
>> messageData: t
>> messageData: s
>> messageData:
>> messageData: a
>> messageData: O
>> messageData: s
>> messageData: c
>> messageData: ,
>> messageData:
>> messageData: a
>> messageData: O
>> messageData: s
>> messageData: c
>> messageData:
>>
>> messageData: 2 syntax errors in orchestra.  compilation
>> invalid messageData:
>>
>>
>> It only seems to happen on errors (which are the most
>> important   messages).   Is there a way to avoid these
>> newlines so it can be   readable?
>>
>> thanks
>> greg
>>
>>
> -- 
> Send bugs reports to this list.
> To unsubscribe, send email to csound-unsubscribe@lists.bath.ac.uk
>