From abf909f9616ee8e2c7b7ebed27d69fc990a5579c Mon Sep 17 00:00:00 2001 From: CrSjimo Date: Sun, 25 Aug 2024 00:20:36 +0800 Subject: [PATCH] update audio plugin --- libs/talcs | 2 +- .../audioplugin/internal/audioplugin.cpp | 2 + .../internal/dialogs/audioexportdialog.cpp | 2 +- .../internal/settings/audioexportpage.cpp | 58 ++++++++++++++++ .../internal/settings/audioexportpage.h | 31 +++++++++ .../internal/settings/midipage.cpp | 2 +- .../internal/settings/pseudosingerpage.cpp | 3 +- .../internal/utils/settingpagesynthhelper.cpp | 68 ++++++++++++++++++- .../internal/utils/settingpagesynthhelper.h | 4 +- 9 files changed, 164 insertions(+), 8 deletions(-) create mode 100644 src/plugins/audioplugin/internal/settings/audioexportpage.cpp create mode 100644 src/plugins/audioplugin/internal/settings/audioexportpage.h diff --git a/libs/talcs b/libs/talcs index 8f104d4..c6d43a5 160000 --- a/libs/talcs +++ b/libs/talcs @@ -1 +1 @@ -Subproject commit 8f104d4f4910a72ab675cc6b000a59ef20044586 +Subproject commit c6d43a5f0b26a6b4851a7722f67c7aeaab98aad5 diff --git a/src/plugins/audioplugin/internal/audioplugin.cpp b/src/plugins/audioplugin/internal/audioplugin.cpp index b810512..ce71923 100644 --- a/src/plugins/audioplugin/internal/audioplugin.cpp +++ b/src/plugins/audioplugin/internal/audioplugin.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace Audio::Internal { @@ -57,6 +58,7 @@ namespace Audio::Internal { audioPage->addPage(new OutputPlaybackPage); audioPage->addPage(new VSTModePage); audioPage->addPage(new MIDIPage); + audioPage->addPage(new AudioExportPage); sc->addPage(audioPage); sc->addPage(new PseudoSingerPage); // TODO diff --git a/src/plugins/audioplugin/internal/dialogs/audioexportdialog.cpp b/src/plugins/audioplugin/internal/dialogs/audioexportdialog.cpp index 42a947d..f0b8473 100644 --- a/src/plugins/audioplugin/internal/dialogs/audioexportdialog.cpp +++ b/src/plugins/audioplugin/internal/dialogs/audioexportdialog.cpp @@ -35,7 +35,7 @@ namespace Audio::Internal { presetLayout->addRow(presetLabel, presetOptionLayout); mainLayout->addLayout(presetLayout); - auto mainOptionsLayout = new QHBoxLayout; + auto mainOptionsLayout = new QVBoxLayout; auto leftLayout = new QVBoxLayout; auto rightLayout = new QVBoxLayout; diff --git a/src/plugins/audioplugin/internal/settings/audioexportpage.cpp b/src/plugins/audioplugin/internal/settings/audioexportpage.cpp new file mode 100644 index 0000000..3db6a38 --- /dev/null +++ b/src/plugins/audioplugin/internal/settings/audioexportpage.cpp @@ -0,0 +1,58 @@ +#include "audioexportpage.h" + +#include +#include +#include +#include + +#include + +namespace Audio::Internal { + + class AudioExportPageWidget : public QWidget { + public: + explicit AudioExportPageWidget(QWidget *parent = nullptr) : QWidget(parent) { + auto mainLayout = new QFormLayout; + auto enableClippingCheckCheckBox = new QCheckBox(tr("Enable &clipping check")); + mainLayout->addRow(enableClippingCheckCheckBox); + auto threadLayout = new QVBoxLayout; + auto threadCountSpinBox = new SVS::ExpressionSpinBox; + threadCountSpinBox->setRange(1, QThread::idealThreadCount()); + threadLayout->addWidget(threadCountSpinBox); + auto multiThreadLabel = new QLabel(tr("Audio exporting will be multi-threaded when the mixing option is \"separated\".")); + multiThreadLabel->setWordWrap(true); + threadLayout->addWidget(multiThreadLabel); + auto threadLayoutLabel = new QLabel(tr("Number of &threads for exporting")); + threadLayoutLabel->setBuddy(threadCountSpinBox); + mainLayout->addRow(threadLayoutLabel, threadLayout); + setLayout(mainLayout); + } + + void accept() { + + } + }; + + AudioExportPage::AudioExportPage(QObject *parent) : Core::ISettingPage("audio.AudioExport", parent) { + setTitle([] { return tr("Audio Export"); }); + setDescription([] { return tr("Configure audio export preferences."); }); + } + + AudioExportPage::~AudioExportPage() = default; + + QString AudioExportPage::sortKeyword() const { + return QStringLiteral("AudioExport"); + } + + QWidget *AudioExportPage::widget() { + if (m_widget) + return m_widget; + return m_widget = new AudioExportPageWidget; + } + bool AudioExportPage::accept() { + m_widget->accept(); + return true; + } + void AudioExportPage::finish() { + } +} \ No newline at end of file diff --git a/src/plugins/audioplugin/internal/settings/audioexportpage.h b/src/plugins/audioplugin/internal/settings/audioexportpage.h new file mode 100644 index 0000000..51d587a --- /dev/null +++ b/src/plugins/audioplugin/internal/settings/audioexportpage.h @@ -0,0 +1,31 @@ +#ifndef AUDIO_AUDIOEXPORTPAGE_H +#define AUDIO_AUDIOEXPORTPAGE_H + +#include + +#include + +namespace Audio::Internal { + + class AudioExportPageWidget; + + class AudioExportPage : public Core::ISettingPage { + Q_OBJECT + public: + explicit AudioExportPage(QObject *parent = nullptr); + ~AudioExportPage() override; + + QString sortKeyword() const override; + + QWidget *widget() override; + + bool accept() override; + void finish() override; + + private: + QPointer m_widget; + }; + +} + +#endif // AUDIO_AUDIOEXPORTPAGE_H diff --git a/src/plugins/audioplugin/internal/settings/midipage.cpp b/src/plugins/audioplugin/internal/settings/midipage.cpp index fef952f..fae5ad8 100644 --- a/src/plugins/audioplugin/internal/settings/midipage.cpp +++ b/src/plugins/audioplugin/internal/settings/midipage.cpp @@ -182,7 +182,7 @@ namespace Audio::Internal { d->m_cachedReleaseMsec = ms->releaseMsec(); d->m_cachedFrequencyOfA = ms->frequencyOfA(); - d->initialize(generatorComboBox, amplitudeSlider, amplitudeSpinBox, attackSlider, attackSpinBox, decaySlider, decaySpinBox, decayRatioSlider, decayRatioSpinBox, releaseSlider, releaseSpinBox); + d->initialize(generatorComboBox, amplitudeSlider, amplitudeSpinBox, attackSlider, attackSpinBox, decaySlider, decaySpinBox, decayRatioSlider, decayRatioSpinBox, releaseSlider, releaseSpinBox, synthesizerTestButton); connect(frequencyOfASpinBox, QOverload::of(&QDoubleSpinBox::valueChanged), this, [=](double value) { d->m_mutex.lock(); diff --git a/src/plugins/audioplugin/internal/settings/pseudosingerpage.cpp b/src/plugins/audioplugin/internal/settings/pseudosingerpage.cpp index 5489527..8091aea 100644 --- a/src/plugins/audioplugin/internal/settings/pseudosingerpage.cpp +++ b/src/plugins/audioplugin/internal/settings/pseudosingerpage.cpp @@ -158,7 +158,7 @@ namespace Audio::Internal { d->initialize(generatorComboBox, amplitudeSlider, amplitudeSpinBox, attackSlider, attackSpinBox, decaySlider, decaySpinBox, decayRatioSlider, - decayRatioSpinBox, releaseSlider, releaseSpinBox); + decayRatioSpinBox, releaseSlider, releaseSpinBox, synthesizerTestButton); connect(synthesizerTestButton, &QAbstractButton::clicked, this, [=](bool checked) { if (checked) { @@ -249,6 +249,7 @@ namespace Audio::Internal { return m_widget = new PseudoSingerPageWidget; } bool PseudoSingerPage::accept() { + m_widget->accept(); return true; } void PseudoSingerPage::finish() { diff --git a/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.cpp b/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.cpp index b60f5de..8326d83 100644 --- a/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.cpp +++ b/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.cpp @@ -1,6 +1,7 @@ #include "settingpagesynthhelper.h" #include +#include #include #include @@ -16,6 +17,23 @@ namespace Audio::Internal { + static struct { + bool hit = false; + bool enabled = false; + + void handlePreviewStarted() { + if (hit) { + enabled = !enabled; + } else { + hit = true; + } + } + + void handlePreviewStopped() { + hit = false; + } + } easterEggHelper; + static talcs::NoteSynthesizerDetectorMessage scores[] = { {0, {47, .5, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, {0, {75, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, @@ -49,7 +67,36 @@ namespace Audio::Internal { talcs::NoteSynthesizerDetectorMessage::Null, }; - SettingPageSynthHelper::SettingPageSynthHelper(QObject *parent) : QObject(parent) { + static talcs::NoteSynthesizerDetectorMessage alternativeScores[] = { + {0, {59, .3, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {0, {66, .3, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {0, {75, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {4, {75, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {4, {73, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {6, {73, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {6, {71, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {10, {71, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {10, {73, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {12, {73, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {12, {59, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {12, {66, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + + {12, {52, .3, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {12, {59, .3, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {12, {75, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {15, {75, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {15, {76, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {16, {76, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {16, {75, .7, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {18, {75, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {18, {73, 1, talcs::NoteSynthesizerDetectorMessage::NoteOn}}, + {24, {73, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {24, {52, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + {24, {59, talcs::NoteSynthesizerDetectorMessage::NoteOff}}, + talcs::NoteSynthesizerDetectorMessage::Null, + }; + + SettingPageSynthHelper::SettingPageSynthHelper(QObject *parent) : QObject(parent), m_adoptedScores(scores) { } SettingPageSynthHelper::~SettingPageSynthHelper() { @@ -62,7 +109,7 @@ namespace Audio::Internal { SVS::ExpressionSpinBox *attackSpinBox, SVS::SeekBar *decaySlider, SVS::ExpressionSpinBox *decaySpinBox, SVS::SeekBar *decayRatioSlider, SVS::ExpressionDoubleSpinBox *decayRatioSpinBox, SVS::SeekBar *releaseSlider, - SVS::ExpressionSpinBox *releaseSpinBox) { + SVS::ExpressionSpinBox *releaseSpinBox, QWidget *previewButton) { connect(generatorComboBox, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { m_cachedGenerator = index; @@ -126,6 +173,14 @@ namespace Audio::Internal { m_testSynthesizer.setDecayTime(AudioHelpers::msecToSample(m_cachedDecayMsec, m_testSynthesizer.sampleRate())); m_testSynthesizer.setDecayRatio(m_cachedDecayRatio); m_testSynthesizer.setReleaseTime(AudioHelpers::msecToSample(m_cachedReleaseMsec, m_testSynthesizer.sampleRate())); + + connect(this, &SettingPageSynthHelper::testFinished, previewButton, [=] { + if (easterEggHelper.enabled) { + previewButton->setToolTip(tr("Why did you play ...?!")); + } else { + previewButton->setToolTip({}); + } + }); } void SettingPageSynthHelper::detectInterval(qint64 intervalLength) { QMutexLocker locker(&m_mutex); @@ -135,6 +190,7 @@ namespace Audio::Internal { } if (m_currentScoreIndex == -1 && !isTestFinished) { isTestFinished = true; + easterEggHelper.handlePreviewStopped(); emit testFinished(); return; } @@ -149,7 +205,7 @@ namespace Audio::Internal { } else if (m_currentScoreIndex < 0) { return talcs::NoteSynthesizerDetectorMessage::Null; } - auto message = scores[m_currentScoreIndex]; + auto message = m_adoptedScores[m_currentScoreIndex]; if (message.position == -1) { m_currentScoreIndex = -1; return talcs::NoteSynthesizerDetectorMessage::Null; @@ -165,6 +221,12 @@ namespace Audio::Internal { void SettingPageSynthHelper::toggleTestState(bool enabled) { QMutexLocker locker(&m_mutex); if (enabled) { + if (easterEggHelper.enabled) { + m_adoptedScores = QRandomGenerator::global()->bounded(0, 2) ? scores : alternativeScores; + } else { + m_adoptedScores = scores; + } + easterEggHelper.handlePreviewStarted(); isTestFinished = false; m_currentPosition = 0; m_currentScoreIndex = 0; diff --git a/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.h b/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.h index 3207ab5..5b90f1a 100644 --- a/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.h +++ b/src/plugins/audioplugin/internal/utils/settingpagesynthhelper.h @@ -26,7 +26,7 @@ namespace Audio::Internal { SVS::ExpressionSpinBox *attackSpinBox, SVS::SeekBar *decaySlider, SVS::ExpressionSpinBox *decaySpinBox, SVS::SeekBar *decayRatioSlider, SVS::ExpressionDoubleSpinBox *decayRatioSpinBox, - SVS::SeekBar *releaseSlider, SVS::ExpressionSpinBox *releaseSpinBox); + SVS::SeekBar *releaseSlider, SVS::ExpressionSpinBox *releaseSpinBox, QWidget *previewButton); void detectInterval(qint64 intervalLength) override; talcs::NoteSynthesizerDetectorMessage nextMessage() override; @@ -42,6 +42,8 @@ namespace Audio::Internal { int m_currentScoreIndex = -1; QAtomicInteger isTestFinished = true; + const talcs::NoteSynthesizerDetectorMessage *m_adoptedScores; + int m_cachedGenerator; double m_cachedAmplitude; int m_cachedAttackMsec;