Outputting a string through an outlet


    Jan 22 2009 | 3:47 pm
    Hello list:
    I am having trouble outputting a string through an outlet. It outputs once on the first run through, but then ceases to continue working.
    Below is the culprit section of code, any insight would be greatly appreciated.
    ---BEGIN CODE---
    numba = atoi(parsed);
    output = (char *)malloc(strlen("/rh/st 0 4096"));
    sprintf(output, "/rh/st %d 0n", calcBoardNo(currentTrack, numba));
    s->s_name = output;
    free(output);
    outlet_anything(x->outlet_1, s, 0, NULL);
    ---END CODE---

    • Jan 22 2009 | 4:14 pm
      On 22 janv. 09, at 16:47, Roberto J. Osorio-Goenaga wrote:
      > Hello list: > > I am having trouble outputting a string through an outlet. It > outputs once on the first run through, but then ceases to continue > working. > > Below is the culprit section of code, any insight would be greatly > appreciated. > [code] > ---BEGIN CODE--- > > numba = atoi(parsed); > > output = (char *)malloc(strlen("/rh/st 0 4096")); > > sprintf(output, "/rh/st %d 0 > ", calcBoardNo(currentTrack, numba)); > > s->s_name = output; > > free(output); > outlet_anything(x->outlet_1, s, 0, NULL);
      In the Max world strings are represented as symbols. You need to output a t_symbol. To create a t_symbol from a C string you can use gensym():
      ... sprintf(output, "/rh/st %d 0", calcBoardNo(currentTrack, numba));
      outlet_anything(x->outlet_1, gensym(output), 0, NULL);
      HTH, ej
    • Jan 22 2009 | 4:41 pm
      That worked beautifully...thank you!
      Now I'm having a strange issue, in which nothing will be output unless i turn debugging on in Max/MSP. Once this is done, output from my external works, even if I turn off debugging afterward.
      I am investigating, and will post my findings for public reference if I am successful.
      Best, -R
    • Jan 22 2009 | 6:01 pm
      Problem fixed, though not sure why yet...
      First, I had a non-aligned pointer. Took care of that, and the problem persisted.
      Not quite certain why, but removing a post() call in the routine eliminated the problem. Do post() and outlet_anything() not get along in the same routine?
      In any case, thanks for the help!
      -R
    • Jan 22 2009 | 8:24 pm
      On 22 janv. 09, at 19:01, Roberto J. Osorio-Goenaga wrote:
      > Problem fixed, though not sure why yet... > > First, I had a non-aligned pointer. Took care of that, and the > problem persisted. > > Not quite certain why, but removing a post() call in the routine > eliminated the problem. Do post() and outlet_anything() not get > along in the same routine?
      post() is equivalent to the sprintf() in C, therefore it takes a C string (array of char). outlet_anything() talks to the Max patches, so you have to send t_symbol as the message name (constructed with gensym()), and an array of t_atom for the arguments of the message that you want to output.
      HTH, ej