Implemented persisting of channel/note for each pad
This commit is contained in:
@ -15,6 +15,7 @@ SOURCES += \
|
||||
audioformat.cpp \
|
||||
audioplayer.cpp \
|
||||
djwidget.cpp \
|
||||
drummachinesettings.cpp \
|
||||
filesmodel.cpp \
|
||||
graphrenderer.cpp \
|
||||
jsonconverters.cpp \
|
||||
@ -39,6 +40,7 @@ HEADERS += \
|
||||
audioformat.h \
|
||||
audioplayer.h \
|
||||
djwidget.h \
|
||||
drummachinesettings.h \
|
||||
filesmodel.h \
|
||||
graphrenderer.h \
|
||||
jsonconverters.h \
|
||||
|
21
drummachinesettings.cpp
Normal file
21
drummachinesettings.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "drummachinesettings.h"
|
||||
|
||||
quint8 DrumMachineSettings::padChannel(quint8 pad) const
|
||||
{
|
||||
return value(QString{"pad%0/channel"}.arg(pad)).toUInt();
|
||||
}
|
||||
|
||||
void DrumMachineSettings::setPadChannel(quint8 pad, quint8 channel)
|
||||
{
|
||||
setValue(QString{"pad%0/channel"}.arg(pad), channel);
|
||||
}
|
||||
|
||||
quint8 DrumMachineSettings::padNote(quint8 pad) const
|
||||
{
|
||||
return value(QString{"pad%0/note"}.arg(pad)).toUInt();
|
||||
}
|
||||
|
||||
void DrumMachineSettings::setPadNote(quint8 pad, quint8 note)
|
||||
{
|
||||
setValue(QString{"pad%0/note"}.arg(pad), note);
|
||||
}
|
15
drummachinesettings.h
Normal file
15
drummachinesettings.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
class DrumMachineSettings : public QSettings
|
||||
{
|
||||
public:
|
||||
using QSettings::QSettings;
|
||||
|
||||
quint8 padChannel(quint8 pad) const;
|
||||
void setPadChannel(quint8 pad, quint8 channel);
|
||||
|
||||
quint8 padNote(quint8 pad) const;
|
||||
void setPadNote(quint8 pad, quint8 note);
|
||||
};
|
@ -101,6 +101,7 @@ MainWindow::MainWindow(const presets::PresetsConfig &presetsConfig, QWidget *par
|
||||
connect(m_ui->pushButtonAudioDevice, &QAbstractButton::pressed, this, &MainWindow::openAudioDevice);
|
||||
|
||||
m_presetsProxyModel.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
m_presetsProxyModel.setSortRole(Qt::EditRole);
|
||||
m_presetsProxyModel.setSourceModel(&m_presetsModel);
|
||||
m_ui->presetsView->setModel(&m_presetsProxyModel);
|
||||
|
||||
@ -111,6 +112,8 @@ MainWindow::MainWindow(const presets::PresetsConfig &presetsConfig, QWidget *par
|
||||
m_ui->filesView->setModel(&m_filesModel);
|
||||
|
||||
connect(m_ui->presetsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &MainWindow::currentRowChanged);
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -251,3 +254,9 @@ void MainWindow::updateAudioDevices()
|
||||
m_ui->comboBoxAudioDevice->addItem(info->name);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadSettings()
|
||||
{
|
||||
m_synthisizer.loadSettings(m_settings);
|
||||
m_ui->samplesWidget->loadSettings(m_settings);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "filesmodel.h"
|
||||
#include "midiinwrapper.h"
|
||||
#include "synthisizer.h"
|
||||
#include "drummachinesettings.h"
|
||||
|
||||
namespace Ui { class MainWindow; }
|
||||
namespace presets { struct PresetsConfig; }
|
||||
@ -38,9 +39,12 @@ private slots:
|
||||
private:
|
||||
void updateMidiDevices();
|
||||
void updateAudioDevices();
|
||||
void loadSettings();
|
||||
|
||||
const std::unique_ptr<Ui::MainWindow> m_ui;
|
||||
|
||||
DrumMachineSettings m_settings;
|
||||
|
||||
std::unique_ptr<PaStream, void(*)(PaStream*)> m_paStream;
|
||||
|
||||
MidiInWrapper m_midiIn;
|
||||
|
@ -140,7 +140,17 @@ QVariant PresetsModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
switch (index.column())
|
||||
{
|
||||
case ColumnId: return handleData(preset.id);
|
||||
case ColumnId:
|
||||
{
|
||||
if (preset.id)
|
||||
{
|
||||
bool ok;
|
||||
if (auto id = preset.id->toInt(&ok); ok)
|
||||
return id;
|
||||
}
|
||||
|
||||
return handleData(preset.id);
|
||||
}
|
||||
case ColumnName: return handleData(preset.name);
|
||||
case ColumnAuthor: return handleData(preset.author);
|
||||
case ColumnOrderBy: return handleData(preset.orderBy);
|
||||
|
@ -20,31 +20,23 @@ SamplesWidget::SamplesWidget(QWidget *parent) :
|
||||
|
||||
connect(m_ui->pushButtonStopAll, &QAbstractButton::pressed, this, &SamplesWidget::stopAll);
|
||||
|
||||
quint8 padNr{};
|
||||
for (SampleWidget &widget : getWidgets())
|
||||
{
|
||||
widget.setPadNr(padNr++);
|
||||
widget.injectNetworkAccessManager(m_networkAccessManager);
|
||||
connect(&widget, &SampleWidget::chokeTriggered, this, &SamplesWidget::chokeTriggered);
|
||||
}
|
||||
|
||||
m_ui->sampleWidget_1->setNote(48);
|
||||
m_ui->sampleWidget_2->setNote(50);
|
||||
m_ui->sampleWidget_3->setNote(52);
|
||||
m_ui->sampleWidget_4->setNote(53);
|
||||
m_ui->sampleWidget_5->setNote(55);
|
||||
m_ui->sampleWidget_6->setNote(57);
|
||||
m_ui->sampleWidget_7->setNote(59);
|
||||
m_ui->sampleWidget_8->setNote(60);
|
||||
m_ui->sampleWidget_9->setNote(62);
|
||||
m_ui->sampleWidget_10->setNote(64);
|
||||
m_ui->sampleWidget_11->setNote(65);
|
||||
m_ui->sampleWidget_12->setNote(67);
|
||||
m_ui->sampleWidget_22->setNote(69);
|
||||
m_ui->sampleWidget_23->setNote(71);
|
||||
m_ui->sampleWidget_24->setNote(72);
|
||||
}
|
||||
|
||||
SamplesWidget::~SamplesWidget() = default;
|
||||
|
||||
void SamplesWidget::loadSettings(DrumMachineSettings &settings)
|
||||
{
|
||||
for (SampleWidget &widget : getWidgets())
|
||||
widget.loadSettings(settings);
|
||||
}
|
||||
|
||||
void SamplesWidget::setPreset(const presets::Preset &preset)
|
||||
{
|
||||
m_preset = preset;
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace Ui { class SamplesWidget; }
|
||||
namespace midi { class MidiMessage; }
|
||||
class SampleWidget;
|
||||
class DrumMachineSettings;
|
||||
|
||||
class SamplesWidget : public QWidget
|
||||
{
|
||||
@ -23,6 +24,8 @@ public:
|
||||
explicit SamplesWidget(QWidget *parent = nullptr);
|
||||
~SamplesWidget() override;
|
||||
|
||||
void loadSettings(DrumMachineSettings &settings);
|
||||
|
||||
void setPreset(const presets::Preset &preset);
|
||||
|
||||
void messageReceived(const midi::MidiMessage &message);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "audiodecoder.h"
|
||||
#include "drummachinesettings.h"
|
||||
|
||||
namespace {
|
||||
QString toString(QString value) { return value; }
|
||||
@ -37,6 +38,14 @@ SampleWidget::SampleWidget(QWidget *parent) :
|
||||
|
||||
SampleWidget::~SampleWidget() = default;
|
||||
|
||||
void SampleWidget::loadSettings(DrumMachineSettings &settings)
|
||||
{
|
||||
m_ui->channelSpinBox->setValue(settings.padChannel(m_padNr));
|
||||
m_ui->noteSpinBox->setValue(settings.padNote(m_padNr));
|
||||
|
||||
m_settings = &settings;
|
||||
}
|
||||
|
||||
void SampleWidget::setFile(const QString &presetId, const presets::File &file)
|
||||
{
|
||||
m_presetId = presetId;
|
||||
@ -78,6 +87,9 @@ quint8 SampleWidget::channel() const
|
||||
void SampleWidget::setChannel(quint8 channel)
|
||||
{
|
||||
m_ui->channelSpinBox->setValue(channel);
|
||||
|
||||
if (m_settings)
|
||||
m_settings->setPadChannel(m_padNr, channel);
|
||||
}
|
||||
|
||||
quint8 SampleWidget::note() const
|
||||
@ -88,6 +100,9 @@ quint8 SampleWidget::note() const
|
||||
void SampleWidget::setNote(quint8 note)
|
||||
{
|
||||
m_ui->noteSpinBox->setValue(note);
|
||||
|
||||
if (m_settings)
|
||||
m_settings->setPadNote(m_padNr, note);
|
||||
}
|
||||
|
||||
int SampleWidget::speed() const
|
||||
|
@ -13,6 +13,7 @@ class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class QAudioBuffer;
|
||||
class AudioDecoder;
|
||||
class DrumMachineSettings;
|
||||
|
||||
class SampleWidget : public QFrame
|
||||
{
|
||||
@ -22,6 +23,11 @@ public:
|
||||
explicit SampleWidget(QWidget *parent = nullptr);
|
||||
~SampleWidget() override;
|
||||
|
||||
quint8 padNr() const { return m_padNr; }
|
||||
void setPadNr(quint8 padNr) { m_padNr = padNr; }
|
||||
|
||||
void loadSettings(DrumMachineSettings &settings);
|
||||
|
||||
void setFile(const QString &presetId, const presets::File &file);
|
||||
|
||||
quint8 channel() const;
|
||||
@ -66,6 +72,8 @@ private:
|
||||
|
||||
const std::unique_ptr<Ui::SampleWidget> m_ui;
|
||||
|
||||
DrumMachineSettings *m_settings{};
|
||||
|
||||
std::shared_ptr<QNetworkReply> m_reply;
|
||||
|
||||
std::unique_ptr<AudioDecoder> m_decoder;
|
||||
@ -77,6 +85,8 @@ private:
|
||||
|
||||
QNetworkAccessManager *m_networkAccessManager{};
|
||||
|
||||
quint8 m_padNr{};
|
||||
|
||||
bool m_learning{};
|
||||
QColor m_oldColor;
|
||||
QBrush m_oldBrush;
|
||||
|
@ -6,6 +6,10 @@
|
||||
|
||||
constexpr double pi = std::acos(-1);
|
||||
|
||||
void Synthisizer::loadSettings(const DrumMachineSettings &settings)
|
||||
{
|
||||
}
|
||||
|
||||
void Synthisizer::writeSamples(frame_t *begin, frame_t *end)
|
||||
{
|
||||
const auto frequency = m_frequency;
|
||||
|
@ -4,9 +4,13 @@
|
||||
|
||||
namespace midi { class MidiMessage; }
|
||||
|
||||
class DrumMachineSettings;
|
||||
|
||||
class Synthisizer
|
||||
{
|
||||
public:
|
||||
void loadSettings(const DrumMachineSettings &settings);
|
||||
|
||||
void setFrequency(int16_t frequency) { m_frequency = frequency; }
|
||||
|
||||
void writeSamples(frame_t *begin, frame_t *end);
|
||||
|
Reference in New Issue
Block a user