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