2 cleanup patches from nickm, plus work on mixer_ui.cc so that it compiles
[ardour.git] / gtk2_ardour / library_ui.h
1 /*
2     Copyright (C) 1999-2002 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_library_ui_h__
21 #define __ardour_library_ui_h__
22
23 #include <map>
24 #include <string>
25 #include <list>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28
29 #include <sigc++/signal.h>
30 #include <gtkmm.h>
31 #include <gtkmm2ext/selector.h>
32
33 #include <ardour/region.h>
34
35 #include "ardour_dialog.h"
36
37 using std::string;
38 using std::map;
39
40 struct RowTaggedString {
41     RowTaggedString (int r, string s) 
42             : row (r), str (s) {}
43
44     int32_t row;
45     string str;
46 };
47
48 class SoundFileBox : public Gtk::VBox 
49 {
50   public:
51         /**
52           @variable uri is the path name of string.
53           @variable metadata whether to show the user-added fields from sfdb.
54         */
55         SoundFileBox (string uri, bool metadata);
56         ~SoundFileBox ();
57
58         sigc::signal<void, string, bool> file_chosen;
59
60   private:
61         string uri;
62         bool metadata;
63         SF_INFO* sf_info;
64
65         char* playcmd;
66         pid_t current_pid;
67         
68         Gtk::Label label;
69         Gtk::Label path;
70         Gtk::Entry path_entry;
71         Gtk::Label length;
72         Gtk::Label format;
73         Gtk::Label channels;
74         Gtk::Label samplerate;
75
76         Gtkmm2ext::Selector fields;
77         string selected_field;
78
79         Gtk::Frame border_frame;
80         
81         Gtk::VBox main_box;
82         Gtk::HBox top_box;
83         Gtk::HBox bottom_box;
84
85         Gtk::Button play_btn;
86         Gtk::Button stop_btn;
87         Gtk::Button add_field_btn;
88         Gtk::Button remove_field_btn;
89
90         static void _fields_refiller (Gtk::CList &list, void* arg);
91         void fields_refiller (Gtk::CList &clist);
92         int setup_labels (string uri);
93         void setup_fields ();
94
95         void play_btn_clicked ();
96         void stop_btn_clicked ();
97         void add_field_clicked ();
98         void remove_field_clicked ();
99
100         void field_selected (Gtkmm2ext::Selector *selector, 
101                                                  Gtkmm2ext::SelectionResult *re);
102         void field_chosen (Gtkmm2ext::Selector *selector, 
103                                                  Gtkmm2ext::SelectionResult *re);
104         void audition_status_changed (bool state);
105 };
106
107 class SearchSounds : public ArdourDialog 
108 {
109   public:
110         SearchSounds ();
111         ~SearchSounds ();
112
113         sigc::signal<void, string, bool> file_chosen;
114
115   private:
116         Gtk::Button find_btn;
117
118         Gtk::RadioButton and_rbtn;
119         Gtk::RadioButton or_rbtn;
120
121         Gtkmm2ext::Selector fields;
122         string selected_field;
123
124         Gtk::VBox main_box;
125         Gtk::HBox rbtn_box;
126         Gtk::HBox bottom_box;
127
128         static void _fields_refiller (Gtk::CList &list, void* arg);
129         void fields_refiller (Gtk::CList &clist);
130         void setup_fields ();
131
132         void field_selected (Gtkmm2ext::Selector *selector, 
133                                                  Gtkmm2ext::SelectionResult *re);
134
135         void find_btn_clicked ();
136
137         void file_found (string uri, bool multi);
138 };
139
140 class SearchResults : public ArdourDialog
141 {
142   public:
143         SearchResults (map<string,string> field_values, bool and_search);
144         ~SearchResults ();
145
146         sigc::signal<void, string, bool> file_chosen;
147
148   private:
149         map<string,string> search_info;
150         bool search_and;
151         string selection;
152
153         Gtk::VBox main_box;
154         Gtk::HBox hbox;
155         Gtk::HBox import_box;
156         
157         Gtk::Button import_btn;
158         Gtk::CheckButton multichan_check;
159   
160         SoundFileBox* info_box;
161
162         Gtkmm2ext::Selector results;
163         static void _results_refiller (Gtk::CList &list, void* arg);
164         void results_refiller (Gtk::CList &clist);
165
166         void import_clicked ();
167
168         void result_chosen (Gtkmm2ext::Selector *selector, 
169                                                  Gtkmm2ext::SelectionResult *re);
170 };
171
172 class LibraryTree : public Gtk::VBox
173 {
174   public:
175         LibraryTree ();
176         ~LibraryTree ();
177
178         sigc::signal<void, string, bool> file_chosen;
179         sigc::signal<void> group_selected;
180         sigc::signal<void, string> member_selected;
181         sigc::signal<void> member_deselected;
182         sigc::signal<void> deselected;
183
184         list<string> selection;
185         void clear_selection ();
186         
187   private:
188         map<string, Gtk::TreeItem*> uri_mapping;
189         map<string, string> uri_parent; // this ugly, but necessary
190
191         string current_member;
192         string current_group;
193         
194         Gtk::HBox hbox;
195         Gtk::VBox framed_box;
196         Gtk::HBox btn_box_top;
197         Gtk::HBox btn_box_bottom;
198
199         Gtk::ScrolledWindow scroll;
200         Gtk::Tree tree;
201
202         Gtk::Button add_btn;
203         Gtk::Button remove_btn;
204         Gtk::Button find_btn;
205         Gtk::Button folder_btn;
206
207         Gtk::FileSelection files_select;
208
209         void file_ok_clicked ();
210         void file_cancel_clicked ();
211         
212         void add_btn_clicked ();
213         void folder_btn_clicked ();
214         void remove_btn_clicked ();
215         void find_btn_clicked ();
216
217         void file_found (string uri, bool multi);
218
219         void cb_group_select (Gtk::TreeItem* item, string uri);
220         void cb_member_select (Gtk::TreeItem* item, string uri);
221         void cb_member_deselect (Gtk::TreeItem* item, string uri);
222
223         void populate ();
224         void subpopulate (Gtk::Tree*, string group);
225
226         void added_group (string, string);
227         void removed_group (string);
228         void added_member (string, string);
229         void removed_member (string);
230         
231         void cancel_import_clicked ();
232 };
233
234 class SoundFileBrowser : public Gtk::VBox {
235   public:
236         SoundFileBrowser ();
237         ~SoundFileBrowser ();
238   
239         sigc::signal<void> group_selected;
240         sigc::signal<void, string> member_selected;
241         sigc::signal<void> member_deselected;
242         sigc::signal<void> deselected;
243   
244         list<RowTaggedString> selection;
245         void clear_selection ();
246
247   private:
248         string current_member;
249         string current_group;
250         Gtk::FileSelection fs_selector;
251         Gtk::CList* file_list;
252
253         void dir_list_selected(gint row, gint col, GdkEvent* ev);
254         void file_list_selected(gint row, gint col, GdkEvent* ev);
255         void file_list_deselected(gint row, gint col, GdkEvent* ev);
256   
257         string safety_check_file(string file);
258 };
259
260 class SoundFileSelector : public ArdourDialog {
261   public:
262         /**
263           @variable action the name given to the action button
264           @variable import is action button sensitive
265           @variable multi does splitting the region by channel make sense here
266           @variable persist should this LibraryTree be hidden or deleted when closed
267           */
268         SoundFileSelector ();
269         ~SoundFileSelector ();
270   
271         void run (string action, bool split_makes_sense, bool hide_after_action = false);
272         void get_result (vector<string>& paths, bool& split);
273         void hide_import_stuff();
274
275         sigc::signal<void,vector<string>,bool> Action;
276         
277   private:
278         bool multiable;
279         bool hide_after_action;
280         bool sfdb;
281   
282         void import_btn_clicked ();
283         void sfdb_group_selected();
284         void browser_group_selected();
285         void member_selected(string member, bool sfdb);
286         void member_deselected(bool sfdb);
287         void sfdb_deselected();
288         void page_switched(Gtk::Notebook_Helpers::Page* page, guint page_num);
289   
290         Gtk::HBox main_box;
291         Gtk::VBox vbox;
292         Gtk::Notebook notebook;
293         Gtk::Label sfdb_label;
294         Gtk::Label fs_label;
295   
296         SoundFileBrowser sf_browser;
297         LibraryTree sfdb_tree;
298   
299         Gtk::HBox import_box;
300         Gtk::Button import_btn;
301         Gtk::CheckButton split_channels;
302         Gtk::CheckButton resample_check;
303         
304         SoundFileBox* info_box;
305 };
306
307 #endif // __ardour_library_ui_h__