Logo Search packages:      
Sourcecode: csound version File versions  Download package

PUBLIC int csoundSetCallback ( CSOUND *  csound,
int(*)(void *userData, void *p, unsigned int type)  func,
void *  userData,
unsigned int  typeMask 
)

Sets general purpose callback function that will be called on various events. The callback is preserved on csoundReset(), and multiple callbacks may be set and will be called in reverse order of registration. If the same function is set again, it is only moved in the list of callbacks so that it will be called first, and the user data and type mask parameters are updated. 'typeMask' can be the bitwise OR of callback types for which the function should be called, or zero for all types. Returns zero on success, CSOUND_ERROR if the specified function pointer or type mask is invalid, and CSOUND_MEMORY if there is not enough memory.

The callback function takes the following arguments: void *userData the "user data" pointer, as specified when setting the callback void *p data pointer, depending on the callback type unsigned int type callback type, can be one of the following (more may be added in future versions of Csound): CSOUND_CALLBACK_KBD_EVENT CSOUND_CALLBACK_KBD_TEXT called by the sensekey opcode to fetch key codes. The data pointer is a pointer to a single value of type 'int', for returning the key code, which can be in the range 1 to 65535, or 0 if there is no keyboard event. For CSOUND_CALLBACK_KBD_EVENT, both key press and release events should be returned (with 65536 (0x10000) added to the key code in the latter case) as unshifted ASCII codes. CSOUND_CALLBACK_KBD_TEXT expects key press events only as the actual text that is typed. The return value should be zero on success, negative on error, and positive if the callback was ignored (for example because the type is not known).

Definition at line 2488 of file csound.c.

  {
      CsoundCallbackEntry_t *pp;

      if (UNLIKELY(func == (int (*)(void *, void *, unsigned int)) NULL ||
          (typeMask
           & (~(CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT))) != 0U))
        return CSOUND_ERROR;
      csoundRemoveCallback(csound, func);
      pp = (CsoundCallbackEntry_t*) malloc(sizeof(CsoundCallbackEntry_t));
      if (UNLIKELY(pp == (CsoundCallbackEntry_t*) NULL))
        return CSOUND_MEMORY;
      pp->typeMask = (typeMask ? typeMask : 0xFFFFFFFFU);
      pp->nxt = (CsoundCallbackEntry_t*) csound->csoundCallbacks_;
      pp->userData = userData;
      pp->func = func;
      csound->csoundCallbacks_ = (void*) pp;

      return CSOUND_SUCCESS;
  }


Generated by  Doxygen 1.6.0   Back to index