use a single controller list

This commit is contained in:
Hoger Dehnhardt 2025-07-25 17:09:12 +02:00
parent 28c89ef3d6
commit fbf6400955
8 changed files with 394 additions and 370 deletions

View file

@ -4,21 +4,14 @@
#include "ardour/debug.h" #include "ardour/debug.h"
#include "console1.h" #include "console1.h"
namespace ArdourSurface { namespace Console1
{
using ControllerID = Console1::ControllerID; using ControllerID = Console1::ControllerID;
class Controller class Controller
{ {
public: public:
enum ControllerType
{
CONTROLLER,
CONTROLLER_BUTTON,
MULTISTATE_BUTTON,
ENCODER,
METER
};
Controller (Console1* console1, ControllerID id) Controller (Console1* console1, ControllerID id)
: console1 (console1) : console1 (console1)
@ -26,15 +19,108 @@ class Controller
{ {
} }
virtual ~Controller () {} Controller (Console1* console1,
ControllerID id,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0)
: console1 (console1)
, _id (id)
, action (action)
, shift_action (shift_action)
, plugin_action (plugin_action)
, plugin_shift_action (plugin_shift_action)
{
}
virtual ~Controller ()
{
}
Console1* console1; Console1* console1;
ControllerID id () const { return _id; } ControllerID id () const
{
return _id;
}
virtual ControllerType get_type () { return CONTROLLER; } virtual void clear_value() {}
virtual ControllerType get_type ()
{
return CONTROLLER;
}
void set_action (std::function<void (uint32_t)> new_action)
{
action = new_action;
}
void set_plugin_action (std::function<void (uint32_t)> new_action)
{
plugin_action = new_action;
}
void set_plugin_shift_action (std::function<void (uint32_t)> new_action)
{
plugin_shift_action = new_action;
}
std::function<void (uint32_t)> get_action (){
return action;
}
std::function<void (uint32_t)> get_shift_action ()
{
return shift_action;
}
std::function<void (uint32_t)> get_plugin_action ()
{
return plugin_action;
}
std::function<void (uint32_t)> get_plugin_shift_action ()
{
return plugin_shift_action;
}
protected: protected:
ControllerID _id; ControllerID _id;
std::function<void (uint32_t)> action;
std::function<void (uint32_t)> shift_action;
std::function<void (uint32_t)> plugin_action;
std::function<void (uint32_t)> plugin_shift_action;
};
class Encoder : public Controller
{
public:
Encoder (Console1* console1,
ControllerID id,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0)
: Controller (console1, id, action, shift_action, plugin_action, plugin_shift_action)
{
console1->controllerMap.insert (std::make_pair (id, this));
}
ControllerType get_type ()
{
return ENCODER;
}
virtual void set_value (uint32_t value)
{
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = value;
console1->write (buf, 3);
}
PBD::Signal<void (uint32_t)>* plugin_signal;
}; };
class ControllerButton : public Controller class ControllerButton : public Controller
@ -46,24 +132,18 @@ class ControllerButton : public Controller
std::function<void (uint32_t)> shift_action = 0, std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0, std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0) std::function<void (uint32_t)> plugin_shift_action = 0)
: Controller (console1, id) : Controller (console1, id, action, shift_action, plugin_action, plugin_shift_action)
, action (action)
, shift_action (shift_action)
, plugin_action (plugin_action)
, plugin_shift_action (plugin_shift_action)
{ {
console1->buttons.insert (std::make_pair (id, this)); console1->controllerMap.insert (std::make_pair (id, this));
} }
ControllerType get_type () { return CONTROLLER_BUTTON; } ControllerType get_type ()
{
void set_action (std::function<void (uint32_t)> new_action) { action = new_action; } return CONTROLLER_BUTTON;
void set_plugin_action (std::function<void (uint32_t)> new_action) { plugin_action = new_action; } }
void set_plugin_shift_action (std::function<void (uint32_t)> new_action) { plugin_shift_action = new_action; }
virtual void set_led_state (bool onoff) virtual void set_led_state (bool onoff)
{ {
// DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
MIDI::byte buf[3]; MIDI::byte buf[3];
buf[0] = 0xB0; buf[0] = 0xB0;
buf[1] = _id; buf[1] = _id;
@ -74,7 +154,6 @@ class ControllerButton : public Controller
virtual void set_led_value (uint32_t val) virtual void set_led_value (uint32_t val)
{ {
// DEBUG_TRACE(DEBUG::Console1, "ControllerButton::set_led_state ...\n");
MIDI::byte buf[3]; MIDI::byte buf[3];
buf[0] = 0xB0; buf[0] = 0xB0;
buf[1] = _id; buf[1] = _id;
@ -82,10 +161,6 @@ class ControllerButton : public Controller
console1->write (buf, 3); console1->write (buf, 3);
} }
std::function<void (uint32_t)> action;
std::function<void (uint32_t)> shift_action;
std::function<void (uint32_t)> plugin_action;
std::function<void (uint32_t)> plugin_shift_action;
}; };
class MultiStateButton : public Controller class MultiStateButton : public Controller
@ -97,19 +172,17 @@ class MultiStateButton : public Controller
std::function<void (uint32_t)> action, std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0, std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0, std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0 std::function<void (uint32_t)> plugin_shift_action = 0)
) : Controller (console1, id, action, shift_action, plugin_action, plugin_shift_action)
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
, plugin_action (action)
, plugin_shift_action (shift_action)
, state_values (state_values) , state_values (state_values)
{ {
console1->multi_buttons.insert (std::make_pair (id, this)); console1->controllerMap.insert (std::make_pair (id, this));
} }
ControllerType get_type () { return MULTISTATE_BUTTON; } ControllerType get_type ()
{
return MULTISTATE_BUTTON;
}
virtual void set_led_state (uint32_t state) virtual void set_led_state (uint32_t state)
{ {
@ -123,16 +196,10 @@ class MultiStateButton : public Controller
console1->write (buf, 3); console1->write (buf, 3);
} }
void set_action (std::function<void (uint32_t)> new_action) { action = new_action; } uint32_t state_count ()
void set_plugin_action (std::function<void (uint32_t)> new_action) { plugin_action = new_action; } {
void set_plugin_shift_action (std::function<void (uint32_t)> new_action) { plugin_shift_action = new_action; } return state_values.size ();
}
uint32_t state_count () { return state_values.size (); }
std::function<void (uint32_t)> action;
std::function<void (uint32_t)> shift_action;
std::function<void (uint32_t)> plugin_action;
std::function<void (uint32_t)> plugin_shift_action;
private: private:
std::vector<uint32_t> state_values; std::vector<uint32_t> state_values;
@ -152,7 +219,10 @@ class Meter : public Controller
console1->meters.insert (std::make_pair (id, this)); console1->meters.insert (std::make_pair (id, this));
} }
ControllerType get_type () { return METER; } ControllerType get_type ()
{
return METER;
}
virtual void set_value (uint32_t value) virtual void set_value (uint32_t value)
{ {
@ -167,46 +237,6 @@ class Meter : public Controller
std::function<void ()> shift_action; std::function<void ()> shift_action;
}; };
class Encoder : public Controller } // namespace Console1
{
public:
Encoder (Console1* console1,
ControllerID id,
std::function<void (uint32_t)> action,
std::function<void (uint32_t)> shift_action = 0,
std::function<void (uint32_t)> plugin_action = 0,
std::function<void (uint32_t)> plugin_shift_action = 0)
: Controller (console1, id)
, action (action)
, shift_action (shift_action)
, plugin_action (plugin_action)
, plugin_shift_action (plugin_action)
{
console1->encoders.insert (std::make_pair (id, this));
}
ControllerType get_type () { return ENCODER; }
void set_action (std::function<void (uint32_t)> new_action) { action = new_action; }
void set_plugin_action (std::function<void (uint32_t)> new_action) { plugin_action = new_action; }
void set_plugin_shift_action (std::function<void (uint32_t)> new_action) { plugin_shift_action = new_action; }
virtual void set_value (uint32_t value)
{
MIDI::byte buf[3];
buf[0] = 0xB0;
buf[1] = _id;
buf[2] = value;
console1->write (buf, 3);
}
std::function<void (uint32_t)> action;
std::function<void (uint32_t val)> shift_action;
std::function<void (uint32_t val)> plugin_action;
std::function<void (uint32_t val)> plugin_shift_action;
PBD::Signal<void(uint32_t)>* plugin_signal;
};
}
#endif // ardour_surface_console1_button_h #endif // ardour_surface_console1_button_h

View file

@ -40,11 +40,13 @@
using namespace PBD; using namespace PBD;
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourSurface;
using namespace std; using namespace std;
using namespace Gtk; using namespace Gtk;
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
namespace Console1
{
void* void*
Console1::get_gui () const Console1::get_gui () const
{ {
@ -383,7 +385,7 @@ C1GUI::change_controller (const Glib::ustring &sPath, const TreeModel::iterator
string controllerName = (*iter)[c1.plugin_controller_columns.controllerName]; string controllerName = (*iter)[c1.plugin_controller_columns.controllerName];
int controllerId = (*iter)[c1.plugin_controller_columns.controllerId]; int controllerId = (*iter)[c1.plugin_controller_columns.controllerId];
pc.parameters[index].controllerId = ArdourSurface::Console1::ControllerID (controllerId); pc.parameters[index].controllerId = Console1::ControllerID (controllerId);
(*row).set_value (plugin_assignment_editor_columns.controllerName, controllerName); (*row).set_value (plugin_assignment_editor_columns.controllerName, controllerName);
DEBUG_TRACE (DEBUG::Console1, DEBUG_TRACE (DEBUG::Console1,
string_compose ("Column Name: Controller, index %1, name %2 \n", index, controllerName)); string_compose ("Column Name: Controller, index %1, name %2 \n", index, controllerName));
@ -488,3 +490,5 @@ void C1GUI::write_plugin_assignment(){
c1.write_plugin_mapping (pc); c1.write_plugin_mapping (pc);
assignement_changed = false; assignement_changed = false;
} }
} // namespace Console1

View file

@ -45,7 +45,7 @@ namespace ActionManager {
#include "console1.h" #include "console1.h"
namespace ArdourSurface { namespace Console1 {
class C1GUI : public Gtk::Notebook class C1GUI : public Gtk::Notebook
{ {
@ -120,7 +120,7 @@ private:
Glib::RefPtr<Gtk::ListStore> build_midi_port_list (std::vector<std::string> const & ports, bool for_input); Glib::RefPtr<Gtk::ListStore> build_midi_port_list (std::vector<std::string> const & ports, bool for_input);
ArdourSurface::Console1::PluginMapping pc; Console1::PluginMapping pc;
Gtk::CellRendererCombo* make_action_renderer (Glib::RefPtr<Gtk::ListStore> model, Gtk::TreeModelColumnBase column); Gtk::CellRendererCombo* make_action_renderer (Glib::RefPtr<Gtk::ListStore> model, Gtk::TreeModelColumnBase column);
void build_plugin_assignment_editor (); void build_plugin_assignment_editor ();
@ -135,6 +135,6 @@ private:
void active_plugin_changed (Gtk::ComboBox* combo); void active_plugin_changed (Gtk::ComboBox* combo);
void write_plugin_assignment (); void write_plugin_assignment ();
}; };
} } // namespace Console1
#endif /* __ardour_console1_gui_h__ */ #endif /* __ardour_console1_gui_h__ */

View file

@ -27,13 +27,15 @@
#include "console1.h" #include "console1.h"
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourSurface;
using namespace PBD; using namespace PBD;
using namespace Glib; using namespace Glib;
using namespace std; using namespace std;
/* Operations */ /* Operations */
namespace Console1
{
void void
Console1::bank (bool up) Console1::bank (bool up)
{ {
@ -145,7 +147,7 @@ Console1::select (const uint32_t i)
void void
Console1::shift (const uint32_t val) Console1::shift (const uint32_t val)
{ {
DEBUG_TRACE (DEBUG::Console1, "shift()\n"); DEBUG_TRACE (DEBUG::Console1, string_compose( "shift (%1)\n", val ));
shift_state = !shift_state; shift_state = !shift_state;
ShiftChange (val); ShiftChange (val);
} }
@ -674,7 +676,7 @@ Console1::map_select ()
void void
Console1::map_shift (bool shift) Console1::map_shift (bool shift)
{ {
DEBUG_TRACE (DEBUG::Console1, "map_shift()\n"); DEBUG_TRACE (DEBUG::Console1, string_compose ("map_shift(%1)\n", shift));
try { try {
ControllerButton* controllerButton = get_button (PRESET); ControllerButton* controllerButton = get_button (PRESET);
controllerButton->set_led_state (shift); controllerButton->set_led_state (shift);
@ -687,7 +689,7 @@ Console1::map_shift (bool shift)
void void
Console1::map_plugin_state (bool plugin_state) Console1::map_plugin_state (bool plugin_state)
{ {
DEBUG_TRACE (DEBUG::Console1, "map_plugin_state()\n"); DEBUG_TRACE (DEBUG::Console1, string_compose ("map_plugin_state(%1)\n", plugin_state) );
try { try {
ControllerButton* controllerButton = get_button (TRACK_GROUP); ControllerButton* controllerButton = get_button (TRACK_GROUP);
controllerButton->set_led_state (in_plugin_state); controllerButton->set_led_state (in_plugin_state);
@ -699,10 +701,6 @@ Console1::map_plugin_state (bool plugin_state)
stop_blinking (ControllerID (FOCUS1 + i)); stop_blinking (ControllerID (FOCUS1 + i));
} }
map_stripable_state (); map_stripable_state ();
} else {
// I don't plan shift functionality with plugins...
shift (0);
// map all plugin related operations
} }
} }
@ -1237,3 +1235,5 @@ Console1::map_encoder (ControllerID controllerID, std::shared_ptr<ARDOUR::Automa
DEBUG_TRACE (DEBUG::Console1, "Encoder not found\n"); DEBUG_TRACE (DEBUG::Console1, "Encoder not found\n");
} }
} }
} // namespace Console1

View file

@ -35,12 +35,12 @@
#include "console1.h" #include "console1.h"
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourSurface;
using namespace PBD; using namespace PBD;
using namespace Glib; using namespace Glib;
using namespace std; using namespace std;
namespace ArdourSurface { namespace Console1
{
bool bool
Console1::ensure_config_dir () Console1::ensure_config_dir ()
@ -136,8 +136,8 @@ Console1::load_mapping (XMLNode* mapping_xml)
parmap.name = param_name; parmap.name = param_name;
parmap.is_switch = (param_type == "switch"); parmap.is_switch = (param_type == "switch");
if (!param_mapping.empty ()) { if (!param_mapping.empty ()) {
ControllerMap::const_iterator m = controllerMap.find (param_mapping); ControllerNameIdMap::const_iterator m = controllerNameIdMap.find (param_mapping);
if (m != controllerMap.end ()) if (m != controllerNameIdMap.end ())
{ {
parmap.controllerId = m->second; parmap.controllerId = m->second;
} }
@ -289,24 +289,23 @@ Console1::remove_plugin_operations ()
{ {
plugin_connections.drop_connections (); plugin_connections.drop_connections ();
for (auto& e : encoders) { for (auto& c : controllerMap) {
e.second->set_plugin_action (0); if (c.first == ControllerID::TRACK_GROUP)
e.second->set_plugin_shift_action (0);
e.second->set_value (0);
}
for (auto& b : buttons) {
if (b.first == ControllerID::TRACK_GROUP)
continue; continue;
if (b.first >= ControllerID::FOCUS1 && b.first <= ControllerID::FOCUS20) if (c.first >= ControllerID::FOCUS1 && c.first <= ControllerID::FOCUS20)
continue; continue;
b.second->set_plugin_action (0); c.second->set_plugin_action (0);
b.second->set_plugin_shift_action (0); c.second->set_plugin_shift_action (0);
b.second->set_led_state (false); c.second->clear_value ();
if( c.second->get_type() == ControllerType::CONTROLLER_BUTTON )
{
ControllerButton* b = dynamic_cast<ControllerButton *> (c.second);
b->set_led_state (false);
} else if (c.second->get_type () == ControllerType::MULTISTATE_BUTTON )
{
MultiStateButton* b = dynamic_cast<MultiStateButton *> (c.second);
b->set_led_state (false);
} }
for (auto& m : multi_buttons) {
m.second->set_plugin_action (0);
m.second->set_plugin_shift_action (0);
m.second->set_led_state (false);
} }
} }
@ -326,12 +325,15 @@ Console1::find_plugin (const int32_t plugin_index)
while ((ext_plugin_index < plugin_index) && (int_plugin_index < (int)bank_size)) { while ((ext_plugin_index < plugin_index) && (int_plugin_index < (int)bank_size)) {
++int_plugin_index; ++int_plugin_index;
DEBUG_TRACE (DEBUG::Console1, string_compose ("find_plugin: int index %1, ext index %2\n", int_plugin_index, ext_plugin_index));
proc = r->nth_plugin (int_plugin_index); proc = r->nth_plugin (int_plugin_index);
if (!proc) { if (!proc) {
DEBUG_TRACE (DEBUG::Console1, "find_plugin: plugin not found\n");
continue; continue;
;
} }
DEBUG_TRACE (DEBUG::Console1, "find_plugin: plugin found\n");
if (!proc->display_to_user ()) { if (!proc->display_to_user ()) {
DEBUG_TRACE (DEBUG::Console1, "find_plugin: display to user failed\n");
continue; continue;
} }
@ -483,7 +485,7 @@ Console1::spill_plugins (const int32_t plugin_index)
return false; return false;
int32_t n_controls = -1; int32_t n_controls = -1;
DEBUG_TRACE (DEBUG::Console1, string_compose ("Found plugin %1\n", proc->name ())); DEBUG_TRACE (DEBUG::Console1, string_compose ("spill_plugins: Found plugin %1\n", proc->name ()));
std::shared_ptr<PluginInsert> plugin_insert = std::dynamic_pointer_cast<PluginInsert> (proc); std::shared_ptr<PluginInsert> plugin_insert = std::dynamic_pointer_cast<PluginInsert> (proc);
if (!plugin_insert) if (!plugin_insert)
return false; return false;
@ -492,7 +494,7 @@ Console1::spill_plugins (const int32_t plugin_index)
if (!plugin) if (!plugin)
return false; return false;
DEBUG_TRACE (DEBUG::Console1, string_compose ("Found plugin id %1\n", plugin->unique_id ())); DEBUG_TRACE (DEBUG::Console1, string_compose ("spill_plugins: Found plugin id %1\n", plugin->unique_id ()));
// Setup mute button // Setup mute button
setup_plugin_mute_button(plugin_insert); setup_plugin_mute_button(plugin_insert);
@ -510,14 +512,14 @@ Console1::spill_plugins (const int32_t plugin_index)
PluginMapping pluginMapping = pmmit->second; PluginMapping pluginMapping = pmmit->second;
DEBUG_TRACE (DEBUG::Console1, DEBUG_TRACE (DEBUG::Console1,
string_compose ("Plugin mapping found for id %1, name %2\n", pluginMapping.id, pluginMapping.name)); string_compose ("spill_plugins: Plugin mapping found for id %1, name %2\n", pluginMapping.id, pluginMapping.name));
set<Evoral::Parameter> p = proc->what_can_be_automated (); set<Evoral::Parameter> p = proc->what_can_be_automated ();
for (set<Evoral::Parameter>::iterator j = p.begin (); j != p.end (); ++j) { for (set<Evoral::Parameter>::iterator j = p.begin (); j != p.end (); ++j) {
++n_controls; ++n_controls;
std::string n = proc->describe_parameter (*j); std::string n = proc->describe_parameter (*j);
DEBUG_TRACE (DEBUG::Console1, string_compose ("Plugin parameter %1: %2\n", n_controls, n)); DEBUG_TRACE (DEBUG::Console1, string_compose ("spill_plugins: Plugin parameter %1: %2\n", n_controls, n));
if (n == "hidden") { if (n == "hidden") {
continue; continue;
} }
@ -555,7 +557,7 @@ Glib::RefPtr<Gtk::ListStore> Console1::getPluginControllerModel()
{ {
plugin_controller_model = Gtk::ListStore::create (plugin_controller_columns); plugin_controller_model = Gtk::ListStore::create (plugin_controller_columns);
Gtk::TreeModel::Row plugin_controller_combo_row; Gtk::TreeModel::Row plugin_controller_combo_row;
for( const auto &controller : controllerMap ){ for( const auto &controller : controllerNameIdMap ){
plugin_controller_combo_row = *(plugin_controller_model->append ()); plugin_controller_combo_row = *(plugin_controller_model->append ());
plugin_controller_combo_row[plugin_controller_columns.controllerId] = controller.second; plugin_controller_combo_row[plugin_controller_columns.controllerId] = controller.second;
plugin_controller_combo_row[plugin_controller_columns.controllerName] = X_(controller.first); plugin_controller_combo_row[plugin_controller_columns.controllerName] = X_(controller.first);
@ -563,4 +565,4 @@ Glib::RefPtr<Gtk::ListStore> Console1::getPluginControllerModel()
return plugin_controller_model; return plugin_controller_model;
} }
} } // namespace Console1

View file

@ -41,12 +41,16 @@
#include "c1_control.h" #include "c1_control.h"
#include "c1_gui.h" #include "c1_gui.h"
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourSurface;
using namespace PBD; using namespace PBD;
using namespace Glib; using namespace Glib;
using namespace std; using namespace std;
namespace Console1
{
Console1::Console1 (Session& s) Console1::Console1 (Session& s)
: MIDISurface (s, X_ ("Softube Console1"), X_ ("Console1"), false) : MIDISurface (s, X_ ("Softube Console1"), X_ ("Console1"), false)
, gui (0) , gui (0)
@ -66,25 +70,17 @@ Console1::~Console1 ()
stop_event_loop (); stop_event_loop ();
MIDISurface::drop (); MIDISurface::drop ();
for (const auto& b : buttons) { for (const auto& c : controllerMap) {
delete b.second; delete c.second;
}
for (const auto& e : encoders) {
delete e.second;
}
for (const auto& m : meters) {
delete m.second;
}
for (const auto& mb : multi_buttons) {
delete mb.second;
} }
} }
void void
Console1::all_lights_out () Console1::all_lights_out ()
{ {
for (ButtonMap::iterator b = buttons.begin (); b != buttons.end (); ++b) { for (ControllerMap::iterator b = controllerMap.begin (); b != controllerMap.end (); ++b) {
b->second->set_led_state (false); if( b->second->get_type() == ControllerType::CONTROLLER_BUTTON )
(dynamic_cast<ControllerButton*>(b->second))->set_led_state (false);
} }
} }
@ -279,7 +275,8 @@ Console1::setup_controls ()
new ControllerButton (this, new ControllerButton (this,
ControllerID (FOCUS1 + i), ControllerID (FOCUS1 + i),
std::function<void (uint32_t)> (std::bind (&Console1::select, this, i)), std::function<void (uint32_t)> (std::bind (&Console1::select, this, i)),
0, std::function<void (uint32_t)> (std::bind (&Console1::select, this, i)),
std::function<void (uint32_t)> (std::bind (&Console1::select_plugin, this, i)),
std::function<void (uint32_t)> (std::bind (&Console1::select_plugin, this, i))); std::function<void (uint32_t)> (std::bind (&Console1::select_plugin, this, i)));
} }
@ -288,6 +285,9 @@ Console1::setup_controls ()
new ControllerButton (this, new ControllerButton (this,
ControllerID::TRACK_GROUP, ControllerID::TRACK_GROUP,
std::function<void (uint32_t)> (std::bind (&Console1::plugin_state, this, _1)),
std::function<void (uint32_t)> (std::bind (&Console1::plugin_state, this, _1)),
std::function<void (uint32_t)> (std::bind (&Console1::plugin_state, this, _1)),
std::function<void (uint32_t)> (std::bind (&Console1::plugin_state, this, _1))); std::function<void (uint32_t)> (std::bind (&Console1::plugin_state, this, _1)));
new ControllerButton ( new ControllerButton (
@ -441,61 +441,39 @@ Console1::handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes* tb
uint32_t value = static_cast<uint32_t> (tb->value); uint32_t value = static_cast<uint32_t> (tb->value);
DEBUG_TRACE (DEBUG::Console1, DEBUG_TRACE (DEBUG::Console1,
string_compose ("handle_midi_controller_message cn: '%1' val: '%2'\n", controller_number, value)); string_compose ("handle_midi_controller_message cn: '%1' val: '%2'\n", controller_number, value));
DEBUG_TRACE (DEBUG::Console1,
string_compose ("handle_midi_controller_message shift state: '%1' plugin state: '%2'\n", shift_state, in_plugin_state));
try { try {
Encoder* e = get_encoder (ControllerID (controller_number)); Controller* controller = controllerMap[ControllerID (controller_number)];
if (in_plugin_state && e->plugin_action) { if (controller ) {
e->plugin_action (value); DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message; Controller Found'\n");
} else if (shift_state && e->shift_action) { if (shift_state && in_plugin_state && controller->get_plugin_shift_action ()) {
e->shift_action (value); controller->get_plugin_shift_action () (value);
DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message: plugin_shift_action'\n" );
} else if (in_plugin_state && controller->get_plugin_action ()) {
controller->get_plugin_action () (value);
DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message: plugin_action'\n");
} else if (shift_state && controller->get_shift_action ()) {
controller->get_shift_action () (value);
DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message: shift_action'\n");
} else { } else {
e->action (value); controller->get_action () (value);
DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message: action'\n");
} }
return; return;
} catch (ControlNotFoundException const&) { }
else {
DEBUG_TRACE (DEBUG::Console1, "handle_midi_controller_message: Controller not found'\n");
}
}
catch (ControlNotFoundException const&) {
DEBUG_TRACE (DEBUG::Console1, DEBUG_TRACE (DEBUG::Console1,
string_compose ("handle_midi_controller_message: encoder not found cn: " string_compose ("handle_midi_controller_message: encoder not found cn: "
"'%1' val: '%2'\n", "'%1' val: '%2'\n",
controller_number, controller_number,
value)); value));
} }
try {
ControllerButton* b = get_button (ControllerID (controller_number));
if (in_plugin_state && b->plugin_action) {
DEBUG_TRACE (DEBUG::Console1, "Executing plugin_action\n");
b->plugin_action (value);
} else if (shift_state && b->shift_action) {
DEBUG_TRACE (DEBUG::Console1, "Executing shift_action\n");
b->shift_action (value);
} else {
DEBUG_TRACE (DEBUG::Console1, "Executing action\n");
b->action (value);
}
return;
} catch (ControlNotFoundException const&) {
DEBUG_TRACE (DEBUG::Console1,
string_compose ("handle_midi_controller_message: button not found cn: "
"'%1' val: '%2'\n",
controller_number,
value));
}
try {
MultiStateButton* mb = get_mbutton (ControllerID (controller_number));
if (shift_state && mb->shift_action) {
mb->shift_action (value);
} else {
mb->action (value);
}
return;
} catch (ControlNotFoundException const&) {
DEBUG_TRACE (DEBUG::Console1,
string_compose ("handle_midi_controller_message: mbutton not found cn: "
"'%1' val: '%2'\n",
controller_number,
value));
}
} }
void void
@ -955,15 +933,6 @@ Console1::blinker ()
return true; return true;
} }
ControllerButton*
Console1::get_button (ControllerID id) const
{
ButtonMap::const_iterator b = buttons.find (id);
if (b == buttons.end ())
throw (ControlNotFoundException ());
return const_cast<ControllerButton*> (b->second);
}
Meter* Meter*
Console1::get_meter (ControllerID id) const Console1::get_meter (ControllerID id) const
{ {
@ -973,22 +942,42 @@ Console1::get_meter (ControllerID id) const
return const_cast<Meter*> (m->second); return const_cast<Meter*> (m->second);
} }
Controller*
Console1::get_controller (ControllerID id) const
{
ControllerMap::const_iterator c = controllerMap.find (id);
if (c == controllerMap.end ())
throw (ControlNotFoundException ());
return (c->second);
}
Controller*
Console1::get_controller (ControllerID id, ControllerType controllerType) const
{
ControllerMap::const_iterator c = controllerMap.find (id);
if ((c == controllerMap.end ()) || (c->second->get_type () != controllerType))
throw (ControlNotFoundException ());
return (c->second);
}
Encoder* Encoder*
Console1::get_encoder (ControllerID id) const Console1::get_encoder (ControllerID id) const
{ {
EncoderMap::const_iterator m = encoders.find (id); return dynamic_cast<Encoder*> (get_controller (id, ControllerType::ENCODER));
if (m == encoders.end ())
throw (ControlNotFoundException ());
return const_cast<Encoder*> (m->second);
} }
ControllerButton*
Console1::get_button (ControllerID id) const
{
return dynamic_cast<ControllerButton*> (get_controller (id, ControllerType::CONTROLLER_BUTTON));
}
MultiStateButton* MultiStateButton*
Console1::get_mbutton (ControllerID id) const Console1::get_mbutton (ControllerID id) const
{ {
MultiStateButtonMap::const_iterator m = multi_buttons.find (id); return dynamic_cast<MultiStateButton*> (get_controller (id, ControllerType::MULTISTATE_BUTTON));
if (m == multi_buttons.end ())
throw (ControlNotFoundException ());
return const_cast<MultiStateButton*> (m->second);
} }
ControllerID ControllerID
@ -1263,10 +1252,11 @@ Console1::master_monitor_has_changed ()
} }
const std::string Console1::findControllerNameById (const ControllerID id){ const std::string Console1::findControllerNameById (const ControllerID id){
for( const auto &controller : controllerMap ){ for( const auto &controller : controllerNameIdMap ){
if( controller.second == id ){ if( controller.second == id ){
return controller.first; return controller.first;
} }
} }
return std::string(); return std::string();
} }
} // namespace Console1

View file

@ -61,20 +61,15 @@ namespace PBD {
class Controllable; class Controllable;
} }
namespace Console1
{
class MIDIControllable; class MIDIControllable;
class MIDIFunction; class MIDIFunction;
class MIDIAction; class MIDIAction;
namespace ArdourSurface {
class C1GUI; class C1GUI;
// XXX TODO: these classes should not be in the ArdourSurface namespace
// which is shared with all other ctrl surfaces.
//
// ArdourSurface::Meter etc may cause conflicts.
// best add a C1 prefix, or additional namespace
class Controller; class Controller;
class ControllerButton; class ControllerButton;
class MultiStateButton; class MultiStateButton;
@ -92,6 +87,14 @@ public:
ControlNotFoundException () {} ControlNotFoundException () {}
}; };
enum ControllerType {
CONTROLLER,
CONTROLLER_BUTTON,
MULTISTATE_BUTTON,
ENCODER,
METER
};
class Console1 : public MIDISurface class Console1 : public MIDISurface
{ {
@ -141,8 +144,7 @@ public:
PBD::Signal<void(bool)> PluginStateChange; PBD::Signal<void(bool)> PluginStateChange;
PBD::Signal<void(bool)> EQBandQBindingChange; PBD::Signal<void(bool)> EQBandQBindingChange;
enum ControllerID enum ControllerID {
{
CONTROLLER_NONE = 0, CONTROLLER_NONE = 0,
VOLUME = 7, VOLUME = 7,
PAN = 10, PAN = 10,
@ -218,16 +220,15 @@ public:
}; };
enum EQ_MODE enum EQ_MODE {
{
EQM_UNDEFINED = -1, EQM_UNDEFINED = -1,
EQM_HARRISON = 0, EQM_HARRISON = 0,
EQM_SSL = 1 EQM_SSL = 1
}; };
using ControllerMap = std::map<std::string, ControllerID>; using ControllerNameIdMap = std::map<std::string, ControllerID>;
ControllerMap controllerMap{ { "CONTROLLER_NONE", ControllerID::CONTROLLER_NONE }, ControllerNameIdMap controllerNameIdMap{ { "CONTROLLER_NONE", ControllerID::CONTROLLER_NONE },
{ "VOLUME", ControllerID::VOLUME }, { "VOLUME", ControllerID::VOLUME },
{ "PAN", ControllerID::PAN }, { "PAN", ControllerID::PAN },
{ "MUTE", ControllerID::MUTE }, { "MUTE", ControllerID::MUTE },
@ -394,28 +395,26 @@ public:
void select_rid_by_index (const uint32_t index); void select_rid_by_index (const uint32_t index);
/* Controller Maps*/ /* Controller Maps*/
typedef std::map<ControllerID, ArdourSurface::ControllerButton*> ButtonMap; typedef std::map<ControllerID, Meter*> MeterMap;
typedef std::map<ControllerID, ArdourSurface::MultiStateButton*> MultiStateButtonMap;
typedef std::map<ControllerID, ArdourSurface::Meter*> MeterMap;
typedef std::map<ControllerID, ArdourSurface::Encoder*> EncoderMap;
ButtonMap buttons; typedef std::map<ControllerID, Controller*> ControllerMap;
ControllerButton* get_button (ControllerID) const;
MultiStateButtonMap multi_buttons;
MultiStateButton* get_mbutton (ControllerID id) const;
MeterMap meters; MeterMap meters;
Meter* get_meter (ControllerID) const; Meter* get_meter (ControllerID) const;
ControllerButton* get_button (ControllerID) const;
MultiStateButton* get_mbutton (ControllerID id) const;
EncoderMap encoders;
Encoder* get_encoder (ControllerID) const; Encoder* get_encoder (ControllerID) const;
ControllerMap controllerMap;
Controller* get_controller (ControllerID id) const;
Controller* get_controller (ControllerID id, ControllerType controllerType) const;
typedef std::map<uint32_t, ControllerID> SendControllerMap; typedef std::map<uint32_t, ControllerID> SendControllerMap;
SendControllerMap send_controllers{ { 0, LOW_FREQ }, { 1, LOW_MID_FREQ }, { 2, HIGH_MID_FREQ }, SendControllerMap send_controllers{ { 0, LOW_FREQ }, { 1, LOW_MID_FREQ }, { 2, HIGH_MID_FREQ }, { 3, HIGH_FREQ },
{ 3, HIGH_FREQ }, { 4, LOW_GAIN }, { 5, LOW_MID_GAIN }, { 4, LOW_GAIN }, { 5, LOW_MID_GAIN }, { 6, HIGH_MID_GAIN }, { 7, HIGH_GAIN },
{ 6, HIGH_MID_GAIN }, { 7, HIGH_GAIN }, { 8, LOW_MID_SHAPE }, { 8, LOW_MID_SHAPE }, { 9, HIGH_MID_SHAPE }, { 10, LOW_MID_SHAPE }, { 11, HIGH_MID_SHAPE } };
{ 9, HIGH_MID_SHAPE }, { 10, LOW_MID_SHAPE }, { 11, HIGH_MID_SHAPE } };
ControllerID get_send_controllerid (uint32_t); ControllerID get_send_controllerid (uint32_t);
@ -707,5 +706,5 @@ public:
Glib::RefPtr<Gtk::ListStore> getPluginControllerModel(); Glib::RefPtr<Gtk::ListStore> getPluginControllerModel();
void write_plugin_mapping (PluginMapping &mapping); void write_plugin_mapping (PluginMapping &mapping);
}; };
} } // namespace Console1
#endif /* ardour_surface_console1_h */ #endif /* ardour_surface_console1_h */

View file

@ -22,15 +22,14 @@
#include "console1.h" #include "console1.h"
using namespace ARDOUR; using namespace ARDOUR;
using namespace ArdourSurface;
static ControlProtocol* static ControlProtocol*
new_console1 (Session* s) new_console1 (Session* s)
{ {
Console1* console1 = 0; Console1::Console1* console1 = 0;
try { try {
console1 = new Console1 (*s); console1 = new Console1::Console1 (*s);
} catch (failed_constructor& err) { } catch (failed_constructor& err) {
delete console1; delete console1;
console1 = 0; console1 = 0;