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

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