#include <glib.h>
+#include "ardour/ardour.h"
+
#include "button.h"
#include "surface.h"
#include "control_group.h"
Control*
Button::factory (Surface& surface, Button::ID bid, int id, const std::string& name, Group& group)
{
- Button* b = new Button (bid, id, name, group);
+ Button* b = new Button (surface, bid, id, name, group);
/* store button with the device-specific ID */
surface.buttons[id] = b;
surface.controls.push_back (b);
return b;
}
+void
+Button::pressed ()
+{
+ press_time = ARDOUR::get_microseconds ();
+}
+
+void
+Button::released ()
+{
+ press_time = 0;
+}
+
+int32_t
+Button::long_press_count ()
+{
+ if (press_time == 0) {
+ return -1; /* button is not pressed */
+ }
+
+ const ARDOUR::microseconds_t delta = ARDOUR::get_microseconds () - press_time;
+
+ if (delta < 500000) {
+ return 0;
+ } else if (delta < 1000000) {
+ return 1;
+ }
+
+ return 2;
+}
int
Button::name_to_id (const std::string& name)
{
#ifndef __ardour_mackie_control_protocol_button_h__
#define __ardour_mackie_control_protocol_button_h__
+#include "ardour/types.h"
+
#include "controls.h"
#include "led.h"
};
- Button (ID bid, int did, std::string name, Group & group)
+ Button (Surface& s, ID bid, int did, std::string name, Group & group)
: Control (did, name, group)
+ , _surface (s)
, _bid (bid)
- , _led (did, name + "_led", group) {}
+ , _led (did, name + "_led", group)
+ , press_time (0) {}
MidiByteArray zero() { return _led.zero (); }
MidiByteArray set_state (LedState ls) { return _led.set_state (ls); }
static int name_to_id (const std::string& name);
static std::string id_to_name (Button::ID);
+ Surface& surface() const { return _surface; }
+
+ void pressed ();
+ void released ();
+
+ int32_t long_press_count ();
+
private:
+ Surface& _surface;
ID _bid; /* device independent button ID */
Led _led;
+ ARDOUR::microseconds_t press_time;
};
} // Mackie namespace
Mackie::LedState click_release (Mackie::Button&);
Mackie::LedState view_press (Mackie::Button&);
Mackie::LedState view_release (Mackie::Button&);
+
+ Mackie::LedState bank_release (Mackie::Button&, uint32_t bank_num);
};
} // namespace
}
LedState
-MackieControlProtocol::F1_press (Button &)
+MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
{
- return off;
+ uint32_t bank_num = basic_bank_num;
+
+ if (b.long_press_count() > 0) {
+ bank_num = 8 + basic_bank_num;
+ }
+
+ switch_banks (n_strips() * bank_num);
+
+ return on;
}
+
LedState
-MackieControlProtocol::F1_release (Button &)
+MackieControlProtocol::F1_press (Button &b)
{
return off;
}
LedState
+MackieControlProtocol::F1_release (Button &b)
+{
+ return bank_release (b, 0);
+}
+LedState
MackieControlProtocol::F2_press (Button &)
{
return off;
}
LedState
-MackieControlProtocol::F2_release (Button &)
+MackieControlProtocol::F2_release (Button &b)
{
- return off;
+ return bank_release (b, 1);
}
LedState
MackieControlProtocol::F3_press (Button &)
return off;
}
LedState
-MackieControlProtocol::F3_release (Button &)
+MackieControlProtocol::F3_release (Button &b)
{
- return off;
+ return bank_release (b, 2);
}
LedState
MackieControlProtocol::F4_press (Button &)
return off;
}
LedState
-MackieControlProtocol::F4_release (Button &)
+MackieControlProtocol::F4_release (Button &b)
{
- return off;
+ return bank_release (b, 3);
}
LedState
MackieControlProtocol::F5_press (Button &)
Button* button = buttons[ev->note_number];
if (button) {
+
+ if (ev->velocity > 64) {
+ button->pressed ();
+ }
+
Strip* strip = dynamic_cast<Strip*> (&button->group());
if (strip) {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", button->id()));
_mcp.handle_button_event (*this, *button, ev->velocity > 64 ? press : release);
}
+
+ if (ev->velocity <= 64) {
+ button->released ();
+ }
+
} else {
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("no button found for %1\n", (int) ev->note_number));
}
+
+ /* button release should reset timer AFTER handler(s) have run */
}
void
#include "pbd/xml++.h"
#include "midi++/types.h"
+#include "ardour/types.h"
+
#include "control_protocol/types.h"
#include "controls.h"
Fader* _master_fader;
float _last_master_gain_written;
PBD::ScopedConnection port_connection;
-
+
void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
MidiByteArray host_connection_query (MidiByteArray& bytes);
MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
};
int connection_state;
+
+ /* this times the duration between press+release events for all
+ possible 127 buttons on THIS surface (not all surfaces).
+ */
+
+ ARDOUR::microseconds_t button_timer[127];
};
}