13
0
livetrax/libs/surfaces/console1/c1_control.h

210 lines
5.4 KiB
C
Raw Normal View History

2023-05-07 10:21:37 -04:00
#ifndef ardour_surface_console1_button_h
#define ardour_surface_console1_button_h
#include "ardour/debug.h"
#include "console1.h"
namespace ArdourSurface {
using ControllerID = Console1::ControllerID;
class Controller
{
public:
enum ControllerType
{
CONTROLLER,
CONTROLLER_BUTTON,
MULTISTATE_BUTTON,
ENCODER,
METER
};
2023-05-16 16:45:11 -04:00
Controller (Console1* console1, ControllerID id)
2023-05-07 10:21:37 -04:00
: console1 (console1)
, _id (id)
{
}
virtual ~Controller () {}
2023-05-16 16:45:11 -04:00
Console1* console1;
2023-05-07 10:21:37 -04:00
ControllerID id () const { return _id; }
virtual ControllerType get_type () { return CONTROLLER; }
protected:
ControllerID _id;
};
class ControllerButton : public Controller
{
public:
2023-05-16 16:45:11 -04:00
ControllerButton (Console1* console1,
2023-05-07 10:21:37 -04:00
ControllerID id,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0 )
2023-05-07 10:21:37 -04:00
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
2023-05-16 16:45:11 -04:00
, plugin_action (plugin_action)
, plugin_shift_action (plugin_shift_action)
2023-05-07 10:21:37 -04:00
{
2023-05-16 16:45:11 -04:00
console1->buttons.insert (std::make_pair (id, this));
2023-05-07 10:21:37 -04:00
}
ControllerType get_type () { return CONTROLLER_BUTTON; }
void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
2023-05-16 16:45:11 -04:00
2023-05-07 10:21:37 -04:00
virtual void set_led_state (bool onoff)
{
// DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = onoff ? 127 : 0;
2023-05-16 16:45:11 -04:00
console1->write (buf, 3);
2023-05-07 10:21:37 -04:00
}
virtual void set_led_value (uint32_t val)
{
// DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = val;
2023-05-16 16:45:11 -04:00
console1->write (buf, 3);
2023-05-07 10:21:37 -04:00
}
std::function<void (uint32_t)> action;
std::function<void (uint32_t)> shift_action;
std::function<void (uint32_t)> plugin_action;
std::function<void (uint32_t)> plugin_shift_action;
2023-05-07 10:21:37 -04:00
};
class MultiStateButton : public Controller
{
public:
2023-05-16 16:45:11 -04:00
MultiStateButton (Console1* console1,
2023-05-07 10:21:37 -04:00
ControllerID id,
std::vector<uint32_t> state_values,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0
)
2023-05-07 10:21:37 -04:00
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
, plugin_action (action)
, plugin_shift_action (shift_action)
2023-05-07 10:21:37 -04:00
, state_values (state_values)
{
2023-05-16 16:45:11 -04:00
console1->multi_buttons.insert (std::make_pair (id, this));
2023-05-07 10:21:37 -04:00
}
ControllerType get_type () { return MULTISTATE_BUTTON; }
virtual void set_led_state (uint32_t state)
{
if (state >= state_values.size ())
return;
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = state_values[state];
2023-05-16 16:45:11 -04:00
console1->write (buf, 3);
2023-05-07 10:21:37 -04:00
}
void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
2023-05-07 10:21:37 -04:00
uint32_t state_count () { return state_values.size (); }
std::function<void (uint32_t)> action;
std::function<void (uint32_t)> shift_action;
std::function<void (uint32_t)> plugin_action;
std::function<void (uint32_t)> plugin_shift_action;
2023-05-07 10:21:37 -04:00
private:
std::vector<uint32_t> state_values;
};
class Meter : public Controller
{
public:
2023-05-16 16:45:11 -04:00
Meter (Console1* console1,
2023-05-07 10:21:37 -04:00
ControllerID id,
std::function<void ()> action,
std::function<void ()> shift_action = 0)
2023-05-07 10:21:37 -04:00
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
{
2023-05-16 16:45:11 -04:00
console1->meters.insert (std::make_pair (id, this));
2023-05-07 10:21:37 -04:00
}
ControllerType get_type () { return METER; }
virtual void set_value (uint32_t value)
{
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = value;
2023-05-16 16:45:11 -04:00
console1->write (buf, 3);
2023-05-07 10:21:37 -04:00
}
std::function<void ()> action;
std::function<void ()> shift_action;
2023-05-07 10:21:37 -04:00
};
class Encoder : public Controller
{
public:
2023-05-16 16:45:11 -04:00
Encoder (Console1* console1,
2023-05-07 10:21:37 -04:00
ControllerID id,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0)
2023-05-07 10:21:37 -04:00
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
2023-05-16 16:45:11 -04:00
, plugin_action (plugin_action)
, plugin_shift_action (plugin_action)
2023-05-07 10:21:37 -04:00
{
2023-05-16 16:45:11 -04:00
console1->encoders.insert (std::make_pair (id, this));
2023-05-07 10:21:37 -04:00
}
ControllerType get_type () { return ENCODER; }
void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
2023-05-16 16:45:11 -04:00
2023-05-07 10:21:37 -04:00
virtual void set_value (uint32_t value)
{
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = value;
2023-05-16 16:45:11 -04:00
console1->write (buf, 3);
2023-05-07 10:21:37 -04:00
}
std::function<void (uint32_t)> action;
std::function<void (uint32_t val)> shift_action;
std::function<void (uint32_t val)> plugin_action;
std::function<void (uint32_t val)> plugin_shift_action;
2023-05-16 16:45:11 -04:00
2024-10-18 12:01:28 -04:00
PBD::Signal<void(uint32_t)>* plugin_signal;
2023-05-07 10:21:37 -04:00
};
}
#endif // ardour_surface_console1_button_h