/[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 1460 - (show annotations) (download) (as text)
Sat Oct 27 12:28:33 2007 UTC (16 years, 5 months ago) by persson
File MIME type: text/x-c++hdr
File size: 10694 byte(s)
* code refactoring: preparing for being able to edit multiple
  dimension regions simultaneously

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/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
44 class MainWindow;
45
46 class PropDialog : public Gtk::Window {
47 public:
48 PropDialog();
49 void set_info(DLS::Info* info);
50 protected:
51 Gtk::Table table;
52 Gtk::Label label[16];
53 Gtk::Entry entry[16];
54 };
55
56 class InstrumentProps : public Gtk::Window {
57 public:
58 InstrumentProps();
59 void set_instrument(gig::Instrument* instrument);
60 sigc::signal<void>& signal_instrument_changed();
61 protected:
62 gig::Instrument* instrument;
63 int update_model;
64
65 template<typename T>
66 void set_value(T value, sigc::slot<void, InstrumentProps*, T> setter) {
67 if (update_model == 0) {
68 setter(this, value);
69 instrument_changed();
70 }
71 }
72
73 template<typename C, typename T>
74 void connect(C& widget, T gig::Instrument::* member) {
75 widget.signal_value_changed().connect(
76 sigc::compose(
77 sigc::bind(sigc::mem_fun(*this, &InstrumentProps::set_value<T>),
78 sigc::bind(sigc::mem_fun(&InstrumentProps::set_member<T>), member)),
79 sigc::mem_fun(widget, &C::get_value)));
80 }
81
82 template<typename C, typename T>
83 void connect(C& widget, void (InstrumentProps::*setter)(T)) {
84 widget.signal_value_changed().connect(
85 sigc::compose(
86 sigc::bind(sigc::mem_fun(*this, &InstrumentProps::set_value<T>),
87 sigc::mem_fun(setter)),
88 sigc::mem_fun(widget, &C::get_value)));
89 }
90
91 template<typename T>
92 void set_member(T value, T gig::Instrument::* member) {
93 instrument->*member = value;
94 }
95
96 void set_IsDrum(bool value);
97 void set_MIDIBank(uint16_t value);
98 void set_MIDIProgram(uint32_t value);
99 void set_DimensionKeyRange_low(uint8_t value);
100 void set_DimensionKeyRange_high(uint8_t value);
101
102 Gtk::VBox vbox;
103 Gtk::HButtonBox buttonBox;
104 Gtk::Button quitButton;
105 Gtk::Table table;
106 StringEntry eName;
107 BoolEntry eIsDrum;
108 NumEntryTemp<uint16_t> eMIDIBank;
109 NumEntryTemp<uint32_t> eMIDIProgram;
110 NumEntryGain eAttenuation;
111 BoolEntryPlus6 eGainPlus6;
112 NumEntryTemp<uint16_t> eEffectSend;
113 NumEntryTemp<int16_t> eFineTune;
114 NumEntryTemp<uint16_t> ePitchbendRange;
115 BoolEntry ePianoReleaseMode;
116 NoteEntry eDimensionKeyRangeLow;
117 NoteEntry eDimensionKeyRangeHigh;
118 int rowno;
119 void add_prop(BoolEntry& prop);
120 void add_prop(BoolEntryPlus6& prop);
121 void add_prop(LabelWidget& prop);
122 sigc::signal<void> instrument_changed;
123 };
124
125 class LoadDialog : public Gtk::Dialog {
126 public:
127 LoadDialog(const Glib::ustring& title, Gtk::Window& parent);
128 void set_fraction(float fraction) { progressBar.set_fraction(fraction); }
129 protected:
130 Gtk::ProgressBar progressBar;
131 };
132
133 class Loader : public sigc::trackable {
134 public:
135 Loader(const char* filename);
136 void launch();
137 Glib::Dispatcher& signal_progress();
138 Glib::Dispatcher& signal_finished();
139 void progress_callback(float fraction);
140 float get_progress();
141 const char* filename;
142 gig::File* gig;
143
144 private:
145 Glib::Thread* thread;
146 void thread_function();
147 Glib::Dispatcher finished_dispatcher;
148 Glib::Dispatcher progress_dispatcher;
149 Glib::Mutex progressMutex;
150 float progress;
151 };
152
153 class MainWindow : public Gtk::Window {
154 public:
155 MainWindow();
156 virtual ~MainWindow();
157 void load_file(const char* name);
158 void load_instrument(gig::Instrument* instr);
159 void file_changed();
160 sigc::signal<void, gig::File*>& signal_file_structure_to_be_changed();
161 sigc::signal<void, gig::File*>& signal_file_structure_changed();
162 sigc::signal<void, std::list<gig::Sample*> >& signal_samples_to_be_removed();
163 sigc::signal<void>& signal_samples_removed();
164 sigc::signal<void, gig::Region*>& signal_region_to_be_changed();
165 sigc::signal<void, gig::Region*>& signal_region_changed();
166 sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_to_be_changed();
167 sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_changed();
168 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& signal_sample_ref_changed();
169
170 protected:
171 Glib::RefPtr<Gtk::ActionGroup> actionGroup;
172 Glib::RefPtr<Gtk::UIManager> uiManager;
173
174 Gtk::Statusbar m_StatusBar;
175 Gtk::Label m_AttachedStateLabel;
176 Gtk::Image m_AttachedStateImage;
177
178 RegionChooser m_RegionChooser;
179 DimRegionChooser m_DimRegionChooser;
180
181 PropDialog propDialog;
182 InstrumentProps instrumentProps;
183
184 sigc::signal<void, gig::File*> file_structure_to_be_changed_signal;
185 sigc::signal<void, gig::File*> file_structure_changed_signal;
186 sigc::signal<void, std::list<gig::Sample*> > samples_to_be_removed_signal;
187 sigc::signal<void> samples_removed_signal;
188 sigc::signal<void, gig::Region*> region_to_be_changed_signal;
189 sigc::signal<void, gig::Region*> region_changed_signal;
190 sigc::signal<void, gig::DimensionRegion*> dimreg_to_be_changed_signal;
191 sigc::signal<void, gig::DimensionRegion*> dimreg_changed_signal;
192 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/> sample_ref_changed_signal;
193
194 void on_instrument_selection_change(int index);
195 void on_sel_change();
196 void region_changed();
197 void dimreg_changed();
198 void on_loader_progress();
199 void on_loader_finished();
200
201 class ModelColumns : public Gtk::TreeModel::ColumnRecord {
202 public:
203 ModelColumns() {
204 add(m_col_name);
205 add(m_col_instr);
206 }
207
208 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
209 Gtk::TreeModelColumn<gig::Instrument*> m_col_instr;
210 } m_Columns;
211
212 Gtk::VBox m_VBox;
213 Gtk::HPaned m_HPaned;
214
215 Gtk::ScrolledWindow m_ScrolledWindow;
216
217 Gtk::TreeView m_TreeView;
218 Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
219
220 class SamplesModel : public Gtk::TreeModel::ColumnRecord {
221 public:
222 SamplesModel() {
223 add(m_col_name);
224 add(m_col_sample);
225 add(m_col_group);
226 }
227
228 Gtk::TreeModelColumn<Glib::ustring> m_col_name;
229 Gtk::TreeModelColumn<gig::Sample*> m_col_sample;
230 Gtk::TreeModelColumn<gig::Group*> m_col_group;
231 } m_SamplesModel;
232
233 class SamplesTreeStore : public Gtk::TreeStore {
234 public:
235 static Glib::RefPtr<SamplesTreeStore> create(const SamplesModel& columns) {
236 return Glib::RefPtr<SamplesTreeStore>( new SamplesTreeStore(columns) );
237 }
238 protected:
239 SamplesTreeStore(const SamplesModel& columns) : Gtk::TreeStore(columns) {}
240 };
241
242 Gtk::ScrolledWindow m_ScrolledWindowSamples;
243 Gtk::TreeView m_TreeViewSamples;
244 Glib::RefPtr<SamplesTreeStore> m_refSamplesTreeModel;
245
246 DimRegionEdit dimreg_edit;
247
248 Gtk::Notebook m_Notebook;
249 Gtk::Notebook m_TreeViewNotebook;
250
251 struct SampleImportItem {
252 gig::Sample* gig_sample; // pointer to the gig::Sample to
253 // which the sample data should be
254 // imported to
255 Glib::ustring sample_path; // file name of the sample to be
256 // imported
257 };
258 std::list<SampleImportItem> m_SampleImportQueue;
259
260
261 void on_action_file_new();
262 void on_action_file_open();
263 void on_action_file_save();
264 void on_action_file_save_as();
265 void on_action_file_properties();
266 void on_action_quit();
267 void show_instr_props();
268 void on_action_view_status_bar();
269 void on_action_help_about();
270
271 // sample right-click popup actions
272 void on_sample_treeview_button_release(GdkEventButton* button);
273 void on_action_sample_properties();
274 void on_action_add_group();
275 void on_action_add_sample();
276 void on_action_remove_sample();
277
278 void on_action_add_instrument();
279 void on_action_remove_instrument();
280
281 LoadDialog* load_dialog;
282 Loader* loader;
283 void load_gig(gig::File* gig, const char* filename, bool isSharedInstrument = false);
284
285 gig::File* file;
286 bool file_is_shared;
287 bool file_has_name;
288 bool file_is_changed;
289 std::string filename;
290 std::string current_dir;
291
292 void set_file_is_shared(bool);
293
294 bool file_save();
295 bool file_save_as();
296 bool check_if_savable();
297
298 void on_button_release(GdkEventButton* button);
299 void on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context);
300 void on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
301 Gtk::SelectionData& selection_data, guint, guint);
302 void on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context,
303 int, int,
304 const Gtk::SelectionData& selection_data,
305 guint, guint time);
306
307 void sample_name_changed(const Gtk::TreeModel::Path& path,
308 const Gtk::TreeModel::iterator& iter);
309 void instrument_name_changed(const Gtk::TreeModel::Path& path,
310 const Gtk::TreeModel::iterator& iter);
311
312 void __import_queued_samples();
313 void __clear();
314
315 bool close_confirmation_dialog();
316 bool leaving_shared_mode_dialog();
317
318 Gtk::Menu* popup_menu;
319
320 bool on_delete_event(GdkEventAny* event);
321
322 bool first_call_to_drag_data_get;
323 };
324
325 #endif

  ViewVC Help
Powered by ViewVC