playlist sort patch from nick_m, improves ordering of playlists in menu. small effect, but nice
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@5284 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
11878127f8
commit
81ce045228
|
@ -1354,6 +1354,12 @@ RouteTimeAxisView::get_child_list()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct PlaylistSorter {
|
||||||
|
bool operator() (boost::shared_ptr<Playlist> a, boost::shared_ptr<Playlist> b) const {
|
||||||
|
return a->sort_id() < b->sort_id();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
|
RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
|
||||||
{
|
{
|
||||||
|
@ -1367,33 +1373,32 @@ RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
|
||||||
menu->set_name ("ArdourContextMenu");
|
menu->set_name ("ArdourContextMenu");
|
||||||
playlist_items.clear();
|
playlist_items.clear();
|
||||||
|
|
||||||
if (playlist_menu) {
|
vector<boost::shared_ptr<Playlist> > playlists, playlists_ds;
|
||||||
delete playlist_menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
playlist_menu = new Menu;
|
|
||||||
playlist_menu->set_name ("ArdourContextMenu");
|
|
||||||
|
|
||||||
vector<boost::shared_ptr<Playlist> > playlists;
|
|
||||||
boost::shared_ptr<Diskstream> ds = get_diskstream();
|
boost::shared_ptr<Diskstream> ds = get_diskstream();
|
||||||
RadioMenuItem::Group playlist_group;
|
RadioMenuItem::Group playlist_group;
|
||||||
|
|
||||||
_session.get_playlists (playlists);
|
|
||||||
|
|
||||||
|
_session.get_playlists (playlists);
|
||||||
|
|
||||||
|
/* find the playlists for this diskstream */
|
||||||
for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
|
for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
|
||||||
|
if (((*i)->get_orig_diskstream_id() == ds->id()) || (ds->playlist()->id() == (*i)->id())) {
|
||||||
|
playlists_ds.push_back(*i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* sort the playlists */
|
||||||
|
PlaylistSorter cmp;
|
||||||
|
sort(playlists_ds.begin(), playlists_ds.end(), cmp);
|
||||||
|
|
||||||
|
/* add the playlists to the menu */
|
||||||
|
for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists_ds.begin(); i != playlists_ds.end(); ++i) {
|
||||||
|
playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name()));
|
||||||
|
RadioMenuItem *item = static_cast<RadioMenuItem*>(&playlist_items.back());
|
||||||
|
|
||||||
if ((*i)->get_orig_diskstream_id() == ds->id()) {
|
item->signal_toggled().connect(bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), item, boost::weak_ptr<Playlist> (*i)));
|
||||||
playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
|
|
||||||
boost::weak_ptr<Playlist> (*i))));
|
if (ds->playlist()->id() == (*i)->id()) {
|
||||||
|
item->set_active();
|
||||||
if (ds->playlist()->id() == (*i)->id()) {
|
|
||||||
static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
|
|
||||||
}
|
|
||||||
} else if (ds->playlist()->id() == (*i)->id()) {
|
|
||||||
playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
|
|
||||||
boost::weak_ptr<Playlist>(*i))));
|
|
||||||
static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1404,26 +1409,28 @@ RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
|
||||||
if (!edit_group() || !edit_group()->is_active()) {
|
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"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
|
||||||
playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
|
playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Use a label which tells the user what is happening
|
// 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 (_("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 (MenuElem (_("Copy Take"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
playlist_items.push_back (SeparatorElem());
|
playlist_items.push_back (SeparatorElem());
|
||||||
playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
|
playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
|
||||||
playlist_items.push_back (SeparatorElem());
|
playlist_items.push_back (SeparatorElem());
|
||||||
|
|
||||||
playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
|
playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
|
RouteTimeAxisView::use_playlist (RadioMenuItem *item, boost::weak_ptr<Playlist> wpl)
|
||||||
{
|
{
|
||||||
assert (is_track());
|
assert (is_track());
|
||||||
|
|
||||||
|
// exit if we were triggered by deactivating the old playlist
|
||||||
|
if (!item->get_active()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boost::shared_ptr<Playlist> pl (wpl.lock());
|
boost::shared_ptr<Playlist> pl (wpl.lock());
|
||||||
|
|
||||||
if (!pl) {
|
if (!pl) {
|
||||||
|
@ -1434,13 +1441,13 @@ RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
|
||||||
|
|
||||||
if (apl) {
|
if (apl) {
|
||||||
if (get_diskstream()->playlist() == apl) {
|
if (get_diskstream()->playlist() == apl) {
|
||||||
// radio button cotnrols mean this function is called for both the
|
// exit when use_playlist is called by the creation of the playlist menu
|
||||||
// old and new playlist
|
// or the playlist choice is unchanged
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_diskstream()->use_playlist (apl);
|
get_diskstream()->use_playlist (apl);
|
||||||
|
|
||||||
|
|
||||||
if (edit_group() && edit_group()->is_active()) {
|
if (edit_group() && edit_group()->is_active()) {
|
||||||
//PBD::stacktrace(cerr, 20);
|
//PBD::stacktrace(cerr, 20);
|
||||||
std::string group_string = "."+edit_group()->name()+".";
|
std::string group_string = "."+edit_group()->name()+".";
|
||||||
|
|
|
@ -249,7 +249,7 @@ protected:
|
||||||
Gtk::Menu* playlist_action_menu;
|
Gtk::Menu* playlist_action_menu;
|
||||||
Gtk::MenuItem* playlist_item;
|
Gtk::MenuItem* playlist_item;
|
||||||
|
|
||||||
void use_playlist (boost::weak_ptr<ARDOUR::Playlist>);
|
void use_playlist (Gtk::RadioMenuItem*, boost::weak_ptr<ARDOUR::Playlist>);
|
||||||
|
|
||||||
ArdourCanvas::SimpleRect* timestretch_rect;
|
ArdourCanvas::SimpleRect* timestretch_rect;
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,8 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
|
||||||
|
|
||||||
std::string name() const { return _name; }
|
std::string name() const { return _name; }
|
||||||
void set_name (std::string str);
|
void set_name (std::string str);
|
||||||
|
|
||||||
|
int sort_id() { return _sort_id; }
|
||||||
|
|
||||||
bool frozen() const { return _frozen; }
|
bool frozen() const { return _frozen; }
|
||||||
void set_frozen (bool yn);
|
void set_frozen (bool yn);
|
||||||
|
@ -178,6 +180,7 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
|
||||||
RegionList regions; /* the current list of regions in the playlist */
|
RegionList regions; /* the current list of regions in the playlist */
|
||||||
std::set<boost::shared_ptr<Region> > all_regions; /* all regions ever added to this playlist */
|
std::set<boost::shared_ptr<Region> > all_regions; /* all regions ever added to this playlist */
|
||||||
string _name;
|
string _name;
|
||||||
|
int _sort_id;
|
||||||
Session& _session;
|
Session& _session;
|
||||||
mutable gint block_notifications;
|
mutable gint block_notifications;
|
||||||
mutable gint ignore_state_changes;
|
mutable gint ignore_state_changes;
|
||||||
|
@ -221,6 +224,8 @@ class Playlist : public PBD::StatefulDestructible, public boost::enable_shared_f
|
||||||
void delay_notifications ();
|
void delay_notifications ();
|
||||||
void release_notifications ();
|
void release_notifications ();
|
||||||
virtual void flush_notifications ();
|
virtual void flush_notifications ();
|
||||||
|
|
||||||
|
void _set_sort_id ();
|
||||||
|
|
||||||
void notify_region_removed (boost::shared_ptr<Region>);
|
void notify_region_removed (boost::shared_ptr<Region>);
|
||||||
void notify_region_added (boost::shared_ptr<Region>);
|
void notify_region_added (boost::shared_ptr<Region>);
|
||||||
|
|
|
@ -377,7 +377,7 @@ Location::set_state (const XMLNode& node)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_start = atoi (prop->value().c_str());
|
_start = atoi (prop->value().c_str());
|
||||||
|
|
||||||
if ((prop = node.property ("end")) == 0) {
|
if ((prop = node.property ("end")) == 0) {
|
||||||
error << _("XML node for Location has no end information") << endmsg;
|
error << _("XML node for Location has no end information") << endmsg;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include <ardour/playlist_factory.h>
|
#include <ardour/playlist_factory.h>
|
||||||
#include <ardour/transient_detector.h>
|
#include <ardour/transient_detector.h>
|
||||||
|
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -78,7 +80,7 @@ Playlist::Playlist (Session& sess, string nom, bool hide)
|
||||||
init (hide);
|
init (hide);
|
||||||
first_set_state = false;
|
first_set_state = false;
|
||||||
_name = nom;
|
_name = nom;
|
||||||
|
_set_sort_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
|
Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
|
||||||
|
@ -86,6 +88,7 @@ Playlist::Playlist (Session& sess, const XMLNode& node, bool hide)
|
||||||
{
|
{
|
||||||
init (hide);
|
init (hide);
|
||||||
_name = "unnamed"; /* reset by set_state */
|
_name = "unnamed"; /* reset by set_state */
|
||||||
|
_set_sort_id();
|
||||||
|
|
||||||
/* set state called by derived class */
|
/* set state called by derived class */
|
||||||
}
|
}
|
||||||
|
@ -269,6 +272,35 @@ Playlist::~Playlist ()
|
||||||
/* GoingAway must be emitted by derived classes */
|
/* GoingAway must be emitted by derived classes */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Playlist::_set_sort_id ()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Playlists are given names like <track name>.<id>
|
||||||
|
or <track name>.<edit group name>.<id> where id
|
||||||
|
is an integer. We extract the id and sort by that.
|
||||||
|
*/
|
||||||
|
|
||||||
|
size_t dot_position = _name.find_last_of(".");
|
||||||
|
if (dot_position == string::npos)
|
||||||
|
{
|
||||||
|
_sort_id = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string t = _name.substr(dot_position + 1);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_sort_id = boost::lexical_cast<int>(t);
|
||||||
|
}
|
||||||
|
catch (boost::bad_lexical_cast e)
|
||||||
|
{
|
||||||
|
_sort_id = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Playlist::set_name (string str)
|
Playlist::set_name (string str)
|
||||||
{
|
{
|
||||||
|
@ -293,6 +325,8 @@ Playlist::set_name (string str)
|
||||||
}
|
}
|
||||||
|
|
||||||
_name = name;
|
_name = name;
|
||||||
|
_set_sort_id();
|
||||||
|
|
||||||
NameChanged(); /* EMIT SIGNAL */
|
NameChanged(); /* EMIT SIGNAL */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1730,6 +1764,7 @@ Playlist::set_state (const XMLNode& node)
|
||||||
|
|
||||||
if (prop->name() == X_("name")) {
|
if (prop->name() == X_("name")) {
|
||||||
_name = prop->value();
|
_name = prop->value();
|
||||||
|
_set_sort_id();
|
||||||
} else if (prop->name() == X_("orig_diskstream_id")) {
|
} else if (prop->name() == X_("orig_diskstream_id")) {
|
||||||
_orig_diskstream_id = prop->value ();
|
_orig_diskstream_id = prop->value ();
|
||||||
} else if (prop->name() == X_("frozen")) {
|
} else if (prop->name() == X_("frozen")) {
|
||||||
|
|
Loading…
Reference in New Issue