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