Indentation and whitespace fixes in sfdb_ui.h
[ardour.git] / gtk2_ardour / sfdb_ui.h
1 /*
2     Copyright (C) 2005-2006 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_sfdb_ui_h__
21 #define __ardour_sfdb_ui_h__
22
23 #include <string>
24 #include <vector>
25 #include <map>
26
27 #include <sigc++/signal.h>
28
29 #include <gtkmm/stock.h>
30 #include <gtkmm/box.h>
31 #include <gtkmm/button.h>
32 #include <gtkmm/checkbutton.h>
33 #include <gtkmm/comboboxtext.h>
34 #include <gtkmm/dialog.h>
35 #include <gtkmm/entry.h>
36 #include <gtkmm/filechooserwidget.h>
37 #include <gtkmm/frame.h>
38 #include <gtkmm/label.h>
39 #include <gtkmm/scale.h>
40 #include <gtkmm/textview.h>
41 #include <gtkmm/table.h>
42 #include <gtkmm/liststore.h>
43 #include <gtkmm/spinbutton.h>
44 #include <gtkmm/notebook.h>
45
46
47 #include "ardour/audiofilesource.h"
48 #include "ardour/session_handle.h"
49
50 #include "ardour_window.h"
51 #include "editing.h"
52 #include "audio_clock.h"
53 #include "instrument_selector.h"
54
55 namespace ARDOUR {
56         class Session;
57 };
58
59 class GainMeter;
60 class Mootcher;
61
62 class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList
63 {
64   public:
65         SoundFileBox (bool persistent);
66         virtual ~SoundFileBox () {};
67
68         void set_session (ARDOUR::Session* s);
69         bool setup_labels (const std::string& filename);
70
71         void audition();
72         bool audition_oneshot();
73         bool autoplay () const;
74         void set_src_quality(ARDOUR::SrcQuality q) { _src_quality = q; }
75         void set_import_position(Editing::ImportPosition p) { _import_position = p; }
76
77   protected:
78         std::string path;
79
80         ARDOUR::SoundFileInfo sf_info;
81
82         Gtk::Table table;
83
84         Gtk::Label length;
85         Gtk::Label format;
86         Gtk::Label channels;
87         Gtk::Label samplerate;
88         Gtk::Label timecode;
89
90         Gtk::Label channels_value;
91         Gtk::Label samplerate_value;
92
93         Gtk::Label format_text;
94         AudioClock length_clock;
95         AudioClock timecode_clock;
96
97         Gtk::Frame border_frame;
98         Gtk::Label preview_label;
99
100         Gtk::TextView tags_entry;
101
102         Gtk::VBox main_box;
103         Gtk::VBox path_box;
104         Gtk::HBox bottom_box;
105
106         Gtk::Button play_btn;
107         Gtk::Button stop_btn;
108         Gtk::CheckButton autoplay_btn;
109         Gtk::Button apply_btn;
110         Gtk::HScale seek_slider;
111
112         PBD::ScopedConnectionList auditioner_connections;
113         void audition_active(bool);
114         void audition_progress(ARDOUR::framecnt_t, ARDOUR::framecnt_t);
115
116         bool tags_entry_left (GdkEventFocus* event);
117         void tags_changed ();
118         void save_tags (const std::vector<std::string>&);
119         void stop_audition ();
120         bool seek_button_press(GdkEventButton*);
121         bool seek_button_release(GdkEventButton*);
122         bool _seeking;
123         ARDOUR::SrcQuality _src_quality;
124         Editing::ImportPosition _import_position;
125 };
126
127 class SoundFileBrowser : public ArdourWindow
128 {
129   private:
130         class FoundTagColumns : public Gtk::TreeModel::ColumnRecord
131         {
132           public:
133                 Gtk::TreeModelColumn<std::string> pathname;
134
135                 FoundTagColumns() { add(pathname); }
136         };
137
138         class FreesoundColumns : public Gtk::TreeModel::ColumnRecord
139         {
140           public:
141                 Gtk::TreeModelColumn<std::string> id;
142                 Gtk::TreeModelColumn<std::string> uri;
143                 Gtk::TreeModelColumn<std::string> filename;
144                 Gtk::TreeModelColumn<std::string> duration;
145                 Gtk::TreeModelColumn<std::string> filesize;
146                 Gtk::TreeModelColumn<std::string> smplrate;
147                 Gtk::TreeModelColumn<std::string> license;
148                 Gtk::TreeModelColumn<bool>        started;
149
150                 FreesoundColumns() {
151                         add(id); 
152                         add(filename); 
153                         add(uri);
154                         add(duration);
155                         add(filesize);
156                         add(smplrate);
157                         add(license);
158                         add(started);
159                 }
160         };
161
162         FoundTagColumns found_list_columns;
163         Glib::RefPtr<Gtk::ListStore> found_list;
164
165         FreesoundColumns freesound_list_columns;
166         Glib::RefPtr<Gtk::ListStore> freesound_list;
167
168         Gtk::Button freesound_more_btn;
169         Gtk::Button freesound_similar_btn;
170
171         void handle_freesound_results(std::string theString);
172   public:
173         SoundFileBrowser (std::string title, ARDOUR::Session* _s, bool persistent);
174         virtual ~SoundFileBrowser ();
175
176         int run ();
177         int status () const { return _status; }
178
179         virtual void set_session (ARDOUR::Session*);
180         std::vector<std::string> get_paths ();
181
182         void clear_selection ();
183
184         Gtk::FileChooserWidget chooser;
185
186         SoundFileBox preview;
187
188         Gtk::Entry found_entry;
189         Gtk::Button found_search_btn;
190         Gtk::TreeView found_list_view;
191
192         Gtk::Entry freesound_entry;
193         Gtk::ComboBoxText freesound_sort;
194
195         Gtk::Button freesound_search_btn;
196         Gtk::TreeView freesound_list_view;
197         Gtk::Notebook notebook;
198
199         void freesound_search();
200         void refresh_display(std::string ID, std::string file);
201         
202   protected:
203         bool resetting_ourselves;
204         int matches;
205         int _status;
206         bool _done;
207
208         Gtk::FileFilter audio_and_midi_filter;
209         Gtk::FileFilter audio_filter;
210         Gtk::FileFilter midi_filter;
211         Gtk::FileFilter custom_filter;
212         Gtk::FileFilter matchall_filter;
213         Gtk::HBox hpacker;
214         Gtk::VBox vpacker;
215
216         Gtk::Button ok_button;
217         Gtk::Button cancel_button;
218         Gtk::Button apply_button;
219
220         static std::string persistent_folder;
221
222         GainMeter* gm;
223         Gtk::VBox meter_packer;
224         void add_gain_meter ();
225         void remove_gain_meter ();
226         void meter ();
227         void start_metering ();
228         void stop_metering ();
229         sigc::connection metering_connection;
230
231         void update_preview ();
232
233         void found_list_view_selected ();
234         void found_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
235         void found_search_clicked ();
236
237         void freesound_list_view_selected ();
238         void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
239         void freesound_search_clicked ();
240         void freesound_more_clicked ();
241         void freesound_similar_clicked ();
242         int freesound_page;
243         
244         void chooser_file_activated ();
245         std::string freesound_get_audio_file(Gtk::TreeIter iter);
246
247         bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
248         bool on_midi_filter (const Gtk::FileFilter::Info& filter_info);
249         bool on_audio_and_midi_filter (const Gtk::FileFilter::Info& filter_info);
250
251         void set_action_sensitive (bool);
252
253         virtual bool reset_options () { return true; }
254
255   protected:
256         void on_show();
257         virtual void do_something(int action);
258 };
259
260 class SoundFileChooser : public SoundFileBrowser
261 {
262   public:
263         SoundFileChooser (std::string title, ARDOUR::Session* _s = 0);
264         virtual ~SoundFileChooser () {};
265
266         std::string get_filename ();
267
268   protected:
269         void on_hide();
270 };
271
272 class SoundFileOmega : public SoundFileBrowser
273 {
274
275   public:
276         SoundFileOmega (std::string title, ARDOUR::Session* _s, 
277                         uint32_t selected_audio_tracks, uint32_t selected_midi_tracks,
278                         bool persistent,
279                         Editing::ImportMode mode_hint = Editing::ImportAsTrack);
280
281         void reset (uint32_t selected_audio_tracks, uint32_t selected_midi_tracks);
282
283         Gtk::ComboBoxText action_combo;
284         Gtk::ComboBoxText where_combo;
285         Gtk::ComboBoxText channel_combo;
286         Gtk::ComboBoxText src_combo;
287         InstrumentSelector instrument_combo;
288
289         Gtk::CheckButton copy_files_btn;
290
291         void set_mode (Editing::ImportMode);
292         Editing::ImportMode get_mode() const;
293         Editing::ImportPosition get_position() const;
294         Editing::ImportDisposition get_channel_disposition() const;
295         ARDOUR::SrcQuality get_src_quality() const;
296
297   protected:
298         void on_hide();
299
300   private:
301         uint32_t selected_audio_track_cnt;
302         uint32_t selected_midi_track_cnt;
303
304         typedef std::map<std::string,Editing::ImportDisposition> DispositionMap;
305         DispositionMap disposition_map;
306
307         Gtk::HBox options;
308         Gtk::VBox block_two;
309         Gtk::VBox block_three;
310         Gtk::VBox block_four;
311
312         bool check_info (const std::vector<std::string>& paths,
313                          bool& same_size, bool& src_needed, bool& multichannel);
314
315         static bool check_link_status (const ARDOUR::Session*, const std::vector<std::string>& paths);
316
317         void file_selection_changed ();
318         bool reset_options ();
319         void reset_options_noret ();
320         bool bad_file_message ();
321         void src_combo_changed ();
322         void where_combo_changed ();
323
324         void do_something (int action);
325 };
326
327 #endif // __ardour_sfdb_ui_h__