diff --git a/gtk2_ardour/mixer_snapshot_substitution_dialog.cc b/gtk2_ardour/mixer_snapshot_substitution_dialog.cc index 32760210f1..3bfdab4172 100644 --- a/gtk2_ardour/mixer_snapshot_substitution_dialog.cc +++ b/gtk2_ardour/mixer_snapshot_substitution_dialog.cc @@ -103,95 +103,95 @@ void MixerSnapshotSubstitutionDialog::fill_combo_box(ComboBoxText* box, const st } } -void MixerSnapshotSubstitutionDialog::on_response(int r) -{ - if(r == RESPONSE_CANCEL) { - substitutions.clear(); - close_self(); - return; - } +// void MixerSnapshotSubstitutionDialog::on_response(int r) +// { +// if(r == RESPONSE_CANCEL) { +// substitutions.clear(); +// close_self(); +// return; +// } - vector dirty = _snapshot->get_routes(); - vector clean = _snapshot->get_routes(); - vector new_s; - vector del_s; +// vector dirty = _snapshot->get_routes(); +// vector clean = _snapshot->get_routes(); +// vector new_s; +// vector del_s; - if(r == RESPONSE_ACCEPT) { - for(vector::iterator c = substitutions.begin(); c != substitutions.end(); c++) { - string route_name = (*c).first->name(); - string subst_name = (*c).second->get_active_text(); - int n = 0; - for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { - MixerSnapshot::State state = (*s); - if(route_name == state.name) { - //state and substitution are matches - if(route_name == subst_name) { - break; - } +// if(r == RESPONSE_ACCEPT) { +// for(vector::iterator c = substitutions.begin(); c != substitutions.end(); c++) { +// string route_name = (*c).first->name(); +// string subst_name = (*c).second->get_active_text(); +// int n = 0; +// for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { +// MixerSnapshot::State state = (*s); +// if(route_name == state.name) { +// //state and substitution are matches +// if(route_name == subst_name) { +// break; +// } - //empty sub - erase it - if(subst_name == " --- ") { - del_s.push_back(state); - break; - } - } - if(subst_name == " --- ") { - break; - } +// //empty sub - erase it +// if(subst_name == " --- ") { +// del_s.push_back(state); +// break; +// } +// } +// if(subst_name == " --- ") { +// break; +// } - bool route_state_exists = state_exists(route_name); - bool subst_state_exists = state_exists(subst_name); +// bool route_state_exists = state_exists(route_name); +// bool subst_state_exists = state_exists(subst_name); - //state exists but we are picking a different source - if(route_name != subst_name) { - if(route_state_exists && subst_state_exists) { - XMLNode copy (get_state_by_name(subst_name).node); - state.node = copy; - state.name = route_name; - } +// //state exists but we are picking a different source +// if(route_name != subst_name) { +// if(route_state_exists && subst_state_exists) { +// XMLNode copy (get_state_by_name(subst_name).node); +// state.node = copy; +// state.name = route_name; +// } - //state did *not* exist, make it and add the substitute node - if(!route_state_exists && subst_state_exists) { - //copy the substitute node - XMLNode copy (get_state_by_name(subst_name).node); +// //state did *not* exist, make it and add the substitute node +// if(!route_state_exists && subst_state_exists) { +// //copy the substitute node +// XMLNode copy (get_state_by_name(subst_name).node); - MixerSnapshot::State s { - "", - route_name, - copy - }; +// MixerSnapshot::State s { +// "", +// route_name, +// copy +// }; - new_s.push_back(s); - } - } - n++; - } - } - } +// new_s.push_back(s); +// } +// } +// n++; +// } +// } +// } - for(vector::iterator s = new_s.begin(); s != new_s.end(); s++) { - dirty.push_back((*s)); - } +// for(vector::iterator s = new_s.begin(); s != new_s.end(); s++) { +// dirty.push_back((*s)); +// } - for(vector::iterator d = del_s.begin(); d != del_s.end(); d++) { - for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { - if((*d).id == (*s).id) { - dirty.erase(s); - s--; - break; - } - } - } +// for(vector::iterator d = del_s.begin(); d != del_s.end(); d++) { +// for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { +// if((*d).id == (*s).id) { +// dirty.erase(s); +// s--; +// break; +// } +// } +// } - for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { - cout << (*s).name << endl; - } - substitutions.clear(); - _snapshot->set_route_states(dirty); - _snapshot->recall(); - _snapshot->set_route_states(clean); - close_self(); -} +// for(vector::iterator s = dirty.begin(); s != dirty.end(); s++) { +// cout << (*s).name << endl; +// } +// substitutions.clear(); +// _snapshot->set_route_states(dirty); +// _snapshot->recall(); +// _snapshot->set_route_states(clean); +// close_self(); +// } bool MixerSnapshotSubstitutionDialog::state_exists(const string name) { diff --git a/gtk2_ardour/mixer_snapshot_substitution_dialog.h b/gtk2_ardour/mixer_snapshot_substitution_dialog.h index 5fa6539274..b29097d2e4 100644 --- a/gtk2_ardour/mixer_snapshot_substitution_dialog.h +++ b/gtk2_ardour/mixer_snapshot_substitution_dialog.h @@ -33,11 +33,16 @@ class MixerSnapshotSubstitutionDialog : public ArdourDialog { public: MixerSnapshotSubstitutionDialog(ARDOUR::MixerSnapshot*); + ARDOUR::MixerSnapshot* get_snapshot() { return _snapshot;}; + void set_snapshot(ARDOUR::MixerSnapshot* new_snapshot) {_snapshot = new_snapshot;}; + + std::vector get_substitutions() {return substitutions;}; + void clear_substitutions() {substitutions.clear();}; + private: bool state_exists(const std::string); ARDOUR::MixerSnapshot::State get_state_by_name(const std::string); void fill_combo_box(Gtk::ComboBoxText*, const std::string); - void on_response(int); std::vector substitutions; diff --git a/gtk2_ardour/mixer_snapshots.cc b/gtk2_ardour/mixer_snapshots.cc index c1d99fe906..4d2b4df60e 100644 --- a/gtk2_ardour/mixer_snapshots.cc +++ b/gtk2_ardour/mixer_snapshots.cc @@ -44,15 +44,13 @@ #include "ardour_ui.h" #include "editor.h" #include "utils.h" +#include "mixer_snapshots.h" +#include "gui_thread.h" #include "pbd/i18n.h" #include "pbd/basename.h" #include "pbd/gstdio_compat.h" -#include "mixer_snapshots.h" - -#include "gui_thread.h" - using namespace std; using namespace PBD; using namespace Gtk; @@ -237,13 +235,110 @@ bool MixerSnapshotList::button_press (GdkEventButton* ev) if (iter) { MixerSnapshot* snapshot = (*iter)[_columns.snapshot]; - snapshot->recall(); + + MixerSnapshotSubstitutionDialog* sub_dialog = new MixerSnapshotSubstitutionDialog(snapshot); + sub_dialog->signal_response().connect(sigc::bind(sigc::mem_fun(*this, &MixerSnapshotList::substitution_dialog_response), sub_dialog)); + sub_dialog->show_all(); + sub_dialog->set_position(WIN_POS_MOUSE); + sub_dialog->present(); + return true; } } return false; } +void MixerSnapshotList::substitution_dialog_response(int response, MixerSnapshotSubstitutionDialog* dialog) +{ + if(!dialog) { + return; + } + + if(response != RESPONSE_ACCEPT) { + delete dialog; + return; + } + + MixerSnapshot* snapshot = dialog->get_snapshot(); + if(!snapshot) { + delete dialog; + return; + } + + vector clean = snapshot->get_routes(); + vector dirty; + + vector::const_iterator p; + vector pairs = dialog->get_substitutions(); + for(p = pairs.begin(); p != pairs.end(); p++) { + boost::shared_ptr route = (*p).first; + ComboBoxText* cb = (*p).second; + + if(!route || !cb) { + continue; + } + + if(route->is_monitor() || route->is_master() || route->is_auditioner()) { + continue; + } + + const string name = route->name(); + const string at = cb->get_active_text(); + + printf( + "*** begining work for route %s, with substitution state %s\n", + name.c_str(), + at.c_str() + ); + + //do not recall this state + if(at == " --- ") { + continue; + } + + const bool route_state_exists = snapshot->route_state_exists(name); + const bool subst_state_exists = snapshot->route_state_exists(at); + if(route_state_exists && subst_state_exists) { + XMLNode copy (snapshot->get_route_state_by_name(at).node); + MixerSnapshot::State new_state { + string(), + name, + copy + }; + dirty.push_back(new_state); + continue; + } else if(!route_state_exists && subst_state_exists) { + XMLNode copy (snapshot->get_route_state_by_name(at).node); + MixerSnapshot::State new_state { + string(), + name, + copy + }; + dirty.push_back(new_state); + continue; + } + } + + //DEBUG OUTPUT + printf("\nDirty States ------------------------------------------\n"); + for(vector::const_iterator i = dirty.begin(); i != dirty.end(); i++) { + string name; + (*i).node.get_property(X_("name"), name); + printf("\nState {id:%s, name:%s, node:%s}\n", (*i).id.c_str(), (*i).name.c_str(), name.c_str()); + } + printf("\n-------------------------------------------------------\n"); + + //this needs to be called to drop it's shared route ptrs + pairs.clear(); + dialog->clear_substitutions(); + delete dialog; + + //swap the vectors Indiana Jones style and then recall + snapshot->set_route_states(dirty); + snapshot->recall(); + snapshot->set_route_states(clean); +} + /* Pop up the snapshot display context menu. * @param button Button used to open the menu. @@ -326,7 +421,7 @@ void MixerSnapshotList::rename_snapshot(TreeModel::iterator& iter) if(jter) { const string name = (*jter)[_columns.name]; const string prompt = string_compose( - _("Do you really want to overwrite snapshot \"%1\" ?\n(this cannot be undone)"), + _("Do you really want to overwrite snapshot \"%1\" ?\n(this cannot be undone)"), name ); @@ -362,9 +457,9 @@ void MixerSnapshotList::promote_snapshot(TreeModel::iterator& iter) //let the user know that this was successful. if(_session->snapshot_manager().promote(snapshot)) { const string label = snapshot->get_label(); - + const string notification = string_compose( - _("Snapshot \"%1\" is now available to all sessions.\n"), + _("Snapshot \"%1\" is now available to all sessions.\n"), label ); diff --git a/gtk2_ardour/mixer_snapshots.h b/gtk2_ardour/mixer_snapshots.h index 1222f691ba..3b1be89fae 100644 --- a/gtk2_ardour/mixer_snapshots.h +++ b/gtk2_ardour/mixer_snapshots.h @@ -31,6 +31,8 @@ #include +#include "mixer_snapshot_substitution_dialog.h" + #include "ardour/mixer_snapshot.h" #include "ardour/mixer_snapshot_manager.h" @@ -98,6 +100,8 @@ private: bool _bug_user; bool _global; + void substitution_dialog_response(int, MixerSnapshotSubstitutionDialog*); + bool button_press (GdkEventButton *); void selection_changed (); void popup_context_menu (int, int32_t, Gtk::TreeModel::iterator&); diff --git a/libs/ardour/ardour/mixer_snapshot.h b/libs/ardour/ardour/mixer_snapshot.h index 55496722ce..18fd91098b 100644 --- a/libs/ardour/ardour/mixer_snapshot.h +++ b/libs/ardour/ardour/mixer_snapshot.h @@ -74,6 +74,9 @@ class LIBARDOUR_API MixerSnapshot ); }; + MixerSnapshot::State get_route_state_by_name(const std::string&); + bool route_state_exists(const std::string&); + std::vector get_routes() {return route_states;}; std::vector get_groups() {return group_states;}; std::vector get_vcas() {return vca_states;}; diff --git a/libs/ardour/mixer_snapshot.cc b/libs/ardour/mixer_snapshot.cc index bc51d8f312..02734c4118 100644 --- a/libs/ardour/mixer_snapshot.cc +++ b/libs/ardour/mixer_snapshot.cc @@ -689,3 +689,29 @@ XMLNode& MixerSnapshot::sanitize_node(XMLNode& node) } return node; } + +MixerSnapshot::State MixerSnapshot::get_route_state_by_name(const string& name) +{ + State route_state {string(), string(), XMLNode("")}; + for(vector::iterator i = route_states.begin(); i != route_states.end(); i++) { + const string state_name = (*i).name; + if(state_name == name) { + route_state.id = (*i).id; + route_state.name = state_name; + route_state.node = (*i).node; + break; + } + } + return route_state; +} + +bool MixerSnapshot::route_state_exists(const string& name) +{ + for(vector::iterator i = route_states.begin(); i != route_states.end(); i++) { + const string state_name = (*i).name; + if(state_name == name) { + return true; + } + } + return false; +} \ No newline at end of file