Ardour  8.7-14-g57a6773833
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  boost::function<void (uint32_t)> action,
46  boost::function<void (uint32_t)> shift_action = 0,
47  boost::function<void (uint32_t)> plugin_action = 0,
48  boost::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 (boost::function<void (uint32_t)> action) { plugin_action = action; }
61  void set_plugin_shift_action (boost::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  boost::function<void (uint32_t)> action;
85  boost::function<void (uint32_t)> shift_action;
86  boost::function<void (uint32_t)> plugin_action;
87  boost::function<void (uint32_t)> plugin_shift_action;
88 };
89 
91 {
92  public:
94  ControllerID id,
95  std::vector<uint32_t> state_values,
96  boost::function<void (uint32_t)> action,
97  boost::function<void (uint32_t)> shift_action = 0,
98  boost::function<void (uint32_t)> plugin_action = 0,
99  boost::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 (boost::function<void (uint32_t)> action) { plugin_action = action; }
126  void set_plugin_shift_action (boost::function<void (uint32_t)> action) { plugin_shift_action = action; }
127 
128  uint32_t state_count () { return state_values.size (); }
129 
130  boost::function<void (uint32_t)> action;
131  boost::function<void (uint32_t)> shift_action;
132  boost::function<void (uint32_t)> plugin_action;
133  boost::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  boost::function<void ()> action,
145  boost::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  boost::function<void ()> action;
165  boost::function<void ()> shift_action;
166 };
167 
168 class Encoder : public Controller
169 {
170  public:
172  ControllerID id,
173  boost::function<void (uint32_t)> action,
174  boost::function<void (uint32_t)> shift_action = 0,
175  boost::function<void (uint32_t)> plugin_action = 0,
176  boost::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 (boost::function<void (uint32_t)> action) { plugin_action = action; }
189  void set_plugin_shift_action (boost::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  boost::function<void (uint32_t)> action;
201  boost::function<void (uint32_t val)> shift_action;
202  boost::function<void (uint32_t val)> plugin_action;
203  boost::function<void (uint32_t val)> plugin_shift_action;
204 
205  PBD::Signal1<void, uint32_t>* plugin_signal;
206 };
207 
208 }
209 #endif // ardour_surface_console1_button_h
MultiStateButtonMap multi_buttons
Definition: console1.h:364
virtual void set_led_state(bool onoff)
Definition: c1_control.h:63
ControllerButton(Console1 *console1, ControllerID id, boost::function< void(uint32_t)> action, boost::function< void(uint32_t)> shift_action=0, boost::function< void(uint32_t)> plugin_action=0, boost::function< void(uint32_t)> plugin_shift_action=0)
Definition: c1_control.h:43
void set_plugin_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:60
boost::function< void(uint32_t)> plugin_shift_action
Definition: c1_control.h:87
boost::function< void(uint32_t)> shift_action
Definition: c1_control.h:85
void set_plugin_shift_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:61
boost::function< void(uint32_t)> plugin_action
Definition: c1_control.h:86
boost::function< void(uint32_t)> action
Definition: c1_control.h:84
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
boost::function< void(uint32_t val)> shift_action
Definition: c1_control.h:201
void set_plugin_shift_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:189
ControllerType get_type()
Definition: c1_control.h:186
boost::function< void(uint32_t)> action
Definition: c1_control.h:200
Encoder(Console1 *console1, ControllerID id, boost::function< void(uint32_t)> action, boost::function< void(uint32_t)> shift_action=0, boost::function< void(uint32_t)> plugin_action=0, boost::function< void(uint32_t)> plugin_shift_action=0)
Definition: c1_control.h:171
void set_plugin_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:188
PBD::Signal1< void, uint32_t > * plugin_signal
Definition: c1_control.h:205
boost::function< void(uint32_t val)> plugin_shift_action
Definition: c1_control.h:203
virtual void set_value(uint32_t value)
Definition: c1_control.h:191
boost::function< void(uint32_t val)> plugin_action
Definition: c1_control.h:202
boost::function< void()> shift_action
Definition: c1_control.h:165
Meter(Console1 *console1, ControllerID id, boost::function< void()> action, boost::function< void()> shift_action=0)
Definition: c1_control.h:142
boost::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
void set_plugin_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:125
boost::function< void(uint32_t)> shift_action
Definition: c1_control.h:131
boost::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
MultiStateButton(Console1 *console1, ControllerID id, std::vector< uint32_t > state_values, boost::function< void(uint32_t)> action, boost::function< void(uint32_t)> shift_action=0, boost::function< void(uint32_t)> plugin_action=0, boost::function< void(uint32_t)> plugin_shift_action=0)
Definition: c1_control.h:93
void set_plugin_shift_action(boost::function< void(uint32_t)> action)
Definition: c1_control.h:126
boost::function< void(uint32_t)> action
Definition: c1_control.h:130
boost::function< void(uint32_t)> plugin_action
Definition: c1_control.h:132
std::vector< uint32_t > state_values
Definition: c1_control.h:136
void write(const MidiByteArray &)