Implemented midi buttons on loopstation page

This commit is contained in:
2022-12-28 01:34:16 +01:00
parent d3fd851d54
commit f80240847b
8 changed files with 141 additions and 38 deletions

View File

@ -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);
}

View File

@ -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);
};

View File

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

View File

@ -28,8 +28,6 @@ struct File
std::optional<QString> stopOnRelease;
std::optional<bool> looped;
std::optional<int> choke;
bool operator==(const File &other) const;
};
struct SequencePad

View File

@ -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()));
}
}

View File

@ -57,6 +57,9 @@
</item>
<item>
<widget class="QPushButton" name="pushButtonRefresh">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>32</width>
@ -113,6 +116,11 @@
</widget>
</widget>
<customwidgets>
<customwidget>
<class>MidiButton</class>
<extends>QPushButton</extends>
<header>widgets/midibutton.h</header>
</customwidget>
<customwidget>
<class>DrumPadSamplesWidget</class>
<extends>QWidget</extends>
@ -131,11 +139,6 @@
<header>widgets/sequencerwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>MidiButton</class>
<extends>QPushButton</extends>
<header>widgets/midibutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -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 &current)
@ -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)

View File

@ -51,7 +51,10 @@
</widget>
</item>
<item>
<widget class="MidiButton" name="pushButtonRefresh">
<widget class="QPushButton" name="pushButtonRefresh">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>32</width>