BuGUI
BUtton Grid User Interface
Loading...
Searching...
No Matches
midi_in.hpp
1#pragma once
2#include <hardware/component.hpp>
3#include <concepts/device.hpp>
4#include <concepts/message.hpp>
5#include <concepts/common.hpp>
6
7#include <libremidi/libremidi.hpp>
8
9namespace bugui
10{
11template <typename Device, typename Controller>
12class midi_in
13 : virtual public component<Device, Controller>
14{
15 using grid_t = grid<Device, Controller>;
16 using buttons_t = buttons<Device, Controller>;
17
18protected:
19 explicit midi_in(Controller* ctrlr)
20 : m_input{{.on_message{[this, ctrlr]
21 (const libremidi::message& message)
22 {
23// TODO : extend with additional options
24// ie. checking for a cc struct inside Device::buttons
25#define case_msg_type(C) \
26{ \
27 if constexpr(has_buttons<Device>) \
28 if constexpr (is_##C<typename Device::buttons>) \
29 { \
30 this->btn_prsr.button_presser::set_midi(message.bytes[2]); \
31 if (buttons_t::on_button_received(ctrlr, message.bytes[1])) \
32 return; \
33 } \
34 \
35 if constexpr (has_grid<Device>) \
36 if constexpr (is_##C<typename Device::grid>) \
37 { \
38 this->prsr.button_presser::set_midi(message.bytes[2]); \
39 if (grid_t::on_grid_received(ctrlr, message.bytes[1])) \
40 return; \
41 } \
42 \
43 break; \
44}
45
46 using enum libremidi::message_type;
47
48 switch (message.get_message_type())
49 {
50 case CONTROL_CHANGE:
51 case_msg_type(cc)
52 case NOTE_ON:
53 case NOTE_OFF:
54 case_msg_type(on_off)
55 default:
56 break;
57 }
58 }},
59 .ignore_sysex = false,
60 .ignore_timing = false,
61 .ignore_sensing = false,
62 }
63 }
64 { }
65
66 ~midi_in() override { m_input.close_port(); }
67
68 libremidi::midi_in m_input;
69};
70
71} // namespace bugui
Empty struct for devices that do not feature labelled buttons.
Definition buttons.hpp:16
Inherits from all type of hardware components like grid, buttons... Provides the hardware type with t...
Definition component.hpp:14
Empty struct fro device's that do not feature a button grid.
Definition grid.hpp:18