1 |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006 - 2015 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/menu.h> |
30 |
#include <gtkmm/paned.h> |
31 |
#include <gtkmm/progressbar.h> |
32 |
#include <gtkmm/radiomenuitem.h> |
33 |
#include <gtkmm/scrolledwindow.h> |
34 |
#include <gtkmm/treestore.h> |
35 |
#include <gtkmm/uimanager.h> |
36 |
#include <gtkmm/window.h> |
37 |
#include <gtkmm/statusbar.h> |
38 |
#include <gtkmm/image.h> |
39 |
|
40 |
#include <sstream> |
41 |
|
42 |
#include "regionchooser.h" |
43 |
#include "dimregionchooser.h" |
44 |
#include "dimregionedit.h" |
45 |
#include "midirules.h" |
46 |
#ifndef OLD_THREADS |
47 |
#include <glibmm/threads.h> |
48 |
#endif |
49 |
|
50 |
class MainWindow; |
51 |
|
52 |
class PropDialog : public Gtk::Window, |
53 |
public PropEditor<DLS::Info> { |
54 |
public: |
55 |
PropDialog(); |
56 |
void set_info(DLS::Info* info); |
57 |
void set_file(gig::File* file); |
58 |
protected: |
59 |
ChoiceEntry<int> eFileFormat; |
60 |
StringEntry eName; |
61 |
StringEntry eCreationDate; |
62 |
StringEntryMultiLine eComments; |
63 |
StringEntry eProduct; |
64 |
StringEntry eCopyright; |
65 |
StringEntry eArtists; |
66 |
StringEntry eGenre; |
67 |
StringEntry eKeywords; |
68 |
StringEntry eEngineer; |
69 |
StringEntry eTechnician; |
70 |
StringEntry eSoftware; |
71 |
StringEntry eMedium; |
72 |
StringEntry eSource; |
73 |
StringEntry eSourceForm; |
74 |
StringEntry eCommissioned; |
75 |
StringEntry eSubject; |
76 |
Gtk::VBox vbox; |
77 |
Gtk::HButtonBox buttonBox; |
78 |
Gtk::Button quitButton; |
79 |
Table table; |
80 |
|
81 |
gig::File* m_file; |
82 |
|
83 |
void onFileFormatChanged(); |
84 |
}; |
85 |
|
86 |
class InstrumentProps : public Gtk::Window, |
87 |
public PropEditor<gig::Instrument> { |
88 |
public: |
89 |
InstrumentProps(); |
90 |
void set_instrument(gig::Instrument* instrument); |
91 |
gig::Instrument* get_instrument() { return m; } |
92 |
void update_name(); |
93 |
sigc::signal<void>& signal_name_changed() { |
94 |
return sig_name_changed; |
95 |
} |
96 |
protected: |
97 |
void set_Name(const gig::String& name); |
98 |
void set_IsDrum(bool value); |
99 |
void set_MIDIBank(uint16_t value); |
100 |
void set_MIDIProgram(uint32_t value); |
101 |
|
102 |
sigc::signal<void> sig_name_changed; |
103 |
Gtk::VBox vbox; |
104 |
Gtk::HButtonBox buttonBox; |
105 |
Gtk::Button quitButton; |
106 |
Table table; |
107 |
StringEntry eName; |
108 |
BoolEntry eIsDrum; |
109 |
NumEntryTemp<uint16_t> eMIDIBank; |
110 |
NumEntryTemp<uint32_t> eMIDIProgram; |
111 |
NumEntryGain eAttenuation; |
112 |
BoolEntryPlus6 eGainPlus6; |
113 |
NumEntryTemp<uint16_t> eEffectSend; |
114 |
NumEntryTemp<int16_t> eFineTune; |
115 |
NumEntryTemp<uint16_t> ePitchbendRange; |
116 |
BoolEntry ePianoReleaseMode; |
117 |
NoteEntry eDimensionKeyRangeLow; |
118 |
NoteEntry eDimensionKeyRangeHigh; |
119 |
}; |
120 |
|
121 |
class ProgressDialog : public Gtk::Dialog { |
122 |
public: |
123 |
ProgressDialog(const Glib::ustring& title, Gtk::Window& parent); |
124 |
void set_fraction(float fraction) { progressBar.set_fraction(fraction); } |
125 |
protected: |
126 |
Gtk::ProgressBar progressBar; |
127 |
}; |
128 |
|
129 |
class Loader : public sigc::trackable { |
130 |
public: |
131 |
Loader(const char* filename); |
132 |
void launch(); |
133 |
Glib::Dispatcher& signal_progress(); |
134 |
Glib::Dispatcher& signal_finished(); ///< Finished successfully, without error. |
135 |
Glib::Dispatcher& signal_error(); |
136 |
void progress_callback(float fraction); |
137 |
float get_progress(); |
138 |
const Glib::ustring filename; |
139 |
Glib::ustring error_message; |
140 |
gig::File* gig; |
141 |
|
142 |
private: |
143 |
Glib::Threads::Thread* thread; |
144 |
void thread_function(); |
145 |
Glib::Dispatcher finished_dispatcher; |
146 |
Glib::Dispatcher progress_dispatcher; |
147 |
Glib::Dispatcher error_dispatcher; |
148 |
Glib::Threads::Mutex progressMutex; |
149 |
float progress; |
150 |
}; |
151 |
|
152 |
class Saver : public sigc::trackable { |
153 |
public: |
154 |
Saver(gig::File* file, Glib::ustring filename = ""); ///< one argument means "save", two arguments means "save as" |
155 |
void launch(); |
156 |
Glib::Dispatcher& signal_progress(); |
157 |
Glib::Dispatcher& signal_finished(); ///< Finished successfully, without error. |
158 |
Glib::Dispatcher& signal_error(); |
159 |
void progress_callback(float fraction); |
160 |
float get_progress(); |
161 |
gig::File* gig; |
162 |
const Glib::ustring filename; |
163 |
Glib::ustring error_message; |
164 |
|
165 |
private: |
166 |
Glib::Threads::Thread* thread; |
167 |
void thread_function(); |
168 |
Glib::Dispatcher finished_dispatcher; |
169 |
Glib::Dispatcher progress_dispatcher; |
170 |
Glib::Dispatcher error_dispatcher; |
171 |
Glib::Threads::Mutex progressMutex; |
172 |
float progress; |
173 |
}; |
174 |
|
175 |
class MainWindow : public Gtk::Window { |
176 |
public: |
177 |
MainWindow(); |
178 |
virtual ~MainWindow(); |
179 |
void load_file(const char* name); |
180 |
void load_instrument(gig::Instrument* instr); |
181 |
void file_changed(); |
182 |
sigc::signal<void, gig::File*>& signal_file_structure_to_be_changed(); |
183 |
sigc::signal<void, gig::File*>& signal_file_structure_changed(); |
184 |
sigc::signal<void, std::list<gig::Sample*> >& signal_samples_to_be_removed(); |
185 |
sigc::signal<void>& signal_samples_removed(); |
186 |
sigc::signal<void, gig::Region*>& signal_region_to_be_changed(); |
187 |
sigc::signal<void, gig::Region*>& signal_region_changed(); |
188 |
sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_to_be_changed(); |
189 |
sigc::signal<void, gig::DimensionRegion*>& signal_dimreg_changed(); |
190 |
sigc::signal<void, gig::Sample*>& signal_sample_changed(); |
191 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& signal_sample_ref_changed(); |
192 |
|
193 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_note_on(); |
194 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_note_off(); |
195 |
|
196 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_hit(); |
197 |
sigc::signal<void, int/*key*/, int/*velocity*/>& signal_keyboard_key_released(); |
198 |
|
199 |
sigc::signal<void, gig::Instrument*>& signal_switch_sampler_instrument(); |
200 |
|
201 |
protected: |
202 |
Glib::RefPtr<Gtk::ActionGroup> actionGroup; |
203 |
Glib::RefPtr<Gtk::UIManager> uiManager; |
204 |
|
205 |
Gtk::Statusbar m_StatusBar; |
206 |
Gtk::Label m_AttachedStateLabel; |
207 |
Gtk::Image m_AttachedStateImage; |
208 |
|
209 |
RegionChooser m_RegionChooser; |
210 |
DimRegionChooser m_DimRegionChooser; |
211 |
|
212 |
PropDialog propDialog; |
213 |
InstrumentProps instrumentProps; |
214 |
MidiRules midiRules; |
215 |
|
216 |
sigc::signal<void, gig::File*> file_structure_to_be_changed_signal; |
217 |
sigc::signal<void, gig::File*> file_structure_changed_signal; |
218 |
sigc::signal<void, std::list<gig::Sample*> > samples_to_be_removed_signal; |
219 |
sigc::signal<void> samples_removed_signal; |
220 |
sigc::signal<void, gig::Region*> region_to_be_changed_signal; |
221 |
sigc::signal<void, gig::Region*> region_changed_signal; |
222 |
sigc::signal<void, gig::DimensionRegion*> dimreg_to_be_changed_signal; |
223 |
sigc::signal<void, gig::DimensionRegion*> dimreg_changed_signal; |
224 |
sigc::signal<void, gig::Sample*> sample_changed_signal; |
225 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/> sample_ref_changed_signal; |
226 |
|
227 |
sigc::signal<void, int/*key*/, int/*velocity*/> note_on_signal; |
228 |
sigc::signal<void, int/*key*/, int/*velocity*/> note_off_signal; |
229 |
|
230 |
sigc::signal<void, gig::Instrument*> switch_sampler_instrument_signal; |
231 |
|
232 |
void on_instrument_selection_change(Gtk::RadioMenuItem* item); |
233 |
void on_sel_change(); |
234 |
void region_changed(); |
235 |
void dimreg_changed(); |
236 |
bool select_dimension_region(gig::DimensionRegion* dimRgn); |
237 |
void select_sample(gig::Sample* sample); |
238 |
void on_loader_progress(); |
239 |
void on_loader_finished(); |
240 |
void on_loader_error(); |
241 |
void on_saver_progress(); |
242 |
void on_saver_error(); |
243 |
void on_saver_finished(); |
244 |
|
245 |
void dimreg_all_dimregs_toggled(); |
246 |
gig::Instrument* get_instrument(); |
247 |
void add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs); |
248 |
void update_dimregs(); |
249 |
|
250 |
class ModelColumns : public Gtk::TreeModel::ColumnRecord { |
251 |
public: |
252 |
ModelColumns() { |
253 |
add(m_col_name); |
254 |
add(m_col_instr); |
255 |
} |
256 |
|
257 |
Gtk::TreeModelColumn<Glib::ustring> m_col_name; |
258 |
Gtk::TreeModelColumn<gig::Instrument*> m_col_instr; |
259 |
} m_Columns; |
260 |
|
261 |
Gtk::VBox m_VBox; |
262 |
Gtk::HPaned m_HPaned; |
263 |
|
264 |
Gtk::ScrolledWindow m_ScrolledWindow; |
265 |
|
266 |
Gtk::TreeView m_TreeView; |
267 |
Glib::RefPtr<Gtk::ListStore> m_refTreeModel; |
268 |
|
269 |
Gtk::Menu* instrument_menu; |
270 |
|
271 |
std::map<gig::Sample*,int> sample_ref_count; |
272 |
|
273 |
class SamplesModel : public Gtk::TreeModel::ColumnRecord { |
274 |
public: |
275 |
SamplesModel() { |
276 |
add(m_col_name); |
277 |
add(m_col_sample); |
278 |
add(m_col_group); |
279 |
add(m_col_refcount); |
280 |
add(m_color); |
281 |
} |
282 |
|
283 |
Gtk::TreeModelColumn<Glib::ustring> m_col_name; |
284 |
Gtk::TreeModelColumn<gig::Sample*> m_col_sample; |
285 |
Gtk::TreeModelColumn<gig::Group*> m_col_group; |
286 |
Gtk::TreeModelColumn<Glib::ustring> m_col_refcount; |
287 |
Gtk::TreeModelColumn<Glib::ustring> m_color; |
288 |
} m_SamplesModel; |
289 |
|
290 |
class SamplesTreeStore : public Gtk::TreeStore { |
291 |
public: |
292 |
static Glib::RefPtr<SamplesTreeStore> create(const SamplesModel& columns) { |
293 |
return Glib::RefPtr<SamplesTreeStore>( new SamplesTreeStore(columns) ); |
294 |
} |
295 |
protected: |
296 |
SamplesTreeStore(const SamplesModel& columns) : Gtk::TreeStore(columns) {} |
297 |
}; |
298 |
|
299 |
Gtk::ScrolledWindow m_ScrolledWindowSamples; |
300 |
Gtk::TreeView m_TreeViewSamples; |
301 |
Glib::RefPtr<SamplesTreeStore> m_refSamplesTreeModel; |
302 |
|
303 |
class ScriptsModel : public Gtk::TreeModel::ColumnRecord { |
304 |
public: |
305 |
ScriptsModel() { |
306 |
add(m_col_name); |
307 |
add(m_col_script); |
308 |
add(m_col_group); |
309 |
} |
310 |
|
311 |
Gtk::TreeModelColumn<Glib::ustring> m_col_name; |
312 |
Gtk::TreeModelColumn<gig::Script*> m_col_script; |
313 |
Gtk::TreeModelColumn<gig::ScriptGroup*> m_col_group; |
314 |
} m_ScriptsModel; |
315 |
|
316 |
class ScriptsTreeStore : public Gtk::TreeStore { |
317 |
public: |
318 |
static Glib::RefPtr<ScriptsTreeStore> create(const ScriptsModel& columns) { |
319 |
return Glib::RefPtr<ScriptsTreeStore>( new ScriptsTreeStore(columns) ); |
320 |
} |
321 |
protected: |
322 |
ScriptsTreeStore(const ScriptsModel& columns) : Gtk::TreeStore(columns) {} |
323 |
}; |
324 |
|
325 |
Gtk::ScrolledWindow m_ScrolledWindowScripts; |
326 |
Gtk::TreeView m_TreeViewScripts; |
327 |
Glib::RefPtr<ScriptsTreeStore> m_refScriptsTreeModel; |
328 |
|
329 |
Gtk::VBox dimreg_vbox; |
330 |
Gtk::HBox dimreg_hbox; |
331 |
Gtk::Label dimreg_label; |
332 |
Gtk::CheckButton dimreg_all_regions; |
333 |
Gtk::CheckButton dimreg_all_dimregs; |
334 |
Gtk::CheckButton dimreg_stereo; |
335 |
DimRegionEdit dimreg_edit; |
336 |
|
337 |
Gtk::Notebook m_TreeViewNotebook; |
338 |
|
339 |
struct SampleImportItem { |
340 |
gig::Sample* gig_sample; // pointer to the gig::Sample to |
341 |
// which the sample data should be |
342 |
// imported to |
343 |
Glib::ustring sample_path; // file name of the sample to be |
344 |
// imported |
345 |
}; |
346 |
std::list<SampleImportItem> m_SampleImportQueue; |
347 |
|
348 |
|
349 |
void on_action_file_new(); |
350 |
void on_action_file_open(); |
351 |
void on_action_file_save(); |
352 |
void on_action_file_save_as(); |
353 |
void on_action_file_properties(); |
354 |
void on_action_quit(); |
355 |
void show_instr_props(); |
356 |
bool instr_props_set_instrument(); |
357 |
void show_midi_rules(); |
358 |
void show_script_slots(); |
359 |
void on_action_view_status_bar(); |
360 |
void on_action_warn_user_on_extensions(); |
361 |
void on_action_sync_sampler_instrument_selection(); |
362 |
void on_action_help_about(); |
363 |
|
364 |
// sample right-click popup actions |
365 |
void on_sample_treeview_button_release(GdkEventButton* button); |
366 |
void on_action_sample_properties(); |
367 |
void on_action_add_group(); |
368 |
void on_action_add_sample(); |
369 |
void on_action_replace_all_samples_in_all_groups(); |
370 |
void on_action_remove_sample(); |
371 |
|
372 |
// script right-click popup actions |
373 |
void on_script_treeview_button_release(GdkEventButton* button); |
374 |
void on_action_add_script_group(); |
375 |
void on_action_add_script(); |
376 |
void on_action_edit_script(); |
377 |
void on_action_remove_script(); |
378 |
|
379 |
void on_action_add_instrument(); |
380 |
void on_action_duplicate_instrument(); |
381 |
void on_action_remove_instrument(); |
382 |
|
383 |
void show_samples_tab(); |
384 |
void show_intruments_tab(); |
385 |
void show_scripts_tab(); |
386 |
|
387 |
void add_instrument(gig::Instrument* instrument); |
388 |
Gtk::RadioMenuItem* add_instrument_to_menu(const Glib::ustring& name, |
389 |
int position = -1); |
390 |
void remove_instrument_from_menu(int index); |
391 |
|
392 |
ProgressDialog* progress_dialog; |
393 |
Loader* loader; |
394 |
Saver* saver; |
395 |
void load_gig(gig::File* gig, const char* filename, bool isSharedInstrument = false); |
396 |
void updateSampleRefCountMap(gig::File* gig); |
397 |
|
398 |
gig::File* file; |
399 |
bool file_is_shared; |
400 |
bool file_has_name; |
401 |
bool file_is_changed; |
402 |
std::string filename; |
403 |
std::string current_gig_dir; |
404 |
std::string current_sample_dir; |
405 |
|
406 |
void set_file_is_shared(bool); |
407 |
|
408 |
bool file_save(); |
409 |
bool file_save_as(); |
410 |
bool check_if_savable(); |
411 |
|
412 |
void on_button_release(GdkEventButton* button); |
413 |
void on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context); |
414 |
void on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
415 |
Gtk::SelectionData& selection_data, guint, guint); |
416 |
void on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context); |
417 |
void on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
418 |
Gtk::SelectionData& selection_data, guint, guint); |
419 |
void on_sample_label_drop_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, |
420 |
int, int, |
421 |
const Gtk::SelectionData& selection_data, |
422 |
guint, guint time); |
423 |
|
424 |
void script_name_changed(const Gtk::TreeModel::Path& path, |
425 |
const Gtk::TreeModel::iterator& iter); |
426 |
void script_double_clicked(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); |
427 |
void sample_name_changed(const Gtk::TreeModel::Path& path, |
428 |
const Gtk::TreeModel::iterator& iter); |
429 |
void instrument_name_changed(const Gtk::TreeModel::Path& path, |
430 |
const Gtk::TreeModel::iterator& iter); |
431 |
void instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it); |
432 |
sigc::connection instrument_name_connection; |
433 |
|
434 |
void on_action_combine_instruments(); |
435 |
void on_action_view_references(); |
436 |
void on_action_merge_files(); |
437 |
void mergeFiles(const std::vector<std::string>& filenames); |
438 |
|
439 |
void on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample); |
440 |
void on_sample_ref_count_incremented(gig::Sample* sample, int offset); |
441 |
void on_samples_to_be_removed(std::list<gig::Sample*> samples); |
442 |
|
443 |
void __import_queued_samples(); |
444 |
void __clear(); |
445 |
void __refreshEntireGUI(); |
446 |
|
447 |
bool close_confirmation_dialog(); |
448 |
bool leaving_shared_mode_dialog(); |
449 |
|
450 |
Gtk::Menu* popup_menu; |
451 |
|
452 |
bool on_delete_event(GdkEventAny* event); |
453 |
|
454 |
bool first_call_to_drag_data_get; |
455 |
|
456 |
bool is_copy_samples_unity_note_enabled() const; |
457 |
bool is_copy_samples_fine_tune_enabled() const; |
458 |
bool is_copy_samples_loop_enabled() const; |
459 |
}; |
460 |
|
461 |
#endif |