-class MIDIPorts : public OptionEditorBox
-{
-public:
- MIDIPorts (RCConfiguration* c)
- : _rc_config (c),
- _add_port_button (Stock::ADD)
- {
- _store = ListStore::create (_model);
- _view.set_model (_store);
- _view.append_column (_("Name"), _model.name);
- _view.get_column(0)->set_resizable (true);
- _view.get_column(0)->set_expand (true);
- _view.append_column_editable (_("Online"), _model.online);
- _view.append_column_editable (_("Trace input"), _model.trace_input);
- _view.append_column_editable (_("Trace output"), _model.trace_output);
-
- HBox* h = manage (new HBox);
- h->set_spacing (4);
- h->pack_start (_view, true, true);
-
- VBox* v = manage (new VBox);
- v->set_spacing (4);
- v->pack_start (_add_port_button, false, false);
- h->pack_start (*v, false, false);
-
- _box->pack_start (*h);
-
- Table* t = manage (new Table (2, 4));
- t->set_spacings (12);
-
- int n = 0;
- Label* l = manage (new Label (_("MTC:")));
- l->set_alignment (1, 0.5);
- t->attach (*l, 0, 1, n, n + 1, EXPAND | FILL, FILL);
- t->attach (_mtc_combo, 1, 2, n, n + 1, EXPAND | FILL, EXPAND | FILL);
- ++n;
-
- l = manage (new Label (_("MIDI clock:")));
- l->set_alignment (1, 0.5);
- t->attach (*l, 0, 1, n, n + 1, FILL, FILL);
- t->attach (_midi_clock_combo, 1, 2, n, n + 1, FILL, FILL);
- ++n;
-
- l = manage (new Label (_("MMC:")));
- l->set_alignment (1, 0.5);
- t->attach (*l, 0, 1, n, n + 1, FILL, FILL);
- t->attach (_mmc_combo, 1, 2, n, n + 1, FILL, FILL);
- ++n;
-
- l = manage (new Label (_("MIDI parameter control:")));
- l->set_alignment (1, 0.5);
- t->attach (*l, 0, 1, n, n + 1, FILL, FILL);
- t->attach (_mpc_combo, 1, 2, n, n + 1, FILL, FILL);
- ++n;
-
- _box->pack_start (*t, true, true);
-
- ports_changed ();
-
- _store->signal_row_changed().connect (mem_fun (*this, &MIDIPorts::model_changed));
-
- _add_port_button.signal_clicked().connect (mem_fun (*this, &MIDIPorts::add_port_clicked));
- _mtc_combo.signal_changed().connect (mem_fun (*this, &MIDIPorts::mtc_combo_changed));
- _mmc_combo.signal_changed().connect (mem_fun (*this, &MIDIPorts::mmc_combo_changed));
- _mpc_combo.signal_changed().connect (mem_fun (*this, &MIDIPorts::mpc_combo_changed));
- _midi_clock_combo.signal_changed().connect (mem_fun (*this, &MIDIPorts::midi_clock_combo_changed));
- }
-
- void parameter_changed (string const & p)
- {
- if (p == "mtc-port-name") {
- _mtc_combo.set_active_text (_rc_config->get_mtc_port_name());
- } else if (p == "mmc-port-name") {
- _mmc_combo.set_active_text (_rc_config->get_mmc_port_name());
- } else if (p == "midi-port-name") {
- _mpc_combo.set_active_text (_rc_config->get_midi_port_name());
- } else if (p == "midi-clock-port-name") {
- _midi_clock_combo.set_active_text (_rc_config->get_midi_clock_port_name());
- }
- }
-
- void set_state_from_config ()
- {
- parameter_changed ("mtc-port-name");
- parameter_changed ("mmc-port-name");
- parameter_changed ("midi-port-name");
- parameter_changed ("midi-clock-port-name");
- }
-
- void mtc_combo_changed ()
- {
- _rc_config->set_mtc_port_name (_mtc_combo.get_active_text());
- }
-
- void mmc_combo_changed ()
- {
- _rc_config->set_mmc_port_name (_mmc_combo.get_active_text());
- }
-
- void mpc_combo_changed ()
- {
- _rc_config->set_midi_port_name (_mpc_combo.get_active_text());
- }
-
- void midi_clock_combo_changed ()
- {
- _rc_config->set_midi_clock_port_name (_midi_clock_combo.get_active_text());
- }
-
-private:
-
- void model_changed (TreeModel::Path const & p, TreeModel::iterator const & i)
- {
- TreeModel::Row r = *i;
-
- MIDI::Port* port = r[_model.port];
- if (!port) {
- return;
- }
-
- if (port->input()) {
-
- if (r[_model.online] == port->input()->offline()) {
- port->input()->set_offline (!r[_model.online]);
- }
-
- if (r[_model.trace_input] != port->input()->tracing()) {
- port->input()->trace (r[_model.trace_input], &cerr, string (port->name()) + _(" input: "));
- }
- }
-
- if (port->output()) {
-
- if (r[_model.trace_output] != port->output()->tracing()) {
- port->output()->trace (r[_model.trace_output], &cerr, string (port->name()) + _(" output: "));
- }
-
- }
-
-
-
- }
-
- void setup_ports_combo (ComboBoxText& c)
- {
- c.clear_items ();
- MIDI::Manager::PortMap const & ports = MIDI::Manager::instance()->get_midi_ports ();
- for (MIDI::Manager::PortMap::const_iterator i = ports.begin(); i != ports.end(); ++i) {
- c.append_text (i->first);
- }
- }
-
- void ports_changed ()
- {
- /* XXX: why is this coming from here? */
- MIDI::Manager::PortMap const & ports = MIDI::Manager::instance()->get_midi_ports ();
-
- _store->clear ();
-
- for (MIDI::Manager::PortMap::const_iterator i = ports.begin(); i != ports.end(); ++i) {
-
- TreeModel::Row r = *_store->append ();
-
- r[_model.name] = i->first;
-
- if (i->second->input()) {
- r[_model.online] = !i->second->input()->offline();
- i->second->input()->OfflineStatusChanged.connect (bind (mem_fun (*this, &MIDIPorts::port_offline_changed), i->second));
- r[_model.trace_input] = i->second->input()->tracing();
- }
-
- if (i->second->output()) {
- r[_model.trace_output] = i->second->output()->tracing();
- }
-
- r[_model.port] = i->second;
- }
-
- setup_ports_combo (_mtc_combo);
- setup_ports_combo (_midi_clock_combo);
- setup_ports_combo (_mmc_combo);
- setup_ports_combo (_mpc_combo);
- }
-
- void port_offline_changed (MIDI::Port* p)
- {
- if (!p->input()) {
- return;
- }
-
- for (TreeModel::Children::iterator i = _store->children().begin(); i != _store->children().end(); ++i) {
- if ((*i)[_model.port] == p) {
- (*i)[_model.online] = !p->input()->offline();
- }
- }
- }
-
- void add_port_clicked ()
- {
- MidiPortDialog dialog;
-
- dialog.set_position (WIN_POS_MOUSE);
-
- dialog.show ();
-
- int const r = dialog.run ();
-
- switch (r) {
- case RESPONSE_ACCEPT:
- break;
- default:
- return;
- break;
- }
-
- Glib::ustring const mode = dialog.port_mode_combo.get_active_text ();
- string smod;
-
- if (mode == _("input")) {
- smod = X_("input");
- } else if (mode == (_("output"))) {
- smod = X_("output");
- } else {
- smod = "duplex";
- }
-
- XMLNode node (X_("MIDI-port"));
-
- node.add_property ("tag", dialog.port_name.get_text());
- node.add_property ("device", X_("ardour")); // XXX this can't be right for all types
- node.add_property ("type", MIDI::PortFactory::default_port_type());
- node.add_property ("mode", smod);
-
- if (MIDI::Manager::instance()->add_port (node) != 0) {
- ports_changed ();
- }
- }
-
- class MIDIModelColumns : public TreeModelColumnRecord
- {
- public:
- MIDIModelColumns ()
- {
- add (name);
- add (online);
- add (trace_input);
- add (trace_output);
- add (port);
- }
-
- TreeModelColumn<string> name;
- TreeModelColumn<bool> online;
- TreeModelColumn<bool> trace_input;
- TreeModelColumn<bool> trace_output;
- TreeModelColumn<MIDI::Port*> port;
- };
-
- RCConfiguration* _rc_config;
- Glib::RefPtr<ListStore> _store;
- MIDIModelColumns _model;
- TreeView _view;
- Button _add_port_button;
- ComboBoxText _mtc_combo;
- ComboBoxText _midi_clock_combo;
- ComboBoxText _mmc_combo;
- ComboBoxText _mpc_combo;
-};
-
-