score-addon-hardware/Hardware/MidiController.hpp

77 lines
1.7 KiB
C++
Raw Normal View History

2024-10-03 23:50:15 +01:00
#ifndef MIDICONTROLLER_HPP
#define MIDICONTROLLER_HPP
#include <Scenario/Application/ScenarioActions.hpp>
#include <score/actions/ActionManager.hpp>
#include <libremidi/libremidi.hpp>
#include "Controller.hpp"
// Macros to temporarly act as the device description file
#define PROGRAMER_MODE {240, 0, 32, 41, 2, 16, 44, 3, 247}
#define SHIFT 80
#define PLAY 19
#define STOP 8
#define UP 91
#define DOWN 92
#define LEFT 93
#define RIGHT 94
#define BLACK 0
#define WHITE 2
#define LIGHT_BLUE 36
#define GREEN 64
#define ORANGE 9
// Grid
#define GRID \
{81, 82, 83, 84, 85, 86, 87, 88}, \
{71, 72, 73, 74, 75, 76, 77, 78}, \
{61, 62, 63, 64, 65, 66, 67, 68}, \
{51, 52, 53, 54, 55, 56, 57, 58}, \
{41, 42, 43, 44, 45, 46, 47, 48}, \
{31, 32, 33, 34, 35, 36, 37, 38}, \
{21, 22, 23, 24, 25, 26, 27, 28}, \
{11, 12, 13, 14, 15, 16, 17, 18}
#define MAX_ROW_INDEX 7
#define MAX_COLUMN_INDEX 7
namespace Explorer
{
class DeviceDocumentPlugin;
}
namespace Hardware
2024-10-03 23:50:15 +01:00
{
class MidiController : public Controller
{
public:
MidiController();
~MidiController();
std::function<void(Controller::Commands, const bool&)> on_command;
void setup(const QString& deviceName = "Launchpad Pro Standalone Port");
void update_grid();
void clear_grid();
void draw_line(const std::array<double, 2>& p1, const std::array<double, 2>& p2);
private:
void open_port_by_name(const QString& deviceName);
u_int8_t grid[MAX_ROW_INDEX + 1][MAX_COLUMN_INDEX + 1];
u_int8_t previous_grid[MAX_ROW_INDEX + 1][MAX_COLUMN_INDEX + 1];
u_int8_t current_grid[MAX_ROW_INDEX + 1][MAX_COLUMN_INDEX + 1];
bool shift{false};
libremidi::midi_out m_output;
libremidi::midi_in m_input;
};
}
#endif // MIDICONTROLLER_HPP