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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1097 - (show annotations) (download) (as text)
Wed Mar 14 23:19:26 2007 UTC (17 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 17752 byte(s)
* implemented renaming of samples, groups and instruments

1 /* -*- c++ -*-
2 * Copyright (C) 2006, 2007 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/alignment.h>
27 #include <gtkmm/box.h>
28 #include <gtkmm/buttonbox.h>
29 #include <gtkmm/combobox.h>
30 #include <gtkmm/comboboxtext.h>
31 #include <gtkmm/dialog.h>
32 #include <gtkmm/entry.h>
33 #include <gtkmm/label.h>
34 #include <gtkmm/liststore.h>
35 #include <gtkmm/notebook.h>
36 #include <gtkmm/paned.h>
37 #include <gtkmm/progressbar.h>
38 #include <gtkmm/scale.h>
39 #include <gtkmm/scrolledwindow.h>
40 #include <gtkmm/spinbutton.h>
41 #include <gtkmm/table.h>
42 #include <gtkmm/treestore.h>
43 #include <gtkmm/treeview.h>
44 #include <gtkmm/uimanager.h>
45 #include <gtkmm/window.h>
46 #include <gtkmm/menuitem.h>
47 #include <gtkmm/treemodel.h>
48
49 #include <sstream>
50
51 #include "regionchooser.h"
52 #include "dimregionchooser.h"
53
54 extern bool update_gui;
55
56 class MainWindow;
57
58 class PropDialog : public Gtk::Window {
59 public:
60 PropDialog();
61 void set_info(DLS::Info* info);
62 protected:
63 Gtk::Table table;
64 Gtk::Label label[16];
65 Gtk::Entry entry[16];
66 };
67
68 class InstrumentProps : public Gtk::Window {
69 public:
70 InstrumentProps();
71 void set_instrument(gig::Instrument* instrument);
72 protected:
73 Gtk::VBox vbox;
74 Gtk::HButtonBox buttonBox;
75 Gtk::Button quitButton;
76 Gtk::Table table;
77 Gtk::Label label[10];
78 Gtk::Entry entry[8];
79 Gtk::CheckButton check[2];
80 };
81
82 class LoadDialog : public Gtk::Dialog {
83 public:
84 LoadDialog();
85 void set_fraction(float fraction) { progressBar.set_fraction(fraction); }
86 protected:
87 Gtk::ProgressBar progressBar;
88 };
89
90 class Loader : public sigc::trackable {
91 public:
92 Loader(const char* filename);
93 void launch();
94 Glib::Dispatcher& signal_progress();
95 Glib::Dispatcher& signal_finished();
96 void progress_callback(float fraction);
97 float get_progress();
98 const char* filename;
99 gig::File* gig;
100
101 private:
102 Glib::Thread* thread;
103 void thread_function();
104 Glib::Dispatcher finished_dispatcher;
105 Glib::Dispatcher progress_dispatcher;
106 Glib::Mutex progressMutex;
107 float progress;
108 };
109
110 class LabelWidget {
111 public:
112 Gtk::Label label;
113 Gtk::Widget& widget;
114
115 LabelWidget(char* labelText, Gtk::Widget& widget);
116 void set_sensitive(bool sensitive = true);
117 };
118
119
120 template<typename T2>
121 class NumEntry : public LabelWidget {
122 protected:
123 Gtk::Adjustment adjust;
124 Gtk::HScale scale;
125 Gtk::SpinButton spinbutton;
126 Gtk::HBox box;
127 T2* dimreg;
128 public:
129 NumEntry(char* labelText, double lower = 0, double upper = 127,
130 int decimals = 0);
131 void set_value(double value) {
132 spinbutton.set_value(value);
133 }
134 Glib::SignalProxy0<void> signal_value_changed() {
135 return spinbutton.signal_value_changed();
136 }
137 double get_value() const {
138 return spinbutton.get_value();
139 }
140 };
141
142 template<typename T2>
143 NumEntry<T2>::NumEntry(char* labelText, double lower, double upper,
144 int decimals) :
145 adjust(lower, lower, upper, 1, 10),
146 scale(adjust),
147 spinbutton(adjust),
148 LabelWidget(labelText, box)
149 {
150 spinbutton.set_digits(decimals);
151 scale.set_draw_value(false);
152 box.pack_start(spinbutton, Gtk::PACK_SHRINK);
153 box.add(scale);
154 }
155
156 class NumEntryGain : public NumEntry<gig::DimensionRegion> {
157 private:
158 void value_changed();
159 public:
160 NumEntryGain(char* labelText,
161 double lower, double upper, int decimals);
162 void set_dimreg(gig::DimensionRegion* dimreg);
163 };
164
165 template<typename T>
166 class NumEntryX : public NumEntry<gig::DimensionRegion> {
167 private:
168 T& (*access)(gig::DimensionRegion*);
169 void value_changed();
170 public:
171 NumEntryX(char* labelText, T& (*access)(gig::DimensionRegion*),
172 double lower = 0, double upper = 127, int decimals = 0);
173 void set_dimreg(gig::DimensionRegion* dimreg);
174 };
175
176 template<typename T>
177 NumEntryX<T>::NumEntryX(char* labelText, T& (*access)(gig::DimensionRegion*),
178 double lower, double upper, int decimals) :
179 NumEntry<gig::DimensionRegion>(labelText, lower, upper, decimals),
180 access(access)
181 {
182 spinbutton.signal_value_changed().connect(
183 sigc::mem_fun(*this, &NumEntryX::value_changed));
184 }
185
186 template<typename T>
187 void NumEntryX<T>::value_changed()
188 {
189 if (dimreg && update_gui) {
190 access(dimreg) = T(spinbutton.get_value());
191 }
192 }
193
194 template<typename T>
195 void NumEntryX<T>::set_dimreg(gig::DimensionRegion* dimreg)
196 {
197 this->dimreg = 0;
198 set_value(access(dimreg));
199 this->dimreg = dimreg;
200 }
201
202
203 class NoteEntry : public NumEntryX<uint8_t> {
204 public:
205 NoteEntry(char* labelText, uint8_t& (*access)(gig::DimensionRegion*));
206 private:
207 int on_input(double* new_value);
208 bool on_output();
209 };
210
211
212 template<typename T, typename T2 = gig::DimensionRegion>
213 class NumEntryTemp : public NumEntry<T2> {
214 using NumEntry<T2>::spinbutton;
215 using NumEntry<T2>::dimreg;
216 private:
217 T T2::* param;
218 void value_changed();
219 public:
220 NumEntryTemp(char* labelText, T T2::* param,
221 double lower = 0, double upper = 127, int decimals = 0);
222 void set_dimreg(gig::DimensionRegion* dimreg);
223 };
224
225 template<typename T, typename T2>
226 NumEntryTemp<T, T2>::NumEntryTemp(char* labelText, T T2::* param,
227 double lower, double upper, int decimals) :
228 NumEntry<T2>(labelText, lower, upper, decimals),
229 param(param)
230 {
231 spinbutton.signal_value_changed().connect(
232 sigc::mem_fun(*this, &NumEntryTemp<T, T2>::value_changed));
233 }
234
235 template<typename T, typename T2>
236 void NumEntryTemp<T, T2>::value_changed()
237 {
238 if (dimreg && update_gui) {
239 dimreg->*param = T(spinbutton.get_value());
240 }
241 }
242
243 template<typename T, typename T2>
244 void NumEntryTemp<T, T2>::set_dimreg(gig::DimensionRegion* dimreg)
245 {
246 this->dimreg = 0;
247 set_value(dimreg->*param);
248 this->dimreg = dimreg;
249 }
250
251
252
253 class NumEntryPermille : public NumEntry<gig::DimensionRegion> {
254 private:
255 uint16_t gig::DimensionRegion::* param;
256 void value_changed();
257 public:
258 NumEntryPermille(char* labelText, uint16_t gig::DimensionRegion::* param,
259 double lower = 0, double upper = 127, int decimals = 0);
260 void set_dimreg(gig::DimensionRegion* dimreg);
261 };
262
263
264 template<typename T>
265 class ChoiceEntry : public LabelWidget {
266 private:
267 Gtk::ComboBoxText combobox;
268 Gtk::Alignment align;
269 T gig::DimensionRegion::* param;
270 gig::DimensionRegion* dimreg;
271 void value_changed();
272 const T* values;
273 public:
274 ChoiceEntry(char* labelText,
275 T gig::DimensionRegion::* param);
276 void set_choices(char** texts, const T* values);
277 void set_dimreg(gig::DimensionRegion* dimreg);
278 int get_active_row_number() { return combobox.get_active_row_number(); }
279 Glib::SignalProxy0<void> signal_changed() {
280 return combobox.signal_changed();
281 }
282 };
283
284 template<typename T>
285 ChoiceEntry<T>::ChoiceEntry(char* labelText,
286 T gig::DimensionRegion::* param) :
287 align(0, 0, 0, 0),
288 LabelWidget(labelText, align),
289 param(param)
290 {
291 combobox.signal_changed().connect(
292 sigc::mem_fun(*this, &ChoiceEntry::value_changed));
293 align.add(combobox);
294 }
295
296 template<typename T>
297 void ChoiceEntry<T>::set_choices(char** texts, const T* values)
298 {
299 for (int i = 0 ; texts[i] ; i++) {
300 combobox.append_text(texts[i]);
301 }
302 this->values = values;
303 }
304
305 template<typename T>
306 void ChoiceEntry<T>::value_changed()
307 {
308 if (dimreg && update_gui) {
309 int rowno = combobox.get_active_row_number();
310 if (rowno != -1) dimreg->*param = values[rowno];
311 }
312 }
313
314 template<typename T>
315 void ChoiceEntry<T>::set_dimreg(gig::DimensionRegion* dimreg)
316 {
317 this->dimreg = 0;
318 T value = dimreg->*param;
319 int row = 0;
320 int nb_rows = combobox.get_model()->children().size();
321 for (; row < nb_rows ; row++) {
322 if (value == values[row]) break;
323 }
324 combobox.set_active(row == nb_rows ? -1 : row);
325 this->dimreg = dimreg;
326 }
327
328
329 class ChoiceEntryLeverageCtrl : public LabelWidget {
330 private:
331 Gtk::ComboBoxText combobox;
332 Gtk::Alignment align;
333 gig::leverage_ctrl_t gig::DimensionRegion::* param;
334 gig::DimensionRegion* dimreg;
335 void value_changed();
336 public:
337 ChoiceEntryLeverageCtrl(char* labelText,
338 gig::leverage_ctrl_t gig::DimensionRegion::* param);
339 void set_dimreg(gig::DimensionRegion* dimreg);
340 int get_active_row_number() { return combobox.get_active_row_number(); }
341 Glib::SignalProxy0<void> signal_changed() {
342 return combobox.signal_changed();
343 }
344 };
345
346
347
348 class BoolEntry : public LabelWidget {
349 private:
350 Gtk::CheckButton checkbutton;
351 bool gig::DimensionRegion::* param;
352 gig::DimensionRegion* dimreg;
353 void value_changed();
354 public:
355 BoolEntry(char* labelText, bool gig::DimensionRegion::* param);
356 void set_dimreg(gig::DimensionRegion* dimreg);
357 bool get_active() { return checkbutton.get_active(); }
358 Glib::SignalProxy0<void> signal_toggled() {
359 return checkbutton.signal_toggled();
360 }
361 };
362
363 class MainWindow : public Gtk::Window {
364 public:
365 MainWindow();
366 virtual ~MainWindow();
367 void getInfo(const char* filename);
368
369 protected:
370 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
371 Glib::RefPtr<Gtk::UIManager> uiManager;
372
373 int rowno;
374 int pageno;
375 int firstRowInBlock;
376
377 NumEntryPermille eEG1PreAttack;
378 NumEntryTemp<double> eEG1Attack;
379 NumEntryTemp<double> eEG1Decay1;
380 NumEntryTemp<double> eEG1Decay2;
381 BoolEntry eEG1InfiniteSustain;
382 NumEntryPermille eEG1Sustain;
383 NumEntryTemp<double> eEG1Release;
384 BoolEntry eEG1Hold;
385 ChoiceEntryLeverageCtrl eEG1Controller;
386 BoolEntry eEG1ControllerInvert;
387 NumEntryTemp<uint8_t> eEG1ControllerAttackInfluence;
388 NumEntryTemp<uint8_t> eEG1ControllerDecayInfluence;
389 NumEntryTemp<uint8_t> eEG1ControllerReleaseInfluence;
390 NumEntryTemp<double> eLFO1Frequency;
391 NumEntryTemp<uint16_t> eLFO1InternalDepth;
392 NumEntryTemp<uint16_t> eLFO1ControlDepth;
393 ChoiceEntry<gig::lfo1_ctrl_t> eLFO1Controller;
394 BoolEntry eLFO1FlipPhase;
395 BoolEntry eLFO1Sync;
396 NumEntryPermille eEG2PreAttack;
397 NumEntryTemp<double> eEG2Attack;
398 NumEntryTemp<double> eEG2Decay1;
399 NumEntryTemp<double> eEG2Decay2;
400 BoolEntry eEG2InfiniteSustain;
401 NumEntryPermille eEG2Sustain;
402 NumEntryTemp<double> eEG2Release;
403 ChoiceEntryLeverageCtrl eEG2Controller;
404 BoolEntry eEG2ControllerInvert;
405 NumEntryTemp<uint8_t> eEG2ControllerAttackInfluence;
406 NumEntryTemp<uint8_t> eEG2ControllerDecayInfluence;
407 NumEntryTemp<uint8_t> eEG2ControllerReleaseInfluence;
408 NumEntryTemp<double> eLFO2Frequency;
409 NumEntryTemp<uint16_t> eLFO2InternalDepth;
410 NumEntryTemp<uint16_t> eLFO2ControlDepth;
411 ChoiceEntry<gig::lfo2_ctrl_t> eLFO2Controller;
412 BoolEntry eLFO2FlipPhase;
413 BoolEntry eLFO2Sync;
414 NumEntryTemp<double> eEG3Attack;
415 NumEntryTemp<int16_t> eEG3Depth;
416 NumEntryTemp<double> eLFO3Frequency;
417 NumEntryTemp<int16_t> eLFO3InternalDepth;
418 NumEntryTemp<int16_t> eLFO3ControlDepth;
419 ChoiceEntry<gig::lfo3_ctrl_t> eLFO3Controller;
420 BoolEntry eLFO3Sync;
421 BoolEntry eVCFEnabled;
422 ChoiceEntry<gig::vcf_type_t> eVCFType;
423 ChoiceEntry<gig::vcf_cutoff_ctrl_t> eVCFCutoffController;
424 BoolEntry eVCFCutoffControllerInvert;
425 NumEntryTemp<uint8_t> eVCFCutoff;
426 ChoiceEntry<gig::curve_type_t> eVCFVelocityCurve;
427 NumEntryTemp<uint8_t> eVCFVelocityScale;
428 NumEntryTemp<uint8_t> eVCFVelocityDynamicRange;
429 NumEntryTemp<uint8_t> eVCFResonance;
430 BoolEntry eVCFResonanceDynamic;
431 ChoiceEntry<gig::vcf_res_ctrl_t> eVCFResonanceController;
432 BoolEntry eVCFKeyboardTracking;
433 NumEntryTemp<uint8_t> eVCFKeyboardTrackingBreakpoint;
434 ChoiceEntry<gig::curve_type_t> eVelocityResponseCurve;
435 NumEntryTemp<uint8_t> eVelocityResponseDepth;
436 NumEntryTemp<uint8_t> eVelocityResponseCurveScaling;
437 ChoiceEntry<gig::curve_type_t> eReleaseVelocityResponseCurve;
438 NumEntryTemp<uint8_t> eReleaseVelocityResponseDepth;
439 NumEntryTemp<uint8_t> eReleaseTriggerDecay;
440 NumEntryX<uint8_t> eCrossfade_in_start;
441 NumEntryX<uint8_t> eCrossfade_in_end;
442 NumEntryX<uint8_t> eCrossfade_out_start;
443 NumEntryX<uint8_t> eCrossfade_out_end;
444 BoolEntry ePitchTrack;
445 ChoiceEntry<gig::dim_bypass_ctrl_t> eDimensionBypass;
446 NumEntryTemp<int8_t> ePan;
447 BoolEntry eSelfMask;
448 ChoiceEntryLeverageCtrl eAttenuationController;
449 BoolEntry eInvertAttenuationController;
450 NumEntryTemp<uint8_t> eAttenuationControllerThreshold;
451 NumEntryTemp<uint8_t> eChannelOffset;
452 BoolEntry eSustainDefeat;
453 BoolEntry eMSDecode;
454 NumEntryTemp<uint16_t> eSampleStartOffset;
455 // NumEntryX<uint8_t> eUnityNote;
456 NoteEntry eUnityNote;
457 NumEntryX<int16_t> eFineTune;
458 NumEntryGain eGain;
459 NumEntryX<uint32_t> eSampleLoops;
460
461 void addProp(LabelWidget& labelwidget);
462 void addString(char* labelText, Gtk::Label*& label,
463 Gtk::Entry*& widget);
464 void addHeader(char* text);
465 void nextPage();
466
467 RegionChooser m_RegionChooser;
468 DimRegionChooser m_DimRegionChooser;
469
470 void set_dim_region(gig::DimensionRegion* d);
471 PropDialog propDialog;
472 InstrumentProps instrumentProps;
473
474 void on_instrument_selection_change(int index);
475 void on_sel_change();
476 void region_changed();
477 void dimreg_changed();
478 void on_loader_progress();
479 void on_loader_finished();
480
481 class ModelColumns : public Gtk::TreeModel::ColumnRecord {
482 public:
483
484 ModelColumns() {
485 add(m_col_name);
486 add(m_col_instr);
487 }
488
489 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
490 Gtk::TreeModelColumn<gig::Instrument*> m_col_instr;
491 } m_Columns;
492
493 Gtk::VBox m_VBox;
494 Gtk::HPaned m_HPaned;
495
496 Gtk::ScrolledWindow m_ScrolledWindow;
497 Gtk::TreeView m_TreeView;
498 Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
499
500 class SamplesModel : public Gtk::TreeModel::ColumnRecord {
501 public:
502 SamplesModel() {
503 add(m_col_name);
504 add(m_col_sample);
505 add(m_col_group);
506 }
507
508 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
509 Gtk::TreeModelColumn<gig::Sample*> m_col_sample;
510 Gtk::TreeModelColumn<gig::Group*> m_col_group;
511 } m_SamplesModel;
512
513 class SamplesTreeStore : public Gtk::TreeStore {
514 public:
515 static Glib::RefPtr<SamplesTreeStore> create(const SamplesModel& columns) {
516 return Glib::RefPtr<SamplesTreeStore>( new SamplesTreeStore(columns) );
517 }
518 protected:
519 SamplesTreeStore(const SamplesModel& columns) : Gtk::TreeStore(columns) {}
520 };
521
522 Gtk::ScrolledWindow m_ScrolledWindowSamples;
523 Gtk::TreeView m_TreeViewSamples;
524 Glib::RefPtr<SamplesTreeStore> m_refSamplesTreeModel;
525
526 Gtk::Notebook m_Notebook;
527 Gtk::Notebook m_TreeViewNotebook;
528
529 Gtk::Table* table[5];
530
531 // dimensionregion parameter widgets
532 // TODO: remove:
533 Gtk::Label* lSample;
534 Gtk::Entry* wSample;
535
536 struct SampleImportItem {
537 gig::Sample* gig_sample; // pointer to the gig::Sample to which the sample data should be imported to
538 Glib::ustring sample_path; // file name of the sample to be imported
539 };
540 std::list<SampleImportItem> m_SampleImportQueue;
541
542 void VCFEnabled_toggled();
543 void VCFCutoffController_changed();
544 void VCFResonanceController_changed();
545 void EG1InfiniteSustain_toggled();
546 void EG2InfiniteSustain_toggled();
547 void EG1Controller_changed();
548 void EG2Controller_changed();
549 void AttenuationController_changed();
550 void LFO1Controller_changed();
551 void LFO2Controller_changed();
552 void LFO3Controller_changed();
553 void crossfade1_changed();
554 void crossfade2_changed();
555 void crossfade3_changed();
556 void crossfade4_changed();
557
558 void on_action_file_new();
559 void on_action_file_open();
560 void on_action_file_save();
561 void on_action_file_save_as();
562 void on_action_file_properties();
563 void on_action_help_about();
564
565 // sample right-click popup actions
566 void on_sample_treeview_button_release(GdkEventButton* button);
567 void on_action_sample_properties();
568 void on_action_add_group();
569 void on_action_add_sample();
570 void on_action_remove_sample();
571
572 LoadDialog* load_dialog;
573 Loader* loader;
574 void load_gig(gig::File* gig, const char* filename);
575
576 gig::File* file;
577
578 void on_button_release(GdkEventButton* button);
579 void on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, Gtk::SelectionData& selection_data, guint, guint);
580 void on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int, int, const Gtk::SelectionData& selection_data, guint, guint time);
581 void sample_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);
582 void instrument_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter);
583
584 void __import_queued_samples();
585
586 Gtk::Menu* popup_menu;
587 };
588
589 #endif

  ViewVC Help
Powered by ViewVC