Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c1: Add GUI for plugin mappings #838

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 162 additions & 7 deletions libs/surfaces/console1/c1_gui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

#include "c1_gui.h"

#include <gtkmm/alignment.h>
#include <gtkmm/label.h>
#include <gtkmm/liststore.h>
#include <gtkmm/cellrenderercombo.h>
#include <gtkmm/cellrenderertoggle.h>

#include <gtkmm/alignment.h>
#include "pbd/file_utils.h"
#include "pbd/i18n.h"
#include "pbd/strsplit.h"
Expand All @@ -32,6 +34,7 @@
#include "ardour/filesystem_paths.h"
#include "ardour/parameter_descriptor.h"
#include "console1.h"
#include "gtkmm2ext/action_model.h"
#include "gtkmm2ext/bindings.h"
#include "gtkmm2ext/gui_thread.h"
#include "gtkmm2ext/utils.h"
Expand All @@ -49,15 +52,15 @@ Console1::get_gui () const
if (!gui) {
const_cast<Console1*> (this)->build_gui ();
}
static_cast<Gtk::VBox*> (gui)->show_all ();
static_cast<Gtk::Notebook*> (gui)->show_all ();
return gui;
}

void
Console1::tear_down_gui ()
{
if (gui) {
Gtk::Widget* w = static_cast<Gtk::VBox*> (gui)->get_parent ();
Gtk::Widget* w = static_cast<Gtk::Widget*> (gui)->get_parent ();
if (w) {
w->hide ();
delete w;
Expand Down Expand Up @@ -150,10 +153,44 @@ C1GUI::C1GUI (Console1& p)
row++;

hpacker.pack_start (table, true, true);
append_page (hpacker, _("Device Setup"));
hpacker.show_all();

// Create the page for plugin mappings
p.load_mappings ();

VBox* plugconfig_packer = manage (new VBox);
HBox* plugselect_packer = manage (new HBox);

l = manage (new Gtk::Label (_("Select Plugin")));
plugselect_packer->pack_start (*l, false, false);

plugconfig_packer->pack_start (*plugselect_packer, false, false);

Glib::RefPtr<Gtk::ListStore> plugin_store_model = ListStore::create (plugin_columns);
TreeModel::Row plugin_combo_row;
for( const auto &pm : c1.getPluginMappingMap() ){
plugin_combo_row = *(plugin_store_model->append ());
plugin_combo_row[plugin_columns.plugin_name] = pm.second.name;
plugin_combo_row[plugin_columns.plugin_id] = pm.first;
DEBUG_TRACE (DEBUG::Console1, string_compose ("Add Plugin: name %1 / %2\n", pm.second.name, pm.first));
}
plugins_combo.pack_start (plugin_columns.plugin_name);
plugins_combo.signal_changed ().connect (
sigc::bind (sigc::mem_fun (*this, &C1GUI::active_plugin_changed), &plugins_combo));
plugins_combo.set_model (plugin_store_model);

plugselect_packer->pack_start (plugins_combo, true, true);
plugin_mapping_scroller.property_shadow_type() = Gtk::SHADOW_NONE;
plugin_mapping_scroller.set_policy(Gtk::PolicyType::POLICY_AUTOMATIC, Gtk::PolicyType::POLICY_AUTOMATIC);

plugin_mapping_scroller.add (plugin_assignment_editor);
plugconfig_packer->pack_start (plugin_mapping_scroller, true, true, 20);

set_spacing (12);
build_plugin_assignment_editor ();

pack_start (hpacker, false, false);
append_page (*plugconfig_packer, _ ("Plugin Mappings"));
plugconfig_packer->show_all ();

/* update the port connection combos */

Expand All @@ -169,7 +206,9 @@ C1GUI::C1GUI (Console1& p)
_port_connections, invalidator (*this), boost::bind (&C1GUI::connection_handler, this), gui_context ());
}

C1GUI::~C1GUI () {}
C1GUI::~C1GUI () {
write_plugin_assignment();
}

void
C1GUI::set_swap_solo_mute ()
Expand Down Expand Up @@ -260,7 +299,7 @@ C1GUI::build_midi_port_list (vector<string> const& ports, bool for_input)

row = *store->append ();
row[midi_port_columns.full_name] = string ();
row[midi_port_columns.short_name] = _ ("Disconnected");
row[midi_port_columns.short_name] = _("Disconnected");

for (vector<string>::const_iterator p = ports.begin (); p != ports.end (); ++p) {
row = *store->append ();
Expand Down Expand Up @@ -307,3 +346,119 @@ C1GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
}
}
}

void
C1GUI::change_controller (const Glib::ustring &sPath, const TreeModel::iterator &iter)
{
Gtk::TreePath path(sPath);
Gtk::TreeModel::iterator row = plugin_assignment_store->get_iter(path);
int index = *path.begin ();
if (row) {

string controllerName = (*iter)[c1.plugin_controller_columns.controllerName];
int controllerId = (*iter)[c1.plugin_controller_columns.controllerId];
pc.parameters[index].controllerId = ArdourSurface::Console1::ControllerID (controllerId);
(*row).set_value (plugin_assignment_editor_columns.controllerName, controllerName);
DEBUG_TRACE (DEBUG::Console1,
string_compose ("Column Name: Controller, index %1, name %2 \n", index, controllerName));
assignement_changed = true;
}
}

void C1GUI::toggle_shift( const Glib::ustring& s){
int index = atoi (s.c_str());
Gtk::TreeModel::iterator row = plugin_assignment_store->get_iter (s);
if( row )
{
bool value = !pc.parameters[index].shift;
pc.parameters[index].shift = value;
(*row).set_value (plugin_assignment_editor_columns.shift, value);
DEBUG_TRACE (DEBUG::Console1, string_compose ("Column Name: Shift, value %1\n", value));
assignement_changed = true;
}
}

CellRendererCombo*
C1GUI::make_action_renderer (Glib::RefPtr<ListStore> model, Gtk::TreeModelColumnBase column)
{
CellRendererCombo* renderer = manage (new CellRendererCombo);
renderer->property_model() = model;
renderer->property_editable() = true;
renderer->property_text_column () = 0;
renderer->property_has_entry () = false;
renderer->signal_changed().connect (sigc::mem_fun(*this, &C1GUI::change_controller));

return renderer;
}

void
C1GUI::build_plugin_assignment_editor ()
{
plugin_assignment_editor.append_column (_("Key"), plugin_assignment_editor_columns.index);
plugin_assignment_editor.append_column (_("Name"), plugin_assignment_editor_columns.name);
plugin_assignment_editor.append_column (_("Switch"), plugin_assignment_editor_columns.is_switch);

TreeViewColumn* col;
CellRendererCombo* renderer;

CellRendererToggle* boolRenderer = manage (new CellRendererToggle);
boolRenderer->set_active ();
boolRenderer->property_activatable() = true;
col = manage (new TreeViewColumn (_ ("Shift"), *boolRenderer));
col->add_attribute (boolRenderer->property_active (), plugin_assignment_editor_columns.shift);
boolRenderer->signal_toggled().connect (sigc::mem_fun(*this, &C1GUI::toggle_shift));
plugin_assignment_editor.append_column (*col);


renderer = make_action_renderer (c1.getPluginControllerModel(), plugin_assignment_editor_columns.controllerName);
col = manage (new TreeViewColumn (_("Control"), *renderer));
col->add_attribute (renderer->property_text(), plugin_assignment_editor_columns.controllerName);
plugin_assignment_editor.append_column (*col);

plugin_assignment_store = ListStore::create (plugin_assignment_editor_columns);
plugin_assignment_editor.set_model (plugin_assignment_store);
}


void
C1GUI::active_plugin_changed(Gtk::ComboBox* combo ){
DEBUG_TRACE (DEBUG::Console1, "C1GUI active_plugin_changed\n");

write_plugin_assignment ();

plugin_assignment_editor.set_model (Glib::RefPtr<TreeModel>());
plugin_assignment_store->clear ();

TreeModel::iterator active = combo->get_active ();
TreeModel::Row plugin_assignment_row;

string new_plugin_name = (*active)[plugin_columns.plugin_name];
string new_plugin_id = (*active)[plugin_columns.plugin_id];
DEBUG_TRACE (DEBUG::Console1, string_compose ("Plugin: selected %1 / %2\n", new_plugin_name, new_plugin_id));
pc = c1.getPluginMappingMap ()[new_plugin_id];

for( auto &parm : pc.parameters ){
plugin_assignment_row = *(plugin_assignment_store->append ());
plugin_assignment_row[plugin_assignment_editor_columns.index] = parm.first;
plugin_assignment_row[plugin_assignment_editor_columns.name] = parm.second.name;
plugin_assignment_row[plugin_assignment_editor_columns.controllerName] = c1.findControllerNameById(parm.second.controllerId);
plugin_assignment_row[plugin_assignment_editor_columns.is_switch] = parm.second.is_switch;
plugin_assignment_row[plugin_assignment_editor_columns.shift] = parm.second.shift;

DEBUG_TRACE (DEBUG::Console1, string_compose ("Parameter Name %1 \n", parm.second.name));
DEBUG_TRACE (DEBUG::Console1, string_compose ("Parameter Index: %1 - index %2 \n", parm.first, parm.second.paramIndex));
DEBUG_TRACE (DEBUG::Console1, string_compose ("ControllerId: %1 \n", parm.second.controllerId));
DEBUG_TRACE (DEBUG::Console1, string_compose ("is switch? %1 \n", parm.second.is_switch));
DEBUG_TRACE (DEBUG::Console1, string_compose ("is shift? %1 \n", parm.second.shift));
}
plugin_assignment_editor.set_model (plugin_assignment_store);

}

void C1GUI::write_plugin_assignment(){
DEBUG_TRACE (DEBUG::Console1, "write_plugin_assignment\n");
if( !assignement_changed )
return;
c1.write_plugin_mapping (pc);
assignement_changed = false;
}
61 changes: 55 additions & 6 deletions libs/surfaces/console1/c1_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,28 @@
#include <gtkmm/combobox.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/image.h>
#include <gtkmm/notebook.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/table.h>
#include <gtkmm/treestore.h>
#include <gtkmm/spinbutton.h>
#include <gtkmm/notebook.h>

namespace Gtk {
class CellRendererCombo;
class ListStore;
}

namespace ActionManager {
class ActionModel;
}

#include "ardour/mode.h"

#include "console1.h"

namespace ArdourSurface {

class C1GUI : public Gtk::VBox
class C1GUI : public Gtk::Notebook
{
public:
C1GUI (Console1&);
Expand All @@ -55,15 +60,23 @@ class C1GUI : public Gtk::VBox
Gtk::Table table;
Gtk::ComboBox input_combo;
Gtk::ComboBox output_combo;
Gtk::ComboBox plugins_combo;
Gtk::ScrolledWindow plugin_mapping_scroller;
Gtk::Image image;
Gtk::CheckButton swap_solo_mute_cb;
Gtk::CheckButton create_plugin_stubs_btn;

Gtk::TreeView plugin_assignment_editor;

Gtk::VBox plugin_packer;

bool assignement_changed = false;

void update_port_combos ();
PBD::ScopedConnection connection_change_connection;
void connection_handler ();
PBD::ScopedConnectionList _port_connections;

struct MidiPortColumns : public Gtk::TreeModel::ColumnRecord {
MidiPortColumns() {
add (short_name);
Expand All @@ -73,17 +86,53 @@ class C1GUI : public Gtk::VBox
Gtk::TreeModelColumn<std::string> full_name;
};

struct PluginColumns : public Gtk::TreeModel::ColumnRecord {
PluginColumns() {
add (plugin_name);
add (plugin_id);
}
Gtk::TreeModelColumn<std::string> plugin_name;
Gtk::TreeModelColumn<std::string> plugin_id;
};

struct PluginAssignamentEditorColumns : public Gtk::TreeModel::ColumnRecord {
PluginAssignamentEditorColumns() {
add (index);
add (name);
add (is_switch);
add (controllerName);
add (shift);
};
Gtk::TreeModelColumn<int> index; // parameter index
Gtk::TreeModelColumn<std::string> name; // readable name of the parameter
Gtk::TreeModelColumn<bool> is_switch;
Gtk::TreeModelColumn<std::string> controllerName; // enum Button::ID
Gtk::TreeModelColumn<bool> shift;
};

MidiPortColumns midi_port_columns;
PluginColumns plugin_columns;
PluginAssignamentEditorColumns plugin_assignment_editor_columns;
Glib::RefPtr<Gtk::ListStore> plugin_assignment_store;

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);

ArdourSurface::Console1::PluginMapping pc;
Gtk::CellRendererCombo* make_action_renderer (Glib::RefPtr<Gtk::ListStore> model, Gtk::TreeModelColumnBase column);
void build_plugin_assignment_editor ();

void change_controller (const Glib::ustring &, const Gtk::TreeIter&);
void toggle_shift ( const Glib::ustring& );

void active_port_changed (Gtk::ComboBox*, bool for_input);

void set_swap_solo_mute ();
void set_create_mapping_stubs ();

void active_plugin_changed (Gtk::ComboBox* combo);
void write_plugin_assignment ();
};

}

#endif /* __ardour_console1_gui_h__ */
Loading