Skip to content

Commit

Permalink
refactor and update Audio Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Aug 2, 2024
1 parent afb5b6b commit 5cdb13e
Show file tree
Hide file tree
Showing 20 changed files with 1,352 additions and 540 deletions.
4 changes: 4 additions & 0 deletions src/plugins/audioplugin/internal/audioplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <audioplugin/internal/builtinformatentry.h>
#include <audioplugin/internal/midipage.h>
#include <audioplugin/internal/midisystem.h>
#include <audioplugin/internal/audioexportdialog.h>

namespace Audio::Internal {

Expand Down Expand Up @@ -96,6 +97,9 @@ namespace Audio::Internal {
new DeviceTester(iAudio->outputSystemInterface(true), iAudio->outputSystemInterface(true));
new DeviceTester(iAudio->outputSystemInterface(false), iAudio->outputSystemInterface(false));

AudioExportDialog dlg;
dlg.exec();

return true;
}
void AudioPlugin::extensionsInitialized() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <QListWidget>
#include <QLabel>

namespace Audio {
namespace Audio::Internal {
AudioExportDialog::AudioExportDialog(QWidget *parent) : QDialog(parent) {
setWindowTitle(tr("Export Audio"));
auto mainLayout = new QVBoxLayout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QListWidget;
class QCheckBox;
class QRadioButton;

namespace Audio {
namespace Audio::Internal {

class AudioExportDialog : public QDialog {
Q_OBJECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <TalcsFormat/AudioFormatIO.h>

namespace Audio {
namespace Audio::Internal {

class AudioFormatIOObject : public QObject, public talcs::AudioFormatIO {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <TalcsFormat/FormatEntry.h>

namespace Audio {
namespace Audio::Internal {

class BuiltInFormatEntry : public talcs::FormatEntry {
Q_OBJECT
Expand Down
128 changes: 85 additions & 43 deletions src/plugins/audioplugin/internal/settings/midipage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,48 +31,43 @@
#include <audioplugin/internal/midisystem.h>
#include <audioplugin/internal/outputsystem.h>
#include <audioplugin/internal/vstconnectionsystem.h>
#include <audioplugin/internal/audiohelpers.h>

namespace Audio::Internal {

static talcs::NoteSynthesizerDetectorMessage scores[] = {
{0, 47, .5, true},
{0, 75, 1, true},
{2, 75, false},
{2, 66, .5, true},
{4, 66, false},
{4, 73, .7, true},
{6, 73, false},
{6, 71, 1, true},
{8, 71, false},
{8, 66, .5, true},
{10, 66, false},
{10, 73, .7, true},
{12, 47, false},
{12, 73, false},

{12, 49, .5, true},
{12, 75, 1, true},
{14, 75, false},
{14, 66, .5, true},
{15, 66, false},
{15, 76, 1, true},
{16, 76, false},
{16, 75, .7, true},
{18, 49, false},
{18, 75, false},
{18, 42, .5, true},
{18, 73, 1, true},
{24, 42, false},
{24, 73, false},
{0, 47, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{0, 75, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{2, 75, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{2, 66, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{4, 66, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{4, 73, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{6, 73, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{6, 71, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{8, 71, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{8, 66, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{10, 66, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{10, 73, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{12, 47, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{12, 73, talcs::NoteSynthesizerDetectorMessage::NoteOff},

{12, 49, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{12, 75, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{14, 75, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{14, 66, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{15, 66, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{15, 76, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{16, 76, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{16, 75, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{18, 49, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{18, 75, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{18, 42, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{18, 73, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn},
{24, 42, talcs::NoteSynthesizerDetectorMessage::NoteOff},
{24, 73, talcs::NoteSynthesizerDetectorMessage::NoteOff},
talcs::NoteSynthesizerDetectorMessage::Null,
};

static double msecToRate(int msec, double sampleRate) {
if (msec == 0)
return 0.005;
return std::pow(0.005, 1000.0 / (msec * sampleRate));
}

class MIDIPageWidget : public QWidget, public talcs::NoteSynthesizerDetector {
Q_OBJECT
public:
Expand All @@ -82,15 +77,15 @@ namespace Audio::Internal {
auto inputGroupBox = new QGroupBox(tr("MIDI Input"));
auto inputLayout = new QFormLayout;
auto deviceComboBox = new QComboBox;
inputLayout->addRow("&Device", deviceComboBox);
inputLayout->addRow(tr("&Device"), deviceComboBox);
inputGroupBox->setLayout(inputLayout);
mainLayout->addWidget(inputGroupBox);

auto synthesizerGroupBox = new QGroupBox(tr("Synthesizer"));
auto synthesizerLayout = new QFormLayout;
auto generatorComboBox = new QComboBox;
generatorComboBox->addItems({tr("Sine wave"), tr("Square wave"), tr("Triangle Wave"), tr("Sawtooth wave")});
synthesizerLayout->addRow("&Generator", generatorComboBox);
synthesizerLayout->addRow(tr("&Generator"), generatorComboBox);

auto amplitudeLayout = new QHBoxLayout;
auto amplitudeSlider = new SVS::SeekBar;
Expand Down Expand Up @@ -118,6 +113,31 @@ namespace Audio::Internal {
auto attackLabel = new QLabel(tr("A&ttack (ms)"));
attackLabel->setBuddy(attackSpinBox);
synthesizerLayout->addRow(attackLabel, attackLayout);

auto decayLayout = new QHBoxLayout;
auto decaySlider = new SVS::SeekBar;
decaySlider->setInterval(1);
decaySlider->setDefaultValue(10);
decaySlider->setRange(0, 1000);
decayLayout->addWidget(decaySlider);
auto decaySpinBox = new SVS::ExpressionSpinBox;
decaySpinBox->setRange(0, 1000);
decayLayout->addWidget(decaySpinBox);
auto decayLabel = new QLabel(tr("D&ecay (ms)"));
decayLabel->setBuddy(decaySpinBox);
synthesizerLayout->addRow(decayLabel, decayLayout);

auto decayRatioLayout = new QHBoxLayout;
auto decayRatioSlider = new SVS::SeekBar;
decayRatioSlider->setDefaultValue(1);
decayRatioSlider->setRange(0, 1);
decayRatioLayout->addWidget(decayRatioSlider);
auto decayRatioSpinBox = new SVS::ExpressionDoubleSpinBox;
decayRatioSpinBox->setRange(0, 1);
decayRatioLayout->addWidget(decayRatioSpinBox);
auto decayRatioLabel = new QLabel(tr("Decay rati&o"));
decayRatioLabel->setBuddy(decayRatioSpinBox);
synthesizerLayout->addRow(decayRatioLabel, decayRatioLayout);

auto releaseLayout = new QHBoxLayout;
auto releaseSlider = new SVS::SeekBar;
Expand Down Expand Up @@ -203,17 +223,31 @@ namespace Audio::Internal {
QSignalBlocker o(attackSlider);
m_cachedAttackMsec = value;
attackSlider->setValue(value);
m_testSynthesizer.setAttackRate(msecToRate(value, m_testSynthesizer.sampleRate()));
m_testSynthesizer.setAttackTime(AudioHelpers::msecToSample(value, m_testSynthesizer.sampleRate()));
});
connect(decaySlider, &SVS::SeekBar::valueChanged, decaySpinBox, &QSpinBox::setValue);
connect(decaySpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, [=](int value) {
QSignalBlocker o(decaySlider);
m_cachedDecayMsec = value;
decaySlider->setValue(value);
m_testSynthesizer.setDecayTime(AudioHelpers::msecToSample(value, m_testSynthesizer.sampleRate()));
});
connect(decayRatioSlider, &SVS::SeekBar::valueChanged, decayRatioSpinBox, &QDoubleSpinBox::setValue);
connect(decayRatioSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, [=](double value) {
QSignalBlocker o(decayRatioSlider);
m_cachedDecayRatio = value;
decayRatioSlider->setValue(value);
m_testSynthesizer.setDecayRatio(value);
});
connect(releaseSlider, &SVS::SeekBar::valueChanged, releaseSpinBox, &QSpinBox::setValue);
connect(releaseSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, [=](int value) {
m_cachedReleaseMsec = value;
releaseSlider->setValue(value);
m_testSynthesizer.setReleaseRate(msecToRate(value, m_testSynthesizer.sampleRate()));
m_testSynthesizer.setReleaseTime(AudioHelpers::msecToSample(value, m_testSynthesizer.sampleRate()));
});
connect(AudioSystem::outputSystem()->context(), &talcs::AbstractOutputContext::sampleRateChanged, this, [=](double sampleRate) {
m_testSynthesizer.setAttackRate(msecToRate(attackSpinBox->value(), sampleRate));
m_testSynthesizer.setReleaseRate(msecToRate(releaseSpinBox->value(), sampleRate));
m_testSynthesizer.setAttackTime(AudioHelpers::msecToSample(attackSpinBox->value(), sampleRate));
m_testSynthesizer.setReleaseTime(AudioHelpers::msecToSample(releaseSpinBox->value(), sampleRate));
});
connect(frequencyOfASpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, [=](double value) {
m_mutex.lock();
Expand All @@ -238,6 +272,8 @@ namespace Audio::Internal {
amplitudeSpinBox->setValue(m_cachedAmplitude = ms->amplitudeDecibel());
amplitudeSlider->setValue(SVS::DecibelLinearizer::decibelToLinearValue(amplitudeSpinBox->value()));
attackSpinBox->setValue(m_cachedAttackMsec = ms->attackMsec());
decaySpinBox->setValue(m_cachedDecayMsec = ms->decayMsec());
decayRatioSpinBox->setValue(m_cachedDecayRatio = ms->decayRatio());
releaseSpinBox->setValue(m_cachedReleaseMsec = ms->releaseMsec());
m_cachedFrequencyOfA = ms->frequencyOfA();
if (qFuzzyIsNull(m_cachedFrequencyOfA)) {
Expand All @@ -253,8 +289,10 @@ namespace Audio::Internal {
AudioSystem::outputSystem()->context()->preMixer()->addSource(&m_testMixer);
m_testSynthesizer.setGenerator(static_cast<talcs::NoteSynthesizer::Generator>(ms->generator()));
m_testMixer.setGain(talcs::Decibels::decibelsToGain(ms->amplitudeDecibel()));
m_testSynthesizer.setAttackRate(msecToRate(ms->attackMsec(), m_testSynthesizer.sampleRate()));
m_testSynthesizer.setReleaseRate(msecToRate(ms->releaseMsec(), m_testSynthesizer.sampleRate()));
m_testSynthesizer.setAttackTime(AudioHelpers::msecToSample(ms->attackMsec(), m_testSynthesizer.sampleRate()));
m_testSynthesizer.setDecayTime(AudioHelpers::msecToSample(ms->decayMsec(), m_testSynthesizer.sampleRate()));
m_testSynthesizer.setDecayRatio(ms->decayRatio());
m_testSynthesizer.setReleaseTime(AudioHelpers::msecToSample(ms->releaseMsec(), m_testSynthesizer.sampleRate()));

connect(synthesizerTestButton, &QAbstractButton::clicked, this, [=](bool checked) {
QMutexLocker locker(&m_mutex);
Expand Down Expand Up @@ -325,6 +363,8 @@ namespace Audio::Internal {
ms->setGenerator(m_cachedGenerator);
ms->setAmplitudeDecibel(m_cachedAmplitude);
ms->setAttackMsec(m_cachedAttackMsec);
ms->setDecayMsec(m_cachedDecayMsec);
ms->setDecayRatio(m_cachedDecayRatio);
ms->setReleaseMsec(m_cachedReleaseMsec);
ms->setFrequencyOfA(m_cachedFrequencyOfA);
AudioSystem::vstConnectionSystem()->syncSynthesizerPreference();
Expand All @@ -342,6 +382,8 @@ namespace Audio::Internal {
int m_cachedGenerator;
double m_cachedAmplitude;
int m_cachedAttackMsec;
int m_cachedDecayMsec;
double m_cachedDecayRatio;
int m_cachedReleaseMsec;
double m_cachedFrequencyOfA;

Expand Down
22 changes: 9 additions & 13 deletions src/plugins/audioplugin/internal/settings/outputplaybackpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@
#include <SVSCraftWidgets/seekbar.h>
#include <SVSCraftCore/decibellinearizer.h>

#include <CoreApi/iloader.h>

#include <audioplugin/internal/audiosystem.h>
#include <audioplugin/internal/outputsystem.h>
#include <audioplugin/internal/devicetester.h>
#include <audioplugin/internal/vstconnectionsystem.h>
#include <audioplugin/internal/audiosettings.h>

namespace Audio::Internal {

Expand All @@ -49,6 +48,7 @@ namespace Audio::Internal {
}

class OutputPlaybackPageWidget : public QWidget {
Q_OBJECT
public:
explicit OutputPlaybackPageWidget(QWidget *parent = nullptr) : QWidget(parent) {
auto mainLayout = new QVBoxLayout;
Expand Down Expand Up @@ -173,10 +173,7 @@ namespace Audio::Internal {
updatePan(sliderValueToPan(value));
});

auto &settings = *Core::ILoader::instance()->settings();
auto obj = settings["Audio"].toObject();

m_fileBufferingReadAheadSizeSpinBox->setValue(obj["fileBufferingReadAheadSize"].toInt());
m_fileBufferingReadAheadSizeSpinBox->setValue(AudioSettings::fileBufferingReadAheadSize());
}

void accept() const {
Expand All @@ -185,12 +182,9 @@ namespace Audio::Internal {
m_hotPlugModeComboBox->currentIndex()));
AudioSystem::outputSystem()->setFileBufferingReadAheadSize(m_fileBufferingReadAheadSizeSpinBox->value());
AudioSystem::vstConnectionSystem()->setFileBufferingReadAheadSize(m_fileBufferingReadAheadSizeSpinBox->value());
auto &settings = *Core::ILoader::instance()->settings();
auto obj = settings["Audio"].toObject();
obj["deviceGain"] = AudioSystem::outputSystem()->outputContext()->controlMixer()->gain();
obj["devicePan"] = AudioSystem::outputSystem()->outputContext()->controlMixer()->pan();
obj["fileBufferingReadAheadSize"] = m_fileBufferingReadAheadSizeSpinBox->value();
settings["Audio"] = obj;
AudioSettings::setDeviceGain(AudioSystem::outputSystem()->outputContext()->controlMixer()->gain());
AudioSettings::setDevicePan(AudioSystem::outputSystem()->outputContext()->controlMixer()->pan());
AudioSettings::setFileBufferingReadAheadSize(m_fileBufferingReadAheadSizeSpinBox->value());
// TODO
}

Expand Down Expand Up @@ -390,4 +384,6 @@ namespace Audio::Internal {
AudioSystem::outputSystem()->outputContext()->controlMixer()->setPan(static_cast<float>(pan));
}

}
}

#include "outputplaybackpage.moc"
25 changes: 10 additions & 15 deletions src/plugins/audioplugin/internal/settings/vstmodepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <QGraphicsView>
#include <QColorDialog>
#include <QMessageBox>

#include <CoreApi/iloader.h>
#include <QJsonObject>

#include <SVSCraftWidgets/expressionspinbox.h>

Expand All @@ -27,6 +26,7 @@
#include <audioplugin/internal/audiosystem.h>
#include <audioplugin/internal/vstconnectionsystem.h>
#include <audioplugin/internal/devicetester.h>
#include <audioplugin/internal/audiosettings.h>

namespace Audio::Internal {

Expand Down Expand Up @@ -266,13 +266,11 @@ namespace Audio::Internal {
connect(customizeThemeButton, &QPushButton::clicked, m_customizeThemeDialog,
&CustomizeThemeDialog::exec);

auto &settings = *Core::ILoader::instance()->settings();
auto obj = settings["Audio"].toObject();
m_editorPortSpinBox->setValue(obj["vstEditorPort"].toInt(28081));
m_pluginPortSpinBox->setValue(obj["vstPluginPort"].toInt(28082));
m_editorPortSpinBox->setValue(AudioSettings::vstEditorPort());
m_pluginPortSpinBox->setValue(AudioSettings::vstPluginPort());
// TODO
m_pluginEditorUsesCustomThemeCheckBox->setChecked(obj["vstPluginEditorUsesCustomTheme"].toBool());
auto vstTheme = obj["vstTheme"].toObject();
m_pluginEditorUsesCustomThemeCheckBox->setChecked(AudioSettings::vstPluginEditorUsesCustomTheme());
auto vstTheme = AudioSettings::vstTheme().toObject();
if (vstTheme.contains("foreground"))
m_customizeThemeDialog->setComponentColor(CustomizeThemeDialog::Foreground, QColor(static_cast<QRgb>(vstTheme["foreground"].toInt())));
if (vstTheme.contains("foregroundBorder"))
Expand Down Expand Up @@ -352,11 +350,9 @@ namespace Audio::Internal {
bool VSTModePage::accept() {
if (!m_widget)
return true;
auto &settings = *Core::ILoader::instance()->settings();
auto obj = settings["Audio"].toObject();
obj["vstEditorPort"] = m_editorPortSpinBox->value();
obj["vstPluginPort"] = m_pluginPortSpinBox->value();
obj["vstTheme"] = QJsonObject({
AudioSettings::setVstEditorPort(m_editorPortSpinBox->value());
AudioSettings::setVstPluginPort(m_pluginPortSpinBox->value());
AudioSettings::setVstTheme(QJsonObject{
{"foreground",
static_cast<int>(
m_customizeThemeDialog->componentColor(CustomizeThemeDialog::Foreground).rgba())},
Expand Down Expand Up @@ -385,8 +381,7 @@ namespace Audio::Internal {
m_customizeThemeDialog->componentColor(CustomizeThemeDialog::BackgroundError)
.rgba()) },
});
obj["vstPluginEditorUsesCustomTheme"] = m_pluginEditorUsesCustomThemeCheckBox->isChecked();
settings["Audio"] = obj;
AudioSettings::setVstPluginEditorUsesCustomTheme(m_pluginEditorUsesCustomThemeCheckBox->isChecked());
VSTConnectionSystem::createVSTConfig();
// TODO
return true;
Expand Down
Loading

0 comments on commit 5cdb13e

Please sign in to comment.