Skip to content

Commit

Permalink
Implement app manager
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Sep 15, 2021
1 parent 6b66eab commit d1fb433
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 260 deletions.
236 changes: 4 additions & 232 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ MainWindow::MainWindow(QString exepath,
{
QMenu *menu = new QMenu();
spectrum = new QAction("Reload spectrum", this);
connect(spectrum, &QAction::triggered, this, &MainWindow::restartSpectrum);
//connect(spectrum, &QAction::triggered, this, &MainWindow::restartSpectrum);
menu->addAction(tr("Reload JamesDSP"), this, SLOT(restart()));
menu->addAction(tr("Reset to defaults"), this, SLOT(reset()));
//menu->addAction(spectrum);
Expand Down Expand Up @@ -479,239 +479,11 @@ MainWindow::~MainWindow()
delete ui;
}

// Spectrum
void MainWindow::setSpectrumVisibility(bool v)
{
/*m_spectrograph->setVisible(v);
if (v)
{
this->findChild<QFrame*>("analysisLayout_spectrum")->setFrameShape(QFrame::StyledPanel);
}
else
{
this->findChild<QFrame*>("analysisLayout_spectrum")->setFrameShape(QFrame::NoFrame);
}*/
}

void MainWindow::initializeSpectrum()
{
/*m_spectrograph = new Spectrograph(this);
m_audioengine = new AudioStreamEngine(this);
int refresh = AppConfig::instance().get<int>(AppConfig::SpectrumRefresh);
if (refresh == 0)
{
refresh = 20;
}
if (refresh < 10)
{
refresh = 10;
}
else if (refresh > 500)
{
refresh = 500;
}
m_audioengine->setNotifyIntervalMs(refresh);
analysisLayout.reset(new QFrame());
analysisLayout->setObjectName("analysisLayout_spectrum");
analysisLayout->setFrameShape(QFrame::Shape::StyledPanel);
analysisLayout->setLayout(new QHBoxLayout);
analysisLayout->layout()->setMargin(0);
analysisLayout->layout()->addWidget(m_spectrograph);
auto buttonbox = ui->centralWidget->layout()->takeAt(ui->centralWidget->layout()->count() - 1);
ui->centralWidget->layout()->addWidget(analysisLayout.data());
ui->centralWidget->layout()->addItem(buttonbox);
analysisLayout.take();
setSpectrumVisibility(false);
connect(&AppConfig::instance(), &AppConfig::spectrumChanged, this, [this](bool needReload) {
toggleSpectrum(AppConfig::instance().get<bool>(AppConfig::SpectrumEnabled), true);
if(needReload)
restartSpectrum();
});*/
}

void MainWindow::restartSpectrum()
{
//toggleSpectrum(false, false);
//toggleSpectrum(AppConfig::instance().get<bool>(AppConfig::SpectrumEnabled), false);
}

void MainWindow::refreshSpectrumParameters()
{
/*int bands = AppConfig::instance().get<int>(AppConfig::SpectrumBands);
int minfreq = AppConfig::instance().get<int>(AppConfig::SpectrumMinFreq);
int maxfreq = AppConfig::instance().get<int>(AppConfig::SpectrumMaxFreq);
int refresh = AppConfig::instance().get<int>(AppConfig::SpectrumRefresh);
float multiplier = AppConfig::instance().get<float>(AppConfig::SpectrumMultiplier);
// Set default values if undefined
if (bands == 0)
{
bands = 100;
}
if (maxfreq == 0)
{
maxfreq = 1000;
}
if (refresh == 0)
{
refresh = 10;
}
if (multiplier == 0)
{
multiplier = 0.15;
}
// Check boundaries
if (bands < 5 )
{
bands = 5;
}
else if (bands > 300)
{
bands = 300;
}
if (minfreq < 0)
{
minfreq = 0;
}
else if (minfreq > 10000)
{
minfreq = 10000;
}
if (maxfreq < 100)
{
maxfreq = 100;
}
else if (maxfreq > 24000)
{
maxfreq = 24000;
}
if (refresh < 10)
{
refresh = 10;
}
else if (refresh > 500)
{
refresh = 500;
}
if (multiplier < 0.01)
{
multiplier = 0.01;
}
else if (multiplier > 1)
{
multiplier = 1;
}
if (maxfreq < minfreq)
{
maxfreq = minfreq + 100;
}
QColor outline;
if (palette().window().style() == Qt::TexturePattern)
{
outline = QColor(0, 0, 0, 160);
}
else
{
outline = palette().window().color().lighter(140);
}
m_spectrograph->setTheme(palette().window().color().lighter(),
palette().highlight().color(),
palette().text().color(),
outline.lighter(108),
AppConfig::instance().get<bool>(AppConfig::SpectrumGrid),
(Spectrograph::Mode) AppConfig::instance().get<int>(AppConfig::SpectrumTheme));
m_spectrograph->setParams(bands, minfreq, maxfreq);
m_audioengine->setNotifyIntervalMs(refresh);
m_audioengine->setMultiplier(multiplier);*/
}

void MainWindow::toggleSpectrum(bool on,
bool ctrl_visibility)
{
/*refreshSpectrumParameters();
if (ctrl_visibility)
{
spectrum->setVisible(on);
}
if (on && (!m_spectrograph->isVisible() || !ctrl_visibility))
{
if (ctrl_visibility)
{
setSpectrumVisibility(true);
this->setFixedSize(this->width(), this->height() + m_spectrograph->size().height());
}
QAudioDeviceInfo in;
for (auto item : QAudioDeviceInfo::availableDevices(QAudio::AudioInput))
{
if (item.deviceName() == AppConfig::instance().getSpectrumInput())
{
in = item;
}
}
m_audioengine->setAudioInputDevice(in);
m_audioengine->initializeRecord();
m_audioengine->startRecording();
connect(m_audioengine, static_cast<void (AudioStreamEngine::*)(QAudio::Mode, QAudio::State)>(&AudioStreamEngine::stateChanged),
this, [this](QAudio::Mode mode, QAudio::State state) {
Q_UNUSED(mode);
if (QAudio::ActiveState != state && QAudio::SuspendedState != state)
{
m_spectrograph->reset();
}
});
connect(m_audioengine, static_cast<void (AudioStreamEngine::*)(qint64, qint64, const FrequencySpectrum &)>(&AudioStreamEngine::spectrumChanged),
this, [this](qint64, qint64, const FrequencySpectrum &spectrum) {
m_spectrograph->spectrumChanged(spectrum);
});
}
else if (!on && (m_spectrograph->isVisible() || !ctrl_visibility))
{
if (ctrl_visibility)
{
setSpectrumVisibility(false);
this->setFixedSize(this->width(), this->height() - m_spectrograph->size().height());
}
m_spectrograph->reset();
m_audioengine->reset();
}*/
}

void MainWindow::fireTimerSignal()
{
if (spectrumReloadSignalQueued)
{
restartSpectrum();
//restartSpectrum();
}

spectrumReloadSignalQueued = false;
Expand Down Expand Up @@ -855,7 +627,7 @@ void MainWindow::savePresetFile(const QString &filename)

void MainWindow::loadExternalFile()
{
QString filename = QFileDialog::getOpenFileName(this, tr("Load custom audio.conf"), "", "*.conf");
QString filename = QFileDialog::getOpenFileName(this, tr("Load custom audio.conf"), "", "JamesDSP Linux configuration (*.conf)");

if (filename == "")
{
Expand All @@ -867,7 +639,7 @@ void MainWindow::loadExternalFile()

void MainWindow::saveExternalFile()
{
QString filename = QFileDialog::getSaveFileName(this, tr("Save current audio.conf"), "", "*.conf");
QString filename = QFileDialog::getSaveFileName(this, tr("Save current audio.conf"), "", "JamesDSP Linux configuration (*.conf)");

if (filename == "")
{
Expand Down
24 changes: 1 addition & 23 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class MainWindow :
void closeEvent(QCloseEvent *event) override;

public slots:
void restartSpectrum();
void reset();
void restart();
void raiseWindow();
Expand All @@ -96,8 +95,7 @@ private slots:
void updateAllUnitLabels();
void loadExternalFile();
void saveExternalFile();
void dialogHandler();
void refreshSpectrumParameters();
void dialogHandler();
void updateEqStringFromWidget();
void bs2bPresetSelectionUpdated();
void reverbPresetSelectionUpdated();
Expand Down Expand Up @@ -151,35 +149,15 @@ private slots:

QJsonTableModel *model;

void initializeSpectrum();
void toggleSpectrum(bool on,
bool ctrl_visibility);
void updateTooltipLabelUnit(QObject *sender,
const QString &text,
bool);
void loadConfig();
void connectActions();

void setSpectrumVisibility(bool v);
void reloadDDCDB();
void setLiveprogSelection(QString path);

static void replaceTab(QTabWidget *tab,
int index,
QWidget *page,
QString title = "")
{
if (title.isEmpty())
{
title = tab->tabText(index);
}

auto toDelete = tab->widget(index);
tab->removeTab(index);
toDelete->deleteLater();
tab->insertTab(index, page, title);
}

void updateIrsSelection();

};
Expand Down
1 change: 1 addition & 0 deletions src/audio/base/Base.pri
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/DspHost.h \
$$PWD/DspStatus.h \
$$PWD/IAppManager.h \
$$PWD/IAudioService.h \
$$PWD/IDspElement.h \
$$PWD/IOutputDevice.h \
Expand Down
17 changes: 17 additions & 0 deletions src/audio/base/IAppManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef IAPPMANAGER_H
#define IAPPMANAGER_H

#include <QObject>

class IAppManager : public QObject
{
Q_OBJECT
public:
virtual ~IAppManager() {}

public slots:


};

#endif // IAPPMANAGER_H
5 changes: 4 additions & 1 deletion src/audio/base/IAudioService.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "IOutputDevice.h"
#include "DspStatus.h"
#include "IAppManager.h"
#include <QObject>

class DspConfig;
Expand All @@ -17,8 +18,10 @@ public slots:
virtual void update(DspConfig* config) = 0;
virtual void reloadLiveprog() = 0;
virtual void reloadService() = 0;
virtual std::vector<IOutputDevice> sinkDevices() = 0;

virtual IAppManager* appManager() = 0;

virtual std::vector<IOutputDevice> sinkDevices() = 0;
virtual DspStatus status() = 0;

signals:
Expand Down
5 changes: 5 additions & 0 deletions src/audio/pipewire/PipewireAudioService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void PipewireAudioService::reloadService()
effects.get()->connect_filters();
}

IAppManager *PipewireAudioService::appManager()
{
return appMgr.get();
}

std::vector<IOutputDevice> PipewireAudioService::sinkDevices()
{
std::vector<IOutputDevice> devices;
Expand Down
3 changes: 2 additions & 1 deletion src/audio/pipewire/PipewireAudioService.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public slots:
void update(DspConfig* config) override;
void reloadLiveprog() override;
void reloadService() override;
std::vector<IOutputDevice> sinkDevices() override;

IAppManager* appManager() override;
std::vector<IOutputDevice> sinkDevices() override;
DspStatus status() override;

private:
Expand Down
Loading

0 comments on commit d1fb433

Please sign in to comment.