diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-11 04:02:46 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2012-04-11 04:02:46 +0000 |
commit | 7c9c4d6dc746604eac95d0ee767a9b9f2795366e (patch) | |
tree | 394c74f26eccae161db113498ae6a180d9ca9373 /libs | |
parent | 722defe41a6119cfe6e9f5a66fdcb2408c12a455 (diff) |
MCP: breakout Led class code; remove builder code for Led changes and put it into Led::set_state() which returns the (possibly empty) MIDI data needed to go back to the MCP device to change the LED visible state
git-svn-id: svn://localhost/ardour2/branches/3.0@11886 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r-- | libs/surfaces/mackie/button.h | 4 | ||||
-rw-r--r-- | libs/surfaces/mackie/controls.cc | 10 | ||||
-rw-r--r-- | libs/surfaces/mackie/controls.h | 2 | ||||
-rw-r--r-- | libs/surfaces/mackie/led.cc | 59 | ||||
-rw-r--r-- | libs/surfaces/mackie/led.h | 14 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.cc | 24 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_midi_builder.cc | 33 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_midi_builder.h | 5 | ||||
-rw-r--r-- | libs/surfaces/mackie/strip.cc | 8 | ||||
-rw-r--r-- | libs/surfaces/mackie/types.h | 24 | ||||
-rw-r--r-- | libs/surfaces/mackie/wscript | 1 |
11 files changed, 107 insertions, 77 deletions
diff --git a/libs/surfaces/mackie/button.h b/libs/surfaces/mackie/button.h index 03a8bfd883..4e624aba75 100644 --- a/libs/surfaces/mackie/button.h +++ b/libs/surfaces/mackie/button.h @@ -101,10 +101,12 @@ public: : Control (id, name, group) , _led (id, name + "_led", group) {} - virtual const Led & led() const { return _led; } + virtual Led & led() { return _led; } virtual type_t type() const { return type_button; }; + MidiByteArray update_message () const; + static Control* factory (Surface&, int id, const char*, Group&); private: diff --git a/libs/surfaces/mackie/controls.cc b/libs/surfaces/mackie/controls.cc index 745da21969..972a28cb0d 100644 --- a/libs/surfaces/mackie/controls.cc +++ b/libs/surfaces/mackie/controls.cc @@ -98,16 +98,6 @@ Pot::factory (Surface& surface, int id, const char* name, Group& group) } Control* -Led::factory (Surface& surface, int id, const char* name, Group& group) -{ - Led* l = new Led (id, name, group); - surface.leds[id] = l; - surface.controls.push_back (l); - group.add (*l); - return l; -} - -Control* Jog::factory (Surface& surface, int id, const char* name, Group& group) { Jog* j = new Jog (id, name, group); diff --git a/libs/surfaces/mackie/controls.h b/libs/surfaces/mackie/controls.h index a87dc46cbf..9d5163680f 100644 --- a/libs/surfaces/mackie/controls.h +++ b/libs/surfaces/mackie/controls.h @@ -65,7 +65,7 @@ public: Control (int id, std::string name, Group& group); virtual ~Control() {} - virtual const Led & led() const { throw MackieControlException ("no led available"); } + virtual Led & led() { throw MackieControlException ("no led available"); } /// type() << 8 + midi id of the control. This /// provides a unique id for any control on the surface. diff --git a/libs/surfaces/mackie/led.cc b/libs/surfaces/mackie/led.cc new file mode 100644 index 0000000000..8dc1d626cc --- /dev/null +++ b/libs/surfaces/mackie/led.cc @@ -0,0 +1,59 @@ +/* + Copyright (C) 2006,2007 John Anderson + Copyright (C) 2012 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "led.h" +#include "surface.h" +#include "control_group.h" + +using namespace Mackie; + +Control* +Led::factory (Surface& surface, int id, const char* name, Group& group) +{ + Led* l = new Led (id, name, group); + surface.leds[id] = l; + surface.controls.push_back (l); + group.add (*l); + return l; +} + +MidiByteArray +Led::set_state (LedState new_state) +{ + if (new_state != state) { + return MidiByteArray(); + } + + state = new_state; + + MIDI::byte msg = 0; + + switch (state.state()) { + case LedState::on: + msg = 0x7f; break; + case LedState::off: + msg = 0x00; break; + case LedState::flashing: + msg = 0x01; break; + case LedState::none: + return MidiByteArray (); + } + + return MidiByteArray (3, 0x90, raw_id(), msg); +} diff --git a/libs/surfaces/mackie/led.h b/libs/surfaces/mackie/led.h index b2bc29ec5f..47ea2adfa0 100644 --- a/libs/surfaces/mackie/led.h +++ b/libs/surfaces/mackie/led.h @@ -21,6 +21,8 @@ #define __ardour_mackie_control_protocol_led_h__ #include "controls.h" +#include "midi_byte_array.h" +#include "types.h" namespace Mackie { @@ -29,14 +31,18 @@ class Led : public Control public: Led (int id, std::string name, Group & group) : Control (id, name, group) + , state (off) { } - virtual const Led & led() const { return *this; } - - virtual type_t type() const { return type_led; } - + Led & led() { return *this; } + type_t type() const { return type_led; } + MidiByteArray set_state (LedState); + static Control* factory (Surface&, int id, const char*, Group&); + + private: + LedState state; }; } diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index 23bb7ee656..cd8eb5a8c8 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -401,7 +401,7 @@ MackieControlProtocol::update_global_button (const string & name, LedState ls) if (surface->controls_by_name.find (name) != surface->controls_by_name.end()) { Button * button = dynamic_cast<Button*> (surface->controls_by_name[name]); - surface->write (builder.build_led (button->led(), ls)); + surface->write (button->led().set_state (ls)); } else { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Button %1 not found\n", name)); } @@ -418,7 +418,7 @@ MackieControlProtocol::update_global_led (const string & name, LedState ls) if (surface->controls_by_name.find (name) != surface->controls_by_name.end()) { Led * led = dynamic_cast<Led*> (surface->controls_by_name[name]); - surface->write (builder.build_led (*led, ls)); + surface->write (led->set_state (ls)); } else { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Led %1 not found\n", name)); } @@ -706,7 +706,7 @@ MackieControlProtocol::notify_solo_active_changed (bool active) Button * rude_solo = reinterpret_cast<Button*> (surface->controls_by_name["solo"]); if (rude_solo) { - surface->write (builder.build_led (*rude_solo, active ? flashing : off)); + surface->write (rude_solo->led().set_state (active ? flashing : off)); } } @@ -775,7 +775,7 @@ MackieControlProtocol::notify_record_state_changed () break; } - surfaces.front()->write (builder.build_led (*rec, ls)); + surfaces.front()->write (rec->led().set_state (ls)); } else { DEBUG_TRACE (DEBUG::MackieControl, "record button control not found\n"); } @@ -877,7 +877,7 @@ void MackieControlProtocol::update_led (Surface& surface, Button& button, Mackie::LedState ls) { if (ls != none) { - surface.port().write (builder.build_led (button, ls)); + surface.port().write (button.led().set_state (ls)); } } @@ -960,8 +960,6 @@ MackieControlProtocol::handle_button_event (Surface& surface, Button& button, Bu return; } - LedState ls; - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2\n", (bs == press ? "press" : "release"), button.raw_id())); ButtonMap::iterator b = button_map.find (button.raw_id()); @@ -971,13 +969,15 @@ MackieControlProtocol::handle_button_event (Surface& surface, Button& button, Bu ButtonHandlers& bh (b->second); switch (bs) { - case press: ls = (this->*(bh.press)) (button); break; - case release: ls = (this->*(bh.release)) (button); break; - case neither: break; + case press: + surface.write (button.led().set_state ((this->*(bh.press)) (button))); + case release: + surface.write (button.led().set_state ((this->*(bh.release)) (button))); + break; + default: + break; } } - - update_led (surface, button, ls); } void diff --git a/libs/surfaces/mackie/mackie_midi_builder.cc b/libs/surfaces/mackie/mackie_midi_builder.cc index beee395333..bfc6ea50cf 100644 --- a/libs/surfaces/mackie/mackie_midi_builder.cc +++ b/libs/surfaces/mackie/mackie_midi_builder.cc @@ -84,33 +84,6 @@ MidiByteArray MackieMidiBuilder::build_led_ring (const LedRing & led_ring, const ); } -MidiByteArray MackieMidiBuilder::build_led (const Button & button, LedState ls) -{ - return build_led (button.led(), ls); -} - -MidiByteArray MackieMidiBuilder::build_led (const Led & led, LedState ls) -{ - MIDI::byte state = 0; - - switch (ls.state()) { - case LedState::on: - state = 0x7f; break; - case LedState::off: - state = 0x00; break; - case LedState::flashing: - state = 0x01; break; - case LedState::none: - return MidiByteArray (); - } - - return MidiByteArray (3 - , midi_button_id - , led.raw_id() - , state - ); -} - MidiByteArray MackieMidiBuilder::build_fader (const Fader & fader, float pos) { int posi = int (0x3fff * pos); @@ -146,14 +119,14 @@ MidiByteArray MackieMidiBuilder::zero_strip (Surface& surface, const Strip & str return retval; } -MidiByteArray MackieMidiBuilder::zero_control (const Control & control) +MidiByteArray MackieMidiBuilder::zero_control (Control & control) { switch (control.type()) { case Control::type_button: - return build_led ((Button&)control, off); + return control.led().set_state (off); case Control::type_led: - return build_led ((Led&)control, off); + return dynamic_cast<Led&>(control).set_state (off); case Control::type_fader: return build_fader ((Fader&)control, 0.0); diff --git a/libs/surfaces/mackie/mackie_midi_builder.h b/libs/surfaces/mackie/mackie_midi_builder.h index e4f929a588..8836f3de2e 100644 --- a/libs/surfaces/mackie/mackie_midi_builder.h +++ b/libs/surfaces/mackie/mackie_midi_builder.h @@ -68,9 +68,6 @@ public: MidiByteArray build_led_ring (const Pot & pot, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot); MidiByteArray build_led_ring (const LedRing & led_ring, const ControlState &, midi_pot_mode mode = midi_pot_mode_dot); - MidiByteArray build_led (const Led & led, LedState ls); - MidiByteArray build_led (const Button & button, LedState ls); - MidiByteArray build_fader (const Fader & fader, float pos); /// return bytes that will reset all controls to their zero positions @@ -78,7 +75,7 @@ public: MidiByteArray zero_strip (Surface&, const Strip & strip); // provide bytes to zero the given control - MidiByteArray zero_control (const Control & control); + MidiByteArray zero_control (Control & control); // display the first 2 chars of the msg in the 2 char display // . is appended to the previous character, so A.B. would diff --git a/libs/surfaces/mackie/strip.cc b/libs/surfaces/mackie/strip.cc index 21a312e407..610fe8dd3b 100644 --- a/libs/surfaces/mackie/strip.cc +++ b/libs/surfaces/mackie/strip.cc @@ -310,7 +310,7 @@ Strip::notify_solo_changed () { if (_route) { Button& button = solo(); - _surface->write (builder.build_led (button, _route->soloed())); + _surface->write (button.led().set_state (_route->soloed() ? on : off)); } } @@ -319,7 +319,7 @@ Strip::notify_mute_changed () { if (_route) { Button & button = mute(); - _surface->write (builder.build_led (button, _route->muted())); + _surface->write (button.led().set_state (_route->muted() ? on : off)); } } @@ -328,7 +328,7 @@ Strip::notify_record_enable_changed () { if (_route) { Button & button = recenable(); - _surface->write (builder.build_led (button, _route->record_enabled())); + _surface->write (button.led().set_state (_route->record_enabled() ? on : off)); } } @@ -421,7 +421,7 @@ Strip::handle_button (SurfacePort & port, Control & control, ButtonState bs) if (!_route) { // no route so always switch the light off // because no signals will be emitted by a non-route - _surface->write (builder.build_led (control.led(), off)); + _surface->write (control.led().set_state (off)); return false; } diff --git a/libs/surfaces/mackie/types.h b/libs/surfaces/mackie/types.h index 4fc52f66e4..bdddf0b248 100644 --- a/libs/surfaces/mackie/types.h +++ b/libs/surfaces/mackie/types.h @@ -36,16 +36,18 @@ class LedState { public: enum state_t { none, off, flashing, on }; - LedState() : _state( none ) {} - LedState( bool yn ): _state( yn ? on : off ) {} - LedState( state_t state ): _state( state ) {} + LedState() : _state (none) {} + LedState (bool yn): _state (yn ? on : off) {} + LedState (state_t state): _state (state) {} - bool operator == ( const LedState & other ) const + LedState& operator= (state_t s) { _state = s; return *this; } + + bool operator == (const LedState & other) const { return state() == other.state(); } - bool operator != ( const LedState & other ) const + bool operator != (const LedState & other) const { return state() != other.state(); } @@ -71,13 +73,13 @@ struct ControlState { ControlState(): pos(0.0), sign(0), delta(0.0), ticks(0), led_state(off), button_state(neither) {} - ControlState( LedState ls ): pos(0.0), delta(0.0), led_state(ls), button_state(neither) {} + ControlState (LedState ls): pos(0.0), delta(0.0), led_state(ls), button_state(neither) {} // Note that this sets both pos and delta to the flt value - ControlState( LedState ls, float flt ): pos(flt), delta(flt), ticks(0), led_state(ls), button_state(neither) {} - ControlState( float flt ): pos(flt), delta(flt), ticks(0), led_state(none), button_state(neither) {} - ControlState( float flt, unsigned int tcks ): pos(flt), delta(flt), ticks(tcks), led_state(none), button_state(neither) {} - ControlState( ButtonState bs ): pos(0.0), delta(0.0), ticks(0), led_state(none), button_state(bs) {} + ControlState (LedState ls, float flt): pos(flt), delta(flt), ticks(0), led_state(ls), button_state(neither) {} + ControlState (float flt): pos(flt), delta(flt), ticks(0), led_state(none), button_state(neither) {} + ControlState (float flt, unsigned int tcks): pos(flt), delta(flt), ticks(tcks), led_state(none), button_state(neither) {} + ControlState (ButtonState bs): pos(0.0), delta(0.0), ticks(0), led_state(none), button_state(bs) {} /// For faders. Between 0 and 1. float pos; @@ -95,7 +97,7 @@ struct ControlState ButtonState button_state; }; -std::ostream & operator << ( std::ostream &, const ControlState & ); +std::ostream & operator << (std::ostream &, const ControlState &); class Control; class Fader; diff --git a/libs/surfaces/mackie/wscript b/libs/surfaces/mackie/wscript index 9aac5ce811..6c0a719654 100644 --- a/libs/surfaces/mackie/wscript +++ b/libs/surfaces/mackie/wscript @@ -26,6 +26,7 @@ def build(bld): fader.cc gui.cc interface.cc + led.cc mackie_control_protocol.cc mackie_jog_wheel.cc mackie_midi_builder.cc |