Skip to content

Commit

Permalink
Merge pull request #4907 from ronso0/sounddeviceerror-status
Browse files Browse the repository at this point in the history
soundio: rename SoundDeviceError > SoundDeviceStatus
  • Loading branch information
Swiftb0y authored Sep 3, 2022
2 parents 6fbc27d + c63b9da commit e28e041
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion src/coreservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "preferences/configobject.h"
#include "preferences/constants.h"
#include "preferences/settingsmanager.h"
#include "soundio/sounddeviceerror.h"
#include "soundio/sounddevicestatus.h"
#include "util/cmdlineargs.h"
#include "util/timer.h"

Expand Down
13 changes: 6 additions & 7 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ void MixxxMainWindow::initialize() {
bool retryClicked;
do {
retryClicked = false;
SoundDeviceError result = m_pCoreServices->getSoundManager()->setupDevices();
if (result == SOUNDDEVICE_ERROR_DEVICE_COUNT ||
result == SOUNDDEVICE_ERROR_EXCESSIVE_OUTPUT_CHANNEL) {
SoundDeviceStatus result = m_pCoreServices->getSoundManager()->setupDevices();
if (result == SoundDeviceStatus::ErrorDeviceCount ||
result == SoundDeviceStatus::ErrorExcessiveOutputChannel) {
if (soundDeviceBusyDlg(&retryClicked) != QDialog::Accepted) {
exit(0);
}
} else if (result != SOUNDDEVICE_ERROR_OK) {
} else if (result != SoundDeviceStatus::Ok) {
if (soundDeviceErrorMsgDlg(result, &retryClicked) !=
QDialog::Accepted) {
exit(0);
Expand Down Expand Up @@ -509,16 +509,15 @@ QDialog::DialogCode MixxxMainWindow::soundDeviceBusyDlg(bool* retryClicked) {
return soundDeviceErrorDlg(title, text, retryClicked);
}


QDialog::DialogCode MixxxMainWindow::soundDeviceErrorMsgDlg(
SoundDeviceError err, bool* retryClicked) {
SoundDeviceStatus status, bool* retryClicked) {
QString title(tr("Sound Device Error"));
QString text("<html> <p>" %
tr("Mixxx was unable to open all the configured sound "
"devices.") +
"</p> <p>" %
m_pCoreServices->getSoundManager()
->getLastErrorMessage(err)
->getLastErrorMessage(status)
.replace("\n", "<br/>") %
"</p><ul>"
"<li>" %
Expand Down
4 changes: 2 additions & 2 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "coreservices.h"
#include "preferences/configobject.h"
#include "preferences/constants.h"
#include "soundio/sounddeviceerror.h"
#include "soundio/sounddevicestatus.h"
#include "track/track_decl.h"
#include "util/parented_ptr.h"

Expand Down Expand Up @@ -104,7 +104,7 @@ class MixxxMainWindow : public QMainWindow {
const QString &title, const QString &text, bool* retryClicked);
QDialog::DialogCode soundDeviceBusyDlg(bool* retryClicked);
QDialog::DialogCode soundDeviceErrorMsgDlg(
SoundDeviceError err, bool* retryClicked);
SoundDeviceStatus status, bool* retryClicked);
QDialog::DialogCode noOutputDlg(bool* continueClicked);

std::shared_ptr<mixxx::CoreServices> m_pCoreServices;
Expand Down
8 changes: 4 additions & 4 deletions src/preferences/dialog/dlgprefsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,17 @@ void DlgPrefSound::slotApply() {
m_config.clearOutputs();
emit writePaths(&m_config);

SoundDeviceError err = SOUNDDEVICE_ERROR_OK;
SoundDeviceStatus status = SoundDeviceStatus::Ok;
{
ScopedWaitCursor cursor;
m_pKeylockEngine->set(keylockComboBox->currentData().toDouble());
m_pSettings->set(ConfigKey("[Master]", "keylock_engine"),
ConfigValue(keylockComboBox->currentData().toInt()));

err = m_pSoundManager->setConfig(m_config);
status = m_pSoundManager->setConfig(m_config);
}
if (err != SOUNDDEVICE_ERROR_OK) {
QString error = m_pSoundManager->getLastErrorMessage(err);
if (status != SoundDeviceStatus::Ok) {
QString error = m_pSoundManager->getLastErrorMessage(status);
QMessageBox::warning(nullptr, tr("Configuration error"), error);
} else {
m_settingsModified = false;
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgprefsound.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "preferences/dialog/ui_dlgprefsounddlg.h"
#include "preferences/usersettings.h"
#include "soundio/sounddevice.h"
#include "soundio/sounddeviceerror.h"
#include "soundio/sounddevicestatus.h"
#include "soundio/soundmanagerconfig.h"

class SoundManager;
Expand Down
9 changes: 5 additions & 4 deletions src/qml/qmlapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ QmlApplication::QmlApplication(
m_pAppEngine(nullptr),
m_fileWatcher({m_mainFilePath}) {
m_pCoreServices->initialize(app);
SoundDeviceError result = m_pCoreServices->getSoundManager()->setupDevices();
if (result != SOUNDDEVICE_ERROR_OK) {
qCritical() << "Error setting up sound devices" << result;
exit(result);
SoundDeviceStatus result = m_pCoreServices->getSoundManager()->setupDevices();
if (result != SoundDeviceStatus::Ok) {
const int reInt = static_cast<int>(result);
qCritical() << "Error setting up sound devices:" << reInt;
exit(reInt);
}

// FIXME: DlgPreferences has some initialization logic that must be executed
Expand Down
14 changes: 7 additions & 7 deletions src/soundio/sounddevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@ void SoundDevice::setFramesPerBuffer(unsigned int framesPerBuffer) {
m_framesPerBuffer = framesPerBuffer;
}

SoundDeviceError SoundDevice::addOutput(const AudioOutputBuffer &out) {
SoundDeviceStatus SoundDevice::addOutput(const AudioOutputBuffer& out) {
// Check if the output channels are already used
foreach (AudioOutputBuffer myOut, m_audioOutputs) {
if (out.channelsClash(myOut)) {
return SOUNDDEVICE_ERROR_DUPLICATE_OUTPUT_CHANNEL;
return SoundDeviceStatus::ErrorDuplicateOutputChannel;
}
}
if (out.getChannelGroup().getChannelBase()
+ out.getChannelGroup().getChannelCount() > getNumOutputChannels()) {
return SOUNDDEVICE_ERROR_EXCESSIVE_OUTPUT_CHANNEL;
return SoundDeviceStatus::ErrorExcessiveOutputChannel;
}
m_audioOutputs.append(out);
return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

void SoundDevice::clearOutputs() {
m_audioOutputs.clear();
}

SoundDeviceError SoundDevice::addInput(const AudioInputBuffer &in) {
SoundDeviceStatus SoundDevice::addInput(const AudioInputBuffer& in) {
// DON'T check if the input channels are already used, there's no reason
// we can't send the same inputted samples to different places in mixxx.
// -- bkgood 20101108
if (in.getChannelGroup().getChannelBase()
+ in.getChannelGroup().getChannelCount() > getNumInputChannels()) {
return SOUNDDEVICE_ERROR_EXCESSIVE_INPUT_CHANNEL;
return SoundDeviceStatus::ErrorExcessiveInputChannel;
}
m_audioInputs.append(in);
return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

void SoundDevice::clearInputs() {
Expand Down
14 changes: 7 additions & 7 deletions src/soundio/sounddevice.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#pragma once

#include <QString>
#include <QList>
#include <QString>

#include "util/types.h"
#include "preferences/usersettings.h"
#include "soundio/sounddeviceerror.h"
#include "soundio/sounddevicestatus.h"
#include "soundio/soundmanagerutil.h"
#include "util/types.h"

class SoundDevice;
class SoundManager;
Expand All @@ -33,17 +33,17 @@ class SoundDevice {
}
void setSampleRate(double sampleRate);
void setFramesPerBuffer(unsigned int framesPerBuffer);
virtual SoundDeviceError open(bool isClkRefDevice, int syncBuffers) = 0;
virtual SoundDeviceStatus open(bool isClkRefDevice, int syncBuffers) = 0;
virtual bool isOpen() const = 0;
virtual SoundDeviceError close() = 0;
virtual SoundDeviceStatus close() = 0;
virtual void readProcess() = 0;
virtual void writeProcess() = 0;
virtual QString getError() const = 0;
virtual unsigned int getDefaultSampleRate() const = 0;
int getNumOutputChannels() const;
int getNumInputChannels() const;
SoundDeviceError addOutput(const AudioOutputBuffer& out);
SoundDeviceError addInput(const AudioInputBuffer& in);
SoundDeviceStatus addOutput(const AudioOutputBuffer& out);
SoundDeviceStatus addInput(const AudioInputBuffer& in);
const QList<AudioInputBuffer>& inputs() const {
return m_audioInputs;
}
Expand Down
11 changes: 0 additions & 11 deletions src/soundio/sounddeviceerror.h

This file was deleted.

8 changes: 4 additions & 4 deletions src/soundio/sounddevicenetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SoundDeviceNetwork::SoundDeviceNetwork(UserSettingsPointer config,
SoundDeviceNetwork::~SoundDeviceNetwork() {
}

SoundDeviceError SoundDeviceNetwork::open(bool isClkRefDevice, int syncBuffers) {
SoundDeviceStatus SoundDeviceNetwork::open(bool isClkRefDevice, int syncBuffers) {
Q_UNUSED(syncBuffers);
kLogger.debug() << "open:" << m_deviceId.name;

Expand Down Expand Up @@ -101,14 +101,14 @@ SoundDeviceError SoundDeviceNetwork::open(bool isClkRefDevice, int syncBuffers)
m_pThread->start(QThread::TimeCriticalPriority);
}

return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

bool SoundDeviceNetwork::isOpen() const {
return (m_inputFifo != nullptr || m_outputFifo != nullptr);
}

SoundDeviceError SoundDeviceNetwork::close() {
SoundDeviceStatus SoundDeviceNetwork::close() {
//kLogger.debug() << "close:" << getInternalName();
m_pNetworkStream->stopStream();
if (m_pThread) {
Expand All @@ -120,7 +120,7 @@ SoundDeviceError SoundDeviceNetwork::close() {
m_outputFifo.reset();
m_inputFifo.reset();

return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

QString SoundDeviceNetwork::getError() const {
Expand Down
4 changes: 2 additions & 2 deletions src/soundio/sounddevicenetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class SoundDeviceNetwork : public SoundDevice {
QSharedPointer<EngineNetworkStream> pNetworkStream);
~SoundDeviceNetwork() override;

SoundDeviceError open(bool isClkRefDevice, int syncBuffers) override;
SoundDeviceStatus open(bool isClkRefDevice, int syncBuffers) override;
bool isOpen() const override;
SoundDeviceError close() override;
SoundDeviceStatus close() override;
void readProcess() override;
void writeProcess() override;
QString getError() const override;
Expand Down
8 changes: 4 additions & 4 deletions src/soundio/sounddevicenotfound.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class SoundDeviceNotFound : public SoundDevice {
m_strDisplayName = name;
}

SoundDeviceError open(bool isClkRefDevice, int syncBuffers) override {
SoundDeviceStatus open(bool isClkRefDevice, int syncBuffers) override {
Q_UNUSED(isClkRefDevice);
Q_UNUSED(syncBuffers);
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
};
bool isOpen() const override { return false; };
SoundDeviceError close() override {
return SOUNDDEVICE_ERROR_ERR;
SoundDeviceStatus close() override {
return SoundDeviceStatus::Error;
};
void readProcess() override { };
void writeProcess() override { };
Expand Down
22 changes: 11 additions & 11 deletions src/soundio/sounddeviceportaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ SoundDevicePortAudio::SoundDevicePortAudio(UserSettingsPointer config,
SoundDevicePortAudio::~SoundDevicePortAudio() {
}

SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers) {
SoundDeviceStatus SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers) {
qDebug() << "SoundDevicePortAudio::open()" << m_deviceId;
PaError err;

if (m_audioOutputs.empty() && m_audioInputs.empty()) {
m_lastError = QStringLiteral(
"No inputs or outputs in SDPA::open() "
"(THIS IS A BUG, this should be filtered by SM::setupDevices)");
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
}

memset(&m_outputParams, 0, sizeof(m_outputParams));
Expand Down Expand Up @@ -325,7 +325,7 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers
if (err != paNoError) {
qWarning() << "Error opening stream:" << Pa_GetErrorText(err);
m_lastError = QString::fromUtf8(Pa_GetErrorText(err));
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
} else {
qDebug() << "Opened PortAudio stream successfully... starting";
}
Expand All @@ -347,7 +347,7 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers
qWarning() << "PortAudio: Close stream error:"
<< Pa_GetErrorText(err) << m_deviceId;
}
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
} else {
qDebug() << "PortAudio: Started stream successfully";
}
Expand All @@ -369,14 +369,14 @@ SoundDeviceError SoundDevicePortAudio::open(bool isClkRefDevice, int syncBuffers
m_clkRefTimer.start();
}
m_pStream = pStream;
return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

bool SoundDevicePortAudio::isOpen() const {
return m_pStream != nullptr;
}

SoundDeviceError SoundDevicePortAudio::close() {
SoundDeviceStatus SoundDevicePortAudio::close() {
//qDebug() << "SoundDevicePortAudio::close()" << m_deviceId;
PaStream* pStream = m_pStream;
m_pStream = nullptr;
Expand All @@ -386,13 +386,13 @@ SoundDeviceError SoundDevicePortAudio::close() {
// 1 means the stream is stopped. 0 means active.
if (err == 1) {
//qDebug() << "PortAudio: Stream already stopped, but no error.";
return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}
// Real PaErrors are always negative.
if (err < 0) {
qWarning() << "PortAudio: Stream already stopped:"
<< Pa_GetErrorText(err) << m_deviceId;
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
}

//Stop the stream.
Expand All @@ -408,15 +408,15 @@ SoundDeviceError SoundDevicePortAudio::close() {
if (err != paNoError) {
qWarning() << "PortAudio: Stop stream error:"
<< Pa_GetErrorText(err) << m_deviceId;
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
}

// Close stream
err = Pa_CloseStream(pStream);
if (err != paNoError) {
qWarning() << "PortAudio: Close stream error:"
<< Pa_GetErrorText(err) << m_deviceId;
return SOUNDDEVICE_ERROR_ERR;
return SoundDeviceStatus::Error;
}

if (m_outputFifo) {
Expand All @@ -431,7 +431,7 @@ SoundDeviceError SoundDevicePortAudio::close() {
m_inputFifo = nullptr;
m_bSetThreadPriority = false;

return SOUNDDEVICE_ERROR_OK;
return SoundDeviceStatus::Ok;
}

QString SoundDevicePortAudio::getError() const {
Expand Down
4 changes: 2 additions & 2 deletions src/soundio/sounddeviceportaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class SoundDevicePortAudio : public SoundDevice {
unsigned int devIndex);
~SoundDevicePortAudio() override;

SoundDeviceError open(bool isClkRefDevice, int syncBuffers) override;
SoundDeviceStatus open(bool isClkRefDevice, int syncBuffers) override;
bool isOpen() const override;
SoundDeviceError close() override;
SoundDeviceStatus close() override;
void readProcess() override;
void writeProcess() override;
QString getError() const override;
Expand Down
11 changes: 11 additions & 0 deletions src/soundio/sounddevicestatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

// Used for returning errors from sounddevice functions.
enum class SoundDeviceStatus {
Error = -1,
Ok = 0,
ErrorDuplicateOutputChannel,
ErrorExcessiveOutputChannel,
ErrorExcessiveInputChannel,
ErrorDeviceCount
};
Loading

0 comments on commit e28e041

Please sign in to comment.