diff --git a/source/tests/Rewire.cpp b/source/tests/Rewire.cpp index 2b8364fbb..be9b00676 100644 --- a/source/tests/Rewire.cpp +++ b/source/tests/Rewire.cpp @@ -15,37 +15,167 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaUtils.hpp" +#include "CarlaString.hpp" #include "rewire/ReWirePanelAPI.h" -int main(/*int argc, char* argv[]*/) -{ - ReWire::ReWireError result; +// ----------------------------------------------------------------------- + +// remove this +namespace ReWire { +extern "C" { +typedef const char* TReWireFileSpec; +} +} - result = ReWire::RWPOpen(); +ReWire::TReWireFileSpec kDeviceSpec = "/home/falktx/.wine32/drive_c/Program Files/Image-Line/FL Studio 11/System/Plugin/ReWire/FLReWire.dll"; - if (result == ReWire::kReWireError_NoError) +// ----------------------------------------------------------------------- + +class RewireThing +{ +public: + RewireThing() + : fIsOpen(false), + fIsRegistered(false), + fIsLoaded(false), + fHandle(0) { - carla_stdout("opened ok"); + fDevName = ""; } - else + + ~RewireThing() { - carla_stdout("opened failed"); - return 1; + close(); } - result = ReWire::RWPClose(); + bool open() + { + CARLA_SAFE_ASSERT_RETURN(! fIsOpen, true); + + const ReWire::ReWireError result(ReWire::RWPOpen()); + + if (result == ReWire::kReWireError_NoError) + { + fIsOpen = true; + carla_stderr("rewire open ok"); + } + else + { + carla_stderr2("rewire open failed"); + } - if (result == ReWire::kReWireError_NoError) + return fIsOpen; + } + + bool start() { - carla_stdout("closed ok"); + char isRunningFlag = 0; + ReWire::ReWireError result = ReWire::RWPIsReWireMixerAppRunning(&isRunningFlag); + + if (isRunningFlag == 0) + { + carla_stderr("rewire mixer is NOT running"); + + result = ReWire::RWPRegisterDevice(kDeviceSpec); + + if (result == ReWire::kReWireError_NoError) + { + fIsRegistered = true; + carla_stderr("rewire register ok"); + } + else if (result == ReWire::kReWireError_AlreadyExists) + { + fIsRegistered = true; + carla_stderr("rewire register already in place"); + } + else + { + carla_stderr2("rewire register failed %i", result); + } + } + else + { + carla_stderr("rewire mixer is running"); + } + + return false; } - else + + void close() { - carla_stdout("closed failed"); - return 1; + if (! fIsOpen) + { + CARLA_SAFE_ASSERT(! fIsLoaded); + CARLA_SAFE_ASSERT(fHandle == 0); + return; + } + + if (fHandle != 0) + { + const ReWire::ReWireError result(ReWire::RWPComDisconnect(fHandle)); + fHandle = 0; + + if (result == ReWire::kReWireError_NoError) + carla_stderr("rewire disconnect ok"); + else + carla_stderr2("rewire disconnect failed"); + } + + if (fIsLoaded) + { + const ReWire::ReWireError result(ReWire::RWPUnloadDevice(fDevName.getBuffer())); + fIsLoaded = false; + + if (result == ReWire::kReWireError_NoError) + carla_stderr("rewire unload ok"); + else + carla_stderr2("rewire unload failed"); + } + + if (fIsRegistered) + { + const ReWire::ReWireError result(ReWire::RWPUnregisterDevice(kDeviceSpec)); + fIsRegistered = false; + + if (result == ReWire::kReWireError_NoError) + carla_stderr("rewire unregister ok"); + else + carla_stderr2("rewire unregister failed"); + } + + const ReWire::ReWireError result(ReWire::RWPClose()); + + if (result == ReWire::kReWireError_NoError) + carla_stderr("rewire close ok"); + else + carla_stderr2("rewire close failed"); + + fIsOpen = false; } +private: + bool fIsOpen; + bool fIsRegistered; + bool fIsLoaded; + ReWire::TRWPPortHandle fHandle; + + CarlaString fDevName; +}; + +// ----------------------------------------------------------------------- + +int main(/*int argc, char* argv[]*/) +{ + RewireThing re; + + if (! re.open()) + return 1; + + re.start(); + re.close(); + return 0; } + +// -----------------------------------------------------------------------