diff --git a/include/audio.hpp b/include/audio.hpp index 8c91f052..b9dc483b 100644 --- a/include/audio.hpp +++ b/include/audio.hpp @@ -99,7 +99,7 @@ struct Device { /** Returns a list of all valid (user-selectable) sample rates. The device may accept sample rates not in this list, but it *must* accept sample rates in the list. */ - virtual std::vector getSampleRates() { + virtual std::set getSampleRates() { return {}; } /** Returns the current sample rate. */ @@ -112,7 +112,7 @@ struct Device { /** Returns a list of all valid (user-selectable) block sizes. The device may accept block sizes not in this list, but it *must* accept block sizes in the list. */ - virtual std::vector getBlockSizes() { + virtual std::set getBlockSizes() { return {}; } /** Returns the current block size. */ @@ -169,11 +169,11 @@ struct Port { std::string getDeviceName(int deviceId); std::string getDeviceDetail(int deviceId, int offset); - std::vector getSampleRates(); + std::set getSampleRates(); int getSampleRate(); void setSampleRate(int sampleRate); - std::vector getBlockSizes(); + std::set getBlockSizes(); int getBlockSize(); void setBlockSize(int blockSize); diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index 0968ce4c..a805261c 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -154,15 +154,14 @@ static void appendAudioSampleRateMenu(ui::Menu* menu, audio::Port* port) { if (!port) return; - std::vector sampleRates = port->getSampleRates(); - std::set sampleRatesSet(sampleRates.begin(), sampleRates.end()); + std::set sampleRates = port->getSampleRates(); // Add current sample rate in case it's not in the list - sampleRatesSet.insert(port->getSampleRate()); + sampleRates.insert(port->getSampleRate()); - if (sampleRatesSet.empty()) { + if (sampleRates.empty()) { menu->addChild(createMenuLabel("(Locked by device)")); } - for (int sampleRate : sampleRatesSet) { + for (int sampleRate : sampleRates) { if (sampleRate <= 0) continue; AudioSampleRateValueItem* item = new AudioSampleRateValueItem; @@ -220,15 +219,14 @@ static void appendAudioBlockSizeMenu(ui::Menu* menu, audio::Port* port) { if (!port) return; - std::vector blockSizes = port->getBlockSizes(); - std::set blockSizesSet(blockSizes.begin(), blockSizes.end()); + std::set blockSizes = port->getBlockSizes(); // Add current block size in case it's not in the list - blockSizesSet.insert(port->getBlockSize()); + blockSizes.insert(port->getBlockSize()); - if (blockSizesSet.empty()) { + if (blockSizes.empty()) { menu->addChild(createMenuLabel("(Locked by device)")); } - for (int blockSize : blockSizesSet) { + for (int blockSize : blockSizes) { if (blockSize <= 0) continue; AudioBlockSizeValueItem* item = new AudioBlockSizeValueItem; diff --git a/src/audio.cpp b/src/audio.cpp index a55c6aaa..7cf2c1f2 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -242,7 +242,7 @@ std::string Port::getDeviceDetail(int deviceId, int offset) { } } -std::vector Port::getSampleRates() { +std::set Port::getSampleRates() { if (!device) return {}; try { @@ -277,7 +277,7 @@ void Port::setSampleRate(int sampleRate) { } } -std::vector Port::getBlockSizes() { +std::set Port::getBlockSizes() { if (!device) return {}; try { diff --git a/src/rtaudio.cpp b/src/rtaudio.cpp index 57a4878f..c7b237cf 100644 --- a/src/rtaudio.cpp +++ b/src/rtaudio.cpp @@ -146,8 +146,8 @@ struct RtAudioDevice : audio::Device { return outputParameters.nChannels; } - std::vector getSampleRates() override { - std::vector sampleRates(deviceInfo.sampleRates.begin(), deviceInfo.sampleRates.end()); + std::set getSampleRates() override { + std::set sampleRates(deviceInfo.sampleRates.begin(), deviceInfo.sampleRates.end()); return sampleRates; } int getSampleRate() override { @@ -159,11 +159,11 @@ struct RtAudioDevice : audio::Device { openStream(); } - std::vector getBlockSizes() override { - std::vector blockSizes; + std::set getBlockSizes() override { + std::set blockSizes; // 32 to 4096 for (int i = 5; i <= 12; i++) { - blockSizes.push_back(1 << i); + blockSizes.insert(1 << i); } return blockSizes; }