Remember last selected audio and midi devices
This commit is contained in:
@ -1,5 +1,45 @@
|
|||||||
#include "drummachinesettings.h"
|
#include "drummachinesettings.h"
|
||||||
|
|
||||||
|
QString DrumMachineSettings::lastAudioDevice() const
|
||||||
|
{
|
||||||
|
return value("lastAudioDevice").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrumMachineSettings::setLastAudioDevice(const QString &lastAudioDevice)
|
||||||
|
{
|
||||||
|
setValue("lastAudioDevice", lastAudioDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int DrumMachineSettings::framesPerBuffer() const
|
||||||
|
{
|
||||||
|
return value("framesPerBuffer", 32).toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrumMachineSettings::setFramesPerBuffer(unsigned int framesPerBuffer)
|
||||||
|
{
|
||||||
|
setValue("framesPerBuffer", framesPerBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DrumMachineSettings::lastMidiInDevice() const
|
||||||
|
{
|
||||||
|
return value("lastMidiInDevice").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrumMachineSettings::setLastMidiInDevice(const QString &lastMidiInDevice)
|
||||||
|
{
|
||||||
|
setValue("lastMidiInDevice", lastMidiInDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DrumMachineSettings::lastMidiOutDevice() const
|
||||||
|
{
|
||||||
|
return value("lastMidiOutDevice").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrumMachineSettings::setLastMidiOutDevice(const QString &lastMidiOutDevice)
|
||||||
|
{
|
||||||
|
setValue("lastMidiOutDevice", lastMidiOutDevice);
|
||||||
|
}
|
||||||
|
|
||||||
quint8 DrumMachineSettings::padChannel(quint8 pad) const
|
quint8 DrumMachineSettings::padChannel(quint8 pad) const
|
||||||
{
|
{
|
||||||
return value(QString{"pad%0/channel"}.arg(pad)).toUInt();
|
return value(QString{"pad%0/channel"}.arg(pad)).toUInt();
|
||||||
|
@ -7,6 +7,18 @@ class DrumMachineSettings : public QSettings
|
|||||||
public:
|
public:
|
||||||
using QSettings::QSettings;
|
using QSettings::QSettings;
|
||||||
|
|
||||||
|
QString lastAudioDevice() const;
|
||||||
|
void setLastAudioDevice(const QString &lastAudioDevice);
|
||||||
|
|
||||||
|
unsigned int framesPerBuffer() const;
|
||||||
|
void setFramesPerBuffer(unsigned int framesPerBuffer);
|
||||||
|
|
||||||
|
QString lastMidiInDevice() const;
|
||||||
|
void setLastMidiInDevice(const QString &lastMidiInDevice);
|
||||||
|
|
||||||
|
QString lastMidiOutDevice() const;
|
||||||
|
void setLastMidiOutDevice(const QString &lastMidiOutDevice);
|
||||||
|
|
||||||
quint8 padChannel(quint8 pad) const;
|
quint8 padChannel(quint8 pad) const;
|
||||||
void setPadChannel(quint8 pad, quint8 channel);
|
void setPadChannel(quint8 pad, quint8 channel);
|
||||||
|
|
||||||
|
146
mainwindow.cpp
146
mainwindow.cpp
@ -53,56 +53,40 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
m_ui->drumPadWidget->injectDecodingThread(m_decoderThread);
|
m_ui->drumPadWidget->injectDecodingThread(m_decoderThread);
|
||||||
m_ui->djWidget->injectDecodingThread(m_decoderThread);
|
m_ui->djWidget->injectDecodingThread(m_decoderThread);
|
||||||
|
|
||||||
updateMidiInDevices();
|
updateAudioDevices();
|
||||||
|
connect(m_ui->pushButtonRefreshAudioDevices, &QAbstractButton::pressed, this, &MainWindow::updateAudioDevices);
|
||||||
|
if (const auto &lastAudioDevice = m_settings.lastAudioDevice(); !lastAudioDevice.isEmpty())
|
||||||
|
{
|
||||||
|
if (const auto index = m_ui->comboBoxAudioDevice->findText(lastAudioDevice); index >= 0)
|
||||||
|
m_ui->comboBoxAudioDevice->setCurrentIndex(index);
|
||||||
|
else
|
||||||
|
goto paDefault;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
paDefault:
|
||||||
|
m_ui->comboBoxAudioDevice->setCurrentIndex(Pa_GetDefaultOutputDevice());
|
||||||
|
}
|
||||||
|
m_ui->spinBoxBufferSize->setValue(m_settings.framesPerBuffer());
|
||||||
|
connect(m_ui->pushButtonAudioDevice, &QAbstractButton::pressed, this, &MainWindow::openAudioDevice);
|
||||||
|
|
||||||
|
updateMidiInDevices();
|
||||||
|
connect(m_ui->pushButtonRefreshMidiIn, &QAbstractButton::pressed, this, &MainWindow::updateMidiInDevices);
|
||||||
|
if (const auto &lastMidiInDevice = m_settings.lastMidiInDevice(); !lastMidiInDevice.isEmpty())
|
||||||
|
{
|
||||||
|
if (const auto index = m_ui->comboBoxMidiIn->findText(lastMidiInDevice); index >= 0)
|
||||||
|
m_ui->comboBoxMidiIn->setCurrentIndex(index);
|
||||||
|
}
|
||||||
|
connect(m_ui->pushButtonMidiIn, &QAbstractButton::pressed, this, &MainWindow::openMidiInDevice);
|
||||||
|
|
||||||
updateMidiOutDevices();
|
updateMidiOutDevices();
|
||||||
|
|
||||||
connect(m_ui->pushButtonRefreshMidiIn, &QAbstractButton::pressed, this, &MainWindow::updateMidiInDevices);
|
|
||||||
|
|
||||||
connect(m_ui->pushButtonRefreshMidiOut, &QAbstractButton::pressed, this, &MainWindow::updateMidiOutDevices);
|
connect(m_ui->pushButtonRefreshMidiOut, &QAbstractButton::pressed, this, &MainWindow::updateMidiOutDevices);
|
||||||
|
if (const auto &lastMidiOutDevice = m_settings.lastMidiOutDevice(); !lastMidiOutDevice.isEmpty())
|
||||||
connect(m_ui->pushButtonMidiIn, &QAbstractButton::pressed, this, [this](){
|
{
|
||||||
if (m_midiIn.isPortOpen())
|
if (const auto index = m_ui->comboBoxMidiOut->findText(lastMidiOutDevice); index >= 0)
|
||||||
m_midiIn.closePort();
|
m_ui->comboBoxMidiOut->setCurrentIndex(index);
|
||||||
else
|
}
|
||||||
{
|
connect(m_ui->pushButtonMidiOut, &QAbstractButton::pressed, this, &MainWindow::openMidiOutDevice);
|
||||||
const auto index = m_ui->comboBoxMidiIn->currentIndex();
|
|
||||||
if (index != -1)
|
|
||||||
m_midiIn.openPort(index, "Input");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ui->comboBoxMidiIn->setDisabled(m_midiIn.isPortOpen());
|
|
||||||
m_ui->pushButtonMidiIn->setText(m_midiIn.isPortOpen() ? tr("Close") : tr("Open"));
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_ui->pushButtonMidiOut, &QAbstractButton::pressed, this, [this](){
|
|
||||||
if (m_midiOut.isPortOpen())
|
|
||||||
{
|
|
||||||
qDebug() << "closing port";
|
|
||||||
unsendColors(m_ui->tabWidget->currentIndex());
|
|
||||||
m_midiOut.closePort();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const auto index = m_ui->comboBoxMidiOut->currentIndex();
|
|
||||||
if (index != -1)
|
|
||||||
{
|
|
||||||
m_midiOut.openPort(index, "Output");
|
|
||||||
sendColors(m_ui->tabWidget->currentIndex());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_ui->comboBoxMidiOut->setDisabled(m_midiOut.isPortOpen());
|
|
||||||
m_ui->pushButtonMidiOut->setText(m_midiOut.isPortOpen() ? tr("Close") : tr("Open"));
|
|
||||||
});
|
|
||||||
|
|
||||||
updateAudioDevices();
|
|
||||||
|
|
||||||
connect(m_ui->pushButtonRefreshAudioDevices, &QAbstractButton::pressed, this, &MainWindow::updateAudioDevices);
|
|
||||||
|
|
||||||
m_ui->comboBoxAudioDevice->setCurrentIndex(Pa_GetDefaultOutputDevice());
|
|
||||||
|
|
||||||
connect(m_ui->pushButtonAudioDevice, &QAbstractButton::pressed, this, &MainWindow::openAudioDevice);
|
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
@ -191,9 +175,51 @@ void MainWindow::openAudioDevice()
|
|||||||
m_ui->comboBoxAudioDevice->setEnabled(false);
|
m_ui->comboBoxAudioDevice->setEnabled(false);
|
||||||
m_ui->spinBoxBufferSize->setEnabled(false);
|
m_ui->spinBoxBufferSize->setEnabled(false);
|
||||||
m_ui->pushButtonAudioDevice->setText(tr("Close"));
|
m_ui->pushButtonAudioDevice->setText(tr("Close"));
|
||||||
|
|
||||||
|
m_settings.setLastAudioDevice(m_ui->comboBoxAudioDevice->currentText());
|
||||||
|
m_settings.setFramesPerBuffer(m_ui->spinBoxBufferSize->value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::openMidiInDevice()
|
||||||
|
{
|
||||||
|
if (m_midiIn.isPortOpen())
|
||||||
|
m_midiIn.closePort();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto index = m_ui->comboBoxMidiIn->currentIndex();
|
||||||
|
if (index != -1)
|
||||||
|
m_midiIn.openPort(index, "Input");
|
||||||
|
m_settings.setLastMidiInDevice(m_ui->comboBoxMidiIn->currentText());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ui->comboBoxMidiIn->setDisabled(m_midiIn.isPortOpen());
|
||||||
|
m_ui->pushButtonMidiIn->setText(m_midiIn.isPortOpen() ? tr("Close") : tr("Open"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::openMidiOutDevice()
|
||||||
|
{
|
||||||
|
if (m_midiOut.isPortOpen())
|
||||||
|
{
|
||||||
|
qDebug() << "closing port";
|
||||||
|
unsendColors(m_ui->tabWidget->currentIndex());
|
||||||
|
m_midiOut.closePort();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const auto index = m_ui->comboBoxMidiOut->currentIndex();
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
m_midiOut.openPort(index, "Output");
|
||||||
|
m_settings.setLastMidiOutDevice(m_ui->comboBoxMidiOut->currentText());
|
||||||
|
sendColors(m_ui->tabWidget->currentIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ui->comboBoxMidiOut->setDisabled(m_midiOut.isPortOpen());
|
||||||
|
m_ui->pushButtonMidiOut->setText(m_midiOut.isPortOpen() ? tr("Close") : tr("Open"));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::messageReceived(const midi::MidiMessage &message)
|
void MainWindow::messageReceived(const midi::MidiMessage &message)
|
||||||
{
|
{
|
||||||
m_ui->statusbar->showMessage(tr("Received midi message: flag: %0 cmd: %1 channel: %2 note: %3 velocity: %4")
|
m_ui->statusbar->showMessage(tr("Received midi message: flag: %0 cmd: %1 channel: %2 note: %3 velocity: %4")
|
||||||
@ -221,6 +247,19 @@ void MainWindow::currentChanged(int index)
|
|||||||
sendColors(index);
|
sendColors(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateAudioDevices()
|
||||||
|
{
|
||||||
|
m_ui->comboBoxAudioDevice->clear();
|
||||||
|
|
||||||
|
const auto count = Pa_GetDeviceCount();
|
||||||
|
|
||||||
|
for (PaDeviceIndex i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
const auto info = Pa_GetDeviceInfo(i);
|
||||||
|
m_ui->comboBoxAudioDevice->addItem(info->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateMidiInDevices()
|
void MainWindow::updateMidiInDevices()
|
||||||
{
|
{
|
||||||
m_ui->comboBoxMidiIn->clear();
|
m_ui->comboBoxMidiIn->clear();
|
||||||
@ -241,19 +280,6 @@ void MainWindow::updateMidiOutDevices()
|
|||||||
m_ui->pushButtonMidiOut->setEnabled(m_ui->comboBoxMidiOut->count() > 0);
|
m_ui->pushButtonMidiOut->setEnabled(m_ui->comboBoxMidiOut->count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateAudioDevices()
|
|
||||||
{
|
|
||||||
m_ui->comboBoxAudioDevice->clear();
|
|
||||||
|
|
||||||
const auto count = Pa_GetDeviceCount();
|
|
||||||
|
|
||||||
for (PaDeviceIndex i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
const auto info = Pa_GetDeviceInfo(i);
|
|
||||||
m_ui->comboBoxAudioDevice->addItem(info->name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::loadSettings()
|
void MainWindow::loadSettings()
|
||||||
{
|
{
|
||||||
m_ui->drumPadWidget->loadSettings(m_settings);
|
m_ui->drumPadWidget->loadSettings(m_settings);
|
||||||
|
@ -30,14 +30,16 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openAudioDevice();
|
void openAudioDevice();
|
||||||
|
void openMidiInDevice();
|
||||||
|
void openMidiOutDevice();
|
||||||
void messageReceived(const midi::MidiMessage &message);
|
void messageReceived(const midi::MidiMessage &message);
|
||||||
void sendMidi(const midi::MidiMessage &midiMsg);
|
void sendMidi(const midi::MidiMessage &midiMsg);
|
||||||
void currentChanged(int index);
|
void currentChanged(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateAudioDevices();
|
||||||
void updateMidiInDevices();
|
void updateMidiInDevices();
|
||||||
void updateMidiOutDevices();
|
void updateMidiOutDevices();
|
||||||
void updateAudioDevices();
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void unsendColors(int index);
|
void unsendColors(int index);
|
||||||
void sendColors(int index);
|
void sendColors(int index);
|
||||||
|
@ -30,9 +30,9 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout">
|
<layout class="QHBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labelUltraDj">
|
<widget class="QLabel" name="labelDrumMachine">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><b>UltraDj</b></string>
|
<string><b>DrumMachine</b></string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user