diff --git a/widgets/drumpadsamplewidget.cpp b/widgets/drumpadsamplewidget.cpp index 30b49dd..2edd454 100755 --- a/widgets/drumpadsamplewidget.cpp +++ b/widgets/drumpadsamplewidget.cpp @@ -168,43 +168,48 @@ void DrumPadSampleWidget::unsendColor() .note = m_ui->pushButtonPlay->learnSetting().note, .velocity = 0 }); + m_lastMidiColor = 0; } void DrumPadSampleWidget::sendColor() { m_sendColors = true; - uint8_t velocity; + uint8_t newColor; if (m_file && m_file->color && m_player.buffer().isValid()) { const auto &color = *m_file->color; if (color == "purple") - velocity = m_player.playing() ? 43 : 18; + newColor = m_player.playing() ? 43 : 18; else if (color == "red") - velocity = m_player.playing() ? 3 : 1; + newColor = m_player.playing() ? 3 : 1; else if (color == "yellow") - velocity = m_player.playing() ? 58 : 33; + newColor = m_player.playing() ? 58 : 33; else if (color == "green") - velocity = m_player.playing() ? 56 : 16; + newColor = m_player.playing() ? 56 : 16; else if (color == "blue") - velocity = m_player.playing() ? 49 : 51; + newColor = m_player.playing() ? 49 : 51; else goto noColor; } else { - noColor: - velocity = 0; +noColor: + newColor = 0; } - emit sendMidi(midi::MidiMessage { - .channel = m_ui->pushButtonPlay->learnSetting().channel, - .cmd = m_ui->pushButtonPlay->learnSetting().cmd, - .flag = true, - .note = m_ui->pushButtonPlay->learnSetting().note, - .velocity = velocity - }); + if (newColor != m_lastMidiColor) + { + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonPlay->learnSetting().channel, + .cmd = m_ui->pushButtonPlay->learnSetting().cmd, + .flag = true, + .note = m_ui->pushButtonPlay->learnSetting().note, + .velocity = newColor + }); + m_lastMidiColor = newColor; + } } void DrumPadSampleWidget::updateStatus() diff --git a/widgets/drumpadsamplewidget.h b/widgets/drumpadsamplewidget.h index 49e34b7..e4fd002 100755 --- a/widgets/drumpadsamplewidget.h +++ b/widgets/drumpadsamplewidget.h @@ -87,4 +87,5 @@ private: bool m_sendColors{}; QColor m_lastColor; + quint8 m_lastMidiColor{}; }; diff --git a/widgets/loopstationsamplewidget.cpp b/widgets/loopstationsamplewidget.cpp index 5907586..e2eab7b 100644 --- a/widgets/loopstationsamplewidget.cpp +++ b/widgets/loopstationsamplewidget.cpp @@ -106,19 +106,54 @@ void LoopStationSampleWidget::unsendColor() .note = m_ui->pushButtonPlay->learnSetting().note, .velocity = 0 }); + m_lastMidiColor = 0; } void LoopStationSampleWidget::sendColor() { m_sendColors = true; - emit sendMidi(midi::MidiMessage { - .channel = m_ui->pushButtonPlay->learnSetting().channel, - .cmd = m_ui->pushButtonPlay->learnSetting().cmd, - .flag = true, - .note = m_ui->pushButtonPlay->learnSetting().note, - .velocity = uint8_t(m_padNr+1) - }); + quint8 newColor; + + if (false) // testing colors on launchpad mk2 + newColor = m_padNr; + else + { + if (m_player.buffer().isValid()) + { + if (m_category == 0) + newColor = m_player.playing() ? 44 : 47; //dunkelblue + 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 + else if (m_category == 4) + newColor = m_player.playing() ? 8 : 11; // orange + else if (m_category == 5) + newColor = m_player.playing() ? 52 : 55; // pink + else + goto noColor; + } + else + { +noColor: + newColor = 0; + } + } + + if (newColor != m_lastMidiColor) + { + emit sendMidi(midi::MidiMessage { + .channel = m_ui->pushButtonPlay->learnSetting().channel, + .cmd = m_ui->pushButtonPlay->learnSetting().cmd, + .flag = true, + .note = m_ui->pushButtonPlay->learnSetting().note, + .velocity = newColor + }); + m_lastMidiColor = newColor; + } } void LoopStationSampleWidget::timeout() diff --git a/widgets/loopstationsamplewidget.h b/widgets/loopstationsamplewidget.h index 474a15c..8e24588 100644 --- a/widgets/loopstationsamplewidget.h +++ b/widgets/loopstationsamplewidget.h @@ -82,4 +82,5 @@ private: bool m_sendColors{}; QColor m_lastColor; + quint8 m_lastMidiColor{}; };