From 8765359db2ba3f655009c1248155862dd60b89c5 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 24 Nov 2015 21:10:22 -0500 Subject: [PATCH] faderport: after connecting, turn off all lights, then party with them, then turn them all off --- libs/surfaces/faderport/faderport.cc | 40 +++++++++++++++++++++++++--- libs/surfaces/faderport/faderport.h | 7 ++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/libs/surfaces/faderport/faderport.cc b/libs/surfaces/faderport/faderport.cc index 11aefa0566..fc8d42f4cb 100644 --- a/libs/surfaces/faderport/faderport.cc +++ b/libs/surfaces/faderport/faderport.cc @@ -17,11 +17,12 @@ */ -#include - +#include #include #include +#include + #include #include @@ -167,10 +168,34 @@ FaderPort::~FaderPort () tear_down_gui (); } +void +FaderPort::all_lights_out () +{ + for (ButtonMap::iterator b = buttons.begin(); b != buttons.end(); ++b) { + b->second.set_led_state (_output_port, false); + g_usleep (1000); + } +} + +void +FaderPort::party () +{ + for (int n = 0; n < 5; ++n) { + for (ButtonMap::iterator b = buttons.begin(); b != buttons.end(); ++b) { + b->second.set_led_state (_output_port, random() % 3); + g_usleep (1000); + } + g_usleep (250000); + } + + all_lights_out (); +} + + FaderPort::ButtonInfo& FaderPort::button_info (ButtonID id) const { - map::const_iterator b = buttons.find (id); + ButtonMap::const_iterator b = buttons.find (id); assert (b != buttons.end()); return const_cast(b->second); } @@ -240,6 +265,10 @@ FaderPort::sysex_handler (MIDI::Parser &p, MIDI::byte *buf, size_t sz) native[2] = 0x64; _output_port->write (native, 3, 0); + + g_usleep (10000); + all_lights_out (); + party (); } } @@ -524,6 +553,11 @@ FaderPort::ButtonInfo::set_led_state (boost::shared_ptr port, int on return; } + if (out < 0) { + /* fader button ID - no LED */ + return; + } + MIDI::byte buf[3]; buf[0] = 0xa0; buf[1] = out; diff --git a/libs/surfaces/faderport/faderport.h b/libs/surfaces/faderport/faderport.h index 570a4f3c18..82006a3507 100644 --- a/libs/surfaces/faderport/faderport.h +++ b/libs/surfaces/faderport/faderport.h @@ -239,8 +239,13 @@ class FaderPort : public ARDOUR::ControlProtocol { } on_release; }; - std::map buttons; + typedef std::map ButtonMap; + + ButtonMap buttons; ButtonInfo& button_info (ButtonID) const; + + void all_lights_out (); + void party (); }; }