From d62b8d5845bd87d82f3fbd72f1cfe68947cc5216 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 19 Dec 2018 09:01:33 -0500 Subject: [PATCH] Put audio in namespace --- include/app/AudioWidget.hpp | 6 +++-- include/audio.hpp | 8 ++++--- include/bridge.hpp | 4 ++-- src/Core/AudioInterface.cpp | 2 +- src/app/AudioWidget.cpp | 8 +++---- src/audio.cpp | 44 +++++++++++++++++++------------------ src/bridge.cpp | 6 ++--- 7 files changed, 42 insertions(+), 36 deletions(-) diff --git a/include/app/AudioWidget.hpp b/include/app/AudioWidget.hpp index ef885d1f..22940af0 100644 --- a/include/app/AudioWidget.hpp +++ b/include/app/AudioWidget.hpp @@ -6,12 +6,14 @@ namespace rack { -struct AudioIO; +namespace audio { + struct IO; +} struct AudioWidget : LedDisplay { /** Not owned */ - AudioIO *audioIO = NULL; + audio::IO *audioIO = NULL; LedDisplayChoice *driverChoice; LedDisplaySeparator *driverSeparator; LedDisplayChoice *deviceChoice; diff --git a/include/audio.hpp b/include/audio.hpp index 5402fba9..19c6434d 100644 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -11,9 +11,10 @@ namespace rack { +namespace audio { -struct AudioIO { +struct IO { // Stream properties int driver = 0; int device = -1; @@ -27,8 +28,8 @@ struct AudioIO { /** Cached */ RtAudio::DeviceInfo deviceInfo; - AudioIO(); - virtual ~AudioIO(); + IO(); + virtual ~IO(); std::vector getDrivers(); std::string getDriverName(int driver); @@ -62,4 +63,5 @@ struct AudioIO { }; +} // namespace audio } // namespace rack diff --git a/include/bridge.hpp b/include/bridge.hpp index d9ea836f..994876f3 100644 --- a/include/bridge.hpp +++ b/include/bridge.hpp @@ -24,8 +24,8 @@ struct BridgeMidiDriver : midi::Driver { void bridgeInit(); void bridgeDestroy(); -void bridgeAudioSubscribe(int channel, AudioIO *audio); -void bridgeAudioUnsubscribe(int channel, AudioIO *audio); +void bridgeAudioSubscribe(int channel, audio::IO *audio); +void bridgeAudioUnsubscribe(int channel, audio::IO *audio); } // namespace rack diff --git a/src/Core/AudioInterface.cpp b/src/Core/AudioInterface.cpp index 3e1b330b..c86f3883 100644 --- a/src/Core/AudioInterface.cpp +++ b/src/Core/AudioInterface.cpp @@ -17,7 +17,7 @@ using namespace rack; -struct AudioInterfaceIO : AudioIO { +struct AudioInterfaceIO : audio::IO { std::mutex engineMutex; std::condition_variable engineCv; std::mutex audioMutex; diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index c78c8ab0..880cc39c 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -7,7 +7,7 @@ namespace rack { struct AudioDriverItem : MenuItem { - AudioIO *audioIO; + audio::IO *audioIO; int driver; void onAction(event::Action &e) override { audioIO->setDriver(driver); @@ -35,7 +35,7 @@ struct AudioDriverChoice : LedDisplayChoice { struct AudioDeviceItem : MenuItem { - AudioIO *audioIO; + audio::IO *audioIO; int device; int offset; void onAction(event::Action &e) override { @@ -87,7 +87,7 @@ struct AudioDeviceChoice : LedDisplayChoice { struct AudioSampleRateItem : MenuItem { - AudioIO *audioIO; + audio::IO *audioIO; int sampleRate; void onAction(event::Action &e) override { audioIO->setSampleRate(sampleRate); @@ -119,7 +119,7 @@ struct AudioSampleRateChoice : LedDisplayChoice { struct AudioBlockSizeItem : MenuItem { - AudioIO *audioIO; + audio::IO *audioIO; int blockSize; void onAction(event::Action &e) override { audioIO->setBlockSize(blockSize); diff --git a/src/audio.cpp b/src/audio.cpp index ac013e49..3960237e 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -6,17 +6,18 @@ namespace rack { +namespace audio { -AudioIO::AudioIO() { +IO::IO() { setDriver(RtAudio::UNSPECIFIED); } -AudioIO::~AudioIO() { +IO::~IO() { closeStream(); } -std::vector AudioIO::getDrivers() { +std::vector IO::getDrivers() { std::vector apis; RtAudio::getCompiledApi(apis); std::vector drivers; @@ -28,7 +29,7 @@ std::vector AudioIO::getDrivers() { return drivers; } -std::string AudioIO::getDriverName(int driver) { +std::string IO::getDriverName(int driver) { switch (driver) { case RtAudio::UNSPECIFIED: return "Unspecified"; case RtAudio::LINUX_ALSA: return "ALSA"; @@ -45,7 +46,7 @@ std::string AudioIO::getDriverName(int driver) { } } -void AudioIO::setDriver(int driver) { +void IO::setDriver(int driver) { // Close device setDevice(-1, 0); @@ -66,7 +67,7 @@ void AudioIO::setDriver(int driver) { } } -int AudioIO::getDeviceCount() { +int IO::getDeviceCount() { if (rtAudio) { return rtAudio->getDeviceCount(); } @@ -76,7 +77,7 @@ int AudioIO::getDeviceCount() { return 0; } -bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { +bool IO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { if (!deviceInfo) return false; @@ -99,7 +100,7 @@ bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { return false; } -int AudioIO::getDeviceChannels(int device) { +int IO::getDeviceChannels(int device) { if (device < 0) return 0; @@ -114,7 +115,7 @@ int AudioIO::getDeviceChannels(int device) { return 0; } -std::string AudioIO::getDeviceName(int device) { +std::string IO::getDeviceName(int device) { if (device < 0) return ""; @@ -129,7 +130,7 @@ std::string AudioIO::getDeviceName(int device) { return ""; } -std::string AudioIO::getDeviceDetail(int device, int offset) { +std::string IO::getDeviceDetail(int device, int offset) { if (device < 0) return ""; @@ -153,14 +154,14 @@ std::string AudioIO::getDeviceDetail(int device, int offset) { return ""; } -void AudioIO::setDevice(int device, int offset) { +void IO::setDevice(int device, int offset) { closeStream(); this->device = device; this->offset = offset; openStream(); } -std::vector AudioIO::getSampleRates() { +std::vector IO::getSampleRates() { if (rtAudio) { try { RtAudio::DeviceInfo deviceInfo = rtAudio->getDeviceInfo(device); @@ -174,7 +175,7 @@ std::vector AudioIO::getSampleRates() { return {}; } -void AudioIO::setSampleRate(int sampleRate) { +void IO::setSampleRate(int sampleRate) { if (sampleRate == this->sampleRate) return; closeStream(); @@ -182,14 +183,14 @@ void AudioIO::setSampleRate(int sampleRate) { openStream(); } -std::vector AudioIO::getBlockSizes() { +std::vector IO::getBlockSizes() { if (rtAudio) { return {64, 128, 256, 512, 1024, 2048, 4096}; } return {}; } -void AudioIO::setBlockSize(int blockSize) { +void IO::setBlockSize(int blockSize) { if (blockSize == this->blockSize) return; closeStream(); @@ -197,7 +198,7 @@ void AudioIO::setBlockSize(int blockSize) { openStream(); } -void AudioIO::setChannels(int numOutputs, int numInputs) { +void IO::setChannels(int numOutputs, int numInputs) { this->numOutputs = numOutputs; this->numInputs = numInputs; onChannelsChange(); @@ -205,13 +206,13 @@ void AudioIO::setChannels(int numOutputs, int numInputs) { static int rtCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData) { - AudioIO *audioIO = (AudioIO*) userData; + IO *audioIO = (IO*) userData; assert(audioIO); audioIO->processStream((const float *) inputBuffer, (float *) outputBuffer, nFrames); return 0; } -void AudioIO::openStream() { +void IO::openStream() { if (device < 0) return; @@ -288,7 +289,7 @@ void AudioIO::openStream() { } } -void AudioIO::closeStream() { +void IO::closeStream() { setChannels(0, 0); if (rtAudio) { @@ -319,7 +320,7 @@ void AudioIO::closeStream() { onCloseStream(); } -json_t *AudioIO::toJson() { +json_t *IO::toJson() { json_t *rootJ = json_object(); json_object_set_new(rootJ, "driver", json_integer(driver)); std::string deviceName = getDeviceName(device); @@ -331,7 +332,7 @@ json_t *AudioIO::toJson() { return rootJ; } -void AudioIO::fromJson(json_t *rootJ) { +void IO::fromJson(json_t *rootJ) { closeStream(); json_t *driverJ = json_object_get(rootJ, "driver"); @@ -370,4 +371,5 @@ void AudioIO::fromJson(json_t *rootJ) { } +} // namespace audio } // namespace rack diff --git a/src/bridge.cpp b/src/bridge.cpp index c3acd733..71c6b1fd 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -22,7 +22,7 @@ namespace rack { struct BridgeClientConnection; static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {}; -static AudioIO *audioListeners[BRIDGE_NUM_PORTS] = {}; +static audio::IO *audioListeners[BRIDGE_NUM_PORTS] = {}; static std::thread serverThread; static bool serverRunning = false; static BridgeMidiDriver *driver = NULL; @@ -416,7 +416,7 @@ void bridgeDestroy() { serverThread.join(); } -void bridgeAudioSubscribe(int port, AudioIO *audio) { +void bridgeAudioSubscribe(int port, audio::IO *audio) { if (!(0 <= port && port < BRIDGE_NUM_PORTS)) return; // Check if an Audio is already subscribed on the port @@ -427,7 +427,7 @@ void bridgeAudioSubscribe(int port, AudioIO *audio) { connections[port]->refreshAudio(); } -void bridgeAudioUnsubscribe(int port, AudioIO *audio) { +void bridgeAudioUnsubscribe(int port, audio::IO *audio) { if (!(0 <= port && port < BRIDGE_NUM_PORTS)) return; if (audioListeners[port] != audio)