mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
add button time and explicit bank switching to MCP support
This commit is contained in:
parent
5762ee114d
commit
c9658134ce
6 changed files with 93 additions and 13 deletions
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include "ardour/ardour.h"
|
||||||
|
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "surface.h"
|
#include "surface.h"
|
||||||
#include "control_group.h"
|
#include "control_group.h"
|
||||||
|
|
@ -29,7 +31,7 @@ using namespace Mackie;
|
||||||
Control*
|
Control*
|
||||||
Button::factory (Surface& surface, Button::ID bid, int id, const std::string& name, Group& group)
|
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 */
|
/* store button with the device-specific ID */
|
||||||
surface.buttons[id] = b;
|
surface.buttons[id] = b;
|
||||||
surface.controls.push_back (b);
|
surface.controls.push_back (b);
|
||||||
|
|
@ -37,6 +39,35 @@ Button::factory (Surface& surface, Button::ID bid, int id, const std::string& na
|
||||||
return 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
|
int
|
||||||
Button::name_to_id (const std::string& name)
|
Button::name_to_id (const std::string& name)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
#ifndef __ardour_mackie_control_protocol_button_h__
|
#ifndef __ardour_mackie_control_protocol_button_h__
|
||||||
#define __ardour_mackie_control_protocol_button_h__
|
#define __ardour_mackie_control_protocol_button_h__
|
||||||
|
|
||||||
|
#include "ardour/types.h"
|
||||||
|
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
|
||||||
|
|
@ -125,10 +127,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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)
|
: Control (did, name, group)
|
||||||
|
, _surface (s)
|
||||||
, _bid (bid)
|
, _bid (bid)
|
||||||
, _led (did, name + "_led", group) {}
|
, _led (did, name + "_led", group)
|
||||||
|
, press_time (0) {}
|
||||||
|
|
||||||
MidiByteArray zero() { return _led.zero (); }
|
MidiByteArray zero() { return _led.zero (); }
|
||||||
MidiByteArray set_state (LedState ls) { return _led.set_state (ls); }
|
MidiByteArray set_state (LedState ls) { return _led.set_state (ls); }
|
||||||
|
|
@ -139,9 +143,18 @@ public:
|
||||||
static int name_to_id (const std::string& name);
|
static int name_to_id (const std::string& name);
|
||||||
static std::string id_to_name (Button::ID);
|
static std::string id_to_name (Button::ID);
|
||||||
|
|
||||||
|
Surface& surface() const { return _surface; }
|
||||||
|
|
||||||
|
void pressed ();
|
||||||
|
void released ();
|
||||||
|
|
||||||
|
int32_t long_press_count ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Surface& _surface;
|
||||||
ID _bid; /* device independent button ID */
|
ID _bid; /* device independent button ID */
|
||||||
Led _led;
|
Led _led;
|
||||||
|
ARDOUR::microseconds_t press_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Mackie namespace
|
} // Mackie namespace
|
||||||
|
|
|
||||||
|
|
@ -486,6 +486,8 @@ class MackieControlProtocol
|
||||||
Mackie::LedState click_release (Mackie::Button&);
|
Mackie::LedState click_release (Mackie::Button&);
|
||||||
Mackie::LedState view_press (Mackie::Button&);
|
Mackie::LedState view_press (Mackie::Button&);
|
||||||
Mackie::LedState view_release (Mackie::Button&);
|
Mackie::LedState view_release (Mackie::Button&);
|
||||||
|
|
||||||
|
Mackie::LedState bank_release (Mackie::Button&, uint32_t bank_num);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
||||||
|
|
@ -559,14 +559,28 @@ MackieControlProtocol::enter_release (Button &)
|
||||||
}
|
}
|
||||||
|
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F1_press (Button &)
|
MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
|
||||||
|
{
|
||||||
|
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_press (Button &b)
|
||||||
{
|
{
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F1_release (Button &)
|
MackieControlProtocol::F1_release (Button &b)
|
||||||
{
|
{
|
||||||
return off;
|
return bank_release (b, 0);
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F2_press (Button &)
|
MackieControlProtocol::F2_press (Button &)
|
||||||
|
|
@ -574,9 +588,9 @@ MackieControlProtocol::F2_press (Button &)
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F2_release (Button &)
|
MackieControlProtocol::F2_release (Button &b)
|
||||||
{
|
{
|
||||||
return off;
|
return bank_release (b, 1);
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F3_press (Button &)
|
MackieControlProtocol::F3_press (Button &)
|
||||||
|
|
@ -584,9 +598,9 @@ MackieControlProtocol::F3_press (Button &)
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F3_release (Button &)
|
MackieControlProtocol::F3_release (Button &b)
|
||||||
{
|
{
|
||||||
return off;
|
return bank_release (b, 2);
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F4_press (Button &)
|
MackieControlProtocol::F4_press (Button &)
|
||||||
|
|
@ -594,9 +608,9 @@ MackieControlProtocol::F4_press (Button &)
|
||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F4_release (Button &)
|
MackieControlProtocol::F4_release (Button &b)
|
||||||
{
|
{
|
||||||
return off;
|
return bank_release (b, 3);
|
||||||
}
|
}
|
||||||
LedState
|
LedState
|
||||||
MackieControlProtocol::F5_press (Button &)
|
MackieControlProtocol::F5_press (Button &)
|
||||||
|
|
|
||||||
|
|
@ -532,6 +532,11 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev)
|
||||||
Button* button = buttons[ev->note_number];
|
Button* button = buttons[ev->note_number];
|
||||||
|
|
||||||
if (button) {
|
if (button) {
|
||||||
|
|
||||||
|
if (ev->velocity > 64) {
|
||||||
|
button->pressed ();
|
||||||
|
}
|
||||||
|
|
||||||
Strip* strip = dynamic_cast<Strip*> (&button->group());
|
Strip* strip = dynamic_cast<Strip*> (&button->group());
|
||||||
|
|
||||||
if (strip) {
|
if (strip) {
|
||||||
|
|
@ -543,9 +548,16 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev)
|
||||||
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", button->id()));
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", button->id()));
|
||||||
_mcp.handle_button_event (*this, *button, ev->velocity > 64 ? press : release);
|
_mcp.handle_button_event (*this, *button, ev->velocity > 64 ? press : release);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev->velocity <= 64) {
|
||||||
|
button->released ();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("no button found for %1\n", (int) ev->note_number));
|
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
|
void
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include "pbd/xml++.h"
|
#include "pbd/xml++.h"
|
||||||
#include "midi++/types.h"
|
#include "midi++/types.h"
|
||||||
|
|
||||||
|
#include "ardour/types.h"
|
||||||
|
|
||||||
#include "control_protocol/types.h"
|
#include "control_protocol/types.h"
|
||||||
|
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
|
|
@ -195,6 +197,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
int connection_state;
|
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];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue