From d64ff6b659eeb5b552dd2f7c94011b75638060de Mon Sep 17 00:00:00 2001 From: Sampo Savolainen Date: Mon, 6 Oct 2008 18:04:12 +0000 Subject: Added take system from 2.0. Thanks to torben for the patch. git-svn-id: svn://localhost/ardour2/branches/3.0@3873 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.cc | 20 ++++--- gtk2_ardour/editor.h | 4 +- gtk2_ardour/route_time_axis.cc | 115 ++++++++++++++++++++++++++++++++++++++--- gtk2_ardour/route_time_axis.h | 9 +++- 4 files changed, 129 insertions(+), 19 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index a04df8d1ad..fb62ad8d70 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -4382,7 +4382,9 @@ void Editor::new_playlists (TimeAxisView* v) { begin_reversible_command (_("new playlists")); - mapover_tracks (mem_fun (*this, &Editor::mapped_use_new_playlist), v); + vector > playlists; + session->get_playlists(playlists); + mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_new_playlist), playlists), v ); commit_reversible_command (); } @@ -4396,7 +4398,9 @@ void Editor::copy_playlists (TimeAxisView* v) { begin_reversible_command (_("copy playlists")); - mapover_tracks (mem_fun (*this, &Editor::mapped_use_copy_playlist), v); + vector > playlists; + session->get_playlists(playlists); + mapover_tracks ( bind(mem_fun (*this, &Editor::mapped_use_copy_playlist), playlists), v ); commit_reversible_command (); } @@ -4410,20 +4414,22 @@ void Editor::clear_playlists (TimeAxisView* v) { begin_reversible_command (_("clear playlists")); - mapover_tracks (mem_fun (*this, &Editor::mapped_clear_playlist), v); + vector > playlists; + session->get_playlists(playlists); + mapover_tracks ( mem_fun (*this, &Editor::mapped_clear_playlist), v ); commit_reversible_command (); } void -Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz) +Editor::mapped_use_new_playlist (RouteTimeAxisView& atv, uint32_t sz, vector > const & playlists) { - atv.use_new_playlist (sz > 1 ? false : true); + atv.use_new_playlist (sz > 1 ? false : true, playlists); } void -Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz) +Editor::mapped_use_copy_playlist (RouteTimeAxisView& atv, uint32_t sz, vector > const & playlists) { - atv.use_copy_playlist (sz > 1 ? false : true); + atv.use_copy_playlist (sz > 1 ? false : true, playlists); } void diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 3bd301b0d8..e3dd1050fc 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -529,8 +529,8 @@ class Editor : public PublicEditor /* functions to be passed to mapover_tracks(), possibly with sigc::bind()-supplied arguments */ void mapped_get_equivalent_regions (RouteTimeAxisView&, uint32_t, RegionView*, vector*) const; - void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t); - void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t); + void mapped_use_new_playlist (RouteTimeAxisView&, uint32_t, vector > const &); + void mapped_use_copy_playlist (RouteTimeAxisView&, uint32_t, vector > const &); void mapped_clear_playlist (RouteTimeAxisView&, uint32_t); /* end */ diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index fe03190b67..71ad6e73bd 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -953,8 +953,46 @@ RouteTimeAxisView::rename_current_playlist () } } +std::string +RouteTimeAxisView::resolve_new_group_playlist_name(std::string &basename, vector > const & playlists) +{ + std::string ret(basename); + + std::string group_string = "."+edit_group()->name()+"."; + + if (basename.find(group_string) == string::npos) { + int maxnumber = 0; + + // iterate through all playlists + for (vector >::const_iterator i = playlists.begin(); i != playlists.end(); ++i) { + std::string tmp = (*i)->name(); + + std::string::size_type idx = tmp.find(group_string); + // find those which belong to this group + if (idx != string::npos) { + tmp = tmp.substr(idx + group_string.length()); + + // and find the largest current number + int x = atoi(tmp.c_str()); + if (x > maxnumber) { + maxnumber = x; + } + } + } + + maxnumber++; + + char buf[32]; + snprintf (buf, sizeof(buf), "%d", maxnumber); + + ret = this->name()+"."+edit_group()->name()+"."+buf; + } + + return ret; +} + void -RouteTimeAxisView::use_copy_playlist (bool prompt) +RouteTimeAxisView::use_copy_playlist (bool prompt, vector > const & playlists_before_op) { string name; @@ -967,10 +1005,14 @@ RouteTimeAxisView::use_copy_playlist (bool prompt) return; name = pl->name(); + + if (edit_group() && edit_group()->is_active()) { + name = resolve_new_group_playlist_name(name, playlists_before_op); + } - do { + while (_session.playlist_by_name(name)) { name = Playlist::bump_name (name, _session); - } while (_session.playlist_by_name(name)); + } // TODO: The prompter "new" button should be de-activated if the user // specifies a playlist name which already exists in the session. @@ -1002,7 +1044,7 @@ RouteTimeAxisView::use_copy_playlist (bool prompt) } void -RouteTimeAxisView::use_new_playlist (bool prompt) +RouteTimeAxisView::use_new_playlist (bool prompt, vector > const & playlists_before_op) { string name; @@ -1015,10 +1057,14 @@ RouteTimeAxisView::use_new_playlist (bool prompt) return; name = pl->name(); + + if (edit_group() && edit_group()->is_active()) { + name = resolve_new_group_playlist_name(name,playlists_before_op); + } - do { + while (_session.playlist_by_name(name)) { name = Playlist::bump_name (name, _session); - } while (_session.playlist_by_name(name)); + } if (prompt) { @@ -1445,8 +1491,17 @@ RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu) playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist))); playlist_items.push_back (SeparatorElem()); - playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this))); - playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this))); + if (!edit_group() || !edit_group()->is_active()) { + playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this))); + playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this))); + + } else { + // Use a label which tells the user what is happening + playlist_items.push_back (MenuElem (_("New Take"), bind(mem_fun(editor, &PublicEditor::new_playlists), this))); + playlist_items.push_back (MenuElem (_("Copy Take"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this))); + + } + playlist_items.push_back (SeparatorElem()); playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this))); playlist_items.push_back (SeparatorElem()); @@ -1468,7 +1523,51 @@ RouteTimeAxisView::use_playlist (boost::weak_ptr wpl) boost::shared_ptr apl = boost::dynamic_pointer_cast (pl); if (apl) { + if (get_diskstream()->playlist() == apl) { + // radio button cotnrols mean this function is called for both the + // old and new playlist + return; + } get_diskstream()->use_playlist (apl); + + + if (edit_group() && edit_group()->is_active()) { + //PBD::stacktrace(cerr, 20); + std::string group_string = "."+edit_group()->name()+"."; + + std::string take_name = apl->name(); + std::string::size_type idx = take_name.find(group_string); + + if (idx == std::string::npos) + return; + + take_name = take_name.substr(idx + group_string.length()); // find the bit containing the take number / name + + for (list::const_iterator i = edit_group()->route_list().begin(); i != edit_group()->route_list().end(); ++i) { + if ( (*i) == this->route().get()) { + continue; + } + + std::string playlist_name = (*i)->name()+group_string+take_name; + + Track *track = dynamic_cast(*i); + if (!track) { + std::cerr << "route " << (*i)->name() << " is not a Track" << std::endl; + continue; + } + + boost::shared_ptr ipl = session().playlist_by_name(playlist_name); + if (!ipl) { + // No playlist for this track for this take yet, make it + track->diskstream()->use_new_playlist(); + track->diskstream()->playlist()->set_name(playlist_name); + } else { + track->diskstream()->use_playlist(ipl); + } + + //(*i)->get_dis + } + } } } diff --git a/gtk2_ardour/route_time_axis.h b/gtk2_ardour/route_time_axis.h index 73d3295aaf..405f4937ab 100644 --- a/gtk2_ardour/route_time_axis.h +++ b/gtk2_ardour/route_time_axis.h @@ -33,6 +33,7 @@ #include #include +#include #include #include "ardour_dialog.h" @@ -95,9 +96,13 @@ public: TimeAxisView::Children get_child_list(); /* The editor calls these when mapping an operation across multiple tracks */ - void use_new_playlist (bool prompt); - void use_copy_playlist (bool prompt); + void use_new_playlist (bool prompt, vector > const &); + void use_copy_playlist (bool prompt, vector > const &); void clear_playlist (); + + /* group playlist name resolving */ + std::string resolve_new_group_playlist_name(std::string &, vector > const &); + void build_playlist_menu (Gtk::Menu *); -- cgit v1.2.3