45ee3e9b649ce0c81de17f3b859d2caee8fe2479
[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/textview.h>
40 #include <gtkmm/table.h>
41 #include <gtkmm/liststore.h>
42 #include <gtkmm/spinbutton.h>
43 #include <gtkmm/notebook.h>
44
45
46 #include "ardour/audiofilesource.h"
47 #include "ardour/session_handle.h"
48
49 #include "ardour_dialog.h"
50 #include "editing.h"
51 #include "audio_clock.h"
52
53 namespace ARDOUR {
54         class Session;
55 };
56
57 class GainMeter;
58
59 class SoundFileBox : public Gtk::VBox, public ARDOUR::SessionHandlePtr
60 {
61   public:
62         SoundFileBox (bool persistent);
63         virtual ~SoundFileBox () {};
64
65         void set_session (ARDOUR::Session* s);
66         bool setup_labels (const std::string& filename);
67
68         void audition();
69         bool audition_oneshot();
70         bool autoplay () const;
71
72   protected:
73         std::string path;
74
75         ARDOUR::SoundFileInfo sf_info;
76
77         Gtk::Table table;
78
79         Gtk::Label length;
80         Gtk::Label format;
81         Gtk::Label channels;
82         Gtk::Label samplerate;
83         Gtk::Label timecode;
84
85         Gtk::Label channels_value;
86         Gtk::Label samplerate_value;
87
88         Gtk::Label format_text;
89         AudioClock length_clock;
90         AudioClock timecode_clock;
91
92         Gtk::Frame border_frame;
93         Gtk::Label preview_label;
94
95         Gtk::TextView tags_entry;
96
97         Gtk::VBox main_box;
98         Gtk::VBox path_box;
99         Gtk::HBox bottom_box;
100
101         Gtk::Button play_btn;
102         Gtk::Button stop_btn;
103         Gtk::CheckButton autoplay_btn;
104         Gtk::Button apply_btn;
105
106         bool tags_entry_left (GdkEventFocus* event);
107         void tags_changed ();
108         void save_tags (const std::vector<std::string>&);
109         void stop_audition ();
110 };
111
112 class SoundFileBrowser : public ArdourDialog
113 {
114   private:
115         class FoundTagColumns : public Gtk::TreeModel::ColumnRecord
116         {
117           public:
118                 Gtk::TreeModelColumn<std::string> pathname;
119
120                 FoundTagColumns() { add(pathname); }
121         };
122
123         class FreesoundColumns : public Gtk::TreeModel::ColumnRecord
124         {
125           public:
126                 Gtk::TreeModelColumn<std::string> id;
127                 Gtk::TreeModelColumn<std::string> uri;
128                 Gtk::TreeModelColumn<std::string> filename;
129
130                 FreesoundColumns() { add(id); add(filename); add(uri); }
131         };
132
133         FoundTagColumns found_list_columns;
134         Glib::RefPtr<Gtk::ListStore> found_list;
135
136         FreesoundColumns freesound_list_columns;
137         Glib::RefPtr<Gtk::ListStore> freesound_list;
138
139         Gtk::Button freesound_stop_btn;
140
141   public:
142         SoundFileBrowser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, bool persistent);
143         virtual ~SoundFileBrowser ();
144
145         virtual void set_session (ARDOUR::Session*);
146         std::vector<std::string> get_paths ();
147
148         void clear_selection ();
149
150         Gtk::FileChooserWidget chooser;
151
152         SoundFileBox preview;
153
154         Gtk::Entry found_entry;
155         Gtk::Button found_search_btn;
156         Gtk::TreeView found_list_view;
157
158         Gtk::Entry freesound_entry;
159         Gtk::ComboBoxText freesound_sort;
160         Gtk::SpinButton freesound_page;
161         
162         Gtk::Button freesound_search_btn;
163         Gtk::TreeView freesound_list_view;
164         Gtk::ProgressBar progress_bar;
165
166         bool freesound_stop;
167
168         void freesound_search();
169
170   protected:
171         bool resetting_ourselves;
172
173         Gtk::FileFilter audio_filter;
174         Gtk::FileFilter midi_filter;
175         Gtk::FileFilter custom_filter;
176         Gtk::FileFilter matchall_filter;
177         Gtk::HBox hpacker;
178
179         static std::string persistent_folder;
180
181         Gtk::Notebook notebook;
182
183         GainMeter* gm;
184         Gtk::VBox meter_packer;
185         void add_gain_meter ();
186         void remove_gain_meter ();
187         void meter ();
188         void start_metering ();
189         void stop_metering ();
190         sigc::connection metering_connection;
191
192         void update_preview ();
193
194         void found_list_view_selected ();
195         void found_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
196         void found_search_clicked ();
197
198         void freesound_list_view_selected ();
199         void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
200         void freesound_search_clicked ();
201         void freesound_stop_clicked ();
202         
203         void chooser_file_activated ();
204
205         bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
206         bool on_midi_filter (const Gtk::FileFilter::Info& filter_info);
207
208         virtual bool reset_options() { return true; }
209
210   protected:
211         void on_show();
212
213 };
214
215 class SoundFileChooser : public SoundFileBrowser
216 {
217   public:
218         SoundFileChooser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s = 0);
219         virtual ~SoundFileChooser () {};
220
221         std::string get_filename ();
222
223   protected:
224         void on_hide();
225 };
226
227 class SoundFileOmega : public SoundFileBrowser
228 {
229
230   public:
231         SoundFileOmega (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, 
232                         uint32_t selected_audio_tracks, uint32_t selected_midi_tracks,
233                         bool persistent,
234                         Editing::ImportMode mode_hint = Editing::ImportAsTrack);
235
236         void reset (uint32_t selected_audio_tracks, uint32_t selected_midi_tracks);
237
238         Gtk::ComboBoxText action_combo;
239         Gtk::ComboBoxText where_combo;
240         Gtk::ComboBoxText channel_combo;
241         Gtk::ComboBoxText src_combo;
242
243         Gtk::CheckButton copy_files_btn;
244
245         void set_mode (Editing::ImportMode);
246         Editing::ImportMode get_mode() const;
247         Editing::ImportPosition get_position() const;
248         Editing::ImportDisposition get_channel_disposition() const;
249         ARDOUR::SrcQuality get_src_quality() const;
250
251   protected:
252         void on_hide();
253
254   private:
255         uint32_t selected_audio_track_cnt;
256         uint32_t selected_midi_track_cnt;
257
258         typedef std::map<std::string,Editing::ImportDisposition> DispositionMap;
259         DispositionMap disposition_map;
260
261         Gtk::HBox options;
262         Gtk::VBox block_two;
263         Gtk::VBox block_three;
264         Gtk::VBox block_four;
265
266         bool check_info (const std::vector<std::string>& paths,
267                          bool& same_size, bool& src_needed, bool& multichannel);
268
269         static bool check_link_status (const ARDOUR::Session*, const std::vector<std::string>& paths);
270
271         void file_selection_changed ();
272         bool reset_options ();
273         void reset_options_noret ();
274         bool bad_file_message ();
275 };
276
277 #endif // __ardour_sfdb_ui_h__