|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- /*
- * Carla Tests
- * Copyright (C) 2014 Filipe Coelho <falktx@falktx.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * For a full copy of the GNU General Public License see the doc/GPL.txt file.
- */
-
- #include "CarlaLibUtils.hpp"
-
- // -----------------------------------------------------------------------
-
- struct OpenInfo {
- ulong size1; // ??
- ulong size2; // 12
- long sampleRate;
- long bufferSize;
- };
-
- struct DevInfo {
- ulong size; // 8288
- char name[32];
- long channelCount; // max limited to 255
- char channelNames[256][32];
- unsigned long defaultChannels[8];
- unsigned long stereoPairs[4];
- unsigned long eventBufferSize;
- long version;
- };
-
- struct AudioInfo {
- ulong size; // 12
- long sampleRate;
- long bufferSize;
- };
-
- struct BusInfo {
- ulong size; // 40
- ulong channel;
- char name[32];
- };
-
- struct EventInfo {
- ulong size; // 36
- ulong bus[32];
- };
-
- struct Event { // 24
- ushort type;
- uchar d1, d2;
- ulong s1, s2, s3, s4, s5;
- };
-
- struct EventBuffer {
- ulong size1; // 20
- ulong size2; // 24
- ulong count;
- ulong maxCount;
- Event* buf;
- };
-
- struct AudioInInfo {
- ulong size; // 1116
- EventBuffer evBuf;
- unsigned long channels[8];
- float* audioBuf[256];
- long tickStart;
- ulong frames;
- ulong playMode;
- ulong tempo; // bpm
- ulong signNumerator;
- ulong signDenominator;
- long loopStartPos;
- long loopEndPos;
- ulong loopOn;
- } ReWireDriveParams;
-
- struct AudioOutInfo {
- ulong size; // 56
- EventBuffer evBuf;
- ulong channels[8];
- };
-
- // -----------------------------------------------------------------------
-
- typedef void (*Fn_RWDEFCloseDevice)();
- typedef void (*Fn_RWDEFDriveAudio)(AudioInInfo* in, AudioOutInfo* out);
- typedef void (*Fn_RWDEFGetDeviceInfo)(DevInfo* info);
- typedef void (*Fn_RWDEFGetDeviceNameAndVersion)(long* version, char* name);
- typedef void (*Fn_RWDEFGetEventBusInfo)(ushort index, BusInfo* info);
- typedef void (*Fn_RWDEFGetEventChannelInfo)(void* v1, void* v2);
- typedef void (*Fn_RWDEFGetEventControllerInfo)(void* v1, ushort index, void* v2);
- typedef void (*Fn_RWDEFGetEventInfo)(EventInfo* info);
- typedef void (*Fn_RWDEFGetEventNoteInfo)(void* v1, ushort index, void* v2);
- typedef void (*Fn_RWDEFIdle)();
- typedef char (*Fn_RWDEFIsCloseOK)();
- typedef char (*Fn_RWDEFIsPanelAppLaunched)();
- typedef int (*Fn_RWDEFLaunchPanelApp)();
- typedef int (*Fn_RWDEFOpenDevice)(OpenInfo* info);
- typedef int (*Fn_RWDEFQuitPanelApp)();
- typedef void (*Fn_RWDEFSetAudioInfo)(AudioInfo* info);
-
- // -----------------------------------------------------------------------------
-
- struct RewireBridge {
- void* lib;
-
- Fn_RWDEFCloseDevice RWDEFCloseDevice;
- Fn_RWDEFDriveAudio RWDEFDriveAudio;
- Fn_RWDEFGetDeviceInfo RWDEFGetDeviceInfo;
- Fn_RWDEFGetDeviceNameAndVersion RWDEFGetDeviceNameAndVersion;
- Fn_RWDEFGetEventBusInfo RWDEFGetEventBusInfo;
- Fn_RWDEFGetEventChannelInfo RWDEFGetEventChannelInfo;
- Fn_RWDEFGetEventControllerInfo RWDEFGetEventControllerInfo;
- Fn_RWDEFGetEventInfo RWDEFGetEventInfo;
- Fn_RWDEFGetEventNoteInfo RWDEFGetEventNoteInfo;
- Fn_RWDEFIdle RWDEFIdle;
- Fn_RWDEFIsCloseOK RWDEFIsCloseOK;
- Fn_RWDEFIsPanelAppLaunched RWDEFIsPanelAppLaunched;
- Fn_RWDEFLaunchPanelApp RWDEFLaunchPanelApp;
- Fn_RWDEFOpenDevice RWDEFOpenDevice;
- Fn_RWDEFQuitPanelApp RWDEFQuitPanelApp;
- Fn_RWDEFSetAudioInfo RWDEFSetAudioInfo;
-
- RewireBridge(const char* const filename)
- : lib(nullptr),
- RWDEFCloseDevice(nullptr),
- RWDEFDriveAudio(nullptr),
- RWDEFGetDeviceInfo(nullptr),
- RWDEFGetDeviceNameAndVersion(nullptr),
- RWDEFGetEventBusInfo(nullptr),
- RWDEFGetEventChannelInfo(nullptr),
- RWDEFGetEventControllerInfo(nullptr),
- RWDEFGetEventInfo(nullptr),
- RWDEFGetEventNoteInfo(nullptr),
- RWDEFIdle(nullptr),
- RWDEFIsCloseOK(nullptr),
- RWDEFIsPanelAppLaunched(nullptr),
- RWDEFLaunchPanelApp(nullptr),
- RWDEFOpenDevice(nullptr),
- RWDEFQuitPanelApp(nullptr),
- RWDEFSetAudioInfo(nullptr)
- {
- lib = lib_open(filename);
-
- if (lib == nullptr)
- {
- fprintf(stderr, "Failed to load DLL, reason:\n%s\n", lib_error(filename));
- return;
- }
- else
- {
- fprintf(stdout, "loaded sucessfully!\n");
- }
-
- #define JOIN(a, b) a ## b
- #define LIB_SYMBOL(NAME) NAME = (Fn_##NAME)lib_symbol(lib, #NAME);
-
- LIB_SYMBOL(RWDEFCloseDevice)
- LIB_SYMBOL(RWDEFDriveAudio)
- LIB_SYMBOL(RWDEFGetDeviceInfo)
- LIB_SYMBOL(RWDEFGetDeviceNameAndVersion)
- LIB_SYMBOL(RWDEFGetEventBusInfo)
- LIB_SYMBOL(RWDEFGetEventChannelInfo)
- LIB_SYMBOL(RWDEFGetEventControllerInfo)
- LIB_SYMBOL(RWDEFGetEventInfo)
- LIB_SYMBOL(RWDEFGetEventNoteInfo)
- LIB_SYMBOL(RWDEFIdle)
- LIB_SYMBOL(RWDEFIsCloseOK)
- LIB_SYMBOL(RWDEFIsPanelAppLaunched)
- LIB_SYMBOL(RWDEFLaunchPanelApp)
- LIB_SYMBOL(RWDEFOpenDevice)
- LIB_SYMBOL(RWDEFQuitPanelApp)
- LIB_SYMBOL(RWDEFSetAudioInfo)
-
- #undef JOIN
- #undef LIB_SYMBOL
- }
-
- ~RewireBridge()
- {
- if (lib != nullptr)
- {
- lib_close(lib);
- lib = nullptr;
- }
- }
- };
-
- // -----------------------------------------------------------------------
-
- int main(/*int argc, char* argv[]*/)
- {
- static const char* const filename = "C:\\Program Files\\Waves\\ReWire\\WavesReWireDevice.dll";
- // static const char* const filename = "C:\\Program Files\\AudioGL\\AudioGL.dll";
-
- RewireBridge bridge(filename);
-
- DevInfo devInfo;
- carla_zeroStruct<DevInfo>(devInfo);
- devInfo.size = 8288;
-
- (bridge.RWDEFGetDeviceInfo)(&devInfo);
-
- carla_stdout("Ok, this is the info:");
- carla_stdout("\tVersion: %i", devInfo.version);
- carla_stdout("\tName: \"%s\"", devInfo.name);
- carla_stdout("\tChannels: %l", devInfo.channelCount);
-
- for (long i=0; i < devInfo.channelCount; ++i)
- carla_stdout("\t\t#%i: \"%s\"", i+1, devInfo.channelNames[i]);
-
- OpenInfo info;
- info.size1 = sizeof(OpenInfo);
- info.size2 = 12;
- info.sampleRate = 44100;
- info.bufferSize = 512;
-
- (bridge.RWDEFOpenDevice)(&info);
-
- #if 0
- carla_stdout("Starting panel...");
- (bridge.RWDEFLaunchPanelApp)();
-
- for (int i=0; i<500; ++i)
- //for (; (bridge.RWDEFIsPanelAppLaunched)() != 0;)
- {
- (bridge.RWDEFIdle)();
- carla_msleep(20);
- }
-
- (bridge.RWDEFQuitPanelApp)();
- #endif
-
- for (; (bridge.RWDEFIsCloseOK)() == 0;)
- carla_msleep(10);
-
- (bridge.RWDEFCloseDevice)();
-
- return 0;
- }
|