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