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,12 +236,55 @@ 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;
}
_dir.AddMenuElem (Gtkmm2ext::MenuElemNoMnemonic (display_name (dir), sigc::bind (sigc::mem_fun (*this, &TriggerClipPicker::list_dir), dir, (Gtk::TreeNodeChildren*)0)));
/* check if a parent path of the given dir already exists,
* or if this new path is parent to any exising ones.
*/
bool insert = true; bool insert = true;
auto it = _root_paths.begin (); auto it = _root_paths.begin ();
while (it != _root_paths.end ()) { while (it != _root_paths.end ()) {
@ -265,7 +308,6 @@ TriggerClipPicker::maybe_add_dir (std::string const& dir)
if (insert) { if (insert) {
_root_paths.insert (dir); _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;