use entered track for fit-tracks if in internal edit mode and no tracks or regions...
[ardour2.git] / gtk2_ardour / session_metadata_dialog.h
blobfbe430e7ad43d0f0f110b730cb16a610ddaf7695
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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)
8 any later version.
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
13 for more details.
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"
25 #include <gtkmm.h>
26 #include <boost/shared_ptr.hpp>
28 #include <string>
29 #include <list>
31 #include "ardour/session_metadata.h"
33 class MetadataField;
34 typedef boost::shared_ptr<MetadataField> MetadataPtr;
36 /// Wraps a metadata field to be used in a GUI
37 class MetadataField {
38 public:
39 MetadataField (std::string const & field_name);
40 virtual ~MetadataField();
41 virtual MetadataPtr copy () = 0;
43 virtual void save_data (ARDOUR::SessionMetadata & data) const = 0;
44 virtual void load_data (ARDOUR::SessionMetadata const & data) = 0;
46 virtual std::string name() { return _name; }
47 virtual std::string value() { return _value; }
49 /// Get widget containing name of field
50 virtual Gtk::Widget & name_widget () = 0;
51 /// Get label containing value of field
52 virtual Gtk::Widget & value_widget () = 0;
53 /// Get widget for editing value
54 virtual Gtk::Widget & edit_widget () = 0;
55 protected:
56 std::string _name;
57 std::string _value;
60 /// MetadataField that contains text
61 class TextMetadataField : public MetadataField {
62 private:
63 typedef std::string (ARDOUR::SessionMetadata::*Getter) () const;
64 typedef void (ARDOUR::SessionMetadata::*Setter) (std::string const &);
65 public:
66 TextMetadataField (Getter getter, Setter setter, std::string const & field_name, guint width = 50);
67 MetadataPtr copy ();
69 void save_data (ARDOUR::SessionMetadata & data) const;
70 void load_data (ARDOUR::SessionMetadata const & data);
72 Gtk::Widget & name_widget ();
73 Gtk::Widget & value_widget ();
74 Gtk::Widget & edit_widget ();
75 private:
76 void update_value ();
78 Getter getter;
79 Setter setter;
81 Gtk::Label* label;
82 Gtk::Label* value_label;
83 Gtk::Entry* entry;
85 uint width;
88 /// MetadataField that accepts only numbers
89 class NumberMetadataField : public MetadataField {
90 private:
91 typedef uint32_t (ARDOUR::SessionMetadata::*Getter) () const;
92 typedef void (ARDOUR::SessionMetadata::*Setter) (uint32_t);
93 public:
94 NumberMetadataField (Getter getter, Setter setter, std::string const & field_name, guint numbers, guint width = 50);
95 MetadataPtr copy ();
97 void save_data (ARDOUR::SessionMetadata & data) const;
98 void load_data (ARDOUR::SessionMetadata const & data);
100 Gtk::Widget & name_widget ();
101 Gtk::Widget & value_widget ();
102 Gtk::Widget & edit_widget ();
103 private:
104 void update_value ();
105 std::string uint_to_str (uint32_t i) const;
106 uint32_t str_to_uint (std::string const & str) const;
108 Getter getter;
109 Setter setter;
111 Gtk::Label* label;
112 Gtk::Label* value_label;
113 Gtk::Entry* entry;
115 guint numbers;
116 guint width;
119 /// Interface for MetadataFields
120 class SessionMetadataSet : public ARDOUR::SessionHandlePtr {
121 public:
122 SessionMetadataSet (std::string const & name);
123 virtual ~SessionMetadataSet () {};
125 void add_data_field (MetadataPtr field);
127 /// allows loading extra data into data sets (for importing etc.)
128 virtual void load_extra_data (ARDOUR::SessionMetadata const & /*data*/) { }
129 /// Saves data to session
130 virtual void save_data () = 0;
132 virtual Gtk::Widget & get_widget () = 0;
133 virtual Gtk::Widget & get_tab_widget () = 0;
135 protected:
136 typedef std::list<MetadataPtr> DataList;
137 DataList list;
138 std::string name;
141 /// Contains MetadataFields for editing
142 class SessionMetadataSetEditable : public SessionMetadataSet {
143 public:
144 SessionMetadataSetEditable (std::string const & name);
146 Gtk::Widget & get_widget () { return vbox; }
147 Gtk::Widget & get_tab_widget ();
149 /// Sets session and loads data
150 void set_session (ARDOUR::Session * s);
151 /// Saves from MetadataFields into data
152 void save_data ();
154 private:
155 Gtk::VBox vbox;
156 Gtk::Table table;
157 Gtk::Label tab_widget;
160 /// Contains MetadataFields for importing
161 class SessionMetadataSetImportable : public SessionMetadataSet {
162 public:
163 SessionMetadataSetImportable (std::string const & name);
165 Gtk::Widget & get_widget () { return tree_view; }
166 Gtk::Widget & get_tab_widget ();
167 Gtk::Widget & get_select_all_widget ();
169 /// Loads importable data from data
170 void load_extra_data (ARDOUR::SessionMetadata const & data);
171 /// Saves from importable data (see load_data) to session_data
172 void save_data ();
174 private:
175 DataList & session_list; // References MetadataSet::list
176 DataList import_list;
178 struct Columns : public Gtk::TreeModel::ColumnRecord
180 public:
181 Gtk::TreeModelColumn<std::string> field;
182 Gtk::TreeModelColumn<std::string> values;
183 Gtk::TreeModelColumn<bool> import;
184 Gtk::TreeModelColumn<MetadataPtr> data;
186 Columns() { add (field); add (values); add (import); add (data); }
189 Glib::RefPtr<Gtk::ListStore> tree;
190 Columns tree_cols;
191 Gtk::TreeView tree_view;
193 Gtk::Label tab_widget;
194 Gtk::CheckButton select_all_check;
196 void select_all ();
197 void selection_changed (std::string const & path);
200 /// Metadata dialog interface
202 * The DataSets are initalized in this class so that all
203 * Dialogs have the same sets of data in the same order.
205 template <typename DataSet>
206 class SessionMetadataDialog : public ArdourDialog
208 public:
209 SessionMetadataDialog (std::string const & name);
211 protected:
212 void init_data ();
213 void load_extra_data (ARDOUR::SessionMetadata const & data);
214 void save_data ();
216 virtual void init_gui () = 0;
217 virtual void save_and_close ();
218 virtual void end_dialog ();
220 void warn_user (std::string const & string);
222 typedef std::list<Gtk::Widget *> WidgetList;
223 typedef boost::shared_ptr<WidgetList> WidgetListPtr;
224 typedef Gtk::Widget & (DataSet::*WidgetFunc) ();
226 /// Returns list of widgets gathered by calling f for each data set
227 WidgetListPtr get_custom_widgets (WidgetFunc f);
229 /// Adds a widget to the table (vertical stacking) with automatic spacing
230 void add_widget (Gtk::Widget & widget);
232 Gtk::Notebook notebook;
234 private:
235 void init_track_data ();
236 void init_album_data ();
237 void init_people_data ();
239 typedef boost::shared_ptr<SessionMetadataSet> DataSetPtr;
240 typedef std::list<DataSetPtr> DataSetList;
241 DataSetList data_list;
243 Gtk::Button * save_button;
244 Gtk::Button * cancel_button;
247 class SessionMetadataEditor : public SessionMetadataDialog<SessionMetadataSetEditable> {
248 public:
249 SessionMetadataEditor ();
250 ~SessionMetadataEditor ();
251 void run ();
252 private:
253 void init_gui ();
256 class SessionMetadataImporter : public SessionMetadataDialog<SessionMetadataSetImportable> {
257 public:
258 SessionMetadataImporter ();
259 ~SessionMetadataImporter ();
260 void run ();
262 private:
263 void init_gui ();
265 // Select all from -widget
266 Gtk::HBox selection_hbox;
267 Gtk::Label selection_label;
271 #endif