Ardour  9.0-pre0-582-g084a23a80d
c1_control.h
Go to the documentation of this file.
1 #ifndef ardour_surface_console1_button_h
2 #define ardour_surface_console1_button_h
3 
4 #include "ardour/debug.h"
5 #include "console1.h"
6 
7 namespace ArdourSurface {
8 
10 
12 {
13  public:
15  {
20  METER
21  };
22 
24  : console1 (console1)
25  , _id (id)
26  {
27  }
28 
29  virtual ~Controller () {}
30 
32  ControllerID id () const { return _id; }
33 
34  virtual ControllerType get_type () { return CONTROLLER; }
35 
36  protected:
38 };
39 
41 {
42  public:
44  ControllerID id,
45  std::function<void (uint32_t)> action,
46  std::function<void (uint32_t)> shift_action = 0,
47  std::function<void (uint32_t)> plugin_action = 0,
48  std::function<void (uint32_t)> plugin_shift_action = 0 )
50  , action (action)
54  {
55  console1->buttons.insert (std::make_pair (id, this));
56  }
57 
59 
60  void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
61  void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
62 
63  virtual void set_led_state (bool onoff)
64  {
65  // DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
66  MIDI::byte buf[3];
67  buf[0] = 0xB0;
68  buf[1] = _id;
69  buf[2] = onoff ? 127 : 0;
70 
71  console1->write (buf, 3);
72  }
73 
74  virtual void set_led_value (uint32_t val)
75  {
76  // DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
77  MIDI::byte buf[3];
78  buf[0] = 0xB0;
79  buf[1] = _id;
80  buf[2] = val;
81 
82  console1->write (buf, 3);
83  }
84  std::function<void (uint32_t)> action;
85  std::function<void (uint32_t)> shift_action;
86  std::function<void (uint32_t)> plugin_action;
87  std::function<void (uint32_t)> plugin_shift_action;
88 };
89 
91 {
92  public:
94  ControllerID id,
95  std::vector<uint32_t> state_values,
96  std::function<void (uint32_t)> action,
97  std::function<void (uint32_t)> shift_action = 0,
98  std::function<void (uint32_t)> plugin_action = 0,
99  std::function<void (uint32_t)> plugin_shift_action = 0
100  )
101  : Controller (console1, id)
102  , action (action)
107  {
108  console1->multi_buttons.insert (std::make_pair (id, this));
109  }
110 
112 
113  virtual void set_led_state (uint32_t state)
114  {
115  if (state >= state_values.size ())
116  return;
117  MIDI::byte buf[3];
118  buf[0] = 0xB0;
119  buf[1] = _id;
120  buf[2] = state_values[state];
121 
122  console1->write (buf, 3);
123  }
124 
125  void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
126  void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
127 
128  uint32_t state_count () { return state_values.size (); }
129 
130  std::function<void (uint32_t)> action;
131  std::function<void (uint32_t)> shift_action;
132  std::function<void (uint32_t)> plugin_action;
133  std::function<void (uint32_t)> plugin_shift_action;
134 
135  private:
136  std::vector<uint32_t> state_values;
137 };
138 
139 class Meter : public Controller
140 {
141  public:
143  ControllerID id,
144  std::function<void ()> action,
145  std::function<void ()> shift_action = 0)
146  : Controller (console1, id)
147  , action (action)
149  {
150  console1->meters.insert (std::make_pair (id, this));
151  }
152 
154 
155  virtual void set_value (uint32_t value)
156  {
157  MIDI::byte buf[3];
158  buf[0] = 0xB0;
159  buf[1] = _id;
160  buf[2] = value;
161 
162  console1->write (buf, 3);
163  }
164  std::function<void ()> action;
165  std::function<void ()> shift_action;
166 };
167 
168 class Encoder : public Controller
169 {
170  public:
172  ControllerID id,
173  std::function<void (uint32_t)> action,
174  std::function<void (uint32_t)> shift_action = 0,
175  std::function<void (uint32_t)> plugin_action = 0,
176  std::function<void (uint32_t)> plugin_shift_action = 0)
177  : Controller (console1, id)
178  , action (action)
182  {
183  console1->encoders.insert (std::make_pair (id, this));
184  }
185 
187 
188  void set_plugin_action (std::function<void (uint32_t)> action) { plugin_action = action; }
189  void set_plugin_shift_action (std::function<void (uint32_t)> action) { plugin_shift_action = action; }
190 
191  virtual void set_value (uint32_t value)
192  {
193  MIDI::byte buf[3];
194  buf[0] = 0xB0;
195  buf[1] = _id;
196  buf[2] = value;
197 
198  console1->write (buf, 3);
199  }
200  std::function<void (uint32_t)> action;
201  std::function<void (uint32_t val)> shift_action;
202  std::function<void (uint32_t val)> plugin_action;
203  std::function<void (uint32_t val)> plugin_shift_action;
204 
205  PBD::Signal<void(uint32_t)>* plugin_signal;
206 };
207 
208 }
209 #endif // ardour_surface_console1_button_h
MultiStateButtonMap multi_buttons
Definition: console1.h:364
ControllerButton(Console1 *console1, 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)
Definition: c1_control.h:43
virtual void set_led_state(bool onoff)
Definition: c1_control.h:63
std::function< void(uint32_t)> shift_action
Definition: c1_control.h:85
void set_plugin_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:60
void set_plugin_shift_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:61
std::function< void(uint32_t)> action
Definition: c1_control.h:84
std::function< void(uint32_t)> plugin_shift_action
Definition: c1_control.h:87
std::function< void(uint32_t)> plugin_action
Definition: c1_control.h:86
virtual void set_led_value(uint32_t val)
Definition: c1_control.h:74
virtual ControllerType get_type()
Definition: c1_control.h:34
ControllerID id() const
Definition: c1_control.h:32
Controller(Console1 *console1, ControllerID id)
Definition: c1_control.h:23
std::function< void(uint32_t)> action
Definition: c1_control.h:200
std::function< void(uint32_t val)> plugin_shift_action
Definition: c1_control.h:203
ControllerType get_type()
Definition: c1_control.h:186
void set_plugin_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:188
std::function< void(uint32_t val)> plugin_action
Definition: c1_control.h:202
Encoder(Console1 *console1, 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)
Definition: c1_control.h:171
void set_plugin_shift_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:189
virtual void set_value(uint32_t value)
Definition: c1_control.h:191
PBD::Signal< void(uint32_t)> * plugin_signal
Definition: c1_control.h:205
std::function< void(uint32_t val)> shift_action
Definition: c1_control.h:201
std::function< void()> action
Definition: c1_control.h:164
virtual void set_value(uint32_t value)
Definition: c1_control.h:155
ControllerType get_type()
Definition: c1_control.h:153
Meter(Console1 *console1, ControllerID id, std::function< void()> action, std::function< void()> shift_action=0)
Definition: c1_control.h:142
std::function< void()> shift_action
Definition: c1_control.h:165
std::function< void(uint32_t)> shift_action
Definition: c1_control.h:131
MultiStateButton(Console1 *console1, 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)
Definition: c1_control.h:93
std::function< void(uint32_t)> plugin_shift_action
Definition: c1_control.h:133
virtual void set_led_state(uint32_t state)
Definition: c1_control.h:113
std::function< void(uint32_t)> plugin_action
Definition: c1_control.h:132
std::function< void(uint32_t)> action
Definition: c1_control.h:130
std::vector< uint32_t > state_values
Definition: c1_control.h:136
void set_plugin_shift_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:126
void set_plugin_action(std::function< void(uint32_t)> action)
Definition: c1_control.h:125
void write(const MidiByteArray &)