diff --git a/drummachinesettings.cpp b/drummachinesettings.cpp index 41fdbe8..9885173 100644 --- a/drummachinesettings.cpp +++ b/drummachinesettings.cpp @@ -232,3 +232,43 @@ void DrumMachineSettings::setLoopstationLastPresetId(const QString &lastPresetId { setValue("loopstation/lastPresetId", lastPresetId); } + +quint8 DrumMachineSettings::loopstationChannelPrevPreset() const +{ + return value("loopstation/prevPreset_channel", 99).toUInt(); +} + +void DrumMachineSettings::setLoopstationChannelPrevPreset(quint8 channel) +{ + setValue("loopstation/prevPreset_channel", channel); +} + +quint8 DrumMachineSettings::loopstationNotePrevPreset() const +{ + return value("loopstation/prevPreset_note", 99).toUInt(); +} + +void DrumMachineSettings::setLoopstationNotePrevPreset(quint8 note) +{ + setValue("loopstation/prevPreset_note", note); +} + +quint8 DrumMachineSettings::loopstationChannelNextPreset() const +{ + return value("loopstation/nextPreset_channel", 99).toUInt(); +} + +void DrumMachineSettings::setLoopstationChannelNextPreset(quint8 channel) +{ + setValue("loopstation/nextPreset_channel", channel); +} + +quint8 DrumMachineSettings::loopstationNoteNextPreset() const +{ + return value("loopstation/nextPreset_note", 99).toUInt(); +} + +void DrumMachineSettings::setLoopstationNoteNextPreset(quint8 note) +{ + setValue("loopstation/nextPreset_note", note); +} diff --git a/drummachinesettings.h b/drummachinesettings.h index 0ff8603..d1d7f89 100644 --- a/drummachinesettings.h +++ b/drummachinesettings.h @@ -71,4 +71,14 @@ public: QString loopstationLastPresetId() const; void setLoopstationLastPresetId(const QString &lastPresetId); + + quint8 loopstationChannelPrevPreset() const; + void setLoopstationChannelPrevPreset(quint8 channel); + quint8 loopstationNotePrevPreset() const; + void setLoopstationNotePrevPreset(quint8 note); + + quint8 loopstationChannelNextPreset() const; + void setLoopstationChannelNextPreset(quint8 channel); + quint8 loopstationNoteNextPreset() const; + void setLoopstationNoteNextPreset(quint8 note); }; diff --git a/drumpadpresets.cpp b/drumpadpresets.cpp index d5208e6..2055c68 100755 --- a/drumpadpresets.cpp +++ b/drumpadpresets.cpp @@ -1,14 +1 @@ #include "drumpadpresets.h" - -namespace drumpad_presets { - -bool File::operator==(const File &other) const -{ - return filename == other.filename && - color == other.color && - stopOnRelease == other.stopOnRelease && - looped == other.looped && - choke == other.choke; -} - -} // namespace drumpad_presets diff --git a/drumpadpresets.h b/drumpadpresets.h index 095dd3d..07ca54b 100755 --- a/drumpadpresets.h +++ b/drumpadpresets.h @@ -28,8 +28,6 @@ struct File std::optional stopOnRelease; std::optional looped; std::optional choke; - - bool operator==(const File &other) const; }; struct SequencePad diff --git a/widgets/drumpadwidget.cpp b/widgets/drumpadwidget.cpp index f5124a7..3e27360 100644 --- a/widgets/drumpadwidget.cpp +++ b/widgets/drumpadwidget.cpp @@ -179,15 +179,14 @@ void DrumPadWidget::requestFinished() return; } - auto reply = std::move(m_reply); - if (reply->error() != QNetworkReply::NoError) - { - QMessageBox::warning(this, tr("Could not load presets!"), tr("Could not load presets!") + "\n\n" + reply->errorString()); - return; - } + m_ui->pushButtonRefresh->setEnabled(true); + auto reply = std::move(m_reply); try { + if (reply->error() != QNetworkReply::NoError) + throw std::runtime_error{QString{"request failed: %0"}.arg(reply->errorString()).toStdString()}; + auto result = json_converters::drumpad::parsePresetsConfig(json_converters::loadJson(reply->readAll())); if (!result.presets) @@ -218,7 +217,7 @@ noLastId: } catch (const std::exception &e) { - QMessageBox::warning(this, tr("error"), tr("error") + "\n\n" + QString::fromStdString(e.what())); + QMessageBox::warning(this, tr("Could not load presets!"), tr("Could not load presets!") + "\n\n" + QString::fromStdString(e.what())); } } diff --git a/widgets/drumpadwidget.ui b/widgets/drumpadwidget.ui index e2dd06a..b318f3b 100644 --- a/widgets/drumpadwidget.ui +++ b/widgets/drumpadwidget.ui @@ -57,6 +57,9 @@ + + false + 32 @@ -113,6 +116,11 @@ + + MidiButton + QPushButton +
widgets/midibutton.h
+
DrumPadSamplesWidget QWidget @@ -131,11 +139,6 @@
widgets/sequencerwidget.h
1
- - MidiButton - QPushButton -
widgets/midibutton.h
-
diff --git a/widgets/loopstationwidget.cpp b/widgets/loopstationwidget.cpp index a76e5c3..1815e29 100644 --- a/widgets/loopstationwidget.cpp +++ b/widgets/loopstationwidget.cpp @@ -56,21 +56,60 @@ void LoopStationWidget::injectDecodingThread(QThread &thread) void LoopStationWidget::loadSettings(DrumMachineSettings &settings) { m_settings = &settings; + + m_ui->pushButtonUp->setChannel(m_settings->loopstationChannelPrevPreset()); + m_ui->pushButtonUp->setNote(m_settings->loopstationNotePrevPreset()); + m_ui->pushButtonDown->setChannel(m_settings->loopstationChannelNextPreset()); + m_ui->pushButtonDown->setNote(m_settings->loopstationNoteNextPreset()); + + connect(m_ui->pushButtonUp, &MidiButton::channelChanged, m_settings, &DrumMachineSettings::setLoopstationChannelPrevPreset); + connect(m_ui->pushButtonUp, &MidiButton::noteChanged, m_settings, &DrumMachineSettings::setLoopstationNotePrevPreset); + connect(m_ui->pushButtonDown, &MidiButton::channelChanged, m_settings, &DrumMachineSettings::setLoopstationChannelNextPreset); + connect(m_ui->pushButtonDown, &MidiButton::noteChanged, m_settings, &DrumMachineSettings::setLoopstationNoteNextPreset); } void LoopStationWidget::unsendColors() { - + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonUp->channel(), + .cmd = midi::Command::NoteOn, + .flag = true, + .note = m_ui->pushButtonUp->note(), + .velocity = 0 + }); + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonDown->channel(), + .cmd = midi::Command::NoteOn, + .flag = true, + .note = m_ui->pushButtonDown->note(), + .velocity = 0 + }); } void LoopStationWidget::sendColors() { - + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonUp->channel(), + .cmd = midi::Command::NoteOn, + .flag = true, + .note = m_ui->pushButtonUp->note(), + .velocity = 127 + }); + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonDown->channel(), + .cmd = midi::Command::NoteOn, + .flag = true, + .note = m_ui->pushButtonDown->note(), + .velocity = 127 + }); } void LoopStationWidget::midiReceived(const midi::MidiMessage &message) { - Q_UNUSED(message); + m_ui->pushButtonUp->midiReceived(message); + m_ui->pushButtonDown->midiReceived(message); + + // TODO } void LoopStationWidget::currentRowChanged(const QModelIndex ¤t) @@ -120,15 +159,14 @@ void LoopStationWidget::requestFinished() return; } - auto reply = std::move(m_reply); - if (reply->error() != QNetworkReply::NoError) - { - QMessageBox::warning(this, tr("Could not load presets!"), tr("Could not load presets!") + "\n\n" + reply->errorString()); - return; - } + m_ui->pushButtonRefresh->setEnabled(true); + auto reply = std::move(m_reply); try { + if (reply->error() != QNetworkReply::NoError) + throw std::runtime_error{QString{"request failed: %0"}.arg(reply->errorString()).toStdString()}; + auto result = json_converters::loopstation::parsePresetsConfig(json_converters::loadJson(reply->readAll())); if (!result.presets) @@ -159,23 +197,48 @@ noLastId: } catch (const std::exception &e) { - QMessageBox::warning(this, tr("error"), tr("error") + "\n\n" + QString::fromStdString(e.what())); + QMessageBox::warning(this, tr("Could not load presets!"), tr("Could not load presets!") + "\n\n" + QString::fromStdString(e.what())); } } void LoopStationWidget::selectFirstPreset() { + if (!m_presetsProxyModel.rowCount()) + return; + selectIndex(m_presetsProxyModel.index(0, 0)); } void LoopStationWidget::selectPrevPreset() { + if (!m_presetsProxyModel.rowCount()) + return; + const auto index = m_ui->presetsView->selectionModel()->currentIndex(); + if (!index.isValid()) + { + qWarning() << "invalid index"; + return; + } + + if (index.row() > 0) + selectIndex(m_presetsProxyModel.index(index.row() - 1, 0)); } void LoopStationWidget::selectNextPreset() { + if (!m_presetsProxyModel.rowCount()) + return; + const auto index = m_ui->presetsView->selectionModel()->currentIndex(); + if (!index.isValid()) + { + qWarning() << "invalid index"; + return; + } + + if (index.row() + 1 < m_presetsProxyModel.rowCount()) + selectIndex(m_presetsProxyModel.index(index.row() + 1, 0)); } void LoopStationWidget::selectIndex(const QModelIndex &index) diff --git a/widgets/loopstationwidget.ui b/widgets/loopstationwidget.ui index c8704bd..929dd1a 100644 --- a/widgets/loopstationwidget.ui +++ b/widgets/loopstationwidget.ui @@ -51,7 +51,10 @@
- + + + false + 32