/[svn]/gigedit/trunk/src/gigedit/mainwindow.h
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/mainwindow.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2325 - (show annotations) (download) (as text)
Sun Mar 4 09:01:40 2012 UTC (12 years ago) by persson
File MIME type: text/x-c++hdr
File size: 12996 byte(s)
* added support for new glibmm threads API

1 /* -*- c++ -*-
2 * Copyright (C) 2006 - 2008 Andreas Persson
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with program; see the file COPYING. If not, write to the Free
16 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #ifndef GIGEDIT_MAINWINDOW_H
21 #define GIGEDIT_MAINWINDOW_H
22
23 #include <gig.h>
24
25 #include <gtkmm/actiongroup.h>
26 #include <gtkmm/buttonbox.h>
27 #include <gtkmm/dialog.h>
28 #include <gtkmm/liststore.h>
29 #include <gtkmm/paned.h>
30 #include <gtkmm/progressbar.h>
31 #include <gtkmm/scrolledwindow.h>
32 #include <gtkmm/treestore.h>
33 #include <gtkmm/uimanager.h>
34 #include <gtkmm/window.h>
35 #include <gtkmm/statusbar.h>
36 #include <gtkmm/image.h>
37
38 #include <sstream>
39
40 #include "regionchooser.h"
41 #include "dimregionchooser.h"
42 #include "dimregionedit.h"
43 #ifndef OLD_THREADS
44 #include <glibmm/threads.h>
45 #endif
46
47 class MainWindow;
48
49 class Table : public Gtk::Table
50 {
51 public:
52 Table(int x, int y);
53 void add(BoolEntry& boolentry);
54 void add(BoolEntryPlus6& boolentry);
55 void add(LabelWidget& labelwidget);
56 private:
57 int rowno;
58 };
59
60 class PropDialog : public Gtk::Window {
61 public:
62 PropDialog();
63 void set_info(DLS::Info* info);
64 sigc::signal<void>& signal_info_changed();
65 protected:
66 sigc::signal<void> info_changed;
67 StringEntry eName;
68 StringEntry eCreationDate;
69 StringEntryMultiLine eComments;
70 StringEntry eProduct;
71 StringEntry eCopyright;
72 StringEntry eArtists;
73 StringEntry eGenre;
74 StringEntry eKeywords;
75 StringEntry eEngineer;
76 StringEntry eTechnician;
77 StringEntry eSoftware;
78 StringEntry eMedium;
79 StringEntry eSource;
80 StringEntry eSourceForm;
81 StringEntry eCommissioned;
82 StringEntry eSubject;
83 Gtk::VBox vbox;
84 Gtk::HButtonBox buttonBox;
85 Gtk::Button quitButton;
86 Table table;
87 int update_model;
88 DLS::Info* info;
89
90 template<typename T>
91 void set_member(T value, T DLS::Info::* member) {
92 if (update_model == 0) {
93 info->*member = value;
94 info_changed();
95 }
96 }
97
98 template<typename C, typename T>
99 void connect(C& widget, T DLS::Info::* member) {
100 widget.signal_value_changed().connect(
101 sigc::compose(
102 sigc::bind(sigc::mem_fun(*this, &PropDialog::set_member<T>), member),
103 sigc::mem_fun(widget, &C::get_value)));
104 }
105 };
106
107 class InstrumentProps : public Gtk::Window {
108 public:
109 InstrumentProps();
110 void set_instrument(gig::Instrument* instrument);
111 sigc::signal<void>& signal_instrument_changed();
112 protected:
113 gig::Instrument* instrument;
114 int update_model;
115
116 template<typename T>
117 void set_value(T value, sigc::slot<void, InstrumentProps*, T> setter) {
118 if (update_model == 0) {
119 setter(this, value);
120 instrument_changed();
121 }
122 }
123
124 template<typename C, typename T>
125 void connect(C& widget, T gig::Instrument::* member) {
126 widget.signal_value_changed().connect(
127 sigc::compose(
128 sigc::bind(sigc::mem_fun(*this, &InstrumentProps::set_value<T>),
129 sigc::bind(sigc::mem_fun(&InstrumentProps::set_member<T>), member)),
130 sigc::mem_fun(widget, &C::get_value)));
131 }
132
133 template<typename C, typename T>
134 void connect(C& widget, void (InstrumentProps::*setter)(T)) {
135 widget.signal_value_changed().connect(
136 sigc::compose(
137 sigc::bind(sigc::mem_fun(*this, &InstrumentProps::set_value<T>),
138 sigc::mem_fun(setter)),
139 sigc::mem_fun(widget, &C::get_value)));
140 }
141
142 template<typename T>
143 void set_member(T value, T gig::Instrument::* member) {
144 instrument->*member = value;
145 }
146
147 void set_IsDrum(bool value);
148 void set_MIDIBank(uint16_t value);
149 void set_MIDIProgram(uint32_t value);
150 void set_DimensionKeyRange_low(uint8_t value);
151 void set_DimensionKeyRange_high(uint8_t value);
152
153 Gtk::VBox vbox;
154 Gtk::HButtonBox buttonBox;
155 Gtk::Button quitButton;
156 Table table;
157 StringEntry eName;
158 BoolEntry eIsDrum;
159 NumEntryTemp<uint16_t> eMIDIBank;
160 NumEntryTemp<uint32_t> eMIDIProgram;
161 NumEntryGain eAttenuation;
162 BoolEntryPlus6 eGainPlus6;
163 NumEntryTemp<uint16_t> eEffectSend;
164 NumEntryTemp<int16_t> eFineTune;
165 NumEntryTemp<uint16_t> ePitchbendRange;
166 BoolEntry ePianoReleaseMode;
167 NoteEntry eDimensionKeyRangeLow;
168 NoteEntry eDimensionKeyRangeHigh;
169 sigc::signal<void> instrument_changed;
170 };
171
172 class LoadDialog : public Gtk::Dialog {
173 public:
174 LoadDialog(const Glib::ustring& title, Gtk::Window& parent);
175 void set_fraction(float fraction) { progressBar.set_fraction(fraction); }
176 protected:
177 Gtk::ProgressBar progressBar;
178 };
179
180 class Loader : public sigc::trackable {
181 public:
182 Loader(const char* filename);
183 void launch();
184 Glib::Dispatcher& signal_progress();
185 Glib::Dispatcher& signal_finished();
186 void progress_callback(float fraction);
187 float get_progress();
188 const char* filename;
189 gig::File* gig;
190
191 private:
192 Glib::Threads::Thread* thread;
193 void thread_function();
194 Glib::Dispatcher finished_dispatcher;
195 Glib::Dispatcher progress_dispatcher;
196 Glib::Threads::Mutex progressMutex;
197 float progress;
198 };
199
200 class MainWindow : public Gtk::Window {
201 public:
202 MainWindow();
203 virtual ~MainWindow();
204 void load_file(const char* name);
205 void load_instrument(gig::Instrument* instr);
206 void file_changed();
207 sigc::signal<void, gig::File*>& signal_file_structure_to_be_changed();
208 sigc::signal<void, gig::File*>& signal_file_structure_changed();
209 sigc::signal<void, std::list<gig::Sample*> >& signal_samples_to_be_removed();
210 sigc::signal<void>& signal_samples_removed();
211 sigc::signal<void, gig::Region*>& signal_region_to_be_changed();
212 sigc::signal<void, gig::Region*>& signal_region_changed();
213 sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_to_be_changed();
214 sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_changed();
215 sigc::signal<void, gig::Sample*>& signal_sample_changed();
216 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& signal_sample_ref_changed();
217
218 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_note_on();
219 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_note_off();
220
221 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit();
222 sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released();
223
224 protected:
225 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
226 Glib::RefPtr<Gtk::UIManager> uiManager;
227
228 Gtk::Statusbar m_StatusBar;
229 Gtk::Label m_AttachedStateLabel;
230 Gtk::Image m_AttachedStateImage;
231
232 RegionChooser m_RegionChooser;
233 DimRegionChooser m_DimRegionChooser;
234
235 PropDialog propDialog;
236 InstrumentProps instrumentProps;
237
238 sigc::signal<void, gig::File*> file_structure_to_be_changed_signal;
239 sigc::signal<void, gig::File*> file_structure_changed_signal;
240 sigc::signal<void, std::list<gig::Sample*> > samples_to_be_removed_signal;
241 sigc::signal<void> samples_removed_signal;
242 sigc::signal<void, gig::Region*> region_to_be_changed_signal;
243 sigc::signal<void, gig::Region*> region_changed_signal;
244 sigc::signal<void, gig::DimensionRegion*> dimreg_to_be_changed_signal;
245 sigc::signal<void, gig::DimensionRegion*> dimreg_changed_signal;
246 sigc::signal<void, gig::Sample*> sample_changed_signal;
247 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/> sample_ref_changed_signal;
248
249 sigc::signal<void, int/*key*/, int/*velocity*/> note_on_signal;
250 sigc::signal<void, int/*key*/, int/*velocity*/> note_off_signal;
251
252 void on_instrument_selection_change(int index);
253 void on_sel_change();
254 void region_changed();
255 void dimreg_changed();
256 void on_loader_progress();
257 void on_loader_finished();
258 void dimreg_all_dimregs_toggled();
259 gig::Instrument* get_instrument();
260 void add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs);
261 void update_dimregs();
262
263 class ModelColumns : public Gtk::TreeModel::ColumnRecord {
264 public:
265 ModelColumns() {
266 add(m_col_name);
267 add(m_col_instr);
268 }
269
270 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
271 Gtk::TreeModelColumn<gig::Instrument*> m_col_instr;
272 } m_Columns;
273
274 Gtk::VBox m_VBox;
275 Gtk::HPaned m_HPaned;
276
277 Gtk::ScrolledWindow m_ScrolledWindow;
278
279 Gtk::TreeView m_TreeView;
280 Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
281
282 class SamplesModel : public Gtk::TreeModel::ColumnRecord {
283 public:
284 SamplesModel() {
285 add(m_col_name);
286 add(m_col_sample);
287 add(m_col_group);
288 }
289
290 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
291 Gtk::TreeModelColumn<gig::Sample*> m_col_sample;
292 Gtk::TreeModelColumn<gig::Group*> m_col_group;
293 } m_SamplesModel;
294
295 class SamplesTreeStore : public Gtk::TreeStore {
296 public:
297 static Glib::RefPtr<SamplesTreeStore> create(const SamplesModel& columns) {
298 return Glib::RefPtr<SamplesTreeStore>( new SamplesTreeStore(columns) );
299 }
300 protected:
301 SamplesTreeStore(const SamplesModel& columns) : Gtk::TreeStore(columns) {}
302 };
303
304 Gtk::ScrolledWindow m_ScrolledWindowSamples;
305 Gtk::TreeView m_TreeViewSamples;
306 Glib::RefPtr<SamplesTreeStore> m_refSamplesTreeModel;
307
308 Gtk::VBox dimreg_vbox;
309 Gtk::HBox dimreg_hbox;
310 Gtk::Label dimreg_label;
311 Gtk::CheckButton dimreg_all_regions;
312 Gtk::CheckButton dimreg_all_dimregs;
313 Gtk::CheckButton dimreg_stereo;
314 DimRegionEdit dimreg_edit;
315
316 Gtk::Notebook m_Notebook;
317 Gtk::Notebook m_TreeViewNotebook;
318
319 struct SampleImportItem {
320 gig::Sample* gig_sample; // pointer to the gig::Sample to
321 // which the sample data should be
322 // imported to
323 Glib::ustring sample_path; // file name of the sample to be
324 // imported
325 };
326 std::list<SampleImportItem> m_SampleImportQueue;
327
328
329 void on_action_file_new();
330 void on_action_file_open();
331 void on_action_file_save();
332 void on_action_file_save_as();
333 void on_action_file_properties();
334 void on_action_quit();
335 void show_instr_props();
336 void on_action_view_status_bar();
337 void on_action_help_about();
338
339 // sample right-click popup actions
340 void on_sample_treeview_button_release(GdkEventButton* button);
341 void on_action_sample_properties();
342 void on_action_add_group();
343 void on_action_add_sample();
344 void on_action_replace_all_samples_in_all_groups();
345 void on_action_remove_sample();
346
347 void on_action_add_instrument();
348 void on_action_remove_instrument();
349
350 LoadDialog* load_dialog;
351 Loader* loader;
352 void load_gig(gig::File* gig, const char* filename, bool isSharedInstrument = false);
353
354 gig::File* file;
355 bool file_is_shared;
356 bool file_has_name;
357 bool file_is_changed;
358 std::string filename;
359 std::string current_gig_dir;
360 std::string current_sample_dir;
361
362 void set_file_is_shared(bool);
363
364 bool file_save();
365 bool file_save_as();
366 bool check_if_savable();
367
368 void on_button_release(GdkEventButton* button);
369 void on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context);
370 void on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
371 Gtk::SelectionData& selection_data, guint, guint);
372 void on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context,
373 int, int,
374 const Gtk::SelectionData& selection_data,
375 guint, guint time);
376
377 void sample_name_changed(const Gtk::TreeModel::Path& path,
378 const Gtk::TreeModel::iterator& iter);
379 void instrument_name_changed(const Gtk::TreeModel::Path& path,
380 const Gtk::TreeModel::iterator& iter);
381
382 void __import_queued_samples();
383 void __clear();
384
385 bool close_confirmation_dialog();
386 bool leaving_shared_mode_dialog();
387
388 Gtk::Menu* popup_menu;
389
390 bool on_delete_event(GdkEventAny* event);
391
392 bool first_call_to_drag_data_get;
393 };
394
395 #endif

  ViewVC Help
Powered by ViewVC