13
0

Trigger clip picker: add support for media meta data

This commit is contained in:
Robin Gareus 2022-01-13 00:06:33 +01:00
parent beb0a96f42
commit 78d15aa153
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04

View File

@ -236,36 +236,78 @@ is_subfolder (std::string const& parent, std::string dir)
return false; return false;
} }
static std::string
display_name (std::string const& dir) {
std::string metadata = Glib::build_filename (dir, ".daw-meta.xml");
if (Glib::file_test (metadata, Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_EXISTS)) {
XMLTree tree;
if (tree.read (metadata) && tree.root()->name () == "DAWDirectory") {
XMLNode* root = tree.root();
std::string type;
if (root->get_property ("type", type)) {
if (type == "bundled") {
return string_compose (_("%1 Bundled Content"), PROGRAM_NAME);
}
}
#if ENABLE_NLS
if (ARDOUR::translations_are_enabled ()) {
for (XMLNodeList::const_iterator n = root->children ("title").begin (); n != root->children ("title").end (); ++n) {
std::string lang;
if (!(*n)->get_property ("lang", lang)) {
continue;
}
if (lang != "en_US") { // TODO: get current lang
continue;
}
return (*n)->child_content ();
}
}
#endif
/* pick first title, if any */
XMLNode* child = root->child ("title");
if (child) {
return child->child_content ();
}
}
}
return Glib::path_get_basename (dir);
}
void void
TriggerClipPicker::maybe_add_dir (std::string const& dir) TriggerClipPicker::maybe_add_dir (std::string const& dir)
{ {
if (Glib::file_test (dir, Glib::FILE_TEST_IS_DIR | Glib::FILE_TEST_EXISTS)) { if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR | Glib::FILE_TEST_EXISTS)) {
_dir.AddMenuElem (Gtkmm2ext::MenuElemNoMnemonic (Glib::path_get_basename (dir), sigc::bind (sigc::mem_fun (*this, &TriggerClipPicker::list_dir), dir, (Gtk::TreeNodeChildren*)0))); return;
}
bool insert = true; _dir.AddMenuElem (Gtkmm2ext::MenuElemNoMnemonic (display_name (dir), sigc::bind (sigc::mem_fun (*this, &TriggerClipPicker::list_dir), dir, (Gtk::TreeNodeChildren*)0)));
auto it = _root_paths.begin ();
while (it != _root_paths.end ()) { /* check if a parent path of the given dir already exists,
bool erase = false; * or if this new path is parent to any exising ones.
if (it->size () > dir.size()) { */
if (is_subfolder (dir, *it)) { bool insert = true;
erase = true; auto it = _root_paths.begin ();
} while (it != _root_paths.end ()) {
} else if (is_subfolder (*it, dir)) { bool erase = false;
insert = false; if (it->size () > dir.size()) {
break; if (is_subfolder (dir, *it)) {
} erase = true;
if (erase) {
auto it2 = it;
++it;
_root_paths.erase (it2);
} else {
++it;
} }
} else if (is_subfolder (*it, dir)) {
insert = false;
break;
} }
if (insert) { if (erase) {
_root_paths.insert (dir); auto it2 = it;
++it;
_root_paths.erase (it2);
} else {
++it;
} }
} }
if (insert) {
_root_paths.insert (dir);
}
} }
/* **************************************************************************** /* ****************************************************************************
@ -436,7 +478,7 @@ TriggerClipPicker::list_dir (std::string const& path, Gtk::TreeNodeChildren cons
if (!pc) { if (!pc) {
_model->clear (); _model->clear ();
_dir.set_active (Glib::path_get_basename (path)); _dir.set_active (display_name (path));
} }
_current_path = path; _current_path = path;