VKeybd: Pass on primary (Ctrl/Cmd) shortcuts
[ardour.git] / gtk2_ardour / sfdb_ui.h
1 /*
2  * Copyright (C) 2005-2007 Taybin Rutkin <taybin@taybin.com>
3  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2008-2014 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2012-2017 Robin Gareus <robin@gareus.org>
7  * Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
8  * Copyright (C) 2015-2017 Tim Mayberry <mojofunk@gmail.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __ardour_sfdb_ui_h__
26 #define __ardour_sfdb_ui_h__
27
28 #include <string>
29 #include <vector>
30 #include <map>
31
32 #include <sigc++/signal.h>
33
34 #include <gtkmm/stock.h>
35 #include <gtkmm/box.h>
36 #include <gtkmm/button.h>
37 #include <gtkmm/checkbutton.h>
38 #include <gtkmm/comboboxtext.h>
39 #include <gtkmm/dialog.h>
40 #include <gtkmm/entry.h>
41 #include <gtkmm/filechooserwidget.h>
42 #include <gtkmm/frame.h>
43 #include <gtkmm/label.h>
44 #include <gtkmm/scale.h>
45 #include <gtkmm/textview.h>
46 #include <gtkmm/table.h>
47 #include <gtkmm/liststore.h>
48 #include <gtkmm/spinbutton.h>
49 #include <gtkmm/notebook.h>
50
51
52 #include "ardour/audiofilesource.h"
53 #include "ardour/session_handle.h"
54
55 #include "ardour_window.h"
56 #include "editing.h"
57 #include "audio_clock.h"
58 #include "instrument_selector.h"
59
60 namespace ARDOUR {
61         class Session;
62 };
63
64 class GainMeter;
65 class Mootcher;
66
67 class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr, public PBD::ScopedConnectionList
68 {
69 public:
70         SoundFileBox (bool persistent);
71         virtual ~SoundFileBox () {};
72
73         void set_session (ARDOUR::Session* s);
74         bool setup_labels (const std::string& filename);
75
76         void audition();
77         bool audition_oneshot();
78         bool autoplay () const;
79         void set_src_quality(ARDOUR::SrcQuality q) { _src_quality = q; }
80         void set_import_position(Editing::ImportPosition p) { _import_position = p; }
81
82 protected:
83         std::string path;
84
85         ARDOUR::SoundFileInfo sf_info;
86
87         Gtk::Table table;
88
89         Gtk::Label length;
90         Gtk::Label format;
91         Gtk::Label channels;
92         Gtk::Label samplerate;
93         Gtk::Label timecode;
94         Gtk::Label tempomap;
95
96         Gtk::Label channels_value;
97         Gtk::Label samplerate_value;
98         Gtk::Label tempomap_value;
99
100         Gtk::Label format_text;
101         AudioClock length_clock;
102         AudioClock timecode_clock;
103
104         Gtk::Frame border_frame;
105         Gtk::Label preview_label;
106
107         Gtk::TextView tags_entry;
108
109         Gtk::VBox main_box;
110         Gtk::VBox path_box;
111         Gtk::HBox bottom_box;
112
113         Gtk::Button play_btn;
114         Gtk::Button stop_btn;
115         Gtk::CheckButton autoplay_btn;
116         Gtk::Button apply_btn;
117         Gtk::HScale seek_slider;
118
119         PBD::ScopedConnectionList auditioner_connections;
120         void audition_active(bool);
121         void audition_progress(ARDOUR::samplecnt_t, ARDOUR::samplecnt_t);
122
123         void update_autoplay ();
124         void autoplay_toggled ();
125
126         bool tags_entry_left (GdkEventFocus* event);
127         void tags_changed ();
128         void save_tags (const std::vector<std::string>&);
129         void stop_audition ();
130         bool seek_button_press(GdkEventButton*);
131         bool seek_button_release(GdkEventButton*);
132         bool _seeking;
133         ARDOUR::SrcQuality _src_quality;
134         Editing::ImportPosition _import_position;
135 };
136
137 class SoundFileBrowser : public ArdourWindow
138 {
139 private:
140         class FoundTagColumns : public Gtk::TreeModel::ColumnRecord
141         {
142         public:
143                 Gtk::TreeModelColumn<std::string> pathname;
144
145                 FoundTagColumns() { add(pathname); }
146         };
147
148         class FreesoundColumns : public Gtk::TreeModel::ColumnRecord
149         {
150         public:
151                 Gtk::TreeModelColumn<std::string> id;
152                 Gtk::TreeModelColumn<std::string> uri;
153                 Gtk::TreeModelColumn<std::string> filename;
154                 Gtk::TreeModelColumn<std::string> duration;
155                 Gtk::TreeModelColumn<std::string> filesize;
156                 Gtk::TreeModelColumn<std::string> smplrate;
157                 Gtk::TreeModelColumn<std::string> license;
158                 Gtk::TreeModelColumn<bool>        started;
159
160                 FreesoundColumns() {
161                         add(id);
162                         add(filename);
163                         add(uri);
164                         add(duration);
165                         add(filesize);
166                         add(smplrate);
167                         add(license);
168                         add(started);
169                 }
170         };
171
172         FoundTagColumns found_list_columns;
173         Glib::RefPtr<Gtk::ListStore> found_list;
174
175         FreesoundColumns freesound_list_columns;
176         Glib::RefPtr<Gtk::ListStore> freesound_list;
177
178         Gtk::Button freesound_more_btn;
179         Gtk::Button freesound_similar_btn;
180
181         void handle_freesound_results(std::string theString);
182
183 public:
184         SoundFileBrowser (std::string title, ARDOUR::Session* _s, bool persistent);
185         virtual ~SoundFileBrowser ();
186
187         int run ();
188         int status () const { return _status; }
189
190         virtual void set_session (ARDOUR::Session*);
191         std::vector<std::string> get_paths ();
192
193         void clear_selection ();
194
195         Gtk::FileChooserWidget chooser;
196
197         SoundFileBox preview;
198
199         Gtk::Entry found_entry;
200         Gtk::Button found_search_btn;
201         Gtk::TreeView found_list_view;
202
203         Gtk::Entry freesound_entry;
204         Gtk::ComboBoxText freesound_sort;
205
206         Gtk::Button freesound_search_btn;
207         Gtk::TreeView freesound_list_view;
208         Gtk::Notebook notebook;
209
210         void freesound_search();
211         void refresh_display(std::string ID, std::string file);
212
213 protected:
214         bool resetting_ourselves;
215         int matches;
216         int _status;
217         bool _done;
218
219         Gtk::FileFilter audio_and_midi_filter;
220         Gtk::FileFilter audio_filter;
221         Gtk::FileFilter midi_filter;
222         Gtk::FileFilter custom_filter;
223         Gtk::FileFilter matchall_filter;
224         Gtk::HBox hpacker;
225         Gtk::VBox vpacker;
226
227         Gtk::Button import_button;
228
229         static std::string persistent_folder;
230
231         GainMeter* gm;
232         Gtk::VBox meter_packer;
233         void add_gain_meter ();
234         void remove_gain_meter ();
235         void meter ();
236         void start_metering ();
237         void stop_metering ();
238         sigc::connection metering_connection;
239
240         void update_preview ();
241
242         void found_list_view_selected ();
243         void found_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
244         void found_search_clicked ();
245
246         void freesound_list_view_selected ();
247         void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
248         void freesound_search_clicked ();
249         void freesound_more_clicked ();
250         void freesound_similar_clicked ();
251         int freesound_page;
252
253         void chooser_file_activated ();
254         std::string freesound_get_audio_file(Gtk::TreeIter iter);
255
256         bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
257         bool on_midi_filter (const Gtk::FileFilter::Info& filter_info);
258         bool on_audio_and_midi_filter (const Gtk::FileFilter::Info& filter_info);
259
260         void set_action_sensitive (bool);
261         bool get_action_sensitive () const;
262
263         virtual bool reset_options () { return true; }
264
265         void on_show();
266         bool on_key_press_event (GdkEventKey*);
267         virtual void do_something(int action);
268 };
269
270 class SoundFileChooser : public SoundFileBrowser
271 {
272 public:
273         SoundFileChooser (std::string title, ARDOUR::Session* _s = 0);
274         virtual ~SoundFileChooser () {};
275
276         std::string get_filename ();
277
278 protected:
279         void on_hide();
280 };
281
282 class SoundFileOmega : public SoundFileBrowser
283 {
284 public:
285         SoundFileOmega (std::string title,
286                         ARDOUR::Session* _s,
287                         uint32_t selected_audio_tracks,
288                         uint32_t selected_midi_tracks,
289                         bool persistent,
290                         Editing::ImportMode mode_hint = Editing::ImportAsTrack);
291
292         void reset (uint32_t selected_audio_tracks, uint32_t selected_midi_tracks);
293
294         Gtk::ComboBoxText action_combo;
295         Gtk::ComboBoxText where_combo;
296         Gtk::ComboBoxText channel_combo;
297         Gtk::ComboBoxText src_combo;
298         Gtk::ComboBoxText midi_track_name_combo;
299         InstrumentSelector instrument_combo;
300
301         Gtk::CheckButton copy_files_btn;
302         Gtk::CheckButton smf_tempo_btn;
303
304         void set_mode (Editing::ImportMode);
305         Editing::ImportMode get_mode() const;
306         ARDOUR::MidiTrackNameSource get_midi_track_name_source () const;
307         bool get_use_smf_tempo_map () const;
308         Editing::ImportPosition get_position() const;
309         Editing::ImportDisposition get_channel_disposition() const;
310         ARDOUR::SrcQuality get_src_quality() const;
311
312 protected:
313         void on_hide();
314
315 private:
316         uint32_t selected_audio_track_cnt;
317         uint32_t selected_midi_track_cnt;
318
319         typedef std::map<std::string,Editing::ImportDisposition> DispositionMap;
320         DispositionMap disposition_map;
321
322         Gtk::Table options;
323         Gtk::VBox block_two;
324         Gtk::VBox block_three;
325         Gtk::VBox block_four;
326
327         bool check_info (const std::vector<std::string>& paths,
328                          bool& same_size, bool& src_needed, bool& multichannel, bool& must_copy);
329
330         static bool check_link_status (const ARDOUR::Session*, const std::vector<std::string>& paths);
331
332         void instrument_combo_changed ();
333
334         void file_selection_changed ();
335         bool reset_options ();
336         void reset_options_noret ();
337         bool bad_file_message ();
338         void src_combo_changed ();
339         void where_combo_changed ();
340
341         void do_something (int action);
342
343         bool _import_active;
344         bool _reset_post_import;
345 };
346
347 #endif // __ardour_sfdb_ui_h__