: 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:
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)
{
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.
--- /dev/null
+/*
+ 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);
+}
#define __ardour_mackie_control_protocol_led_h__
#include "controls.h"
+#include "midi_byte_array.h"
+#include "types.h"
namespace Mackie {
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;
};
}
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));
}
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));
}
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));
}
}
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");
}
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));
}
}
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());
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
);
}
-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);
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);
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
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
{
if (_route) {
Button& button = solo();
- _surface->write (builder.build_led (button, _route->soloed()));
+ _surface->write (button.led().set_state (_route->soloed() ? on : off));
}
}
{
if (_route) {
Button & button = mute();
- _surface->write (builder.build_led (button, _route->muted()));
+ _surface->write (button.led().set_state (_route->muted() ? on : off));
}
}
{
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));
}
}
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;
}
{
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();
}
{
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;
ButtonState button_state;
};
-std::ostream & operator << ( std::ostream &, const ControlState & );
+std::ostream & operator << (std::ostream &, const ControlState &);
class Control;
class Fader;
fader.cc
gui.cc
interface.cc
+ led.cc
mackie_control_protocol.cc
mackie_jog_wheel.cc
mackie_midi_builder.cc