Implemented parsing of loop station presets
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "audioformat.h"
|
||||
#include "midicontainers.h"
|
||||
#include "jsonconverters.h"
|
||||
#include "drumpadjsonconverters.h"
|
||||
#include "drummachinesettings.h"
|
||||
|
||||
DrumPadWidget::DrumPadWidget(QWidget *parent) :
|
||||
@@ -19,6 +20,7 @@ DrumPadWidget::DrumPadWidget(QWidget *parent) :
|
||||
|
||||
connect(m_ui->pushButtonUp, &QAbstractButton::pressed, this, &DrumPadWidget::selectPrevPreset);
|
||||
connect(m_ui->pushButtonDown, &QAbstractButton::pressed, this, &DrumPadWidget::selectNextPreset);
|
||||
connect(m_ui->pushButtonRefresh, &QAbstractButton::pressed, this, &DrumPadWidget::loadPresets);
|
||||
|
||||
connect(m_ui->sequencerWidget, &SequencerWidget::sendMidi, this, &DrumPadWidget::sendMidi);
|
||||
connect(m_ui->samplesWidget, &SamplesWidget::sendMidi, this, &DrumPadWidget::sendMidi);
|
||||
@@ -37,8 +39,6 @@ DrumPadWidget::DrumPadWidget(QWidget *parent) :
|
||||
m_ui->filesView->setModel(&m_filesModel);
|
||||
|
||||
connect(m_ui->presetsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &DrumPadWidget::currentRowChanged);
|
||||
|
||||
connect(m_ui->pushButtonRefresh, &QAbstractButton::pressed, this, &DrumPadWidget::loadPresets);
|
||||
}
|
||||
|
||||
DrumPadWidget::~DrumPadWidget() = default;
|
||||
@@ -182,7 +182,7 @@ void DrumPadWidget::requestFinished()
|
||||
|
||||
try
|
||||
{
|
||||
auto result = json_converters::parseDrumPadPresetsConfig(json_converters::loadJson(reply->readAll()));
|
||||
auto result = json_converters::drumpad::parsePresetsConfig(json_converters::loadJson(reply->readAll()));
|
||||
|
||||
if (!result.presets)
|
||||
throw std::runtime_error("presets missing in response");
|
||||
|
@@ -21,7 +21,7 @@
|
||||
<item>
|
||||
<layout class="QVBoxLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<layout class="QHBoxLayout" stretch="1,0,0,0">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="clearButtonEnabled">
|
||||
|
@@ -1,13 +1,26 @@
|
||||
#include "loopstationwidget.h"
|
||||
#include "ui_loopstationwidget.h"
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "audioformat.h"
|
||||
#include "midicontainers.h"
|
||||
#include "jsonconverters.h"
|
||||
#include "loopstationjsonconverters.h"
|
||||
#include "drummachinesettings.h"
|
||||
|
||||
LoopStationWidget::LoopStationWidget(QWidget *parent) :
|
||||
QWidget{parent},
|
||||
QSplitter{parent},
|
||||
m_ui{std::make_unique<Ui::LoopStationWidget>()}
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
connect(m_ui->pushButtonUp, &QAbstractButton::pressed, this, &LoopStationWidget::selectPrevPreset);
|
||||
connect(m_ui->pushButtonDown, &QAbstractButton::pressed, this, &LoopStationWidget::selectNextPreset);
|
||||
connect(m_ui->pushButtonRefresh, &QAbstractButton::pressed, this, &LoopStationWidget::loadPresets);
|
||||
}
|
||||
|
||||
LoopStationWidget::~LoopStationWidget() = default;
|
||||
@@ -19,7 +32,8 @@ void LoopStationWidget::writeSamples(frame_t *begin, frame_t *end)
|
||||
|
||||
void LoopStationWidget::injectNetworkAccessManager(QNetworkAccessManager &networkAccessManager)
|
||||
{
|
||||
|
||||
m_networkAccessManager = &networkAccessManager;
|
||||
loadPresets();
|
||||
}
|
||||
|
||||
void LoopStationWidget::injectDecodingThread(QThread &thread)
|
||||
@@ -46,3 +60,66 @@ void LoopStationWidget::midiReceived(const midi::MidiMessage &message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LoopStationWidget::loadPresets()
|
||||
{
|
||||
if (!m_networkAccessManager)
|
||||
{
|
||||
qWarning() << "no network access manager available";
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui->pushButtonRefresh->setEnabled(false);
|
||||
|
||||
QNetworkRequest request{QUrl{"https://brunner.ninja/komposthaufen/groovepad/presets_config_v2.json"}};
|
||||
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
|
||||
request.setAttribute(QNetworkRequest::CacheSaveControlAttribute, true);
|
||||
|
||||
m_reply = std::unique_ptr<QNetworkReply>(m_networkAccessManager->get(request));
|
||||
connect(m_reply.get(), &QNetworkReply::finished, this, &LoopStationWidget::requestFinished);
|
||||
}
|
||||
|
||||
void LoopStationWidget::requestFinished()
|
||||
{
|
||||
if (!m_reply)
|
||||
{
|
||||
qWarning() << "no valid reply";
|
||||
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;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
auto result = json_converters::loopstation::parsePresetsConfig(json_converters::loadJson(reply->readAll()));
|
||||
|
||||
if (!result.presets)
|
||||
throw std::runtime_error("presets missing in response");
|
||||
|
||||
// TODO
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
QMessageBox::warning(this, tr("error"), tr("error") + "\n\n" + QString::fromStdString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void LoopStationWidget::selectFirstPreset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LoopStationWidget::selectPrevPreset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LoopStationWidget::selectNextPreset()
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QSplitter>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Ui { class LoopStationWidget; }
|
||||
namespace midi { struct MidiMessage; }
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
class DrumMachineSettings;
|
||||
struct frame_t;
|
||||
|
||||
class LoopStationWidget : public QWidget
|
||||
class LoopStationWidget : public QSplitter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -31,6 +32,17 @@ signals:
|
||||
public slots:
|
||||
void midiReceived(const midi::MidiMessage &message);
|
||||
|
||||
private slots:
|
||||
void loadPresets();
|
||||
void requestFinished();
|
||||
void selectFirstPreset();
|
||||
void selectPrevPreset();
|
||||
void selectNextPreset();
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Ui::LoopStationWidget> m_ui;
|
||||
|
||||
QNetworkAccessManager *m_networkAccessManager{};
|
||||
|
||||
std::unique_ptr<QNetworkReply> m_reply;
|
||||
};
|
||||
|
@@ -1,29 +1,98 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LoopStationWidget</class>
|
||||
<widget class="QWidget" name="LoopStationWidget">
|
||||
<widget class="QSplitter" name="LoopStationWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>1014</width>
|
||||
<height>442</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>50</y>
|
||||
<width>261</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hier könnte ihre LoopStation stehen.</string>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,0,0">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="clearButtonEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MidiButton" name="pushButtonUp">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>⬆</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MidiButton" name="pushButtonDown">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>⬇</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MidiButton" name="pushButtonRefresh">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>↻</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>261</width>
|
||||
<height>18</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hier könnte ihre LoopStation stehen.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MidiButton</class>
|
||||
<extends>QPushButton</extends>
|
||||
<header>widgets/midibutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Reference in New Issue
Block a user