Work in progress

This commit is contained in:
2023-06-10 21:31:50 +02:00
parent bd597b97b6
commit b740cfa4b6
11 changed files with 1053 additions and 255 deletions

View File

@ -27,6 +27,8 @@ struct MidiMessage
bool operator==(const MidiMessage &other) const;
};
static_assert(sizeof(MidiMessage) == 3);
} // namespace midi
Q_DECLARE_METATYPE(midi::Command)

View File

@ -3,6 +3,9 @@
#include <QCoreApplication>
#include <QMetaType>
#include <QDebug>
#include <QDateTime>
#include <chrono>
#include "midicontainers.h"
@ -67,9 +70,37 @@ void MidiInWrapper::mycallback(double deltatime, std::vector<unsigned char> *mes
return;
}
if (message->size() == 1)
{
if (const auto opcode = message->at(0); opcode == 250)
{
wrapper->m_counting = true;
wrapper->m_timerCounter = 0;
}
else if (opcode == 252)
{
wrapper->m_counting = false;
}
else if (opcode == 248)
{
if (wrapper->m_counting)
{
if (wrapper->m_timerCounter == 0 || wrapper->m_timerCounter == 12)
wrapper->onQuarterNote();
wrapper->m_timerCounter++;
if (wrapper->m_timerCounter >= 24)
wrapper->m_timerCounter = 0;
}
}
else
qWarning() << "unknown opcode" << opcode;
return;
}
if (message->size() < sizeof(midi::MidiMessage))
{
qCritical() << "called with message that is shorter than 3 bytes";
qCritical() << "called with message that is shorter than 3 bytes (" << message->size() << ')';
return;
}

View File

@ -26,9 +26,13 @@ public:
signals:
void midiReceived(const midi::MidiMessage &message);
void onQuarterNote();
private:
static void mycallback(double deltatime, std::vector<unsigned char> *message, void *userData);
RtMidiIn midiIn;
int m_timerCounter{};
bool m_counting{true};
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>326</height>
<width>439</width>
<height>585</height>
</rect>
</property>
<property name="windowTitle">
@ -15,36 +15,30 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelColorPrevPreset">
<property name="text">
<string>Color Prev Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevPreset</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelColorNextPreset">
<property name="text">
<string>Color Next Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorNextPreset</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelColorPrevSequence">
<property name="text">
<string>Color Prev Sequence:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevSequence</cstring>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSpinBox" name="spinBoxColorNextSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelColorNextSequence">
@ -56,33 +50,177 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelColorPlayPause">
<item row="10" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QSpinBox" name="spinBoxColorRedIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="11" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QSpinBox" name="spinBoxColorYellowPlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="13" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QSpinBox" name="ColorBlueIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_19">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="14" column="0">
<widget class="QLabel" name="labelColorOther">
<property name="text">
<string>Color Play Pause:</string>
<string>Color Other:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPlayPause</cstring>
<cstring>ColorOtherPlaying</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelColorStopSequence">
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QSpinBox" name="spinBoxColorStopSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="14" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_19">
<item>
<widget class="QSpinBox" name="ColorOtherPlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="12" column="0">
<widget class="QLabel" name="labelColorGreen">
<property name="text">
<string>Color Stop Sequence:</string>
<string>Color Green:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorStopSequence</cstring>
<cstring>ColorGreenPlaying</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelColorSwap">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QSpinBox" name="spinBoxColorSwap">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelColorPurple">
<property name="text">
<string>Color Swap:</string>
<string>Color Purple:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorSwap</cstring>
<cstring>spinBoxColorPurplePlaying</cstring>
</property>
</widget>
</item>
@ -96,6 +234,13 @@
</property>
</widget>
</item>
<item row="8" column="2">
<widget class="QLabel" name="labelIdle">
<property name="text">
<string>Idle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -120,137 +265,47 @@
</item>
</layout>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="spinBoxColorNextPreset">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="1" column="0">
<widget class="QLabel" name="labelColorNextPreset">
<property name="text">
<string>Color Next Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorNextPreset</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSpinBox" name="spinBoxColorPrevSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="5" column="0">
<widget class="QLabel" name="labelColorStopSequence">
<property name="text">
<string>Color Stop Sequence:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorStopSequence</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSpinBox" name="spinBoxColorNextSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="2" column="0">
<widget class="QLabel" name="labelColorPrevSequence">
<property name="text">
<string>Color Prev Sequence:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevSequence</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item row="12" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QSpinBox" name="spinBoxColorPlayPause">
<widget class="QSpinBox" name="ColorGreenIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QSpinBox" name="spinBoxColorStopSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QSpinBox" name="spinBoxColorSwap">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<spacer name="horizontalSpacer_18">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -288,8 +343,328 @@
</item>
</layout>
</item>
<item row="12" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QSpinBox" name="ColorGreenPlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="1">
<widget class="QLabel" name="labelPlaying">
<property name="text">
<string>Playing</string>
</property>
</widget>
</item>
<item row="13" column="0">
<widget class="QLabel" name="labelColorBlue">
<property name="text">
<string>Color Blue:</string>
</property>
<property name="buddy">
<cstring>ColorBluePlaying</cstring>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelColorRed">
<property name="text">
<string>Color Red:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorRedPlaying</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="spinBoxColorNextPreset">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QSpinBox" name="spinBoxColorRedPlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QSpinBox" name="spinBoxColorPlayPause">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="11" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QSpinBox" name="spinBoxColorYellowIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="11" column="0">
<widget class="QLabel" name="labelColorYellow">
<property name="text">
<string>Color Yellow:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorYellowPlaying</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelColorSwap">
<property name="text">
<string>Color Swap:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorSwap</cstring>
</property>
</widget>
</item>
<item row="13" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QSpinBox" name="ColorBluePlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="14" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_20">
<item>
<widget class="QSpinBox" name="ColorOtherIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QSpinBox" name="spinBoxColorPrevSequence">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelColorPrevPreset">
<property name="text">
<string>Color Prev Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevPreset</cstring>
</property>
</widget>
</item>
<item row="9" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QSpinBox" name="spinBoxColorPurpleIdle">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QSpinBox" name="spinBoxColorPurplePlaying">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelColorPlayPause">
<property name="text">
<string>Color Play Pause:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPlayPause</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

View File

@ -124,13 +124,13 @@ void LoopStationSampleWidget::sendColor(bool force)
if (m_player.buffer().isValid())
{
if (m_category == 0)
newColor = m_player.playing() ? 44 : 47; //dunkelblue
newColor = m_player.playing() ? 44 : 47; // darkblue
else if (m_category == 1)
newColor = m_player.playing() ? 16 : 19; // green
else if (m_category == 2)
newColor = m_player.playing() ? 48 : 51; // violet
else if (m_category == 3)
newColor = m_player.playing() ? 36 : 39; // hellblue
newColor = m_player.playing() ? 36 : 39; // lightblue
else if (m_category == 4)
newColor = m_player.playing() ? 8 : 11; // orange
else if (m_category == 5)
@ -203,18 +203,19 @@ void LoopStationSampleWidget::updateStatus()
#endif
;
if (m_category == 0)
newColor = QColor{bright, dark, bright};
newColor = QColor{dark, dark, bright}; // darkblue
else if (m_category == 1)
newColor = QColor{bright, dark, dark};
newColor = QColor{dark, bright, dark}; // green
else if (m_category == 2)
newColor = QColor{bright, bright, dark};
newColor = QColor{bright, dark, bright}; // violet
else if (m_category == 3)
newColor = QColor{dark, bright, dark};
newColor = QColor{dark, bright, bright}; // lightblue
else if (m_category == 4)
newColor = QColor{dark, dark, bright};
newColor = QColor{bright, bright, dark}; // yellow
else if (m_category == 5)
newColor = QColor{dark, bright, bright};
newColor = QColor{bright, dark, dark}; // red
else
{
qWarning() << "unknown category:" << m_category;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>439</width>
<height>230</height>
<height>435</height>
</rect>
</property>
<property name="windowTitle">
@ -15,82 +15,18 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelColorPrevPreset">
<property name="text">
<string>Color Prev Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevPreset</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSpinBox" name="spinBoxColorPrevPreset">
<widget class="QSpinBox" name="spinBoxColorStop">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelColorNextPreset">
<property name="text">
<string>Color Next Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorNextPreset</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelColorPlayPause">
<property name="text">
<string>Color Play Pause:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPlayPause</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelColorStop">
<property name="text">
<string>Color Stop:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorStop</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="spinBoxColorNextPreset">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -128,17 +64,395 @@
</item>
</layout>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item row="4" column="2">
<widget class="QLabel" name="labelIdle">
<property name="text">
<string>Idle</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QSpinBox" name="spinBoxColorStop">
<widget class="QSpinBox" name="spinBoxColorNextPreset">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="4" column="1">
<widget class="QLabel" name="labelPlaying">
<property name="text">
<string>Playing</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="labelColorCategory0">
<property name="text">
<string>Color Category 0:</string>
</property>
<property name="buddy">
<cstring>spinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelColorPlayPause">
<property name="text">
<string>Color Play Pause:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPlayPause</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QSpinBox" name="spinBox"/>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelColorStop">
<property name="text">
<string>Color Stop:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorStop</cstring>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="labelColorCategory4">
<property name="text">
<string>Color Category 4:</string>
</property>
<property name="buddy">
<cstring>spinBox_9</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelColorNextPreset">
<property name="text">
<string>Color Next Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorNextPreset</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelColorPrevPreset">
<property name="text">
<string>Color Prev Preset:</string>
</property>
<property name="buddy">
<cstring>spinBoxColorPrevPreset</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="labelColorCategory1">
<property name="text">
<string>Color Category 1:</string>
</property>
<property name="buddy">
<cstring>spinBox_3</cstring>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="labelColorCategory2">
<property name="text">
<string>Color Category 2:</string>
</property>
<property name="buddy">
<cstring>spinBox_5</cstring>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelColorCategory3">
<property name="text">
<string>Color Category 3</string>
</property>
<property name="buddy">
<cstring>spinBox_7</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="spinBoxColorPrevPreset">
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="10" column="0">
<widget class="QLabel" name="labelColorCategory5">
<property name="text">
<string>Color Category 5:</string>
</property>
<property name="buddy">
<cstring>spinBox_11</cstring>
</property>
</widget>
</item>
<item row="5" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QSpinBox" name="spinBox_2"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QSpinBox" name="spinBox_3"/>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QSpinBox" name="spinBox_4"/>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QSpinBox" name="spinBox_5"/>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="7" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QSpinBox" name="spinBox_6"/>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QSpinBox" name="spinBox_7"/>
</item>
<item>
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="8" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QSpinBox" name="spinBox_8"/>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="9" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QSpinBox" name="spinBox_9"/>
</item>
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="9" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QSpinBox" name="spinBox_10"/>
</item>
<item>
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="10" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QSpinBox" name="spinBox_11"/>
</item>
<item>
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="10" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_16">
<item>
<widget class="QSpinBox" name="spinBox_12"/>
</item>
<item>
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -154,6 +468,19 @@
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">

View File

@ -46,6 +46,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_ui->loopStationWidget->injectNetworkAccessManager(m_networkAccessManager);
connect(&m_midiIn, &MidiInWrapper::midiReceived, this, &MainWindow::midiReceived);
connect(&m_midiIn, &MidiInWrapper::onQuarterNote, this, &MainWindow::onQuarterNote);
{
QEventLoop eventLoop;
@ -327,6 +328,11 @@ void MainWindow::midiReceived(const midi::MidiMessage &message)
m_ui->synthisizerWidget->midiReceived(message);
}
void MainWindow::onQuarterNote()
{
m_ui->synthisizerWidget->onQuarterNote();
}
void MainWindow::sendMidi(const midi::MidiMessage &midiMsg)
{
if (m_midiOut.isPortOpen())

View File

@ -33,6 +33,7 @@ private slots:
void openMidiInDevice();
void openMidiOutDevice();
void midiReceived(const midi::MidiMessage &message);
void onQuarterNote();
void sendMidi(const midi::MidiMessage &midiMsg);
void currentChanged(int index);

View File

@ -3,6 +3,9 @@
#include <cmath>
#include <QDebug>
#include <QTimer>
#include "audioformat.h"
#include "midicontainers.h"
@ -12,15 +15,20 @@ SynthisizerWidget::SynthisizerWidget(QWidget *parent) :
{
m_ui->setupUi(this);
connect(m_ui->horizontalSliderVolume, &QSlider::valueChanged,
&m_synthisizer, [&synthisizer=m_synthisizer](int value){ synthisizer.setVolume(float(value) / 100.f); });
for (Synthisizer &synthisizer : m_synthisizers)
connect(m_ui->horizontalSliderVolume, &QSlider::valueChanged,
&synthisizer, [&synthisizer](int value){ synthisizer.setVolume(float(value) / 100.f); });
// m_synthisizers.at(8).setFrequency(1209);
// m_synthisizers.at(9).setFrequency(697);
}
SynthisizerWidget::~SynthisizerWidget() = default;
void SynthisizerWidget::writeSamples(frame_t *begin, frame_t *end)
{
m_synthisizer.writeSamples(begin, end);
for (Synthisizer &synthisizer : m_synthisizers)
synthisizer.writeSamples(begin, end);
}
void SynthisizerWidget::loadSettings(DrumMachineSettings &settings)
@ -38,11 +46,27 @@ void SynthisizerWidget::sendColors()
void SynthisizerWidget::midiReceived(const midi::MidiMessage &message)
{
auto freq = 440.*std::pow(std::pow(2., 1./12.), message.note-48);
if (message.cmd == midi::Command::NoteOff || (message.cmd == midi::Command::NoteOn && message.velocity == 0))
{
if (m_synthisizer.frequency() == int16_t(440.*std::pow(std::pow(2., 1./12.), message.note-48)))
m_synthisizer.setFrequency(0);
for (Synthisizer &synthisizer : m_synthisizers)
if (synthisizer.frequency() == int16_t(freq))
synthisizer.setFrequency(0);
}
else if (message.cmd == midi::Command::NoteOn)
m_synthisizer.setFrequency(440.*std::pow(std::pow(2., 1./12.), message.note-48));
{
for (Synthisizer &synthisizer : m_synthisizers)
if (!synthisizer.frequency())
{
synthisizer.setFrequency(freq);
break;
}
}
}
void SynthisizerWidget::onQuarterNote()
{
auto &synthisizer = m_synthisizers.back();
synthisizer.setFrequency(440.);
QTimer::singleShot(6, &synthisizer, [&synthisizer](){ synthisizer.setFrequency(0.); });
}

View File

@ -28,9 +28,10 @@ signals:
public slots:
void midiReceived(const midi::MidiMessage &message);
void onQuarterNote();
private:
const std::unique_ptr<Ui::SynthisizerWidget> m_ui;
Synthisizer m_synthisizer;
std::array<Synthisizer, 10> m_synthisizers;
};

View File

@ -58,6 +58,32 @@
<cstring>horizontalSliderVolume</cstring>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>30</x>
<y>170</y>
<width>55</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Bpm</string>
</property>
</widget>
<widget class="QDoubleSpinBox" name="doubleSpinBox">
<property name="geometry">
<rect>
<x>110</x>
<y>170</y>
<width>62</width>
<height>27</height>
</rect>
</property>
<property name="maximum">
<double>999.990000000000009</double>
</property>
</widget>
</widget>
<resources/>
<connections/>