Skip to content

Commit

Permalink
update audio plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
CrSjimo committed Aug 24, 2024
1 parent 4c39afb commit abf909f
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/plugins/audioplugin/internal/audioplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <audioplugin/internal/midisystem.h>
#include <audioplugin/internal/audioexportdialog.h>
#include <audioplugin/internal/pseudosingerpage.h>
#include <audioplugin/internal/audioexportpage.h>

namespace Audio::Internal {

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions src/plugins/audioplugin/internal/settings/audioexportpage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "audioexportpage.h"

#include <QCheckBox>
#include <QFormLayout>
#include <QThread>
#include <QLabel>

#include <SVSCraftWidgets/expressionspinbox.h>

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() {
}
}
31 changes: 31 additions & 0 deletions src/plugins/audioplugin/internal/settings/audioexportpage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef AUDIO_AUDIOEXPORTPAGE_H
#define AUDIO_AUDIOEXPORTPAGE_H

#include <QPointer>

#include <CoreApi/isettingpage.h>

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<AudioExportPageWidget> m_widget;
};

}

#endif // AUDIO_AUDIOEXPORTPAGE_H
2 changes: 1 addition & 1 deletion src/plugins/audioplugin/internal/settings/midipage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::of(&QDoubleSpinBox::valueChanged), this, [=](double value) {
d->m_mutex.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -249,6 +249,7 @@ namespace Audio::Internal {
return m_widget = new PseudoSingerPageWidget;
}
bool PseudoSingerPage::accept() {
m_widget->accept();
return true;
}
void PseudoSingerPage::finish() {
Expand Down
68 changes: 65 additions & 3 deletions src/plugins/audioplugin/internal/utils/settingpagesynthhelper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "settingpagesynthhelper.h"

#include <QComboBox>
#include <QRandomGenerator>

#include <TalcsCore/Decibels.h>
#include <TalcsMidi/MidiMessage.h>
Expand All @@ -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}},
Expand Down Expand Up @@ -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() {
Expand All @@ -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<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
m_cachedGenerator = index;
Expand Down Expand Up @@ -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);
Expand All @@ -135,6 +190,7 @@ namespace Audio::Internal {
}
if (m_currentScoreIndex == -1 && !isTestFinished) {
isTestFinished = true;
easterEggHelper.handlePreviewStopped();
emit testFinished();
return;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +42,8 @@ namespace Audio::Internal {
int m_currentScoreIndex = -1;
QAtomicInteger<bool> isTestFinished = true;

const talcs::NoteSynthesizerDetectorMessage *m_adoptedScores;

int m_cachedGenerator;
double m_cachedAmplitude;
int m_cachedAttackMsec;
Expand Down

0 comments on commit abf909f

Please sign in to comment.