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