2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __session_metadata_dialog_h__
21 #define __session_metadata_dialog_h__
23 #include "ardour_dialog.h"
26 #include <boost/shared_ptr.hpp>
31 #include <ardour/session_metadata.h>
37 typedef boost::shared_ptr<MetadataField> MetadataPtr;
39 /// Wraps a metadata field to be used in a GUI
42 MetadataField (ustring const & field_name);
43 virtual ~MetadataField();
44 virtual MetadataPtr copy () = 0;
46 virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
47 virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
49 virtual ustring name() { return _name; }
50 virtual ustring value() { return _value; }
52 /// Get widget containing name of field
53 virtual Gtk::Widget & name_widget () = 0;
54 /// Get label containing value of field
55 virtual Gtk::Widget & value_widget () = 0;
56 /// Get widget for editing value
57 virtual Gtk::Widget & edit_widget () = 0;
63 /// MetadataField that contains text
64 class TextMetadataField : public MetadataField {
66 typedef ustring (ARDOUR::SessionMetadata::*Getter) () const;
67 typedef void (ARDOUR::SessionMetadata::*Setter) (ustring const &);
69 TextMetadataField (Getter getter, Setter setter, ustring const & field_name, guint width = 50);
72 void save_data (ARDOUR::SessionMetadata & data) const;
73 void load_data (ARDOUR::SessionMetadata const & data);
75 Gtk::Widget & name_widget ();
76 Gtk::Widget & value_widget ();
77 Gtk::Widget & edit_widget ();
85 Gtk::Label* value_label;
91 /// MetadataField that accepts only numbers
92 class NumberMetadataField : public MetadataField {
94 typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
95 typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
97 NumberMetadataField (Getter getter, Setter setter, ustring const & field_name, guint numbers, guint width = 50);
100 void save_data (ARDOUR::SessionMetadata & data) const;
101 void load_data (ARDOUR::SessionMetadata const & data);
103 Gtk::Widget & name_widget ();
104 Gtk::Widget & value_widget ();
105 Gtk::Widget & edit_widget ();
107 void update_value ();
108 ustring uint_to_str (uint32_t i) const;
109 uint32_t str_to_uint (ustring const & str) const;
115 Gtk::Label* value_label;
122 /// Interface for MetadataFields
123 class SessionMetadataSet {
125 SessionMetadataSet (ustring const & name);
126 virtual ~SessionMetadataSet () {};
128 void add_data_field (MetadataPtr field);
130 /// Sets session, into which the data is eventually saved
131 virtual void set_session (ARDOUR::Session * s) { session = s; }
132 /// allows loading extra data into data sets (for importing etc.)
133 virtual void load_extra_data (ARDOUR::SessionMetadata const & data) { }
134 /// Saves data to session
135 virtual void save_data () = 0;
137 virtual Gtk::Widget & get_widget () = 0;
138 virtual Gtk::Widget & get_tab_widget () = 0;
141 typedef std::list<MetadataPtr> DataList;
144 ARDOUR::Session *session;
147 /// Contains MetadataFields for editing
148 class SessionMetadataSetEditable : public SessionMetadataSet {
150 SessionMetadataSetEditable (ustring const & name);
152 Gtk::Widget & get_widget () { return table; }
153 Gtk::Widget & get_tab_widget ();
155 /// Sets session and loads data
156 void set_session (ARDOUR::Session * s);
157 /// Saves from MetadataFields into data
162 Gtk::Label tab_widget;
165 /// Contains MetadataFields for importing
166 class SessionMetadataSetImportable : public SessionMetadataSet {
168 SessionMetadataSetImportable (ustring const & name);
170 Gtk::Widget & get_widget () { return tree_view; }
171 Gtk::Widget & get_tab_widget ();
172 Gtk::Widget & get_select_all_widget ();
174 /// Loads importable data from data
175 void load_extra_data (ARDOUR::SessionMetadata const & data);
176 /// Saves from importable data (see load_data) to session_data
180 DataList & session_list; // References MetadataSet::list
181 DataList import_list;
183 struct Columns : public Gtk::TreeModel::ColumnRecord
186 Gtk::TreeModelColumn<ustring> field;
187 Gtk::TreeModelColumn<ustring> values;
188 Gtk::TreeModelColumn<bool> import;
189 Gtk::TreeModelColumn<MetadataPtr> data;
191 Columns() { add (field); add (values); add (import); add (data); }
194 Glib::RefPtr<Gtk::ListStore> tree;
196 Gtk::TreeView tree_view;
198 Gtk::Label tab_widget;
199 Gtk::CheckButton select_all_check;
202 void selection_changed (ustring const & path);
205 /// Metadata dialog interface
207 * The DataSets are initalized in this class so that all
208 * Dialogs have the same sets of data in the same order.
210 template <typename DataSet>
211 class SessionMetadataDialog : public ArdourDialog
214 SessionMetadataDialog (ustring const & name);
218 void load_extra_data (ARDOUR::SessionMetadata const & data);
221 virtual void init_gui () = 0;
222 virtual void save_and_close ();
223 virtual void end_dialog ();
225 void warn_user (ustring const & string);
227 typedef std::list<Gtk::Widget *> WidgetList;
228 typedef boost::shared_ptr<WidgetList> WidgetListPtr;
229 typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
231 /// Returns list of widgets gathered by calling f for each data set
232 WidgetListPtr get_custom_widgets (WidgetFunc f);
234 /// Adds a widget to the table (vertical stacking) with automatic spacing
235 void add_widget (Gtk::Widget & widget);
237 Gtk::Notebook notebook;
240 void init_track_data ();
241 void init_album_data ();
242 void init_people_data ();
244 typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
245 typedef std::list<DataSetPtr> DataSetList;
246 DataSetList data_list;
248 Gtk::Button * save_button;
249 Gtk::Button * cancel_button;
252 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable> {
254 SessionMetadataEditor ();
255 ~SessionMetadataEditor ();
261 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
263 SessionMetadataImporter ();
264 ~SessionMetadataImporter ();
270 // Select all from -widget
271 Gtk::HBox selection_hbox;
272 Gtk::Label selection_label;