diff --git a/common/JackMidiDriver.cpp b/common/JackMidiDriver.cpp index 82a3e29a..b8993e7a 100644 --- a/common/JackMidiDriver.cpp +++ b/common/JackMidiDriver.cpp @@ -138,6 +138,7 @@ int JackMidiDriver::ProcessNull() return 0; } +/* int JackMidiDriver::Process() { if (Read() < 0) { @@ -172,6 +173,65 @@ int JackMidiDriver::Process() } return 0; } +*/ + +int JackMidiDriver::Process() +{ + return (fEngineControl->fSyncMode) ? ProcessSync() : ProcessAsync(); +} + +int JackMidiDriver::ProcessSync() +{ + int res = 0; + + // Read input buffers for the current cycle + if (Read() < 0) { + jack_error("JackMidiDriver::ProcessSync: read error, skip cycle"); + return 0; // Skip cycle, but continue processing... + } + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + jack_error("JackMidiDriver::ProcessSync - ResumeRefNum error"); + res = -1; + } + + if (fGraphManager->SuspendRefNum(&fClientControl, fSynchroTable, + DRIVER_TIMEOUT_FACTOR * + fEngineControl->fTimeOutUsecs) < 0) { + jack_error("JackMidiDriver::ProcessSync - SuspendRefNum error"); + res = -1; + } + + // Write output buffers from the current cycle + if (Write() < 0) { + jack_error("JackMidiDriver::ProcessSync - Write error"); + } + + return res; +} + +int JackMidiDriver::ProcessAsync() +{ + int res = 0; + + // Read input buffers for the current cycle + if (Read() < 0) { + jack_error("JackMidiDriver::ProcessAsync: read error, skip cycle"); + return 0; // Skip cycle, but continue processing... + } + + // Write output buffers from the previous cycle + if (Write() < 0) { + jack_error("JackMidiDriver::ProcessAsync - Write error"); + } + + if (fGraphManager->ResumeRefNum(&fClientControl, fSynchroTable) < 0) { + jack_error("JackMidiDriver::ProcessAsync - ResumeRefNum error"); + res = -1; + } + + return res; +} JackMidiBuffer* JackMidiDriver::GetInputBuffer(int port_index) { diff --git a/common/JackMidiDriver.h b/common/JackMidiDriver.h index 7c5bc5e0..1ce627d3 100644 --- a/common/JackMidiDriver.h +++ b/common/JackMidiDriver.h @@ -39,15 +39,15 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver int fCaptureChannels; int fPlaybackChannels; - + jack_ringbuffer_t* fRingBuffer[DRIVER_PORT_NUM]; jack_port_id_t fCapturePortList[DRIVER_PORT_NUM]; jack_port_id_t fPlaybackPortList[DRIVER_PORT_NUM]; - + JackMidiBuffer* GetInputBuffer(int port_index); JackMidiBuffer* GetOutputBuffer(int port_index); - + public: JackMidiDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table); @@ -62,16 +62,18 @@ class SERVER_EXPORT JackMidiDriver : public JackDriver const char* playback_driver_name, jack_nframes_t capture_latency, jack_nframes_t playback_latency); - + virtual int Process(); + virtual int ProcessSync(); + virtual int ProcessAsync(); virtual int ProcessNull(); virtual int Attach(); virtual int Detach(); - + virtual int Read(); virtual int Write(); - + }; } // end of namespace