Skip to content

Commit

Permalink
Simplify FEC setRendererStatus overloads
Browse files Browse the repository at this point in the history
No need to store BearStatus. FEC is only interested in what colour and text it should use.
  • Loading branch information
firthm01 committed Jan 26, 2024
1 parent 355dae9 commit d127c20
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ void BinauralMonitoringJuceFrontendConnector::setDataFileComboBox(
void BinauralMonitoringJuceFrontendConnector::setRendererStatusLabel(
std::shared_ptr<Label> label) {
rendererStatusLabel_ = label;
if(cachedBearStatusOverride_.has_value()){
setRendererStatus(cachedBearStatusOverride_.value());
} else {
setRendererStatus(cachedBearStatus_);
}
setRendererStatus(cachedBearStatusText_, cachedBearStatusColour_);
}

void BinauralMonitoringJuceFrontendConnector::setListenerOrientationInstance(
Expand Down Expand Up @@ -360,65 +356,54 @@ void BinauralMonitoringJuceFrontendConnector::setOscInvertQuatZ(bool invert) {

void BinauralMonitoringJuceFrontendConnector::setRendererStatus(
const ear::plugin::BearStatus& bearStatus) {
if (auto rendererStatusLabelLocked = rendererStatusLabel_.lock()) {
if (bearStatus.startupSuccess == BearStatusStates::SUCCEEDED) {
// Is running. See if accepting listener position data
if (bearStatus.listenerDataSetSuccess == BearStatusStates::FAILED) {
rendererStatusLabelLocked->setColour(
juce::Label::textColourId,
ear::plugin::ui::EarColours::StatusWarning);
juce::String msg("Renderer did not accept listener orientation data: ");
msg += juce::String(bearStatus.listenerDataSetErrorDesc);
rendererStatusLabelLocked->setText(
msg, juce::NotificationType::dontSendNotification);
} else {
// Other states (good or insignificant) for listener data - BEAR is running
rendererStatusLabelLocked->setColour(
juce::Label::textColourId, ear::plugin::ui::EarColours::Label);
rendererStatusLabelLocked->setText(
"Running...", juce::NotificationType::dontSendNotification);
}
} else if (bearStatus.startupSuccess == BearStatusStates::FAILED) {
rendererStatusLabelLocked->setColour(
juce::Label::textColourId, ear::plugin::ui::EarColours::StatusBad);
juce::String msg("Renderer startup failed: ");
msg += juce::String(bearStatus.startupErrorDesc) + " (";
auto dataFile = bearStatus.startupConfig.get_data_path();
removePath(dataFile);
msg += juce::String(dataFile) + ").";
rendererStatusLabelLocked->setText(
msg, juce::NotificationType::dontSendNotification);
} else if (bearStatus.startupSuccess == BearStatusStates::NOT_ATTEMPTED) {
// Unusual case - we should always expect a start attempt (class init)
assert(false);
rendererStatusLabelLocked->setColour(
juce::Label::textColourId, ear::plugin::ui::EarColours::StatusWarning);
rendererStatusLabelLocked->setText(
"Renderer not started.",
juce::NotificationType::dontSendNotification);

if (bearStatus.startupSuccess == BearStatusStates::SUCCEEDED) {
// Is running. See if accepting listener position data
if (bearStatus.listenerDataSetSuccess == BearStatusStates::FAILED) {
juce::String msg("Renderer did not accept listener orientation data: ");
msg += juce::String(bearStatus.listenerDataSetErrorDesc);
setRendererStatus(msg, ear::plugin::ui::EarColours::StatusWarning);
} else {
// Unimplemented case
assert(false);
// Other states (good or insignificant) for listener data - BEAR is running
setRendererStatus("Running...", ear::plugin::ui::EarColours::Label);
}

} else if (bearStatus.startupSuccess == BearStatusStates::FAILED) {
juce::String msg("Renderer startup failed: ");
msg += juce::String(bearStatus.startupErrorDesc) + " (";
auto dataFile = bearStatus.startupConfig.get_data_path();
removePath(dataFile);
msg += juce::String(dataFile) + ").";
setRendererStatus(msg, ear::plugin::ui::EarColours::StatusBad);

} else if (bearStatus.startupSuccess == BearStatusStates::NOT_ATTEMPTED) {
// Unusual case - we should always expect a start attempt (class init)
assert(false);
setRendererStatus("Renderer not started.",
ear::plugin::ui::EarColours::StatusWarning);

} else {
// Unimplemented case
assert(false);
}
cachedBearStatus_ = bearStatus;
cachedBearStatusOverride_.reset();
}

void BinauralMonitoringJuceFrontendConnector::setRendererStatus(
const juce::String& statusText) {
const juce::String& statusText, const juce::Colour& statusColour) {
if (auto rendererStatusLabelLocked = rendererStatusLabel_.lock()) {
rendererStatusLabelLocked->setColour(juce::Label::textColourId,
ear::plugin::ui::EarColours::Label);
statusColour);
rendererStatusLabelLocked->setText(
statusText, juce::NotificationType::dontSendNotification);
}

cachedBearStatusOverride_ = statusText;
cachedBearStatusText_ = statusText;
cachedBearStatusColour_ = statusColour;
}

void BinauralMonitoringJuceFrontendConnector::setRendererStatusRestarting() {
setRendererStatus(juce::String("Renderer starting..."));
setRendererStatus(juce::String("Renderer starting..."),
ear::plugin::ui::EarColours::Label);
}

void BinauralMonitoringJuceFrontendConnector::setDataFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "binaural_monitoring_plugin_processor.hpp"
#include "binaural_monitoring_audio_processor.hpp"
#include <memory>
#include <optional>

namespace ear {
namespace plugin {
Expand Down Expand Up @@ -83,7 +82,8 @@ class BinauralMonitoringJuceFrontendConnector

// Renderer status and Data File setters
void setRendererStatus(const ear::plugin::BearStatus& bearStatus);
void setRendererStatus(const juce::String& statusText);
void setRendererStatus(const juce::String& statusText,
const juce::Colour& statusColour);
void setRendererStatusRestarting();
void setDataFile(const juce::String& dataFile);

Expand Down Expand Up @@ -145,8 +145,8 @@ class BinauralMonitoringJuceFrontendConnector
bool cachedOscInvertQuatX_;
bool cachedOscInvertQuatY_;
bool cachedOscInvertQuatZ_;
ear::plugin::BearStatus cachedBearStatus_;
std::optional<juce::String> cachedBearStatusOverride_;
juce::String cachedBearStatusText_;
juce::Colour cachedBearStatusColour_;

/// Listener Orientation Object
std::shared_ptr<ListenerOrientation> listenerOrientation;
Expand Down

0 comments on commit d127c20

Please sign in to comment.