diff --git a/DrumMachine.pro b/DrumMachine.pro index ad42e0a..ddfed8d 100755 --- a/DrumMachine.pro +++ b/DrumMachine.pro @@ -40,6 +40,7 @@ SOURCES += \ widgets/samplewidget.cpp \ widgets/scratchwidget.cpp \ widgets/sequencerwidget.cpp \ + widgets/settingsdialog.cpp \ widgets/synthisizerwidget.cpp \ widgets/trackdeck.cpp @@ -72,6 +73,7 @@ HEADERS += \ widgets/samplewidget.h \ widgets/scratchwidget.h \ widgets/sequencerwidget.h \ + widgets/settingsdialog.h \ widgets/synthisizerwidget.h \ widgets/trackdeck.h @@ -84,5 +86,6 @@ FORMS += \ widgets/sampleswidget.ui \ widgets/samplewidget.ui \ widgets/sequencerwidget.ui \ + widgets/settingsdialog.ui \ widgets/synthisizerwidget.ui \ widgets/trackdeck.ui diff --git a/drummachinesettings.cpp b/drummachinesettings.cpp index 4ed2cf8..416c85c 100644 --- a/drummachinesettings.cpp +++ b/drummachinesettings.cpp @@ -1,5 +1,38 @@ #include "drummachinesettings.h" +#include +#include + +QString DrumMachineSettings::defaultCacheDir() const +{ + return QStandardPaths::writableLocation(QStandardPaths::CacheLocation); +} + +QString DrumMachineSettings::cacheDir() const +{ + return value("cacheDir", defaultCacheDir()).toString(); +} + +void DrumMachineSettings::setCacheDir(const QString &cacheDir) +{ + setValue("cacheDir", cacheDir); +} + +qint64 DrumMachineSettings::defaultMaximumCacheSize() const +{ + return 2ull * 1024 * 1024 * 1024; +} + +qint64 DrumMachineSettings::maximumCacheSize() const +{ + return value("maximumCacheSize", defaultMaximumCacheSize()).value(); +} + +void DrumMachineSettings::setMaximumCacheSize(qint64 maximumCacheSize) +{ + setValue("maximumCacheSize", maximumCacheSize); +} + QString DrumMachineSettings::lastAudioDevice() const { return value("lastAudioDevice").toString(); diff --git a/drummachinesettings.h b/drummachinesettings.h index c915832..235f813 100644 --- a/drummachinesettings.h +++ b/drummachinesettings.h @@ -7,6 +7,14 @@ class DrumMachineSettings : public QSettings public: using QSettings::QSettings; + QString defaultCacheDir() const; + QString cacheDir() const; + void setCacheDir(const QString &cacheDir); + + qint64 defaultMaximumCacheSize() const; + qint64 maximumCacheSize() const; + void setMaximumCacheSize(qint64 maximumCacheSize); + QString lastAudioDevice() const; void setLastAudioDevice(const QString &lastAudioDevice); diff --git a/drumpadpresetsmodel.cpp b/drumpadpresetsmodel.cpp index a1f8901..feb2cc9 100755 --- a/drumpadpresetsmodel.cpp +++ b/drumpadpresetsmodel.cpp @@ -90,7 +90,7 @@ const drumpad_presets::Preset &DrumPadPresetsModel::getPreset(const QModelIndex const drumpad_presets::Preset &DrumPadPresetsModel::getPreset(int row) const { - Q_ASSERT(row >= 0 && row < std::size(m_drumpad_presets)); + Q_ASSERT(row >= 0 && row < int(std::size(m_drumpad_presets))); return m_drumpad_presets.at(row); } @@ -132,7 +132,7 @@ QVariant DrumPadPresetsModel::data(const QModelIndex &index, int role) const return {}; if (index.row() < 0) return {}; - if (index.row() >= std::size(m_drumpad_presets)) + if (index.row() >= int(std::size(m_drumpad_presets))) return {}; const auto &preset = getPreset(index); diff --git a/main.cpp b/main.cpp index ca0b38b..4efde39 100755 --- a/main.cpp +++ b/main.cpp @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) QApplication app{argc, argv}; QCoreApplication::setOrganizationDomain("brunner.ninja"); QCoreApplication::setOrganizationName("brunner.ninja"); - QCoreApplication::setApplicationName("miditest"); + QCoreApplication::setApplicationName("DrumMachine"); QCoreApplication::setApplicationVersion("1.0"); qDebug() << "supportsSsl:" << QSslSocket::supportsSsl() diff --git a/treetotableproxymodel.cpp b/treetotableproxymodel.cpp index 9a2fd12..88ad44a 100644 --- a/treetotableproxymodel.cpp +++ b/treetotableproxymodel.cpp @@ -307,20 +307,36 @@ void TreeToTableProxyModel::sourceColumnsRemoved(const QModelIndex &parent, int void TreeToTableProxyModel::sourceRowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) { - + Q_UNUSED(sourceParent) + Q_UNUSED(sourceStart) + Q_UNUSED(sourceEnd) + Q_UNUSED(destinationParent) + Q_UNUSED(destinationRow) } void TreeToTableProxyModel::sourceRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) { - + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + Q_UNUSED(destination) + Q_UNUSED(row) } void TreeToTableProxyModel::sourceColumnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) { - + Q_UNUSED(sourceParent) + Q_UNUSED(sourceStart) + Q_UNUSED(sourceEnd) + Q_UNUSED(destinationParent) + Q_UNUSED(destinationColumn) } void TreeToTableProxyModel::sourceColumnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column) { - + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + Q_UNUSED(destination) + Q_UNUSED(column) } diff --git a/widgets/djwidget.cpp b/widgets/djwidget.cpp index 6db406b..67061d5 100644 --- a/widgets/djwidget.cpp +++ b/widgets/djwidget.cpp @@ -79,6 +79,7 @@ void DjWidget::writeSamples(frame_t *begin, frame_t *end) void DjWidget::loadSettings(DrumMachineSettings &settings) { + Q_UNUSED(settings) } void DjWidget::unsendColors() @@ -91,6 +92,7 @@ void DjWidget::sendColors() void DjWidget::midiReceived(const midi::MidiMessage &message) { + Q_UNUSED(message) } void DjWidget::directorySelected() diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 6796b85..72b647d 100755 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -11,6 +11,7 @@ #include "audioformat.h" #include "midicontainers.h" +#include "settingsdialog.h" namespace { void DummyDeleter(PaStream *stream); @@ -33,8 +34,9 @@ MainWindow::MainWindow(QWidget *parent) : { m_ui->setupUi(this); - m_cache.setCacheDirectory("cache"); - m_cache.setMaximumCacheSize(2ull * 1024 * 1024 * 1024); + m_cache.setCacheDirectory(m_settings.cacheDir()); + m_cache.setMaximumCacheSize(m_settings.maximumCacheSize()); + m_networkAccessManager.setCache(&m_cache); m_ui->drumPadWidget->injectNetworkAccessManager(m_networkAccessManager); @@ -53,6 +55,8 @@ MainWindow::MainWindow(QWidget *parent) : m_ui->loopStationWidget->injectDecodingThread(m_decoderThread); m_ui->djWidget->injectDecodingThread(m_decoderThread); + connect(m_ui->pushButtonSettings, &QAbstractButton::pressed, this, &MainWindow::showSettings); + updateAudioDevices(); connect(m_ui->pushButtonRefreshAudioDevices, &QAbstractButton::pressed, this, &MainWindow::updateAudioDevices); if (const auto &lastAudioDevice = m_settings.lastAudioDevice(); !lastAudioDevice.isEmpty()) @@ -126,6 +130,16 @@ int MainWindow::writeSamples(frame_t *begin, frame_t *end) return paContinue; } +void MainWindow::showSettings() +{ + SettingsDialog dialog{m_settings, m_cache.cacheSize(), this}; + if (dialog.exec() == QDialog::Accepted) + { + m_cache.setCacheDirectory(m_settings.cacheDir()); + m_cache.setMaximumCacheSize(m_settings.maximumCacheSize()); + } +} + void MainWindow::openAudioDevice() { if (m_paStream) diff --git a/widgets/mainwindow.h b/widgets/mainwindow.h index f99eaaa..9ebb76d 100755 --- a/widgets/mainwindow.h +++ b/widgets/mainwindow.h @@ -28,6 +28,7 @@ public: int writeSamples(frame_t *begin, frame_t *end); private slots: + void showSettings(); void openAudioDevice(); void openMidiInDevice(); void openMidiOutDevice(); diff --git a/widgets/mainwindow.ui b/widgets/mainwindow.ui index a4a3c88..f6f62bd 100755 --- a/widgets/mainwindow.ui +++ b/widgets/mainwindow.ui @@ -36,6 +36,19 @@ + + + + + 32 + 16777215 + + + + ⚙️ + + + diff --git a/widgets/previewwidget.cpp b/widgets/previewwidget.cpp index bf07645..e2f3eba 100644 --- a/widgets/previewwidget.cpp +++ b/widgets/previewwidget.cpp @@ -82,6 +82,8 @@ void PreviewWidget::mouseMoveEvent(QMouseEvent *event) void PreviewWidget::clicked(int x, int y) { + Q_UNUSED(y) + if (!m_buffer.isValid()) return; diff --git a/widgets/sampleswidget.cpp b/widgets/sampleswidget.cpp index c8ad069..f22e7bd 100755 --- a/widgets/sampleswidget.cpp +++ b/widgets/sampleswidget.cpp @@ -102,7 +102,7 @@ void SamplesWidget::sendColors() void SamplesWidget::sequencerTriggerSample(int index) { const auto widgets = getWidgets(); - if (index < 0 || index >= std::size(widgets)) + if (index < 0 || index >= int(std::size(widgets))) { qDebug() << "index out of range" << index; return; diff --git a/widgets/scratchwidget.cpp b/widgets/scratchwidget.cpp index 1f08fe6..718fabf 100644 --- a/widgets/scratchwidget.cpp +++ b/widgets/scratchwidget.cpp @@ -19,6 +19,8 @@ ScratchWidget::ScratchWidget(QWidget *parent) : void ScratchWidget::paintEvent(QPaintEvent *event) { + Q_UNUSED(event) + QPainter painter; painter.begin(this); diff --git a/widgets/sequencerwidget.ui b/widgets/sequencerwidget.ui index e207136..afd3310 100755 --- a/widgets/sequencerwidget.ui +++ b/widgets/sequencerwidget.ui @@ -103,7 +103,7 @@ 0 - 0 + -272 878 828 @@ -124,7 +124,7 @@ - + QFrame::HLine @@ -141,7 +141,7 @@ - + QFrame::HLine @@ -158,7 +158,7 @@ - + QFrame::HLine @@ -168,7 +168,7 @@ - + QFrame::HLine @@ -178,7 +178,7 @@ - + QFrame::HLine @@ -195,7 +195,7 @@ - + QFrame::HLine @@ -205,7 +205,7 @@ - + QFrame::HLine @@ -229,7 +229,7 @@ - + QFrame::HLine @@ -246,7 +246,7 @@ - + QFrame::HLine @@ -277,7 +277,7 @@ - + QFrame::HLine @@ -287,7 +287,7 @@ - + QFrame::HLine @@ -325,7 +325,7 @@ - + QFrame::HLine @@ -342,7 +342,7 @@ - + QFrame::HLine @@ -352,7 +352,7 @@ - + QFrame::HLine @@ -362,7 +362,7 @@ - + QFrame::HLine @@ -372,7 +372,7 @@ - + QFrame::HLine @@ -382,7 +382,7 @@ - + QFrame::HLine @@ -392,7 +392,7 @@ - + QFrame::HLine @@ -409,7 +409,7 @@ - + QFrame::HLine @@ -419,7 +419,7 @@ - + QFrame::HLine @@ -436,7 +436,7 @@ - + QFrame::HLine @@ -453,7 +453,7 @@ - + QFrame::VLine @@ -477,7 +477,7 @@ - + QFrame::HLine @@ -494,7 +494,7 @@ - + QFrame::HLine @@ -511,7 +511,7 @@ - + QFrame::HLine diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp new file mode 100644 index 0000000..6480f83 --- /dev/null +++ b/widgets/settingsdialog.cpp @@ -0,0 +1,98 @@ +#include "settingsdialog.h" +#include "ui_settingsdialog.h" + +#include +#include +#include +#include + +#include "drummachinesettings.h" + +SettingsDialog::SettingsDialog(DrumMachineSettings &settings, qint64 currentCacheSize, QWidget *parent) : + QDialog{parent}, + m_ui{std::make_unique()}, + m_settings{settings} +{ + m_ui->setupUi(this); + + connect(m_ui->toolButtonSelectCacheDir, &QAbstractButton::pressed, this, &SettingsDialog::selectCacheDir); + connect(m_ui->buttonBox, &QDialogButtonBox::clicked, this, &SettingsDialog::buttonClicked); + + resetFields(); + + m_ui->labelCurrentCacheSize->setText(tr("(Current Cache Size: %0MB)").arg(currentCacheSize / 1024 / 1024)); +} + +SettingsDialog::~SettingsDialog() = default; + +void SettingsDialog::accept() +{ + { + const auto &cacheDir = m_ui->lineEditCacheDir->text(); + + try + { + if (cacheDir.isEmpty()) + throw tr("Empty cacheDir!"); + else if (QDir dir{cacheDir}; !dir.exists() && !dir.mkpath(dir.absolutePath())) + throw tr("Could not create cache directory!"); + } + catch (const QString &e) + { + QMessageBox::warning(this, e, e); + return; + } + + if (m_settings.cacheDir() != cacheDir) + m_settings.setCacheDir(cacheDir); + } + + const auto maximumCacheSize = qint64{m_ui->spinBoxMaxCacheSize->value()} * 1024 * 1024; + if (m_settings.maximumCacheSize() != maximumCacheSize) + m_settings.setMaximumCacheSize(maximumCacheSize); + + QDialog::accept(); +} + +void SettingsDialog::buttonClicked(QAbstractButton *button) +{ + if (!button) + { + qWarning() << "invalid button"; + return; + } + + switch (m_ui->buttonBox->standardButton(button)) + { + case QDialogButtonBox::Reset: + resetFields(); + return; + case QDialogButtonBox::RestoreDefaults: + restoreDefaults(); + return; + default:; + } +} + +void SettingsDialog::resetFields() +{ + m_ui->lineEditCacheDir->setText(m_settings.cacheDir()); + m_ui->spinBoxMaxCacheSize->setValue(m_settings.maximumCacheSize() / 1024 / 1024); +} + +void SettingsDialog::restoreDefaults() +{ + m_ui->lineEditCacheDir->setText(m_settings.defaultCacheDir()); + m_ui->spinBoxMaxCacheSize->setValue(m_settings.defaultMaximumCacheSize() / 1024 / 1024); +} + +void SettingsDialog::selectCacheDir() +{ + QDir dir{m_ui->lineEditCacheDir->text()}; + if (!dir.exists()) + dir = QDir{m_settings.cacheDir()}; + const auto selected = QFileDialog::getExistingDirectory(this, tr("Select cache dir"), dir.exists() ? dir.absolutePath() : QString{}); + if (selected.isEmpty()) + return; + m_ui->lineEditCacheDir->setText(selected); +} diff --git a/widgets/settingsdialog.h b/widgets/settingsdialog.h new file mode 100644 index 0000000..648558e --- /dev/null +++ b/widgets/settingsdialog.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include + +namespace Ui { class SettingsDialog; } +class DrumMachineSettings; +class QAbstractButton; + +class SettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SettingsDialog(DrumMachineSettings &settings, qint64 currentCacheSize, QWidget *parent = nullptr); + ~SettingsDialog() override; + +public slots: + void accept() override; + +private slots: + void buttonClicked(QAbstractButton *button); + void resetFields(); + void restoreDefaults(); + void selectCacheDir(); + +private: + const std::unique_ptr m_ui; + DrumMachineSettings &m_settings; +}; diff --git a/widgets/settingsdialog.ui b/widgets/settingsdialog.ui new file mode 100644 index 0000000..8bb4bcc --- /dev/null +++ b/widgets/settingsdialog.ui @@ -0,0 +1,123 @@ + + + SettingsDialog + + + + 0 + 0 + 439 + 214 + + + + Settings + + + + + + + + Cache Dir: + + + lineEditCacheDir + + + + + + + + + + + + ... + + + + + + + + + + + MB + + + 2147483647 + + + + + + + (Current Cache Size: 0) + + + + + + + + + Max Cache Size: + + + spinBoxMaxCacheSize + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +