Skip to content

Commit

Permalink
[update] rebase on current master
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudk committed Sep 14, 2024
1 parent 44d0cd4 commit 8e3426c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <wobjectimpl.h>

#include <score/application/ApplicationContext.hpp>
#include <Explorer/DocumentPlugin/DeviceDocumentPlugin.hpp>
#include <score/actions/ActionManager.hpp>
#include <Scenario/Application/ScenarioActions.hpp>
Expand Down Expand Up @@ -38,7 +39,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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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<typename T>
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,21 @@ class MidiController : public Controller
MidiController();
~MidiController();

std::function<void(Controller::Commands, const bool&)> onCommand;
std::function<void(Controller::Commands, const bool&)> 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 <typename T>
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;
};

}
Expand Down

0 comments on commit 8e3426c

Please sign in to comment.