diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/Hardware.cpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/Hardware.cpp index 2d39a7d077..6aa83238e4 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/Hardware.cpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/Hardware.cpp @@ -38,7 +38,7 @@ Hardware::Hardware(const score::DocumentContext& doc) void Hardware::setupController() { ctl = new MidiController{}; - ctl->onCommand = commandCallback; + ctl->on_command = commandCallback; ctl->setup(); *img = QImage(8, 8, QImage::Format_RGB16); diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.cpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.cpp index a97c875256..dc432e2c38 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.cpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.cpp @@ -5,30 +5,33 @@ namespace RemoteControl { MidiController::MidiController() - : m_output{} - , m_input{} + : m_output{} + , m_input{{.on_message = [this] (const libremidi::message& message) { - m_input.set_callback([this](const libremidi::message& message) { - - if (message.get_message_type() == libremidi::message_type::CONTROL_CHANGE) - switch (message.bytes[1]) - { + if (message.get_message_type() == libremidi::message_type::CONTROL_CHANGE) + switch (message.bytes[1]) + { case SHIFT: shift = message.bytes[2] > 0; break; case PLAY: if (message.bytes[2] > 0) - onCommand(Controller::Play, shift); + on_command(Controller::Play, shift); break; case STOP: if (message.bytes[2] > 0) - onCommand(Controller::Stop, shift); + on_command(Controller::Stop, shift); break; default: break; + } +}, + .ignore_sysex = false, + .ignore_timing = false, + .ignore_sensing = false, + } } - }); -} +{} MidiController::~MidiController() { @@ -38,45 +41,53 @@ MidiController::~MidiController() void MidiController::setup(const QString& deviceName) { - openPortByName(m_output, deviceName); + open_port_by_name(deviceName); if (m_output.is_port_open()) { - m_output.send_message(msg); + using namespace libremidi; + m_output.send_message(message PROGRAMER_MODE); u_int8_t notes[]{SHIFT, PLAY, STOP}; u_int8_t colors[]{WHITE, GREEN, ORANGE}; for (int i = 0; i < 3; i++) { - m_output.send_message(msg.note_on(1, notes[i], colors[i])); + m_output.send_message(channel_events::note_on(1, notes[i], colors[i])); } - openPortByName(m_input, deviceName); - - gridWidth = NUM_ROWS; - gridHeigt = NUM_COLUMNS; + grid_width = NUM_ROWS; + grid_heigt = NUM_COLUMNS; } } -void MidiController::setTileFromRgb(int index, const QRgb& value) +void MidiController::set_tile_from_rgb(int index, const QRgb& value) { - } -template -void MidiController::openPortByName(T& libremidi, const QString& deviceName) +void MidiController::open_port_by_name(const QString& deviceName) { - int n_ports = libremidi.get_port_count(); + libremidi::observer obs; - if (n_ports == 0) - return; + for (const auto& input : obs.get_input_ports()) + { + if (deviceName == QString::fromStdString(input.port_name).split(":").back()) + m_input.open_port(input); + } + + // TODO : error handling here + if (m_input.is_port_connected()) return; - for (int i = 0; i < n_ports; i++) + auto outputs = obs.get_output_ports(); + + for (const auto& output : obs.get_output_ports()) { - if (deviceName == QString().fromStdString(libremidi.get_port_name(i)).split(":").back()) - libremidi.open_port(i); + if (deviceName == QString::fromStdString(output.port_name).split(":").back()) + m_output.open_port(output); } + + // TODO : error handling here + if (m_output.is_port_connected()) return; } } diff --git a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.hpp b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.hpp index f37f5a0e5a..c630cdc02e 100644 --- a/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.hpp +++ b/src/plugins/score-plugin-remotecontrol/RemoteControl/Hardware/MidiController.hpp @@ -37,23 +37,21 @@ class MidiController : public Controller MidiController(); ~MidiController(); - std::function onCommand; + std::function on_command; void setup(const QString& deviceName = " Launchpad Pro Standalone Port"); - void setTileFromRgb(int index, const QRgb& value); + void set_tile_from_rgb(int index, const QRgb& value); - int gridWidth{}; - int gridHeigt{}; + int grid_width{}; + int grid_heigt{}; private: bool shift{false}; - template - void openPortByName(T& libremidi, const QString& deviceName); + void open_port_by_name(const QString& deviceName); libremidi::midi_out m_output; libremidi::midi_in m_input; - libremidi::message msg PROGRAMER_MODE; }; }