merge 3.0 from 2.0-ongoing@3243
[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
40 #include <ardour/session.h>
41 #include <ardour/audiofilesource.h>
42
43 #include "ardour_dialog.h"
44 #include "editing.h"
45
46 namespace ARDOUR {
47         class Session;
48 };
49
50 class GainMeter;
51
52 class SoundFileBox : public Gtk::VBox
53 {
54   public:
55         SoundFileBox (bool persistent);
56         virtual ~SoundFileBox () {};
57         
58         void set_session (ARDOUR::Session* s);
59         bool setup_labels (const Glib::ustring& filename);
60
61         void audition();
62         bool audition_oneshot();
63         bool autoplay () const;
64
65   protected:
66         ARDOUR::Session* _session;
67         Glib::ustring 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<Glib::ustring> pathname;
113                 
114                 FoundTagColumns() { add(pathname); }
115         };
116         
117         FoundTagColumns found_list_columns;
118         Glib::RefPtr<Gtk::ListStore> found_list;
119
120         FoundTagColumns freesound_list_columns;
121         Glib::RefPtr<Gtk::ListStore> freesound_list;
122
123   public:
124         SoundFileBrowser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, bool persistent);
125         virtual ~SoundFileBrowser ();
126         
127         virtual void set_session (ARDOUR::Session*);
128         std::vector<Glib::ustring> get_paths ();
129         
130         void clear_selection ();
131
132         Gtk::FileChooserWidget chooser;
133
134         SoundFileBox preview;
135
136         Gtk::Entry found_entry;
137         Gtk::Button found_search_btn;
138         Gtk::TreeView found_list_view;
139
140         Gtk::Entry freesound_name_entry;
141         Gtk::Entry freesound_pass_entry;
142         Gtk::Entry freesound_entry;
143         Gtk::Button freesound_search_btn;
144         Gtk::TreeView freesound_list_view;
145
146         void freesound_search_thread();
147
148   protected:
149         bool resetting_ourselves;
150         
151         Gtk::FileFilter audio_filter;
152         Gtk::FileFilter midi_filter;
153         Gtk::FileFilter matchall_filter;
154         Gtk::HBox hpacker;
155
156         static Glib::ustring persistent_folder;
157
158         Gtk::Notebook notebook;
159
160         GainMeter* gm;
161         Gtk::VBox meter_packer;
162         void add_gain_meter ();
163         void remove_gain_meter ();
164         void meter ();
165         void start_metering ();
166         void stop_metering ();
167         sigc::connection metering_connection;
168
169         void update_preview ();
170
171         void found_list_view_selected ();
172         void found_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
173         void found_search_clicked ();
174
175         void freesound_list_view_selected ();
176         void freesound_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*);
177         void freesound_search_clicked ();
178         
179         void chooser_file_activated ();
180         
181         bool on_audio_filter (const Gtk::FileFilter::Info& filter_info);
182         bool on_midi_filter (const Gtk::FileFilter::Info& filter_info);
183
184         virtual bool reset_options() { return true; }
185
186   protected:
187         void on_show();
188
189 };
190
191 class SoundFileChooser : public SoundFileBrowser
192 {
193   public:
194         SoundFileChooser (Gtk::Window& parent, std::string title, ARDOUR::Session* _s = 0);
195         virtual ~SoundFileChooser () {};
196         
197         Glib::ustring get_filename ();
198
199   protected:
200         void on_hide();
201 };
202
203 class SoundFileOmega : public SoundFileBrowser
204 {
205
206   public:
207         SoundFileOmega (Gtk::Window& parent, std::string title, ARDOUR::Session* _s, int selected_tracks, bool persistent, 
208                         Editing::ImportMode mode_hint = Editing::ImportAsTrack);
209         
210         void reset (int selected_tracks);
211         
212         Gtk::ComboBoxText action_combo;
213         Gtk::ComboBoxText where_combo;
214         Gtk::ComboBoxText channel_combo;
215         Gtk::ComboBoxText src_combo;
216
217         Gtk::CheckButton copy_files_btn;
218
219         void set_mode (Editing::ImportMode);
220         Editing::ImportMode get_mode() const;
221         Editing::ImportPosition get_position() const;
222         Editing::ImportDisposition get_channel_disposition() const;
223         ARDOUR::SrcQuality get_src_quality() const;
224
225   protected:
226         void on_hide();
227
228   private:
229         uint32_t selected_track_cnt;
230
231         typedef std::map<Glib::ustring,Editing::ImportDisposition> DispositionMap;
232         DispositionMap disposition_map;
233
234         Gtk::HBox options;
235         Gtk::VBox block_two;
236         Gtk::VBox block_three;
237         Gtk::VBox block_four;
238
239         bool check_info (const std::vector<Glib::ustring>& paths, 
240                          bool& same_size, bool& src_needed, bool& multichannel);
241
242         static bool check_link_status (const ARDOUR::Session&, const std::vector<Glib::ustring>& paths);
243
244         void file_selection_changed ();
245         bool reset_options ();
246         void reset_options_noret ();
247         bool bad_file_message ();
248 };
249
250 #endif // __ardour_sfdb_ui_h__