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