Inital support for Steinberg's CC121 control surface

This commit is contained in:
W.P. van Paassen 2016-10-11 19:21:21 +02:00 committed by Paul Davis
parent bbb20272d5
commit 5a3fe4aa20
11 changed files with 2835 additions and 0 deletions

BIN
gtk2_ardour/icons/cc121.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -80,6 +80,7 @@ namespace PBD {
LIBARDOUR_API extern DebugBits BackendPorts;
LIBARDOUR_API extern DebugBits VSTCallbacks;
LIBARDOUR_API extern DebugBits FaderPort;
LIBARDOUR_API extern DebugBits CC121;
LIBARDOUR_API extern DebugBits VCA;
LIBARDOUR_API extern DebugBits Push2;

View File

@ -77,5 +77,6 @@ PBD::DebugBits PBD::DEBUG::BackendThreads = PBD::new_debug_bit ("backendthreads"
PBD::DebugBits PBD::DEBUG::BackendPorts = PBD::new_debug_bit ("backendports");
PBD::DebugBits PBD::DEBUG::VSTCallbacks = PBD::new_debug_bit ("vstcallbacks");
PBD::DebugBits PBD::DEBUG::FaderPort = PBD::new_debug_bit ("faderport");
PBD::DebugBits PBD::DEBUG::CC121 = PBD::new_debug_bit ("cc121");
PBD::DebugBits PBD::DEBUG::VCA = PBD::new_debug_bit ("vca");
PBD::DebugBits PBD::DEBUG::Push2 = PBD::new_debug_bit ("push2");

1290
libs/surfaces/cc121/cc121.cc Normal file

File diff suppressed because it is too large Load Diff

342
libs/surfaces/cc121/cc121.h Normal file
View File

@ -0,0 +1,342 @@
/*
Copyright (C) 2006 Paul Davis
Copyright (C) 2016 W.P. van Paassen
Thanks to Rolf Meyerhoff for reverse engineering the CC121 protocol.
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.
*/
#ifndef ardour_surface_cc121_h
#define ardour_surface_cc121_h
#include <list>
#include <map>
#include <set>
#include <glibmm/threads.h>
#define ABSTRACT_UI_EXPORTS
#include "pbd/abstract_ui.h"
#include "ardour/types.h"
#include "control_protocol/control_protocol.h"
namespace PBD {
class Controllable;
class ControllableDescriptor;
}
#include <midi++/types.h>
//#include "pbd/signals.h"
//#include "midi_byte_array.h"
#include "types.h"
#include "glibmm/main.h"
namespace MIDI {
class Parser;
class Port;
}
namespace ARDOUR {
class AsyncMIDIPort;
class Bundle;
class Port;
class Session;
class MidiPort;
}
class MIDIControllable;
class MIDIFunction;
class MIDIAction;
namespace ArdourSurface {
struct CC121Request : public BaseUI::BaseRequestObject {
public:
CC121Request () {}
~CC121Request () {}
};
class CC121 : public ARDOUR::ControlProtocol, public AbstractUI<CC121Request> {
public:
CC121 (ARDOUR::Session&);
virtual ~CC121();
int set_active (bool yn);
/* we probe for a device when our ports are connected. Before that,
there's no way to know if the device exists or not.
*/
static bool probe() { return true; }
static void* request_factory (uint32_t);
XMLNode& get_state ();
int set_state (const XMLNode&, int version);
bool has_editor () const { return true; }
void* get_gui () const;
void tear_down_gui ();
/* Note: because the CC121 speaks an inherently duplex protocol,
we do not implement get/set_feedback() since this aspect of
support for the protocol is not optional.
*/
void do_request (CC121Request*);
int stop ();
void thread_init ();
PBD::Signal0<void> ConnectionChange;
boost::shared_ptr<ARDOUR::Port> input_port();
boost::shared_ptr<ARDOUR::Port> output_port();
enum ButtonID {
Rec = 0x00,
Solo = 0x08,
Mute = 0x10,
Left = 0x30,
Right = 0x31,
EButton = 0x33,
Function1 = 0x36,
Function2 = 0x37,
Function3 = 0x38,
Function4 = 0x39,
Value = 0x3A,
Footswitch = 0x3B,
FP_Read = 0x4A,
FP_Write = 0x4B,
Loop = 0x56,
ToStart = 0x58,
ToEnd = 0x5A,
Rewind = 0x5B,
Ffwd = 0x5C,
Stop = 0x5D,
Play = 0x5E,
RecEnable = 0x5F,
FaderTouch = 0x68,
EQ1Enable = 0x70,
EQ2Enable = 0x71,
EQ3Enable = 0x72,
EQ4Enable = 0x73,
EQType = 0x74,
AllBypass = 0x75,
Jog = 0x76,
Lock = 0x77,
InputMonitor = 0x78,
OpenVST = 0x79,
Output = 22
};
enum ButtonState {
ShiftDown = 0x1,
RewindDown = 0x2,
StopDown = 0x4,
UserDown = 0x8,
LongPress = 0x10
};
void set_action (ButtonID, std::string const& action_name, bool on_press, CC121::ButtonState = ButtonState (0));
std::string get_action (ButtonID, bool on_press, CC121::ButtonState = ButtonState (0));
std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
private:
boost::shared_ptr<ARDOUR::Stripable> _current_stripable;
boost::weak_ptr<ARDOUR::Stripable> pre_master_stripable;
boost::weak_ptr<ARDOUR::Stripable> pre_monitor_stripable;
boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
// Bundle to represent our input ports
boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
// Bundle to represent our output ports
boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
PBD::ScopedConnectionList midi_connections;
bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
mutable void *gui;
void build_gui ();
bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
PBD::ScopedConnection port_connection;
enum ConnectionState {
InputConnected = 0x1,
OutputConnected = 0x2
};
int connection_state;
void connected ();
bool _device_active;
int fader_msb;
int fader_lsb;
bool fader_is_touched;
enum JogMode { scroll=1, zoom=2 };
JogMode _jogmode;
ARDOUR::microseconds_t last_encoder_time;
int last_good_encoder_delta;
int last_encoder_delta, last_last_encoder_delta;
void button_press_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
void button_release_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
void fader_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
void encoder_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
/* void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);*/
ButtonState button_state;
friend class Button;
class Button {
public:
enum ActionType {
NamedAction,
InternalFunction,
};
Button (CC121& f, std::string const& str, ButtonID i)
: fp (f)
, name (str)
, id (i)
, flash (false)
{}
void set_action (std::string const& action_name, bool on_press, CC121::ButtonState = ButtonState (0));
void set_action (boost::function<void()> function, bool on_press, CC121::ButtonState = ButtonState (0));
std::string get_action (bool press, CC121::ButtonState bs = ButtonState (0));
void set_led_state (boost::shared_ptr<MIDI::Port>, bool onoff);
void invoke (ButtonState bs, bool press);
bool uses_flash () const { return flash; }
void set_flash (bool yn) { flash = yn; }
XMLNode& get_state () const;
int set_state (XMLNode const&);
sigc::connection timeout_connection;
private:
CC121& fp;
std::string name;
ButtonID id;
bool flash;
struct ToDo {
ActionType type;
/* could be a union if boost::function didn't require a
* constructor
*/
std::string action_name;
boost::function<void()> function;
};
typedef std::map<CC121::ButtonState,ToDo> ToDoMap;
ToDoMap on_press;
ToDoMap on_release;
};
typedef std::map<ButtonID,Button> ButtonMap;
ButtonMap buttons;
Button& get_button (ButtonID) const;
std::set<ButtonID> buttons_down;
std::set<ButtonID> consumed;
void all_lights_out ();
void close ();
void start_midi_handling ();
void stop_midi_handling ();
PBD::ScopedConnectionList session_connections;
void connect_session_signals ();
void map_recenable_state ();
void map_transport_state ();
sigc::connection periodic_connection;
bool periodic ();
sigc::connection heartbeat_connection;
sigc::connection blink_connection;
typedef std::list<ButtonID> Blinkers;
Blinkers blinkers;
bool blink_state;
bool blink ();
bool beat ();
void start_blinking (ButtonID);
void stop_blinking (ButtonID);
void set_current_stripable (boost::shared_ptr<ARDOUR::Stripable>);
void drop_current_stripable ();
void use_master ();
void use_monitor ();
void gui_track_selection_changed (ARDOUR::StripableNotificationListPtr);
PBD::ScopedConnection selection_connection;
PBD::ScopedConnectionList stripable_connections;
void map_stripable_state ();
void map_solo ();
void map_mute ();
bool rec_enable_state;
void map_recenable ();
void map_gain ();
void map_cut ();
void map_auto ();
/* operations (defined in operations.cc) */
void read ();
void write ();
void input_monitor ();
void left ();
void right ();
void touch ();
void off ();
void undo ();
void redo ();
void solo ();
void mute ();
void jog ();
void rec_enable ();
void ardour_pan_azimuth (float);
void ardour_pan_width (float);
void mixbus_pan (float);
void punch ();
};
}
#endif /* ardour_surface_cc121_h */

View File

@ -0,0 +1,80 @@
/*
Copyright (C) 2012 Paul Davis
Copyright (C) 2016 W.P. van Paassen
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 <pbd/failed_constructor.h>
#include "control_protocol/control_protocol.h"
#include "cc121.h"
using namespace ARDOUR;
using namespace ArdourSurface;
static ControlProtocol*
new_cc121_midi_protocol (ControlProtocolDescriptor* /*descriptor*/, Session* s)
{
CC121* fp;
try {
fp = new CC121 (*s);
} catch (failed_constructor& err) {
return 0;
}
if (fp->set_active (true)) {
delete fp;
return 0;
}
return fp;
}
static void
delete_cc121_midi_protocol (ControlProtocolDescriptor* /*descriptor*/, ControlProtocol* cp)
{
delete cp;
}
static bool
probe_cc121_midi_protocol (ControlProtocolDescriptor* /*descriptor*/)
{
return CC121::probe ();
}
static void*
cc121_request_buffer_factory (uint32_t num_requests)
{
return CC121::request_factory (num_requests);
}
static ControlProtocolDescriptor cc121_midi_descriptor = {
/*name : */ "Steinberg CC121",
/*id : */ "uri://ardour.org/surfaces/cc121:0",
/*ptr : */ 0,
/*module : */ 0,
/*mandatory : */ 0,
/*supports_feedback : */ true,
/*probe : */ probe_cc121_midi_protocol,
/*initialize : */ new_cc121_midi_protocol,
/*destroy : */ delete_cc121_midi_protocol,
/*request_buffer_factory */ cc121_request_buffer_factory
};
extern "C" ARDOURSURFACE_API ControlProtocolDescriptor* protocol_descriptor () { return &cc121_midi_descriptor; }

629
libs/surfaces/cc121/gui.cc Normal file
View File

@ -0,0 +1,629 @@
/*
Copyright (C) 2015 Paul Davis
Copyright (C) 2016 W.P. van Paassen
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 <gtkmm/alignment.h>
#include <gtkmm/label.h>
#include <gtkmm/liststore.h>
#include "pbd/unwind.h"
#include "pbd/strsplit.h"
#include "pbd/file_utils.h"
#include "gtkmm2ext/bindings.h"
#include "gtkmm2ext/gtk_ui.h"
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h"
#include "ardour/audioengine.h"
#include "ardour/filesystem_paths.h"
#include "cc121.h"
#include "gui.h"
#include "pbd/i18n.h"
using namespace PBD;
using namespace ARDOUR;
using namespace ArdourSurface;
using namespace std;
using namespace Gtk;
using namespace Gtkmm2ext;
void*
CC121::get_gui () const
{
if (!gui) {
const_cast<CC121*>(this)->build_gui ();
}
static_cast<Gtk::VBox*>(gui)->show_all();
return gui;
}
void
CC121::tear_down_gui ()
{
if (gui) {
Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
if (w) {
w->hide();
delete w;
}
}
delete static_cast<CC121GUI*> (gui);
gui = 0;
}
void
CC121::build_gui ()
{
gui = (void*) new CC121GUI (*this);
}
/*--------------------*/
CC121GUI::CC121GUI (CC121& p)
: fp (p)
, table (2, 5)
, action_table (5, 4)
, ignore_active_change (false)
{
set_border_width (12);
table.set_row_spacings (4);
table.set_col_spacings (6);
table.set_border_width (12);
table.set_homogeneous (false);
std::string data_file_path;
string name = "cc121.png";
Searchpath spath(ARDOUR::ardour_data_search_path());
spath.add_subdirectory_to_paths ("icons");
find_file (spath, name, data_file_path);
if (!data_file_path.empty()) {
image.set (data_file_path);
hpacker.pack_start (image, false, false);
}
Gtk::Label* l;
Gtk::Alignment* align;
int row = 0;
int action_row = 1;
input_combo.pack_start (midi_port_columns.short_name);
output_combo.pack_start (midi_port_columns.short_name);
input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &CC121GUI::active_port_changed), &input_combo, true));
output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &CC121GUI::active_port_changed), &output_combo, false));
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
l->set_alignment (1.0, 0.5);
table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
l->set_alignment (1.0, 0.5);
table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
row++;
build_available_action_menu ();
build_user_action_combo (function1_combo, CC121::ButtonState(0), CC121::Function1);
build_user_action_combo (function2_combo, CC121::ButtonState(0), CC121::Function2);
build_user_action_combo (function3_combo, CC121::ButtonState(0), CC121::Function3);
build_user_action_combo (function4_combo, CC121::ButtonState(0), CC121::Function4);
build_user_action_combo (value_combo, CC121::ButtonState(0), CC121::Value);
build_user_action_combo (lock_combo, CC121::ButtonState(0), CC121::Lock);
build_user_action_combo (eq1_combo, CC121::ButtonState(0), CC121::EQ1Enable);
build_user_action_combo (eq2_combo, CC121::ButtonState(0), CC121::EQ2Enable);
build_user_action_combo (eq3_combo, CC121::ButtonState(0), CC121::EQ3Enable);
build_user_action_combo (eq4_combo, CC121::ButtonState(0), CC121::EQ4Enable);
build_user_action_combo (eqtype_combo, CC121::ButtonState(0), CC121::EQType);
build_user_action_combo (allbypass_combo, CC121::ButtonState(0), CC121::AllBypass);
build_foot_action_combo (foot_combo, CC121::ButtonState(0));
action_table.set_row_spacings (4);
action_table.set_col_spacings (6);
action_table.set_border_width (12);
action_table.set_homogeneous (false);
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Function 1")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (function1_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Function 2")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (function2_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Function 3")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (function3_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Function 4")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (function4_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Value")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (value_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Lock")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (lock_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("EQ1")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (eq1_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("EQ2")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (eq2_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("EQ3")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (eq3_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("EQ4")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (eq4_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("EQType")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (eqtype_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("AllBypass")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (allbypass_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
l = manage (new Gtk::Label);
l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Footswitch")));
l->set_alignment (1.0, 0.5);
action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
align = manage (new Alignment);
align->set (0.0, 0.5);
align->add (foot_combo);
action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
action_row++;
table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
row++;
hpacker.pack_start (table, true, true);
pack_start (hpacker, false, false);
/* update the port connection combos */
update_port_combos ();
/* catch future changes to connection state */
fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&CC121GUI::connection_handler, this), gui_context());
}
CC121GUI::~CC121GUI ()
{
}
void
CC121GUI::connection_handler ()
{
/* ignore all changes to combobox active strings here, because we're
updating them to match a new ("external") reality - we were called
because port connections have changed.
*/
PBD::Unwinder<bool> ici (ignore_active_change, true);
update_port_combos ();
}
void
CC121GUI::update_port_combos ()
{
vector<string> midi_inputs;
vector<string> midi_outputs;
ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
bool input_found = false;
bool output_found = false;
int n;
input_combo.set_model (input);
output_combo.set_model (output);
Gtk::TreeModel::Children children = input->children();
Gtk::TreeModel::Children::iterator i;
i = children.begin();
++i; /* skip "Disconnected" */
for (n = 1; i != children.end(); ++i, ++n) {
string port_name = (*i)[midi_port_columns.full_name];
if (fp.input_port()->connected_to (port_name)) {
input_combo.set_active (n);
input_found = true;
break;
}
}
if (!input_found) {
input_combo.set_active (0); /* disconnected */
}
children = output->children();
i = children.begin();
++i; /* skip "Disconnected" */
for (n = 1; i != children.end(); ++i, ++n) {
string port_name = (*i)[midi_port_columns.full_name];
if (fp.output_port()->connected_to (port_name)) {
output_combo.set_active (n);
output_found = true;
break;
}
}
if (!output_found) {
output_combo.set_active (0); /* disconnected */
}
}
void
CC121GUI::build_available_action_menu ()
{
/* build a model of all available actions (needs to be tree structured
* more)
*/
available_action_model = TreeStore::create (action_columns);
vector<string> paths;
vector<string> labels;
vector<string> tooltips;
vector<string> keys;
vector<Glib::RefPtr<Gtk::Action> > actions;
Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
typedef std::map<string,TreeIter> NodeMap;
NodeMap nodes;
NodeMap::iterator r;
vector<string>::iterator k;
vector<string>::iterator p;
vector<string>::iterator t;
vector<string>::iterator l;
available_action_model->clear ();
TreeIter rowp;
TreeModel::Row parent;
/* Disabled item (row 0) */
rowp = available_action_model->append();
parent = *(rowp);
parent[action_columns.name] = _("Disabled");
for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
TreeModel::Row row;
vector<string> parts;
parts.clear ();
split (*p, parts, '/');
if (parts.empty()) {
continue;
}
//kinda kludgy way to avoid displaying menu items as mappable
if ( parts[1] == _("Main_menu") )
continue;
if ( parts[1] == _("JACK") )
continue;
if ( parts[1] == _("redirectmenu") )
continue;
if ( parts[1] == _("Editor_menus") )
continue;
if ( parts[1] == _("RegionList") )
continue;
if ( parts[1] == _("ProcessorMenu") )
continue;
if ((r = nodes.find (parts[1])) == nodes.end()) {
/* top level is missing */
TreeIter rowp;
TreeModel::Row parent;
rowp = available_action_model->append();
nodes[parts[1]] = rowp;
parent = *(rowp);
parent[action_columns.name] = parts[1];
row = *(available_action_model->append (parent.children()));
} else {
row = *(available_action_model->append ((*r->second)->children()));
}
/* add this action */
if (l->empty ()) {
row[action_columns.name] = *t;
action_map[*t] = *p;
} else {
row[action_columns.name] = *l;
action_map[*l] = *p;
}
string path = (*p);
/* ControlProtocol::access_action() is not interested in the
legacy "<Actions>/" prefix part of a path.
*/
path = path.substr (strlen ("<Actions>/"));
row[action_columns.path] = path;
}
}
void
CC121GUI::action_changed (Gtk::ComboBox* cb, CC121::ButtonID id, CC121::ButtonState bs)
{
TreeModel::const_iterator row = cb->get_active ();
string action_path = (*row)[action_columns.path];
/* release binding */
fp.set_action (id, action_path, false, bs);
}
void
CC121GUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, CC121::ButtonID id, CC121::ButtonState bs)
{
Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
TreeIter rowp;
TreeModel::Row row;
string current_action = fp.get_action (id, false, bs); /* lookup release action */
int active_row = -1;
int n;
vector<pair<string,string> >::const_iterator i;
rowp = model->append();
row = *(rowp);
row[action_columns.name] = _("Disabled");
row[action_columns.path] = string();
if (current_action.empty()) {
active_row = 0;
}
for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
rowp = model->append();
row = *(rowp);
row[action_columns.name] = i->first;
row[action_columns.path] = i->second;
if (current_action == i->second) {
active_row = n+1;
}
}
cb.set_model (model);
cb.pack_start (action_columns.name);
if (active_row >= 0) {
cb.set_active (active_row);
}
cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &CC121GUI::action_changed), &cb, id, bs));
}
void
CC121GUI::build_foot_action_combo (Gtk::ComboBox& cb, CC121::ButtonState bs)
{
vector<pair<string,string> > actions;
actions.push_back (make_pair (string("Toggle Roll"), string(X_("Transport/ToggleRoll"))));
actions.push_back (make_pair (string("Toggle Rec-Enable"), string(X_("Transport/Record"))));
actions.push_back (make_pair (string("Toggle Roll+Rec"), string(X_("Transport/record-roll"))));
actions.push_back (make_pair (string("Toggle Loop"), string(X_("Transport/Loop"))));
actions.push_back (make_pair (string("Toggle Click"), string(X_("Transport/ToggleClick"))));
build_action_combo (cb, actions, CC121::Footswitch, bs);
}
bool
CC121GUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
{
TreeModel::Row row = *iter;
string path = row[action_columns.path];
if (path == action_path) {
*found = iter;
return true;
}
return false;
}
void
CC121GUI::build_user_action_combo (Gtk::ComboBox& cb, CC121::ButtonState bs, CC121::ButtonID id)
{
cb.set_model (available_action_model);
cb.pack_start (action_columns.name);
cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &CC121GUI::action_changed), &cb, id, bs));
/* set the active "row" to the right value for the current button binding */
string current_action = fp.get_action (id, false, bs); /* lookup release action */
if (current_action.empty()) {
cb.set_active (0); /* "disabled" */
return;
}
TreeModel::iterator iter = available_action_model->children().end();
available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &CC121GUI::find_action_in_model), current_action, &iter));
if (iter != available_action_model->children().end()) {
cb.set_active (iter);
} else {
cb.set_active (0);
}
}
Glib::RefPtr<Gtk::ListStore>
CC121GUI::build_midi_port_list (vector<string> const & ports, bool for_input)
{
Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
TreeModel::Row row;
row = *store->append ();
row[midi_port_columns.full_name] = string();
row[midi_port_columns.short_name] = _("Disconnected");
for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
row = *store->append ();
row[midi_port_columns.full_name] = *p;
std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
if (pn.empty ()) {
pn = (*p).substr ((*p).find (':') + 1);
}
row[midi_port_columns.short_name] = pn;
}
return store;
}
void
CC121GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
{
if (ignore_active_change) {
return;
}
TreeModel::iterator active = combo->get_active ();
string new_port = (*active)[midi_port_columns.full_name];
if (new_port.empty()) {
if (for_input) {
fp.input_port()->disconnect_all ();
} else {
fp.output_port()->disconnect_all ();
}
return;
}
if (for_input) {
if (!fp.input_port()->connected_to (new_port)) {
fp.input_port()->disconnect_all ();
fp.input_port()->connect (new_port);
}
} else {
if (!fp.output_port()->connected_to (new_port)) {
fp.output_port()->disconnect_all ();
fp.output_port()->connect (new_port);
}
}
}

116
libs/surfaces/cc121/gui.h Normal file
View File

@ -0,0 +1,116 @@
/*
Copyright (C) 2015 Paul Davis
Copyright (C) 2016 W.P. van Paassen
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.
*/
#ifndef __ardour_cc121_gui_h__
#define __ardour_cc121_gui_h__
#include <vector>
#include <string>
#include <gtkmm/box.h>
#include <gtkmm/combobox.h>
#include <gtkmm/image.h>
#include <gtkmm/table.h>
#include <gtkmm/treestore.h>
namespace Gtk {
class CellRendererCombo;
class ListStore;
}
#include "cc121.h"
namespace ArdourSurface {
class CC121GUI : public Gtk::VBox
{
public:
CC121GUI (CC121&);
~CC121GUI ();
private:
CC121& fp;
Gtk::HBox hpacker;
Gtk::Table table;
Gtk::Table action_table;
Gtk::ComboBox input_combo;
Gtk::ComboBox output_combo;
Gtk::Image image;
Gtk::ComboBox foot_combo;
Gtk::ComboBox function1_combo;
Gtk::ComboBox function2_combo;
Gtk::ComboBox function3_combo;
Gtk::ComboBox function4_combo;
Gtk::ComboBox value_combo;
Gtk::ComboBox lock_combo;
Gtk::ComboBox eq1_combo;
Gtk::ComboBox eq2_combo;
Gtk::ComboBox eq3_combo;
Gtk::ComboBox eq4_combo;
Gtk::ComboBox eqtype_combo;
Gtk::ComboBox allbypass_combo;
void update_port_combos ();
PBD::ScopedConnection connection_change_connection;
void connection_handler ();
struct MidiPortColumns : public Gtk::TreeModel::ColumnRecord {
MidiPortColumns() {
add (short_name);
add (full_name);
}
Gtk::TreeModelColumn<std::string> short_name;
Gtk::TreeModelColumn<std::string> full_name;
};
MidiPortColumns midi_port_columns;
bool ignore_active_change;
Glib::RefPtr<Gtk::ListStore> build_midi_port_list (std::vector<std::string> const & ports, bool for_input);
void active_port_changed (Gtk::ComboBox*,bool for_input);
struct ActionColumns : public Gtk::TreeModel::ColumnRecord {
ActionColumns() {
add (name);
add (path);
}
Gtk::TreeModelColumn<std::string> name;
Gtk::TreeModelColumn<std::string> path;
};
ActionColumns action_columns;
Glib::RefPtr<Gtk::TreeStore> available_action_model;
std::map<std::string,std::string> action_map; // map from action names to paths
void build_action_combo (Gtk::ComboBox& cb, std::vector<std::pair<std::string,std::string> > const & actions, CC121::ButtonID, CC121::ButtonState);
void build_user_action_combo (Gtk::ComboBox&, CC121::ButtonState, CC121::ButtonID);
void build_foot_action_combo (Gtk::ComboBox&, CC121::ButtonState);
void build_available_action_menu ();
void action_changed (Gtk::ComboBox*, CC121::ButtonID, CC121::ButtonState);
bool find_action_in_model (const Gtk::TreeModel::iterator& iter, std::string const & action_path, Gtk::TreeModel::iterator* found);
};
}
#endif /* __ardour_cc121_gui_h__ */

View File

@ -0,0 +1,340 @@
/*
Copyright (C) 2015 Paul Davis
Copyright (C) 2016 W.P. van Paassen
Thanks to Rolf Meyerhoff for reverse engineering the CC121 protocol.
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 "ardour/async_midi_port.h"
#include "ardour/monitor_processor.h"
#include "ardour/monitor_control.h"
#include "ardour/pannable.h"
#include "ardour/plugin_insert.h"
#include "ardour/rc_configuration.h"
#include "ardour/record_enable_control.h"
#include "ardour/session.h"
#include "ardour/track.h"
#include "ardour/types.h"
#include "cc121.h"
using namespace ARDOUR;
using namespace ArdourSurface;
using namespace PBD;
/* this value is chosen to given smooth motion from 0..1.0 in about 270 degrees
* of encoder rotation.
*/
static const double encoder_divider = 24.0;
void
CC121::input_monitor ()
{
if (_current_stripable) {
MonitorChoice choice = _current_stripable->monitoring_control()->monitoring_choice ();
switch(choice) {
case MonitorAuto:
_current_stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::NoGroup);
get_button(InputMonitor).set_led_state (_output_port, true);
break;
case MonitorInput:
_current_stripable->monitoring_control()->set_value (MonitorDisk, PBD::Controllable::NoGroup);
get_button(InputMonitor).set_led_state (_output_port, false);
break;
case MonitorDisk:
_current_stripable->monitoring_control()->set_value (MonitorCue, PBD::Controllable::NoGroup);
get_button(InputMonitor).set_led_state (_output_port, false);
break;
case MonitorCue:
_current_stripable->monitoring_control()->set_value (MonitorInput, PBD::Controllable::NoGroup);
get_button(InputMonitor).set_led_state (_output_port, true);
break;
default:
break;
}
}
}
void
CC121::left ()
{
access_action ("Editor/select-prev-route");
//ToDo: bank by 8?
//if ( (button_state & ShiftDown) == ShiftDown )
}
void
CC121::right ()
{
access_action ("Editor/select-next-route");
//ToDo: bank by 8?
//if ( (button_state & ShiftDown) == ShiftDown )
}
void
CC121::read ()
{
if (_current_stripable) {
boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
if (gain) {
gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Play );
}
}
}
void
CC121::write ()
{
if (_current_stripable) {
boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
if (gain) {
gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Write );
}
}
}
void
CC121::touch ()
{
if (_current_stripable) {
boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
if (gain) {
gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Touch );
}
}
}
void
CC121::off ()
{
if (_current_stripable) {
boost::shared_ptr<AutomationControl> gain = _current_stripable->gain_control ();
if (gain) {
gain->set_automation_state( (ARDOUR::AutoState) ARDOUR::Off );
}
}
}
void
CC121::undo ()
{
ControlProtocol::Undo (); /* EMIT SIGNAL */
}
void
CC121::redo ()
{
ControlProtocol::Redo (); /* EMIT SIGNAL */
}
void
CC121::jog()
{
if (_jogmode == scroll) {
_jogmode = zoom;
}
else {
_jogmode = scroll;
}
get_button (Jog).set_led_state (_output_port, _jogmode == scroll);
}
void
CC121::mute ()
{
if (!_current_stripable) {
return;
}
if (_current_stripable == session->monitor_out()) {
boost::shared_ptr<MonitorProcessor> mp = _current_stripable->monitor_control();
mp->set_cut_all (!mp->cut_all());
return;
}
_current_stripable->mute_control()->set_value (!_current_stripable->mute_control()->muted(), PBD::Controllable::UseGroup);
}
void
CC121::solo ()
{
if (!_current_stripable) {
return;
}
_current_stripable->solo_control()->set_value (!_current_stripable->solo_control()->soloed(), PBD::Controllable::UseGroup);
}
void
CC121::rec_enable ()
{
if (!_current_stripable) {
return;
}
boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_current_stripable);
if (!t) {
return;
}
t->rec_enable_control()->set_value (!t->rec_enable_control()->get_value(), Controllable::UseGroup);
}
void
CC121::use_master ()
{
boost::shared_ptr<Stripable> r = session->master_out();
if (r) {
if (_current_stripable == r) {
r = pre_master_stripable.lock();
set_current_stripable (r);
get_button(Output).set_led_state (_output_port, false);
blinkers.remove (Output);
} else {
if (_current_stripable != session->master_out() && _current_stripable != session->monitor_out()) {
pre_master_stripable = boost::weak_ptr<Stripable> (_current_stripable);
}
set_current_stripable (r);
get_button(Output).set_led_state (_output_port, true);
blinkers.remove (Output);
}
}
}
void
CC121::use_monitor ()
{
boost::shared_ptr<Stripable> r = session->monitor_out();
if (r) {
if (_current_stripable == r) {
r = pre_monitor_stripable.lock();
set_current_stripable (r);
get_button(Output).set_led_state (_output_port, false);
blinkers.remove (Output);
} else {
if (_current_stripable != session->master_out() && _current_stripable != session->monitor_out()) {
pre_monitor_stripable = boost::weak_ptr<Stripable> (_current_stripable);
}
set_current_stripable (r);
get_button(Output).set_led_state (_output_port, true);
blinkers.push_back (Output);
}
}
}
void
CC121::ardour_pan_azimuth (float delta)
{
if (!_current_stripable) {
return;
}
boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_current_stripable);
if (!r) {
return;
}
boost::shared_ptr<Pannable> pannable = r->pannable ();
if (!pannable) {
return;
}
boost::shared_ptr<AutomationControl> azimuth = pannable->pan_azimuth_control;
if (!azimuth) {
return;
}
azimuth->set_value (azimuth->interface_to_internal (azimuth->internal_to_interface (azimuth->get_value()) + (delta)), Controllable::NoGroup);
}
void
CC121::ardour_pan_width(float delta)
{
if (!_current_stripable) {
return;
}
boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_current_stripable);
if (!r) {
return;
}
boost::shared_ptr<Pannable> pannable = r->pannable ();
if (!pannable) {
return;
}
boost::shared_ptr<AutomationControl> width = pannable->pan_width_control;
if (!width) {
return;
}
width->set_value (width->interface_to_internal (width->internal_to_interface (width->get_value()) + (delta)), Controllable::NoGroup);
}
void
CC121::mixbus_pan (float delta)
{
#ifdef MIXBUS
if (!_current_stripable) {
return;
}
boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_current_stripable);
if (!r) {
return;
}
const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
boost::shared_ptr<ARDOUR::PluginInsert> plug = r->ch_post();
if (!plug) {
return;
}
boost::shared_ptr<AutomationControl> azimuth = boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
if (!azimuth) {
return;
}
azimuth->set_value (azimuth->interface_to_internal (azimuth->internal_to_interface (azimuth->get_value()) + (delta)), Controllable::NoGroup);
#endif
}
void
CC121::punch ()
{
access_action ("Transport/TogglePunch");
}

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python
from waflib.extras import autowaf as autowaf
import os
# Mandatory variables
top = '.'
out = 'build'
def options(opt):
autowaf.set_options(opt)
def configure(conf):
autowaf.configure(conf)
def build(bld):
obj = bld(features = 'cxx cxxshlib')
obj.source = '''
cc121.cc
gui.cc
cc121_interface.cc
operations.cc
'''
obj.export_includes = ['.']
obj.defines = [ 'PACKAGE="ardour_cc121"' ]
obj.defines += [ 'ARDOURSURFACE_DLL_EXPORTS' ]
obj.includes = [ '.', './cc121']
obj.name = 'libardour_cc121'
obj.target = 'ardour_cc121'
obj.uselib = 'GTKMM GTK GDK XML'
obj.use = 'libardour libardour_cp libgtkmm2ext libpbd'
obj.install_path = os.path.join(bld.env['LIBDIR'], 'surfaces')
def shutdown():
autowaf.shutdown()

View File

@ -22,6 +22,7 @@ out = 'build'
children = [
'control_protocol',
'faderport',
'cc121',
'generic_midi',
'mackie',
]
@ -74,6 +75,7 @@ def build(bld):
bld.recurse('control_protocol')
bld.recurse('generic_midi')
bld.recurse('faderport')
bld.recurse('cc121')
bld.recurse('mackie')
if bld.is_defined ('HAVE_LO'):