summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Mueller <github@johannes-mueller.org>2017-08-18 19:53:46 +0200
committerRobin Gareus <robin@gareus.org>2017-08-20 21:09:30 +0200
commitae51d5fd4ebb90f782334ac0b4addc0c88e1629c (patch)
tree2409ee3fa7ad3c9c5f207324f44d0f67bf4befd4
parent908369ab3e31f82eae3734cfe61421912d2fba6a (diff)
Let the user add a template description on saving session templates
-rw-r--r--gtk2_ardour/ardour_ui.cc46
-rw-r--r--gtk2_ardour/ardour_ui.h3
-rw-r--r--gtk2_ardour/save_template_dialog.cc71
-rw-r--r--gtk2_ardour/save_template_dialog.h47
-rw-r--r--gtk2_ardour/wscript1
-rw-r--r--libs/ardour/ardour/session.h4
-rw-r--r--libs/ardour/session_state.cc16
7 files changed, 151 insertions, 37 deletions
diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc
index 8d931bbbd3..873d114cf2 100644
--- a/gtk2_ardour/ardour_ui.cc
+++ b/gtk2_ardour/ardour_ui.cc
@@ -169,6 +169,7 @@ typedef uint64_t microseconds_t;
#include "route_time_axis.h"
#include "route_params_ui.h"
#include "save_as_dialog.h"
+#include "save_template_dialog.h"
#include "script_selector.h"
#include "session_archive_dialog.h"
#include "session_dialog.h"
@@ -3158,60 +3159,43 @@ ARDOUR_UI::transport_rec_enable_blink (bool onoff)
}
}
-bool
-ARDOUR_UI::process_save_template_prompter (Prompter& prompter)
+void
+ARDOUR_UI::save_template_dialog_response (int response, SaveTemplateDialog* d)
{
- string name;
+ if (response == RESPONSE_ACCEPT) {
+ const string name = d->get_template_name ();
+ const string desc = d->get_description ();
- prompter.get_result (name);
-
- if (name.length()) {
- int failed = _session->save_template (name);
+ int failed = _session->save_template (name, desc);
if (failed == -2) { /* file already exists. */
- bool overwrite = overwrite_file_dialog (prompter,
+ bool overwrite = overwrite_file_dialog (*d,
_("Confirm Template Overwrite"),
_("A template already exists with that name. Do you want to overwrite it?"));
if (overwrite) {
- _session->save_template (name, true);
+ _session->save_template (name, desc, true);
}
else {
- return false;
+ d->show ();
+ return;
}
}
}
-
- return true;
+ delete d;
}
void
ARDOUR_UI::save_template ()
{
- Prompter prompter (true);
-
if (!check_audioengine (_main_window)) {
return;
}
- prompter.set_name (X_("Prompter"));
- prompter.set_title (_("Save Template"));
- prompter.set_prompt (_("Name for template:"));
- prompter.set_initial_text(_session->name() + _("-template"));
- prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
-
- bool finished = false;
- while (!finished) {
- switch (prompter.run()) {
- case RESPONSE_ACCEPT:
- finished = process_save_template_prompter (prompter);
- break;
+ SaveTemplateDialog* d = new SaveTemplateDialog (*_session);
- default:
- finished = true;
- break;
- }
- }
+ d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::save_template_dialog_response), d));
+ d->show ();
}
void ARDOUR_UI::manage_templates ()
diff --git a/gtk2_ardour/ardour_ui.h b/gtk2_ardour/ardour_ui.h
index aed1be2e6b..fbe1486736 100644
--- a/gtk2_ardour/ardour_ui.h
+++ b/gtk2_ardour/ardour_ui.h
@@ -127,6 +127,7 @@ class MainClock;
class Mixer_UI;
class PublicEditor;
class SaveAsDialog;
+class SaveTemplateDialog;
class SessionDialog;
class SessionOptionEditorWindow;
class Splash;
@@ -621,7 +622,7 @@ private:
void open_session ();
void open_recent_session ();
- bool process_save_template_prompter (ArdourWidgets::Prompter& prompter);
+ void save_template_dialog_response (int response, SaveTemplateDialog* d);
void save_template ();
void manage_templates ();
diff --git a/gtk2_ardour/save_template_dialog.cc b/gtk2_ardour/save_template_dialog.cc
new file mode 100644
index 0000000000..ed803bf405
--- /dev/null
+++ b/gtk2_ardour/save_template_dialog.cc
@@ -0,0 +1,71 @@
+/*
+ Copyright (C) 2017 Paul Davis
+ Author: Johannes Mueller
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <gtkmm/box.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/label.h>
+#include <gtkmm/stock.h>
+
+#include "pbd/i18n.h"
+#include "ardour/session.h"
+
+#include "save_template_dialog.h"
+
+using namespace Gtk;
+using namespace ARDOUR;
+
+SaveTemplateDialog::SaveTemplateDialog (const Session& s)
+ : ArdourDialog (_("Save as template"))
+{
+ _name_editor.get_buffer()->set_text (s.name() + _("-template"));
+ _description_editor.set_wrap_mode (Gtk::WRAP_WORD);
+ _description_editor.set_size_request(400, 300);
+
+ HBox* hb = manage (new HBox);
+ hb->set_spacing (8);
+ Label* lb = manage (new Label(_("Template name:")));
+ hb->pack_start (*lb, false, true);
+ hb->pack_start (_name_editor, true, true);
+
+ Frame* fd = manage (new Frame(_("Description:")));
+ fd->add (_description_editor);
+
+ get_vbox()->set_spacing (8);
+ get_vbox()->pack_start (*fd);
+ get_vbox()->pack_start (*hb);
+
+ add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
+
+ show_all_children ();
+}
+
+
+std::string
+SaveTemplateDialog::get_template_name () const
+{
+ return _name_editor.get_buffer()->get_text();
+}
+
+std::string
+SaveTemplateDialog::get_description () const
+{
+ return _description_editor.get_buffer()->get_text();
+}
diff --git a/gtk2_ardour/save_template_dialog.h b/gtk2_ardour/save_template_dialog.h
new file mode 100644
index 0000000000..6b98d5cfba
--- /dev/null
+++ b/gtk2_ardour/save_template_dialog.h
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2017 Paul Davis
+ Author: Johannes Mueller
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __ardour_gtk_save_template_dialog_h__
+#define __ardour_gtk_save_template_dialog_h__
+
+#include <gtkmm/entry.h>
+#include <gtkmm/textview.h>
+
+#include "ardour_dialog.h"
+
+namespace ARDOUR
+{
+class Session;
+}
+
+class SaveTemplateDialog : public ArdourDialog
+{
+public:
+ SaveTemplateDialog (const ARDOUR::Session& s);
+
+ std::string get_template_name () const;
+ std::string get_description () const;
+
+private:
+ Gtk::Entry _name_editor;
+ Gtk::TextView _description_editor;
+};
+
+#endif /* __ardour_gtk_save_template_dialog_h__ */
diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript
index b0106c683d..598674079a 100644
--- a/gtk2_ardour/wscript
+++ b/gtk2_ardour/wscript
@@ -218,6 +218,7 @@ gtk2_ardour_sources = [
'route_ui.cc',
'ruler_dialog.cc',
'save_as_dialog.cc',
+ 'save_template_dialog.cc',
'search_path_option.cc',
'script_selector.cc',
'selection.cc',
diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 6fe760c2b8..0581d706ff 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -259,7 +259,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
*/
RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, const std::string& template_path, const std::string& name, PlaylistDisposition pd = NewPlaylist);
RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, XMLNode&, const std::string& name, PlaylistDisposition pd = NewPlaylist);
- std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
+ std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
uint32_t channels, std::vector<std::string> const & smf_track_names);
int bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t,std::string)> callback);
@@ -531,7 +531,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
int archive_session (const std::string&, const std::string&, ArchiveEncode compress_audio = FLAC_16BIT, bool only_used_sources = false, Progress* p = 0);
int restore_state (std::string snapshot_name);
- int save_template (std::string template_name, bool replace_existing = false);
+ int save_template (const std::string& template_name, const std::string& description = "", bool replace_existing = false);
int save_history (std::string snapshot_name = "");
int restore_history (std::string snapshot_name);
void remove_state (std::string snapshot_name);
diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc
index 0a1eb2ace6..0bf09f76c6 100644
--- a/libs/ardour/session_state.cc
+++ b/libs/ardour/session_state.cc
@@ -2356,7 +2356,7 @@ Session::XMLSourceFactory (const XMLNode& node)
}
int
-Session::save_template (string template_name, bool replace_existing)
+Session::save_template (const string& template_name, const string& description, bool replace_existing)
{
if ((_state_of_the_state & CannotSave) || template_name.empty ()) {
return -1;
@@ -2411,12 +2411,22 @@ Session::save_template (string template_name, bool replace_existing)
SessionSaveUnderway (); /* EMIT SIGNAL */
XMLTree tree;
-
+ XMLNode* root;
{
PBD::Unwinder<std::string> uw (_template_state_dir, template_dir_path);
- tree.set_root (&get_template());
+ root = &get_template();
+ }
+
+ if (!description.empty()) {
+ XMLNode* desc = new XMLNode(X_("description"));
+ XMLNode* desc_cont = new XMLNode(X_("content"), description);
+ desc->add_child_nocopy (*desc_cont);
+
+ root->add_child_nocopy (*desc);
}
+ tree.set_root (root);
+
if (!tree.write (template_file_path)) {
error << _("template not saved") << endmsg;
return -1;