BuGUI
BUtton Grid User Interface
Loading...
Searching...
No Matches
midi_out.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>
13 : public virtual component<Device, Controller>
14{
15 using grid_t = grid<Device, Controller>;
16 using buttons_t = buttons<Device, Controller>;
17
18protected:
19 ~midi_out() override
20 {
21 clear();
22 m_output.close_port();
23 }
24
25 void init()
26 { m_output.send_message(Device::init()); }
27
28 void clear() override
29 {
30 using namespace libremidi;
31
32 if constexpr(has_clear<Device>)
33 m_output.send_message(Device::clear());
34 else
35 {
36 if constexpr (has_grid<Device>)
37 grid_t::clear([this] (auto id)
38 { m_output.send_message(144, id, 0); }); // OFF
39 }
40 }
41
42 void set_grid(painter& p) override
43 {
44 if constexpr (has_color<Device> && has_grid<Device>)
45 grid_t::paint(p, [this] (auto id, const auto& color)
46 { m_output.send_message(144, id, color.get()); }); // NOTE_ON
47 }
48
49 void set_button(const button_painter& p) override
50 {
51 if constexpr (has_buttons<Device>)
52 {
53 buttons_t::paint(p, [this] (auto id, const auto& color)
54 { m_output.send_message(144, id, color.get()); }); // NOTE_ON
55 }
56 }
57
58 libremidi::midi_out m_output;
59};
60
61} // namespace bugui
Definition midi_out.hpp:14
void set_button(const button_painter &p) override
Pass a reference to the button_painter object and display it's content to the device's buttons.
Definition midi_out.hpp:49
void clear() override
Turns off all LEDs.
Definition midi_out.hpp:28
void set_grid(painter &p) override
Pass a reference to the painter object and display it's content to the grid.
Definition midi_out.hpp:42
Definition device.hpp:40
Definition device.hpp:54
Definition device.hpp:12
Definition device.hpp:31
Conveys button colors from the controller to the base_hardware.
Definition button_painter.hpp:10
Empty struct for devices that do not feature labelled buttons.
Definition buttons.hpp:16
Generic colour class holding RGBA values of a primary and a secondary colour. The blinking and pulsin...
Definition color.hpp:12
rgba get() const noexcept
Retrieves the primary colour as rgba values.
Definition color.hpp:55
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
The painter class.
Definition painter.hpp:12