MCP: breakout Led class code; remove builder code for Led changes and put it into...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 11 Apr 2012 04:02:46 +0000 (04:02 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 11 Apr 2012 04:02:46 +0000 (04:02 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11886 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/surfaces/mackie/button.h
libs/surfaces/mackie/controls.cc
libs/surfaces/mackie/controls.h
libs/surfaces/mackie/led.cc [new file with mode: 0644]
libs/surfaces/mackie/led.h
libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_midi_builder.cc
libs/surfaces/mackie/mackie_midi_builder.h
libs/surfaces/mackie/strip.cc
libs/surfaces/mackie/types.h
libs/surfaces/mackie/wscript

index 03a8bfd883f2b7e6cf7ef6c52e363e15c58c7df8..4e624aba75470dcfe1e6f7410a901fab22fbe037 100644 (file)
@@ -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:
index 745da219697f439455430dab3ff3b4afcda6c6a6..972a28cb0df0546877ea06daaec12174599ec8d8 100644 (file)
@@ -97,16 +97,6 @@ Pot::factory (Surface& surface, int id, const char* name, Group& group)
        return p;
 }
 
-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)
 {
index a87dc46cbfff763d8466cc0936b3349726bef8b1..9d5163680f282df9321e151b6ef102f082d3c06d 100644 (file)
@@ -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 (file)
index 0000000..8dc1d62
--- /dev/null
@@ -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);
+}
index b2bc29ec5f5dfb1f0437c5f4af9df217b257f010..47ea2adfa02605f5082b4946a5fbcc2a2b24d0ee 100644 (file)
@@ -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;
 };
 
 }
index 23bb7ee6569dea7e194d641496fcdbc1f90f1a74..cd8eb5a8c8aa888774cac573459a1f2973153c4b 100644 (file)
@@ -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
index beee3953337050f312a53477ce56cc2366ecb382..bfc6ea50cfbe755d799eb24c0e6e1e48787b9ba5 100644 (file)
@@ -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);
index e4f929a58854c472077b23ecc9a1dd35fe692bdf..8836f3de2e46e773e3e3761ef73446ebb8b0f385 100644 (file)
@@ -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
index 21a312e4075e3154145cf141f7078426b6f6314a..610fe8dd3be6992dbe124b92ef8bcd0d6a870dbf 100644 (file)
@@ -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;
        }
 
index 4fc52f66e4b498d1b58c568965d94e9c84440673..bdddf0b248db36e4927a524076aaaadb7f1fc290 100644 (file)
@@ -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;
index 9aac5ce811e1de55eb6e796c9069dbb9d156735a..6c0a719654f434ca4cd1122dfad4266b37fd2d7e 100644 (file)
@@ -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