Browse Source

Change `audio::Device::getSampleRates()` and `getBlockSizes()` to return a set instead of a vector.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
3e0c375a89
4 changed files with 19 additions and 21 deletions
  1. +4
    -4
      include/audio.hpp
  2. +8
    -10
      src/app/AudioWidget.cpp
  3. +2
    -2
      src/audio.cpp
  4. +5
    -5
      src/rtaudio.cpp

+ 4
- 4
include/audio.hpp View File

@@ -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<int> getSampleRates() {
virtual std::set<int> 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<int> getBlockSizes() {
virtual std::set<int> 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<int> getSampleRates();
std::set<int> getSampleRates();
int getSampleRate();
void setSampleRate(int sampleRate);

std::vector<int> getBlockSizes();
std::set<int> getBlockSizes();
int getBlockSize();
void setBlockSize(int blockSize);



+ 8
- 10
src/app/AudioWidget.cpp View File

@@ -154,15 +154,14 @@ static void appendAudioSampleRateMenu(ui::Menu* menu, audio::Port* port) {
if (!port)
return;

std::vector<int> sampleRates = port->getSampleRates();
std::set<int> sampleRatesSet(sampleRates.begin(), sampleRates.end());
std::set<int> 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<int> blockSizes = port->getBlockSizes();
std::set<int> blockSizesSet(blockSizes.begin(), blockSizes.end());
std::set<int> 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;


+ 2
- 2
src/audio.cpp View File

@@ -242,7 +242,7 @@ std::string Port::getDeviceDetail(int deviceId, int offset) {
}
}

std::vector<int> Port::getSampleRates() {
std::set<int> Port::getSampleRates() {
if (!device)
return {};
try {
@@ -277,7 +277,7 @@ void Port::setSampleRate(int sampleRate) {
}
}

std::vector<int> Port::getBlockSizes() {
std::set<int> Port::getBlockSizes() {
if (!device)
return {};
try {


+ 5
- 5
src/rtaudio.cpp View File

@@ -146,8 +146,8 @@ struct RtAudioDevice : audio::Device {
return outputParameters.nChannels;
}

std::vector<int> getSampleRates() override {
std::vector<int> sampleRates(deviceInfo.sampleRates.begin(), deviceInfo.sampleRates.end());
std::set<int> getSampleRates() override {
std::set<int> sampleRates(deviceInfo.sampleRates.begin(), deviceInfo.sampleRates.end());
return sampleRates;
}
int getSampleRate() override {
@@ -159,11 +159,11 @@ struct RtAudioDevice : audio::Device {
openStream();
}

std::vector<int> getBlockSizes() override {
std::vector<int> blockSizes;
std::set<int> getBlockSizes() override {
std::set<int> blockSizes;
// 32 to 4096
for (int i = 5; i <= 12; i++) {
blockSizes.push_back(1 << i);
blockSizes.insert(1 << i);
}
return blockSizes;
}


Loading…
Cancel
Save