void SysExOutputProcessor::clear() { // Release any reference to the data. _evData = EvData(); _state = Clear; _curPos = 0; }
bool SysExOutputProcessor::getCurChunk(unsigned char* dst, int sampleRate) { if(!dst) return false; switch(_state) { case Clear: case Finished: fprintf(stderr, "SysExOutputProcessor: getCurChunk called while State is not Sending.\n"); return false; break; case Sending: { unsigned char* p = dst; bool is_chunk = false; // The remaining number of data bytes (minus any start/end byte). size_t sz = 0; if((int)_curPos < _evData.dataLen) sz = _evData.dataLen - _curPos; // Are we on the first chunk? Leave room for the start byte. if(_curPos == 0) ++sz; // Should there be more chunks? That is, will the data so far - // plus an end byte - not fit into a chunk? if(sz > (_chunkSize - 1)) { // Limit the final size. sz = _chunkSize; is_chunk = true; } // Are we on the first chunk? if(_curPos == 0) { // Add the start byte. *p++ = ME_SYSEX; --sz; } // Besides any start byte, is there any actual data to copy? if(sz != 0) { // Copy the data to the destination. memcpy(p, _evData.data + _curPos, sz); // Advance the pointer. p += sz; // Advance the current position. _curPos += sz; } // Are there no more chunks to follow? if(!is_chunk) { // Add the end byte. *p = ME_SYSEX_END; // We are finished. _state = Finished; // Release any reference to the data. _evData = EvData(); } // Estimate the number of audio frames it should take (or took) to transmit the current midi chunk. // Advance the current chunk frame so that the driver can schedule the next chunk. // Do it even if the state has Finished, so the driver can wait until the last chunk is done // before calling Clear() or Reset() (setting the state to Clear). _curChunkFrame += sysexDuration(sz, sampleRate); } break; } return true; }
const EvData Event::eventData() const { return ev ? ev->eventData() : EvData(); }