mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-07 14:15:46 +01:00
Save templates as directories with plugin state, if
there is any, and copy that state to sessions created from those templates. Should fix #4525. Breaks existing session templates, sorry; they can be fixed by moving the .template file into a new directory with the name of the template (minus the .template). git-svn-id: svn://localhost/ardour2/branches/3.0@10982 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
a03f3229f4
commit
73a91402cd
7 changed files with 89 additions and 61 deletions
|
|
@ -390,9 +390,6 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
|
|||
void remove_pending_capture_state ();
|
||||
int rename (const std::string&);
|
||||
|
||||
static int rename_template (std::string old_name, std::string new_name);
|
||||
static int delete_template (std::string name);
|
||||
|
||||
PBD::Signal1<void,std::string> StateSaved;
|
||||
PBD::Signal0<void> StateReady;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ namespace ARDOUR {
|
|||
void find_route_templates (std::vector<TemplateInfo>& template_names);
|
||||
void find_session_templates (std::vector<TemplateInfo>& template_names);
|
||||
|
||||
std::string session_template_dir_to_file (std::string const &);
|
||||
|
||||
} // namespace ARDOUR
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -502,9 +502,11 @@ Session::ensure_subdirs ()
|
|||
return 0;
|
||||
}
|
||||
|
||||
/** Caller must not hold process lock */
|
||||
/** @param session_template directory containing session template, or empty.
|
||||
* Caller must not hold process lock.
|
||||
*/
|
||||
int
|
||||
Session::create (const string& mix_template, BusProfile* bus_profile)
|
||||
Session::create (const string& session_template, BusProfile* bus_profile)
|
||||
{
|
||||
if (g_mkdir_with_parents (_path.c_str(), 0755) < 0) {
|
||||
error << string_compose(_("Session: cannot create session folder \"%1\" (%2)"), _path, strerror (errno)) << endmsg;
|
||||
|
|
@ -517,8 +519,8 @@ Session::create (const string& mix_template, BusProfile* bus_profile)
|
|||
|
||||
_writable = exists_and_writable (sys::path (_path));
|
||||
|
||||
if (!mix_template.empty()) {
|
||||
std::string in_path = mix_template;
|
||||
if (!session_template.empty()) {
|
||||
std::string in_path = session_template_dir_to_file (session_template);
|
||||
|
||||
ifstream in(in_path.c_str());
|
||||
|
||||
|
|
@ -532,16 +534,22 @@ Session::create (const string& mix_template, BusProfile* bus_profile)
|
|||
if (out) {
|
||||
out << in.rdbuf();
|
||||
_is_new = false;
|
||||
|
||||
/* Copy plugin state files from template to new session */
|
||||
sys::path template_plugins = session_template;
|
||||
template_plugins /= X_("plugins");
|
||||
sys::copy_files (template_plugins, plugins_dir ());
|
||||
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
error << string_compose (_("Could not open %1 for writing mix template"), out_path)
|
||||
error << string_compose (_("Could not open %1 for writing session template"), out_path)
|
||||
<< endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
error << string_compose (_("Could not open mix template %1 for reading"), in_path)
|
||||
error << string_compose (_("Could not open session template %1 for reading"), in_path)
|
||||
<< endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -2048,61 +2056,38 @@ Session::save_template (string template_name)
|
|||
|
||||
tree.set_root (&get_template());
|
||||
|
||||
sys::path template_file_path(user_template_dir);
|
||||
template_file_path /= template_name + template_suffix;
|
||||
|
||||
if (sys::exists (template_file_path))
|
||||
sys::path template_dir_path(user_template_dir);
|
||||
|
||||
/* directory to put the template in */
|
||||
template_dir_path /= template_name;
|
||||
if (sys::exists (template_dir_path))
|
||||
{
|
||||
warning << string_compose(_("Template \"%1\" already exists - new version not created"),
|
||||
template_file_path.to_string()) << endmsg;
|
||||
template_dir_path.to_string()) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sys::create_directories (template_dir_path);
|
||||
|
||||
/* file to write */
|
||||
sys::path template_file_path = template_dir_path;
|
||||
template_file_path /= template_name + template_suffix;
|
||||
|
||||
if (!tree.write (template_file_path.to_string())) {
|
||||
error << _("template not saved") << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* copy plugin state directory */
|
||||
|
||||
sys::path template_plugin_state_path = template_dir_path;
|
||||
template_plugin_state_path /= X_("plugins");
|
||||
sys::create_directories (template_plugin_state_path);
|
||||
sys::copy_files (plugins_dir(), template_plugin_state_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Session::rename_template (string old_name, string new_name)
|
||||
{
|
||||
sys::path old_path (user_template_directory());
|
||||
old_path /= old_name + template_suffix;
|
||||
|
||||
sys::path new_path(user_template_directory());
|
||||
new_path /= new_name + template_suffix;
|
||||
|
||||
if (sys::exists (new_path)) {
|
||||
warning << string_compose(_("Template \"%1\" already exists - template not renamed"),
|
||||
new_path.to_string()) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
try {
|
||||
sys::rename (old_path, new_path);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Session::delete_template (string name)
|
||||
{
|
||||
sys::path path = user_template_directory();
|
||||
path /= name + template_suffix;
|
||||
|
||||
try {
|
||||
sys::remove (path);
|
||||
return 0;
|
||||
} catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Session::refresh_disk_space ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include <glibmm.h>
|
||||
|
||||
#include "pbd/filesystem.h"
|
||||
#include "pbd/basename.h"
|
||||
#include "pbd/pathscanner.h"
|
||||
|
|
@ -66,11 +68,23 @@ user_route_template_directory ()
|
|||
static bool
|
||||
template_filter (const string &str, void */*arg*/)
|
||||
{
|
||||
cerr << "Checking into " << str << " using " << template_suffix << endl;
|
||||
return (str.length() > strlen(template_suffix) &&
|
||||
str.find (template_suffix) == (str.length() - strlen (template_suffix)));
|
||||
if (!Glib::file_test (str, Glib::FILE_TEST_IS_DIR)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
string
|
||||
session_template_dir_to_file (string const & dir)
|
||||
{
|
||||
sys::path dir_path = dir;
|
||||
sys::path file_path = dir;
|
||||
file_path /= dir_path.leaf() + template_suffix;
|
||||
return file_path.to_string ();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
find_session_templates (vector<TemplateInfo>& template_names)
|
||||
{
|
||||
|
|
@ -79,7 +93,7 @@ find_session_templates (vector<TemplateInfo>& template_names)
|
|||
SearchPath spath (system_template_directory());
|
||||
spath += user_template_directory ();
|
||||
|
||||
templates = scanner (spath.to_string(), template_filter, 0, false, true);
|
||||
templates = scanner (spath.to_string(), template_filter, 0, true, true);
|
||||
|
||||
if (!templates) {
|
||||
cerr << "Found nothing along " << spath.to_string() << endl;
|
||||
|
|
@ -89,18 +103,18 @@ find_session_templates (vector<TemplateInfo>& template_names)
|
|||
cerr << "Found " << templates->size() << " along " << spath.to_string() << endl;
|
||||
|
||||
for (vector<string*>::iterator i = templates->begin(); i != templates->end(); ++i) {
|
||||
string fullpath = *(*i);
|
||||
string file = session_template_dir_to_file (**i);
|
||||
|
||||
XMLTree tree;
|
||||
|
||||
if (!tree.read (fullpath.c_str())) {
|
||||
if (!tree.read (file.c_str())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TemplateInfo rti;
|
||||
|
||||
rti.name = basename_nosuffix (fullpath);
|
||||
rti.path = fullpath;
|
||||
rti.name = basename_nosuffix (**i);
|
||||
rti.path = **i;
|
||||
|
||||
template_names.push_back (rti);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include "pbd/filesystem.h"
|
||||
#include "pbd/error.h"
|
||||
#include "pbd/compose.h"
|
||||
#include "pbd/pathscanner.h"
|
||||
|
||||
#include "i18n.h"
|
||||
|
||||
|
|
@ -198,6 +199,27 @@ copy_file(const path & from_path, const path & to_path)
|
|||
}
|
||||
}
|
||||
|
||||
static
|
||||
bool accept_all_files (string const &, void *)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
copy_files(const path & from_path, const path & to_dir)
|
||||
{
|
||||
PathScanner scanner;
|
||||
vector<string*>* files = scanner (from_path.to_string(), accept_all_files, 0, true, false);
|
||||
for (vector<string*>::iterator i = files->begin(); i != files->end(); ++i) {
|
||||
sys::path from = from_path;
|
||||
from /= **i;
|
||||
sys::path to = to_dir;
|
||||
to /= **i;
|
||||
|
||||
copy_file (from, to);
|
||||
}
|
||||
}
|
||||
|
||||
string
|
||||
basename (const path & p)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -178,6 +178,12 @@ void rename (const path& from_path, const path& to_path);
|
|||
*/
|
||||
void copy_file(const path & from_path, const path & to_path);
|
||||
|
||||
/**
|
||||
* Attempt to copy all regular files from from_path to a new directory.
|
||||
* This method does not recurse.
|
||||
*/
|
||||
void copy_files(const path & from_path, const path & to_dir);
|
||||
|
||||
/**
|
||||
* @return The substring of the filename component of the path, starting
|
||||
* at the beginning of the filename up to but not including the last dot.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue