Skip to content

Commit

Permalink
damc_gui: only show widgets with OSC value
Browse files Browse the repository at this point in the history
Hide widgets that didn't received an OSC value.
When an OSC value is not received, this means that it is not supported.
  • Loading branch information
amurzeau committed Aug 19, 2023
1 parent 48b1a58 commit 4bedbb7
Show file tree
Hide file tree
Showing 21 changed files with 322 additions and 45 deletions.
3 changes: 2 additions & 1 deletion damc_gui/BalanceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <QHideEvent>

BalanceController::BalanceController(OutputController* parent, OscContainer* oscParent)
: QDialog(parent), ui(new Ui::BalanceController), oscBalances(oscParent, "balance") {
: ManagedVisibilityWidget<QDialog>(parent), ui(new Ui::BalanceController), oscBalances(oscParent, "balance") {
ui->setupUi(this);
oscBalances.setWidget(
this, ui->verticalLayout, [parent](QWidget* parentWidget, OscContainer* oscParent, int name) -> QWidget* {
Balance* balance = new Balance(parentWidget, oscParent, std::to_string(name));
balance->addChangeCallback([parent](bool) { parent->updateBalanceEnable(); });
return balance;
});
manageWidgetsVisiblity();
}

BalanceController::~BalanceController() {
Expand Down
3 changes: 2 additions & 1 deletion damc_gui/BalanceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "OscWidgetArray.h"
#include <QDialog>
#include "ManagedVisibilityWidget.h"

namespace Ui {
class BalanceController;
Expand All @@ -11,7 +12,7 @@ class Balance;
class Balance;
class OutputController;

class BalanceController : public QDialog {
class BalanceController : public ManagedVisibilityWidget<QDialog> {
Q_OBJECT

public:
Expand Down
4 changes: 3 additions & 1 deletion damc_gui/CompressorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <QHideEvent>

CompressorController::CompressorController(QWidget* parent, OscContainer* oscParent, const std::string& name)
: QDialog(parent),
: ManagedVisibilityWidget<QDialog>(parent),
OscContainer(oscParent, name),
ui(new Ui::CompressorController),
oscEnablePeak(this, "enable"),
Expand Down Expand Up @@ -38,6 +38,8 @@ CompressorController::CompressorController(QWidget* parent, OscContainer* oscPar
oscReleaseTime.setScale(1000);
oscAttackTime.setScale(1000);
oscLufsIntegrationTime.setScale(1000);

manageWidgetsVisiblity();
}

CompressorController::~CompressorController() {
Expand Down
4 changes: 3 additions & 1 deletion damc_gui/CompressorController.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#pragma once

#include "ManagedVisibilityWidget.h"
#include "OscWidgetMapper.h"
#include "WidgetAutoHidden.h"
#include <Osc/OscContainer.h>
#include <QDialog>

namespace Ui {
class CompressorController;
}

class CompressorController : public QDialog, public OscContainer {
class CompressorController : public ManagedVisibilityWidget<QDialog>, public OscContainer {
public:
explicit CompressorController(QWidget* parent, OscContainer* oscParent, const std::string& name);
~CompressorController();
Expand Down
4 changes: 3 additions & 1 deletion damc_gui/GlobalConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <Osc/OscContainer.h>

GlobalConfigDialog::GlobalConfigDialog(QWidget* parent, OscContainer* oscParent)
: QDialog(parent),
: ManagedVisibilityWidget<QDialog>(parent),
ui(new Ui::GlobalConfigDialog),
oscEnableAutoConnect(oscParent, "enableAutoConnect"),
oscMonitorConnections(oscParent, "enableConnectionMonitoring"),
Expand Down Expand Up @@ -59,6 +59,8 @@ GlobalConfigDialog::GlobalConfigDialog(QWidget* parent, OscContainer* oscParent)

memoryAvailable.setWidget(ui->availableMemorySpinBox, false);
memoryAvailable.addChangeCallback([this](int32_t value) { updateMemoryUsagePercent(); });

manageWidgetsVisiblity();
}

GlobalConfigDialog::~GlobalConfigDialog() {
Expand Down
4 changes: 3 additions & 1 deletion damc_gui/GlobalConfigDialog.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once

#include "ManagedVisibilityWidget.h"
#include "OscWidgetMapper.h"
#include "WidgetAutoHidden.h"
#include <QDialog>

namespace Ui {
class GlobalConfigDialog;
}

class GlobalConfigDialog : public QDialog {
class GlobalConfigDialog : public ManagedVisibilityWidget<QDialog> {
Q_OBJECT

public:
Expand Down
11 changes: 9 additions & 2 deletions damc_gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
#include "ui_MainWindow.h"
#include <QInputDialog>

MainWindow::MainWindow(OscRoot* oscRoot, QWidget* parent)
MainWindow::MainWindow(OscRoot* oscRoot, bool isMicrocontrollerDamc, QWidget* parent)
: QWidget(parent),
ui(new Ui::MainWindow),
oscRoot(oscRoot),
isMicrocontrollerDamc(isMicrocontrollerDamc),
outputInterfaces(oscRoot, "strip"),
oscTypeArray(oscRoot, "type_list"),
oscPortaudioDeviceArray(oscRoot, "device_list"),
oscWasapiDeviceArray(oscRoot, "device_list_wasapi") {
ui->setupUi(this);

if(isMicrocontrollerDamc) {
ui->showDisabledCheckBox->hide();
ui->addButton->hide();
ui->removeButton->hide();
}

globalConfigDialog = new GlobalConfigDialog(this, oscRoot);
connect(globalConfigDialog, &GlobalConfigDialog::showStateChanged, [this](bool shown) {
ui->globalConfigButton->setChecked(shown);
});

outputInterfaces.setWidget(
this, ui->horizontalLayout, [this](QWidget*, OscContainer* oscParent, int name) -> QWidget* {
return new OutputController(this, oscParent, std::to_string(name));
return new OutputController(this, oscParent, std::to_string(name), this->isMicrocontrollerDamc);
});

connect(ui->globalConfigButton, &QAbstractButton::clicked, this, &MainWindow::onShowGlobalConfig);
Expand Down
4 changes: 3 additions & 1 deletion damc_gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MainWindow : public QWidget {
Q_OBJECT

public:
explicit MainWindow(OscRoot* oscRoot, QWidget* parent = 0);
explicit MainWindow(OscRoot* oscRoot, bool isMicrocontrollerDamc, QWidget* parent = 0);
~MainWindow();

void removeInstance(int key);
Expand All @@ -41,6 +41,8 @@ protected slots:
Ui::MainWindow* ui;

OscRoot* oscRoot;
bool isMicrocontrollerDamc;

OscWidgetArray outputInterfaces;

GlobalConfigDialog* globalConfigDialog;
Expand Down
51 changes: 32 additions & 19 deletions damc_gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,36 @@
<rect>
<x>0</x>
<y>0</y>
<width>271</width>
<height>409</height>
<width>410</width>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
<string>Digital Audio Mixing Console - DAMC</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="QPushButton" name="removeButton">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Remove</string>
<string>Add</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="showDisabledCheckBox">
<property name="text">
<string>Show disabled</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="globalConfigButton">
<property name="text">
<string>Config</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<item row="1" column="0" colspan="5">
<widget class="QWidget" name="outputsWidgets" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
Expand All @@ -42,26 +56,25 @@
</layout>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="showDisabledCheckBox">
<item row="0" column="4">
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Show disabled</string>
<string>Remove</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="globalConfigButton">
<property name="text">
<string>Config</string>
<spacer name="buttonsSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
Expand Down
12 changes: 12 additions & 0 deletions damc_gui/ManagedVisibilityWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "WidgetAutoHidden.h"

template<class T> class ManagedVisibilityWidget : public T {
public:
using T::T;
void manageWidgetsVisiblity() { widgetAutoHidden.addContainerWidgets({this}); }

private:
WidgetAutoHidden widgetAutoHidden;
};
10 changes: 10 additions & 0 deletions damc_gui/OscWidgetMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ template<class T, class UnderlyingType>
void OscWidgetMapper<T, UnderlyingType>::setWidget(T* widget, bool updateOnChange) {
this->widgets.push_back(widget);

widget->setVisible(false);

updateWidget(widget);

if(updateOnChange) {
Expand All @@ -22,6 +24,8 @@ void OscWidgetMapper<T, UnderlyingType>::setWidget(T* widget, bool updateOnChang
notifyChanged(widget);
});
} else {
// Stateless buttons won't receive any value, so never hide them
widget->setVisible(true);
connect(widget, &T::clicked, [this, widget](bool value) {
this->value = 1;
notifyChanged(widget);
Expand Down Expand Up @@ -80,6 +84,12 @@ void OscWidgetMapper<T, UnderlyingType>::execute(const std::vector<OscArgument>&
if(!getArgumentAs<UnderlyingType>(arguments[0], value))
return;

for(T* widget : widgets) {
if(widget->isHidden()) {
widget->setVisible(true);
}
}

this->defaultValue = false;

if(this->value == value)
Expand Down
28 changes: 21 additions & 7 deletions damc_gui/OscWidgetMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,27 @@

template<class T> struct OscWidgetMapperType {};

template<> struct OscWidgetMapperType<QAbstractSlider> { using type = int32_t; };
template<> struct OscWidgetMapperType<QAbstractButton> { using type = bool; };
template<> struct OscWidgetMapperType<QDoubleSpinBox> { using type = float; };
template<> struct OscWidgetMapperType<QSpinBox> { using type = int32_t; };
template<> struct OscWidgetMapperType<QComboBox> { using type = int32_t; };
template<> struct OscWidgetMapperType<QGroupBox> { using type = bool; };
template<> struct OscWidgetMapperType<QLineEdit> { using type = std::string; };
template<> struct OscWidgetMapperType<QAbstractSlider> {
using type = int32_t;
};
template<> struct OscWidgetMapperType<QAbstractButton> {
using type = bool;
};
template<> struct OscWidgetMapperType<QDoubleSpinBox> {
using type = float;
};
template<> struct OscWidgetMapperType<QSpinBox> {
using type = int32_t;
};
template<> struct OscWidgetMapperType<QComboBox> {
using type = int32_t;
};
template<> struct OscWidgetMapperType<QGroupBox> {
using type = bool;
};
template<> struct OscWidgetMapperType<QLineEdit> {
using type = std::string;
};

template<class T, class UnderlyingType = typename OscWidgetMapperType<T>::type>
class OscWidgetMapper : public QObject, public OscContainer {
Expand Down
10 changes: 9 additions & 1 deletion damc_gui/OutputController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

#define DRAG_FORMAT "application/x-dndwaveoutputinstancewidget"

OutputController::OutputController(MainWindow* parent, OscContainer* oscParent, const std::string& name)
OutputController::OutputController(MainWindow* parent,
OscContainer* oscParent,
const std::string& name,
bool isMicrocontrollerDamc)
: QWidget(parent),
OscContainer(oscParent, name),
ui(new Ui::OutputController),
Expand All @@ -38,6 +41,11 @@ OutputController::OutputController(MainWindow* parent, OscContainer* oscParent,
// By default hide, it will be shown if enabled
hide();

if(isMicrocontrollerDamc) {
// No add/remove with microcontroller DAMC
ui->removeButton->hide();
}

oscEnable.setWidget(ui->enableCheckBox);
oscMute.setWidget(ui->muteButton);
oscDelay.setWidget(ui->delaySpinBox);
Expand Down
5 changes: 4 additions & 1 deletion damc_gui/OutputController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class LevelMeterWidget;
class OutputController : public QWidget, public OscContainer {
Q_OBJECT
public:
explicit OutputController(MainWindow* parent, OscContainer* oscParent, const std::string& name);
explicit OutputController(MainWindow* parent,
OscContainer* oscParent,
const std::string& name,
bool isMicrocontrollerDamc);
~OutputController();

void showConfigDialog();
Expand Down
8 changes: 4 additions & 4 deletions damc_gui/OutputController.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>70</width>
<width>77</width>
<height>391</height>
</rect>
</property>
Expand Down Expand Up @@ -50,7 +50,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
<height>0</height>
</size>
</property>
</spacer>
Expand Down Expand Up @@ -95,7 +95,7 @@
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<spacer name="volumeLevelSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down Expand Up @@ -217,7 +217,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="levelLabelSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
Expand Down
Loading

0 comments on commit 4bedbb7

Please sign in to comment.