Ejemplo n.º 1
0
void init() {
  PmError err1;
  PtError err2;
  
  if (isInit) return;
  
  mexPrintf("Initialising PortMidi\n");
  
  MUTEX_LOCK;
  note      = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  channel   = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  velocity  = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  timestamp = malloc(INPUT_BUFFER_SIZE*sizeof(int32_t));
  if (!(channel && note && velocity && timestamp)) {
    FREE(channel);
    FREE(note);
    FREE(velocity);
    FREE(timestamp);
    MUTEX_UNLOCK;
    mexErrMsgTxt("Could not allocate memory");
  }
  else {
    MUTEX_UNLOCK;
  }
  
  err1 = Pm_Initialize();
  reportPmError(err1);
  
  err2 = Pt_Start(1, receive_poll, NULL);
  reportPtError(err2);
  
  /* getting here means that PortMidi and PortTime are both fine */
  mexAtExit(exitFunction);
  isInit = 1;
}
Ejemplo n.º 2
0
void exitFunction() {
  if (isInit) {
    mexPrintf("Terminating PortMidi\n");
    reportPtError(Pt_Stop());
    if (inStream != NULL) {
      reportPmError(Pm_Close(inStream));
      inStream = NULL;
    }
    Pm_Terminate();
    FREE(channel);
    FREE(note);
    FREE(velocity);
    FREE(timestamp);
    isInit = 0;
    deviceOpen = -1;
    numReceived = 0;
  }
}