1 |
/* |
/* |
2 |
* Copyright (C) 2006-2016 Andreas Persson |
* Copyright (C) 2006-2017 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
35 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
36 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
37 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
38 |
|
#include <gtkmm/stock.h> |
39 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
40 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
41 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
42 |
|
#include <gtkmm/accelmap.h> |
43 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
44 |
#include "wrapLabel.hh" |
#include "wrapLabel.hh" |
45 |
#endif |
#endif |
59 |
#include "ReferencesView.h" |
#include "ReferencesView.h" |
60 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
61 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
62 |
|
#include "gfx/builtinpix.h" |
63 |
|
#include "MacroEditor.h" |
64 |
|
#include "MacrosSetup.h" |
65 |
|
#if defined(__APPLE__) |
66 |
|
# include "MacHelper.h" |
67 |
|
#endif |
68 |
|
|
69 |
|
static const Gdk::ModifierType primaryModifierKey = |
70 |
|
#if defined(__APPLE__) |
71 |
|
Gdk::META_MASK; // Cmd key on Mac |
72 |
|
#else |
73 |
|
Gdk::CONTROL_MASK; // Ctrl key on all other OSs |
74 |
|
#endif |
75 |
|
|
76 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
77 |
m_DimRegionChooser(*this), |
m_DimRegionChooser(*this), |
78 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
79 |
dimreg_all_regions(_("all regions")), |
dimreg_all_regions(_("all regions")), |
80 |
dimreg_all_dimregs(_("all dimension splits")), |
dimreg_all_dimregs(_("all dimension splits")), |
81 |
dimreg_stereo(_("both channels")) |
dimreg_stereo(_("both channels")), |
82 |
|
labelLegend(_("Legend:")), |
83 |
|
labelNoSample(_(" No Sample")), |
84 |
|
labelMissingSample(_(" Missing some Sample(s)")), |
85 |
|
labelLooped(_(" Looped")), |
86 |
|
labelSomeLoops(_(" Some Loop(s)")) |
87 |
{ |
{ |
88 |
|
loadBuiltInPix(); |
89 |
|
|
90 |
|
this->file = NULL; |
91 |
|
|
92 |
// set_border_width(5); |
// set_border_width(5); |
|
// set_default_size(400, 200); |
|
93 |
|
|
94 |
|
if (!Settings::singleton()->autoRestoreWindowDimension) { |
95 |
|
set_default_size(800, 600); |
96 |
|
set_position(Gtk::WIN_POS_CENTER); |
97 |
|
} |
98 |
|
|
99 |
add(m_VBox); |
add(m_VBox); |
100 |
|
|
129 |
dimreg_hbox.add(dimreg_stereo); |
dimreg_hbox.add(dimreg_stereo); |
130 |
dimreg_vbox.add(dimreg_edit); |
dimreg_vbox.add(dimreg_edit); |
131 |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
132 |
|
{ |
133 |
|
legend_hbox.add(labelLegend); |
134 |
|
|
135 |
|
imageNoSample.set(redDot); |
136 |
|
imageNoSample.set_alignment(Gtk::ALIGN_END); |
137 |
|
labelNoSample.set_alignment(Gtk::ALIGN_START); |
138 |
|
legend_hbox.add(imageNoSample); |
139 |
|
legend_hbox.add(labelNoSample); |
140 |
|
|
141 |
|
imageMissingSample.set(yellowDot); |
142 |
|
imageMissingSample.set_alignment(Gtk::ALIGN_END); |
143 |
|
labelMissingSample.set_alignment(Gtk::ALIGN_START); |
144 |
|
legend_hbox.add(imageMissingSample); |
145 |
|
legend_hbox.add(labelMissingSample); |
146 |
|
|
147 |
|
imageLooped.set(blackLoop); |
148 |
|
imageLooped.set_alignment(Gtk::ALIGN_END); |
149 |
|
labelLooped.set_alignment(Gtk::ALIGN_START); |
150 |
|
legend_hbox.add(imageLooped); |
151 |
|
legend_hbox.add(labelLooped); |
152 |
|
|
153 |
|
imageSomeLoops.set(grayLoop); |
154 |
|
imageSomeLoops.set_alignment(Gtk::ALIGN_END); |
155 |
|
labelSomeLoops.set_alignment(Gtk::ALIGN_START); |
156 |
|
legend_hbox.add(imageSomeLoops); |
157 |
|
legend_hbox.add(labelSomeLoops); |
158 |
|
|
159 |
|
legend_hbox.show_all_children(); |
160 |
|
} |
161 |
|
dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK); |
162 |
m_HPaned.add2(dimreg_vbox); |
m_HPaned.add2(dimreg_vbox); |
163 |
|
|
164 |
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
173 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
174 |
|
|
175 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
176 |
actionGroup->add(Gtk::Action::create("New", _("_New")), |
actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), |
|
Gtk::AccelKey("<control>n"), |
|
177 |
sigc::mem_fun( |
sigc::mem_fun( |
178 |
*this, &MainWindow::on_action_file_new)); |
*this, &MainWindow::on_action_file_new)); |
179 |
actionGroup->add(Gtk::Action::create("Open", _("_Open...")), |
Glib::RefPtr<Gtk::Action> action = |
180 |
Gtk::AccelKey("<control>o"), |
Gtk::Action::create("Open", Gtk::Stock::OPEN); |
181 |
|
action->property_label() = action->property_label() + "..."; |
182 |
|
actionGroup->add(action, |
183 |
sigc::mem_fun( |
sigc::mem_fun( |
184 |
*this, &MainWindow::on_action_file_open)); |
*this, &MainWindow::on_action_file_open)); |
185 |
actionGroup->add(Gtk::Action::create("Save", _("_Save")), |
actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), |
|
Gtk::AccelKey("<control>s"), |
|
186 |
sigc::mem_fun( |
sigc::mem_fun( |
187 |
*this, &MainWindow::on_action_file_save)); |
*this, &MainWindow::on_action_file_save)); |
188 |
actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")), |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
189 |
|
action->property_label() = action->property_label() + "..."; |
190 |
|
actionGroup->add(action, |
191 |
Gtk::AccelKey("<shift><control>s"), |
Gtk::AccelKey("<shift><control>s"), |
192 |
sigc::mem_fun( |
sigc::mem_fun( |
193 |
*this, &MainWindow::on_action_file_save_as)); |
*this, &MainWindow::on_action_file_save_as)); |
194 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
195 |
_("_Properties")), |
Gtk::Stock::PROPERTIES), |
196 |
sigc::mem_fun( |
sigc::mem_fun( |
197 |
*this, &MainWindow::on_action_file_properties)); |
*this, &MainWindow::on_action_file_properties)); |
198 |
actionGroup->add(Gtk::Action::create("InstrProperties", |
actionGroup->add(Gtk::Action::create("InstrProperties", |
199 |
_("_Properties")), |
Gtk::Stock::PROPERTIES), |
200 |
sigc::mem_fun( |
sigc::mem_fun( |
201 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
202 |
actionGroup->add(Gtk::Action::create("MidiRules", |
actionGroup->add(Gtk::Action::create("MidiRules", |
207 |
_("_Script Slots...")), |
_("_Script Slots...")), |
208 |
sigc::mem_fun( |
sigc::mem_fun( |
209 |
*this, &MainWindow::show_script_slots)); |
*this, &MainWindow::show_script_slots)); |
210 |
actionGroup->add(Gtk::Action::create("Quit", _("_Quit")), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
|
Gtk::AccelKey("<control>q"), |
|
211 |
sigc::mem_fun( |
sigc::mem_fun( |
212 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
213 |
actionGroup->add( |
actionGroup->add( |
219 |
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
220 |
); |
); |
221 |
actionGroup->add( |
actionGroup->add( |
222 |
Gtk::Action::create("MenuScript", _("S_cript")), |
Gtk::Action::create("MenuScript", _("Scr_ipt")), |
223 |
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
224 |
); |
); |
225 |
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
226 |
|
actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script"))); |
227 |
|
|
228 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
229 |
|
|
230 |
|
const Gdk::ModifierType primaryModifierKey = |
231 |
|
#if defined(__APPLE__) |
232 |
|
Gdk::META_MASK; // Cmd key on Mac |
233 |
|
#else |
234 |
|
Gdk::CONTROL_MASK; // Ctrl key on all other OSs |
235 |
|
#endif |
236 |
|
|
237 |
|
actionGroup->add(Gtk::Action::create("CopyDimRgn", |
238 |
|
_("Copy selected dimension region")), |
239 |
|
Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK), |
240 |
|
sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)); |
241 |
|
|
242 |
|
actionGroup->add(Gtk::Action::create("PasteDimRgn", |
243 |
|
_("Paste dimension region")), |
244 |
|
Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK), |
245 |
|
sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)); |
246 |
|
|
247 |
|
actionGroup->add(Gtk::Action::create("AdjustClipboard", |
248 |
|
_("Adjust Clipboard Content")), |
249 |
|
Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK), |
250 |
|
sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)); |
251 |
|
|
252 |
|
actionGroup->add(Gtk::Action::create("SelectPrevInstr", |
253 |
|
_("Select Previous Instrument")), |
254 |
|
Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey), |
255 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_instrument)); |
256 |
|
|
257 |
|
actionGroup->add(Gtk::Action::create("SelectNextInstr", |
258 |
|
_("Select Next Instrument")), |
259 |
|
Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey), |
260 |
|
sigc::mem_fun(*this, &MainWindow::select_next_instrument)); |
261 |
|
|
262 |
|
actionGroup->add(Gtk::Action::create("SelectPrevRegion", |
263 |
|
_("Select Previous Region")), |
264 |
|
Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey), |
265 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_region)); |
266 |
|
|
267 |
|
actionGroup->add(Gtk::Action::create("SelectNextRegion", |
268 |
|
_("Select Next Region")), |
269 |
|
Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey), |
270 |
|
sigc::mem_fun(*this, &MainWindow::select_next_region)); |
271 |
|
|
272 |
|
actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone", |
273 |
|
_("Select Previous Dimension Region Zone")), |
274 |
|
Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK), |
275 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)); |
276 |
|
|
277 |
|
actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone", |
278 |
|
_("Select Next Dimension Region Zone")), |
279 |
|
Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK), |
280 |
|
sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)); |
281 |
|
|
282 |
|
actionGroup->add(Gtk::Action::create("SelectPrevDimension", |
283 |
|
_("Select Previous Dimension")), |
284 |
|
Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK), |
285 |
|
sigc::mem_fun(*this, &MainWindow::select_prev_dimension)); |
286 |
|
|
287 |
|
actionGroup->add(Gtk::Action::create("SelectNextDimension", |
288 |
|
_("Select Next Dimension")), |
289 |
|
Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK), |
290 |
|
sigc::mem_fun(*this, &MainWindow::select_next_dimension)); |
291 |
|
|
292 |
|
actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone", |
293 |
|
_("Add Previous Dimension Region Zone to Selection")), |
294 |
|
Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), |
295 |
|
sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)); |
296 |
|
|
297 |
|
actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone", |
298 |
|
_("Add Next Dimension Region Zone to Selection")), |
299 |
|
Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), |
300 |
|
sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)); |
301 |
|
|
302 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
303 |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
304 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
315 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
316 |
|
|
317 |
|
|
318 |
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro"))); |
319 |
|
|
320 |
|
|
321 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w"))); |
322 |
toggle_action = |
toggle_action = |
323 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
324 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
345 |
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
346 |
); |
); |
347 |
|
|
348 |
actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help"))); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
349 |
actionGroup->add(Gtk::Action::create("About", _("_About")), |
actionGroup->add(Gtk::Action::create("MenuHelp", |
350 |
|
action->property_label())); |
351 |
|
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
352 |
sigc::mem_fun( |
sigc::mem_fun( |
353 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
354 |
actionGroup->add( |
actionGroup->add( |
360 |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
361 |
); |
); |
362 |
actionGroup->add( |
actionGroup->add( |
363 |
Gtk::Action::create("RemoveInstrument", _("_Remove")), |
Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")), |
364 |
|
Gtk::AccelKey(GDK_KEY_j, primaryModifierKey), |
365 |
|
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
366 |
|
); |
367 |
|
actionGroup->add( |
368 |
|
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
369 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
370 |
); |
); |
371 |
|
|
412 |
|
|
413 |
// sample right-click popup actions |
// sample right-click popup actions |
414 |
actionGroup->add( |
actionGroup->add( |
415 |
Gtk::Action::create("SampleProperties", _("_Properties")), |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
416 |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
417 |
); |
); |
418 |
actionGroup->add( |
actionGroup->add( |
424 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
425 |
); |
); |
426 |
actionGroup->add( |
actionGroup->add( |
427 |
Gtk::Action::create("RemoveSample", _("_Remove")), |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
428 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
429 |
); |
); |
430 |
actionGroup->add( |
actionGroup->add( |
460 |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
461 |
); |
); |
462 |
actionGroup->add( |
actionGroup->add( |
463 |
Gtk::Action::create("RemoveScript", _("_Remove")), |
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
464 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
465 |
); |
); |
466 |
|
|
483 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
484 |
" </menu>" |
" </menu>" |
485 |
" <menu action='MenuEdit'>" |
" <menu action='MenuEdit'>" |
486 |
|
" <menuitem action='CopyDimRgn'/>" |
487 |
|
" <menuitem action='AdjustClipboard'/>" |
488 |
|
" <menuitem action='PasteDimRgn'/>" |
489 |
|
" <separator/>" |
490 |
|
" <menuitem action='SelectPrevInstr'/>" |
491 |
|
" <menuitem action='SelectNextInstr'/>" |
492 |
|
" <separator/>" |
493 |
|
" <menuitem action='SelectPrevRegion'/>" |
494 |
|
" <menuitem action='SelectNextRegion'/>" |
495 |
|
" <separator/>" |
496 |
|
" <menuitem action='SelectPrevDimension'/>" |
497 |
|
" <menuitem action='SelectNextDimension'/>" |
498 |
|
" <menuitem action='SelectPrevDimRgnZone'/>" |
499 |
|
" <menuitem action='SelectNextDimRgnZone'/>" |
500 |
|
" <menuitem action='SelectAddPrevDimRgnZone'/>" |
501 |
|
" <menuitem action='SelectAddNextDimRgnZone'/>" |
502 |
|
" <separator/>" |
503 |
" <menuitem action='CopySampleUnity'/>" |
" <menuitem action='CopySampleUnity'/>" |
504 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
505 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
506 |
" </menu>" |
" </menu>" |
507 |
|
" <menu action='MenuMacro'>" |
508 |
|
" </menu>" |
509 |
" <menu action='MenuSample'>" |
" <menu action='MenuSample'>" |
510 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
511 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
524 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
525 |
" <menuitem action='MidiRules'/>" |
" <menuitem action='MidiRules'/>" |
526 |
" <menuitem action='ScriptSlots'/>" |
" <menuitem action='ScriptSlots'/>" |
527 |
|
" <menu action='AssignScripts'/>" |
528 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
529 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
530 |
|
" <menuitem action='CombInstruments'/>" |
531 |
" <separator/>" |
" <separator/>" |
532 |
" <menuitem action='RemoveInstrument'/>" |
" <menuitem action='RemoveInstrument'/>" |
533 |
" </menu>" |
" </menu>" |
564 |
" <menuitem action='ScriptSlots'/>" |
" <menuitem action='ScriptSlots'/>" |
565 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
566 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
567 |
|
" <menuitem action='CombInstruments'/>" |
568 |
" <separator/>" |
" <separator/>" |
569 |
" <menuitem action='RemoveInstrument'/>" |
" <menuitem action='RemoveInstrument'/>" |
570 |
" </popup>" |
" </popup>" |
659 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
660 |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
661 |
|
|
662 |
|
assign_scripts_menu = static_cast<Gtk::MenuItem*>( |
663 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu(); |
664 |
|
|
665 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
666 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
667 |
m_VBox.pack_start(m_HPaned); |
m_VBox.pack_start(m_HPaned); |
695 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
696 |
m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr); |
m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr); |
697 |
m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name); |
m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name); |
698 |
|
m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts); |
699 |
m_TreeView.set_headers_visible(true); |
m_TreeView.set_headers_visible(true); |
700 |
|
|
701 |
// establish drag&drop within the instrument tree view, allowing to reorder |
// establish drag&drop within the instrument tree view, allowing to reorder |
871 |
|
|
872 |
// select 'Instruments' tab by default |
// select 'Instruments' tab by default |
873 |
// (gtk allows this only if the tab childs are visible, thats why it's here) |
// (gtk allows this only if the tab childs are visible, thats why it's here) |
874 |
m_TreeViewNotebook.set_current_page(1); |
m_TreeViewNotebook.set_current_page(1); |
875 |
|
|
876 |
|
Gtk::Clipboard::get()->signal_owner_change().connect( |
877 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change) |
878 |
|
); |
879 |
|
updateClipboardPasteAvailable(); |
880 |
|
updateClipboardCopyAvailable(); |
881 |
|
|
882 |
|
// setup macros and their keyboard accelerators |
883 |
|
{ |
884 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
885 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
886 |
|
)->get_submenu(); |
887 |
|
|
888 |
|
const Gdk::ModifierType noModifier = (Gdk::ModifierType)0; |
889 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier); |
890 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier); |
891 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier); |
892 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier); |
893 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier); |
894 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier); |
895 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier); |
896 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier); |
897 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier); |
898 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier); |
899 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier); |
900 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier); |
901 |
|
Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey); |
902 |
|
|
903 |
|
Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group(); |
904 |
|
menuMacro->set_accel_group(accelGroup); |
905 |
|
|
906 |
|
updateMacroMenu(); |
907 |
|
} |
908 |
|
|
909 |
|
// setup "Assign Scripts" keyboard accelerators |
910 |
|
{ |
911 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK); |
912 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK); |
913 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK); |
914 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK); |
915 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK); |
916 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK); |
917 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK); |
918 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK); |
919 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK); |
920 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK); |
921 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK); |
922 |
|
Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK); |
923 |
|
|
924 |
|
Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group(); |
925 |
|
assign_scripts_menu->set_accel_group(accelGroup); |
926 |
|
} |
927 |
|
|
928 |
|
Glib::signal_idle().connect_once( |
929 |
|
sigc::mem_fun(*this, &MainWindow::bringToFront), |
930 |
|
200 |
931 |
|
); |
932 |
} |
} |
933 |
|
|
934 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
935 |
{ |
{ |
936 |
} |
} |
937 |
|
|
938 |
|
void MainWindow::bringToFront() { |
939 |
|
#if defined(__APPLE__) |
940 |
|
macRaiseAppWindow(); |
941 |
|
#endif |
942 |
|
raise(); |
943 |
|
present(); |
944 |
|
} |
945 |
|
|
946 |
|
void MainWindow::updateMacroMenu() { |
947 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
948 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
949 |
|
)->get_submenu(); |
950 |
|
|
951 |
|
// remove all entries from "Macro" menu |
952 |
|
{ |
953 |
|
const std::vector<Gtk::Widget*> children = menuMacro->get_children(); |
954 |
|
for (int i = 0; i < children.size(); ++i) { |
955 |
|
Gtk::Widget* child = children[i]; |
956 |
|
menuMacro->remove(*child); |
957 |
|
delete child; |
958 |
|
} |
959 |
|
} |
960 |
|
|
961 |
|
// (re)load all macros from config file |
962 |
|
try { |
963 |
|
Settings::singleton()->loadMacros(m_macros); |
964 |
|
} catch (Serialization::Exception e) { |
965 |
|
std::cerr << "Exception while loading macros: " << e.Message << std::endl; |
966 |
|
} catch (...) { |
967 |
|
std::cerr << "Unknown exception while loading macros!" << std::endl; |
968 |
|
} |
969 |
|
|
970 |
|
// add all configured macros as menu items to the "Macro" menu |
971 |
|
for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) { |
972 |
|
const Serialization::Archive& macro = m_macros[iMacro]; |
973 |
|
std::string name = |
974 |
|
macro.name().empty() ? |
975 |
|
(std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name(); |
976 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(name); |
977 |
|
item->signal_activate().connect( |
978 |
|
sigc::bind( |
979 |
|
sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro |
980 |
|
) |
981 |
|
); |
982 |
|
menuMacro->append(*item); |
983 |
|
item->set_accel_path("<Macros>/macro_" + ToString(iMacro)); |
984 |
|
Glib::ustring comment = macro.comment(); |
985 |
|
if (!comment.empty()) |
986 |
|
item->set_tooltip_text(comment); |
987 |
|
} |
988 |
|
// if there are no macros configured at all, then show a dummy entry instead |
989 |
|
if (m_macros.empty()) { |
990 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros")); |
991 |
|
item->set_sensitive(false); |
992 |
|
menuMacro->append(*item); |
993 |
|
} |
994 |
|
|
995 |
|
// add separator line to menu |
996 |
|
menuMacro->append(*new Gtk::SeparatorMenuItem); |
997 |
|
|
998 |
|
{ |
999 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ...")); |
1000 |
|
item->signal_activate().connect( |
1001 |
|
sigc::mem_fun(*this, &MainWindow::setupMacros) |
1002 |
|
); |
1003 |
|
menuMacro->append(*item); |
1004 |
|
item->set_accel_path("<Macros>/SetupMacros"); |
1005 |
|
} |
1006 |
|
|
1007 |
|
menuMacro->show_all_children(); |
1008 |
|
} |
1009 |
|
|
1010 |
|
void MainWindow::onMacroSelected(int iMacro) { |
1011 |
|
printf("onMacroSelected(%d)\n", iMacro); |
1012 |
|
if (iMacro < 0 || iMacro >= m_macros.size()) return; |
1013 |
|
Glib::ustring errorText; |
1014 |
|
try { |
1015 |
|
applyMacro(m_macros[iMacro]); |
1016 |
|
} catch (Serialization::Exception e) { |
1017 |
|
errorText = e.Message; |
1018 |
|
} catch (...) { |
1019 |
|
errorText = _("Unknown exception while applying macro"); |
1020 |
|
} |
1021 |
|
if (!errorText.empty()) { |
1022 |
|
Glib::ustring txt = _("Applying macro failed:\n") + errorText; |
1023 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1024 |
|
msg.run(); |
1025 |
|
} |
1026 |
|
} |
1027 |
|
|
1028 |
|
void MainWindow::setupMacros() { |
1029 |
|
MacrosSetup* setup = new MacrosSetup(); |
1030 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
1031 |
|
setup->setMacros(m_macros, &m_serializationArchive, pDimRgn); |
1032 |
|
setup->signal_macros_changed().connect( |
1033 |
|
sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged) |
1034 |
|
); |
1035 |
|
setup->show(); |
1036 |
|
} |
1037 |
|
|
1038 |
|
void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) { |
1039 |
|
m_macros = macros; |
1040 |
|
Settings::singleton()->saveMacros(m_macros); |
1041 |
|
updateMacroMenu(); |
1042 |
|
} |
1043 |
|
|
1044 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
1045 |
{ |
{ |
1046 |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
1105 |
add_region_to_dimregs(region, stereo, all_dimregs); |
add_region_to_dimregs(region, stereo, all_dimregs); |
1106 |
} |
} |
1107 |
} |
} |
1108 |
|
|
1109 |
|
m_RegionChooser.setModifyAllRegions(all_regions); |
1110 |
|
m_DimRegionChooser.setModifyAllRegions(all_regions); |
1111 |
|
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
1112 |
|
m_DimRegionChooser.setModifyBothChannels(stereo); |
1113 |
|
|
1114 |
|
updateClipboardCopyAvailable(); |
1115 |
} |
} |
1116 |
|
|
1117 |
void MainWindow::dimreg_all_dimregs_toggled() |
void MainWindow::dimreg_all_dimregs_toggled() |
1141 |
} |
} |
1142 |
} |
} |
1143 |
|
|
1144 |
|
updateScriptListOfMenu(); |
1145 |
|
|
1146 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
1147 |
|
|
1148 |
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
1273 |
// save the file as separate temporary file first, |
// save the file as separate temporary file first, |
1274 |
// then move the saved file over the old file |
// then move the saved file over the old file |
1275 |
// (may result in performance speedup during save) |
// (may result in performance speedup during save) |
1276 |
String tmpname = filename + ".TMP"; |
gig::String tmpname = filename + ".TMP"; |
1277 |
gig->Save(tmpname, &progress); |
gig->Save(tmpname, &progress); |
1278 |
#if defined(WIN32) |
#if defined(WIN32) |
1279 |
if (!DeleteFile(filename.c_str())) { |
if (!DeleteFile(filename.c_str())) { |
1281 |
} |
} |
1282 |
#else // POSIX ... |
#else // POSIX ... |
1283 |
if (unlink(filename.c_str())) { |
if (unlink(filename.c_str())) { |
1284 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno))); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno))); |
1285 |
} |
} |
1286 |
#endif |
#endif |
1287 |
if (rename(tmpname.c_str(), filename.c_str())) { |
if (rename(tmpname.c_str(), filename.c_str())) { |
1288 |
#if defined(WIN32) |
#if defined(WIN32) |
1289 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
1290 |
#else |
#else |
1291 |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno))); |
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno))); |
1292 |
#endif |
#endif |
1293 |
} |
} |
1294 |
} |
} |
1416 |
g_free(msg); |
g_free(msg); |
1417 |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
1418 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
1419 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1420 |
dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
1421 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
1422 |
int response = dialog.run(); |
int response = dialog.run(); |
1423 |
dialog.hide(); |
dialog.hide(); |
1448 |
"used by the sampler until you tell the sampler explicitly to " |
"used by the sampler until you tell the sampler explicitly to " |
1449 |
"load it.")); |
"load it.")); |
1450 |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
1451 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1452 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
1453 |
int response = dialog.run(); |
int response = dialog.run(); |
1454 |
dialog.hide(); |
dialog.hide(); |
1462 |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
1463 |
|
|
1464 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
1465 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1466 |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1467 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1468 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1469 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
1658 |
|
|
1659 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
1660 |
{ |
{ |
1661 |
Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
1662 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1663 |
dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
1664 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1665 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
1666 |
|
|
1746 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1747 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1748 |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1749 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1750 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1751 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",iter->second.sample_path.c_str()); |
1752 |
SF_INFO info; |
SF_INFO info; |
1753 |
info.format = 0; |
info.format = 0; |
1754 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info); |
1755 |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
1756 |
try { |
try { |
1757 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
1774 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1775 |
} |
} |
1776 |
|
|
1777 |
|
// reset write position for sample |
1778 |
|
iter->first->SetPos(0); |
1779 |
|
|
1780 |
const int bufsize = 10000; |
const int bufsize = 10000; |
1781 |
switch (bitdepth) { |
switch (bitdepth) { |
1782 |
case 16: { |
case 16: { |
1786 |
// libsndfile does the conversion for us (if needed) |
// libsndfile does the conversion for us (if needed) |
1787 |
int n = sf_readf_short(hFile, buffer, bufsize); |
int n = sf_readf_short(hFile, buffer, bufsize); |
1788 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1789 |
iter->gig_sample->Write(buffer, n); |
iter->first->Write(buffer, n); |
1790 |
cnt -= n; |
cnt -= n; |
1791 |
} |
} |
1792 |
delete[] buffer; |
delete[] buffer; |
1806 |
dstbuf[j++] = srcbuf[i] >> 24; |
dstbuf[j++] = srcbuf[i] >> 24; |
1807 |
} |
} |
1808 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1809 |
iter->gig_sample->Write(dstbuf, n); |
iter->first->Write(dstbuf, n); |
1810 |
cnt -= n; |
cnt -= n; |
1811 |
} |
} |
1812 |
delete[] srcbuf; |
delete[] srcbuf; |
1817 |
// cleanup |
// cleanup |
1818 |
sf_close(hFile); |
sf_close(hFile); |
1819 |
// let the sampler re-cache the sample if needed |
// let the sampler re-cache the sample if needed |
1820 |
sample_changed_signal.emit(iter->gig_sample); |
sample_changed_signal.emit(iter->first); |
1821 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
1822 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
1823 |
std::list<SampleImportItem>::iterator cur = iter; |
std::map<gig::Sample*, SampleImportItem>::iterator cur = iter; |
1824 |
++iter; |
++iter; |
1825 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
1826 |
} catch (std::string what) { |
} catch (std::string what) { |
1827 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
1828 |
if (!error_files.empty()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1829 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += iter->second.sample_path += " (" + what + ")"; |
1830 |
++iter; |
++iter; |
1831 |
} |
} |
1832 |
} |
} |
1868 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1869 |
#endif |
#endif |
1870 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1871 |
dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson"); |
1872 |
const std::string sComment = |
const std::string sComment = |
1873 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1874 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1884 |
dialog.set_comments(sComment.c_str()); |
dialog.set_comments(sComment.c_str()); |
1885 |
dialog.set_website("http://www.linuxsampler.org"); |
dialog.set_website("http://www.linuxsampler.org"); |
1886 |
dialog.set_website_label("http://www.linuxsampler.org"); |
dialog.set_website_label("http://www.linuxsampler.org"); |
1887 |
|
dialog.set_position(Gtk::WIN_POS_CENTER); |
1888 |
dialog.run(); |
dialog.run(); |
1889 |
} |
} |
1890 |
|
|
1906 |
eSourceForm(_("Source form")), |
eSourceForm(_("Source form")), |
1907 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1908 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1909 |
quitButton(_("_Close"), true), |
quitButton(Gtk::Stock::CLOSE), |
1910 |
table(2, 1), |
table(2, 1), |
1911 |
m_file(NULL) |
m_file(NULL) |
1912 |
{ |
{ |
1913 |
|
if (!Settings::singleton()->autoRestoreWindowDimension) { |
1914 |
|
set_default_size(470, 390); |
1915 |
|
set_position(Gtk::WIN_POS_MOUSE); |
1916 |
|
} |
1917 |
|
|
1918 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
1919 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
1920 |
|
|
2034 |
} |
} |
2035 |
|
|
2036 |
InstrumentProps::InstrumentProps() : |
InstrumentProps::InstrumentProps() : |
2037 |
quitButton(_("_Close"), true), |
quitButton(Gtk::Stock::CLOSE), |
2038 |
table(2,1), |
table(2,1), |
2039 |
eName(_("Name")), |
eName(_("Name")), |
2040 |
eIsDrum(_("Is drum")), |
eIsDrum(_("Is drum")), |
2049 |
eDimensionKeyRangeLow(_("Keyswitching range low")), |
eDimensionKeyRangeLow(_("Keyswitching range low")), |
2050 |
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
2051 |
{ |
{ |
2052 |
|
if (!Settings::singleton()->autoRestoreWindowDimension) { |
2053 |
|
//set_default_size(470, 390); |
2054 |
|
set_position(Gtk::WIN_POS_MOUSE); |
2055 |
|
} |
2056 |
|
|
2057 |
set_title(_("Instrument Properties")); |
set_title(_("Instrument Properties")); |
2058 |
|
|
2059 |
eDimensionKeyRangeLow.set_tip( |
eDimensionKeyRangeLow.set_tip( |
2178 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
2179 |
instrument = gig->GetNextInstrument(), ++index) { |
instrument = gig->GetNextInstrument(), ++index) { |
2180 |
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
2181 |
|
const int iScriptSlots = instrument->ScriptSlotCount(); |
2182 |
|
|
2183 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
2184 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
2185 |
row[m_Columns.m_col_nr] = index; |
row[m_Columns.m_col_nr] = index; |
2186 |
row[m_Columns.m_col_name] = name; |
row[m_Columns.m_col_name] = name; |
2187 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
2188 |
|
row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : ""; |
2189 |
|
|
2190 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
2191 |
} |
} |
2324 |
|
|
2325 |
ScriptSlots* window = new ScriptSlots; |
ScriptSlots* window = new ScriptSlots; |
2326 |
window->setInstrument(instrument); |
window->setInstrument(instrument); |
2327 |
|
window->signal_script_slots_changed().connect( |
2328 |
|
sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified) |
2329 |
|
); |
2330 |
//window->reparent(*this); |
//window->reparent(*this); |
2331 |
window->show(); |
window->show(); |
2332 |
} |
} |
2333 |
|
|
2334 |
|
void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) { |
2335 |
|
if (!pInstrument) return; |
2336 |
|
const int iScriptSlots = pInstrument->ScriptSlotCount(); |
2337 |
|
|
2338 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2339 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2340 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2341 |
|
if (row[m_Columns.m_col_instr] != pInstrument) continue; |
2342 |
|
row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : ""; |
2343 |
|
break; |
2344 |
|
} |
2345 |
|
|
2346 |
|
// causes the sampler to reload the instrument with the new script |
2347 |
|
on_sel_change(); |
2348 |
|
} |
2349 |
|
|
2350 |
|
void MainWindow::assignScript(gig::Script* pScript) { |
2351 |
|
if (!pScript) { |
2352 |
|
printf("assignScript() : !script\n"); |
2353 |
|
return; |
2354 |
|
} |
2355 |
|
printf("assignScript('%s')\n", pScript->Name.c_str()); |
2356 |
|
|
2357 |
|
gig::Instrument* pInstrument = get_instrument(); |
2358 |
|
if (!pInstrument) { |
2359 |
|
printf("!instrument\n"); |
2360 |
|
return; |
2361 |
|
} |
2362 |
|
|
2363 |
|
pInstrument->AddScriptSlot(pScript); |
2364 |
|
|
2365 |
|
onScriptSlotsModified(pInstrument); |
2366 |
|
} |
2367 |
|
|
2368 |
void MainWindow::on_action_refresh_all() { |
void MainWindow::on_action_refresh_all() { |
2369 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
2370 |
} |
} |
2637 |
} |
} |
2638 |
} |
} |
2639 |
|
|
2640 |
|
void MainWindow::updateScriptListOfMenu() { |
2641 |
|
// remove all entries from "Assign Script" menu |
2642 |
|
{ |
2643 |
|
const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children(); |
2644 |
|
for (int i = 0; i < children.size(); ++i) { |
2645 |
|
Gtk::Widget* child = children[i]; |
2646 |
|
assign_scripts_menu->remove(*child); |
2647 |
|
delete child; |
2648 |
|
} |
2649 |
|
} |
2650 |
|
|
2651 |
|
int iTotalScripts = 0; |
2652 |
|
|
2653 |
|
if (!file) goto noScripts; |
2654 |
|
|
2655 |
|
// add all configured macros as menu items to the "Macro" menu |
2656 |
|
for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) { |
2657 |
|
gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup); |
2658 |
|
for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) { |
2659 |
|
gig::Script* pScript = pGroup->GetScript(iScript); |
2660 |
|
std::string name = pScript->Name; |
2661 |
|
|
2662 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(name); |
2663 |
|
item->signal_activate().connect( |
2664 |
|
sigc::bind( |
2665 |
|
sigc::mem_fun(*this, &MainWindow::assignScript), pScript |
2666 |
|
) |
2667 |
|
); |
2668 |
|
assign_scripts_menu->append(*item); |
2669 |
|
item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts)); |
2670 |
|
//item->set_tooltip_text(comment); |
2671 |
|
} |
2672 |
|
} |
2673 |
|
|
2674 |
|
noScripts: |
2675 |
|
|
2676 |
|
// if there are no macros configured at all, then show a dummy entry instead |
2677 |
|
if (!iTotalScripts) { |
2678 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts")); |
2679 |
|
item->set_sensitive(false); |
2680 |
|
assign_scripts_menu->append(*item); |
2681 |
|
} |
2682 |
|
|
2683 |
|
assign_scripts_menu->show_all_children(); |
2684 |
|
} |
2685 |
|
|
2686 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
2687 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
2688 |
|
|
2725 |
rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1; |
rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1; |
2726 |
rowInstr[m_Columns.m_col_name] = name; |
rowInstr[m_Columns.m_col_name] = name; |
2727 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
2728 |
|
rowInstr[m_Columns.m_col_scripts] = ""; |
2729 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
2730 |
|
|
2731 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
2732 |
|
select_instrument(instrument); |
|
m_TreeView.get_selection()->select(iterInstr); |
|
|
|
|
2733 |
file_changed(); |
file_changed(); |
2734 |
} |
} |
2735 |
|
|
3012 |
|
|
3013 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
3014 |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
3015 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
3016 |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
3017 |
dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample |
dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample |
3018 |
|
|
3019 |
// matches all file types supported by libsndfile |
// matches all file types supported by libsndfile |
3143 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
3144 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
3145 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
3146 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
3147 |
// add sample to the tree view |
// add sample to the tree view |
3148 |
if (replace) { |
if (replace) { |
3149 |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
3213 |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
3214 |
description.show(); |
description.show(); |
3215 |
entryArea.show_all(); |
entryArea.show_all(); |
3216 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
3217 |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
3218 |
dialog.set_select_multiple(false); |
dialog.set_select_multiple(false); |
3219 |
if (current_sample_dir != "") { |
if (current_sample_dir != "") { |
3253 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
3254 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
3255 |
sched_item.sample_path = filename; |
sched_item.sample_path = filename; |
3256 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
3257 |
sf_close(hFile); |
sf_close(hFile); |
3258 |
file_changed(); |
file_changed(); |
3259 |
} |
} |
3305 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
3306 |
// them from the import queue |
// them from the import queue |
3307 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
3308 |
member != members.end(); ++member) { |
member != members.end(); ++member) |
3309 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
{ |
3310 |
iter != m_SampleImportQueue.end(); ++iter) { |
if (m_SampleImportQueue.count(*member)) { |
3311 |
if ((*iter).gig_sample == *member) { |
printf("Removing previously added sample '%s' from group '%s'\n", |
3312 |
printf("Removing previously added sample '%s' from group '%s'\n", |
m_SampleImportQueue[sample].sample_path.c_str(), name.c_str()); |
3313 |
(*iter).sample_path.c_str(), name.c_str()); |
m_SampleImportQueue.erase(*member); |
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3314 |
} |
} |
3315 |
} |
} |
3316 |
file_changed(); |
file_changed(); |
3325 |
samples_removed_signal.emit(); |
samples_removed_signal.emit(); |
3326 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
3327 |
// the import queue |
// the import queue |
3328 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3329 |
iter != m_SampleImportQueue.end(); ++iter) { |
printf("Removing previously added sample '%s'\n", |
3330 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue[sample].sample_path.c_str()); |
3331 |
printf("Removing previously added sample '%s'\n", |
m_SampleImportQueue.erase(sample); |
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3332 |
} |
} |
3333 |
dimreg_changed(); |
dimreg_changed(); |
3334 |
file_changed(); |
file_changed(); |
3384 |
gig::Sample* sample = *itSample; |
gig::Sample* sample = *itSample; |
3385 |
// remove sample from the .gig file |
// remove sample from the .gig file |
3386 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
3387 |
// if sample was just previously added, remove it fro the import queue |
// if sample was just previously added, remove it from the import queue |
3388 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3389 |
iter != m_SampleImportQueue.end(); ++iter) |
printf("Removing previously added sample '%s'\n", |
3390 |
{ |
m_SampleImportQueue[sample].sample_path.c_str()); |
3391 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue.erase(sample); |
|
printf("Removing previously added sample '%s'\n", |
|
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3392 |
} |
} |
3393 |
} |
} |
3394 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
3701 |
|
|
3702 |
void MainWindow::on_action_combine_instruments() { |
void MainWindow::on_action_combine_instruments() { |
3703 |
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); |
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); |
3704 |
|
|
3705 |
|
// take over selection from instruments list view for the combine dialog's |
3706 |
|
// list view as pre-selection |
3707 |
|
std::set<int> indeces; |
3708 |
|
{ |
3709 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
3710 |
|
std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows(); |
3711 |
|
for (int r = 0; r < rows.size(); ++r) { |
3712 |
|
Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); |
3713 |
|
if (it) { |
3714 |
|
Gtk::TreeModel::Row row = *it; |
3715 |
|
int index = row[m_Columns.m_col_nr]; |
3716 |
|
indeces.insert(index); |
3717 |
|
} |
3718 |
|
} |
3719 |
|
} |
3720 |
|
d->setSelectedInstruments(indeces); |
3721 |
|
|
3722 |
d->show_all(); |
d->show_all(); |
|
d->resize(500, 400); |
|
3723 |
d->run(); |
d->run(); |
3724 |
if (d->fileWasChanged()) { |
if (d->fileWasChanged()) { |
3725 |
// update GUI with new instrument just created |
// update GUI with new instrument just created |
3854 |
} |
} |
3855 |
|
|
3856 |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
3857 |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
3858 |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
3859 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
3860 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
3981 |
m_TreeViewNotebook.set_current_page(2); |
m_TreeViewNotebook.set_current_page(2); |
3982 |
} |
} |
3983 |
|
|
3984 |
|
void MainWindow::select_instrument_by_dir(int dir) { |
3985 |
|
if (!file) return; |
3986 |
|
gig::Instrument* pInstrument = get_instrument(); |
3987 |
|
if (!pInstrument) { |
3988 |
|
select_instrument( file->GetInstrument(0) ); |
3989 |
|
return; |
3990 |
|
} |
3991 |
|
for (int i = 0; file->GetInstrument(i); ++i) { |
3992 |
|
if (file->GetInstrument(i) == pInstrument) { |
3993 |
|
select_instrument( file->GetInstrument(i + dir) ); |
3994 |
|
return; |
3995 |
|
} |
3996 |
|
} |
3997 |
|
} |
3998 |
|
|
3999 |
|
void MainWindow::select_prev_instrument() { |
4000 |
|
select_instrument_by_dir(-1); |
4001 |
|
} |
4002 |
|
|
4003 |
|
void MainWindow::select_next_instrument() { |
4004 |
|
select_instrument_by_dir(1); |
4005 |
|
} |
4006 |
|
|
4007 |
|
void MainWindow::select_prev_region() { |
4008 |
|
m_RegionChooser.select_prev_region(); |
4009 |
|
} |
4010 |
|
|
4011 |
|
void MainWindow::select_next_region() { |
4012 |
|
m_RegionChooser.select_next_region(); |
4013 |
|
} |
4014 |
|
|
4015 |
|
void MainWindow::select_next_dim_rgn_zone() { |
4016 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
4017 |
|
m_DimRegionChooser.select_next_dimzone(); |
4018 |
|
} |
4019 |
|
|
4020 |
|
void MainWindow::select_prev_dim_rgn_zone() { |
4021 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
4022 |
|
m_DimRegionChooser.select_prev_dimzone(); |
4023 |
|
} |
4024 |
|
|
4025 |
|
void MainWindow::select_add_next_dim_rgn_zone() { |
4026 |
|
m_DimRegionChooser.select_next_dimzone(true); |
4027 |
|
} |
4028 |
|
|
4029 |
|
void MainWindow::select_add_prev_dim_rgn_zone() { |
4030 |
|
m_DimRegionChooser.select_prev_dimzone(true); |
4031 |
|
} |
4032 |
|
|
4033 |
|
void MainWindow::select_prev_dimension() { |
4034 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
4035 |
|
m_DimRegionChooser.select_prev_dimension(); |
4036 |
|
} |
4037 |
|
|
4038 |
|
void MainWindow::select_next_dimension() { |
4039 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
4040 |
|
m_DimRegionChooser.select_next_dimension(); |
4041 |
|
} |
4042 |
|
|
4043 |
|
#define CLIPBOARD_DIMENSIONREGION_TARGET \ |
4044 |
|
("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat()) |
4045 |
|
|
4046 |
|
void MainWindow::copy_selected_dimrgn() { |
4047 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
4048 |
|
if (!pDimRgn) { |
4049 |
|
updateClipboardPasteAvailable(); |
4050 |
|
updateClipboardCopyAvailable(); |
4051 |
|
return; |
4052 |
|
} |
4053 |
|
|
4054 |
|
std::vector<Gtk::TargetEntry> targets; |
4055 |
|
targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) ); |
4056 |
|
|
4057 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
4058 |
|
clipboard->set( |
4059 |
|
targets, |
4060 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_get), |
4061 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_clear) |
4062 |
|
); |
4063 |
|
|
4064 |
|
m_serializationArchive.serialize(pDimRgn); |
4065 |
|
|
4066 |
|
updateClipboardPasteAvailable(); |
4067 |
|
} |
4068 |
|
|
4069 |
|
void MainWindow::paste_copied_dimrgn() { |
4070 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
4071 |
|
clipboard->request_contents( |
4072 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, |
4073 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received) |
4074 |
|
); |
4075 |
|
updateClipboardPasteAvailable(); |
4076 |
|
} |
4077 |
|
|
4078 |
|
void MainWindow::adjust_clipboard_content() { |
4079 |
|
MacroEditor* editor = new MacroEditor(); |
4080 |
|
editor->setMacro(&m_serializationArchive, true); |
4081 |
|
editor->show(); |
4082 |
|
} |
4083 |
|
|
4084 |
|
void MainWindow::updateClipboardPasteAvailable() { |
4085 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
4086 |
|
clipboard->request_targets( |
4087 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets) |
4088 |
|
); |
4089 |
|
} |
4090 |
|
|
4091 |
|
void MainWindow::updateClipboardCopyAvailable() { |
4092 |
|
bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion(); |
4093 |
|
static_cast<Gtk::MenuItem*>( |
4094 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn") |
4095 |
|
)->set_sensitive(bDimensionRegionCopyIsPossible); |
4096 |
|
} |
4097 |
|
|
4098 |
|
void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) { |
4099 |
|
updateClipboardPasteAvailable(); |
4100 |
|
} |
4101 |
|
|
4102 |
|
void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) { |
4103 |
|
const std::string target = selection_data.get_target(); |
4104 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
4105 |
|
selection_data.set( |
4106 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/, |
4107 |
|
&m_serializationArchive.rawData()[0], |
4108 |
|
m_serializationArchive.rawData().size() |
4109 |
|
); |
4110 |
|
} else { |
4111 |
|
std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n"; |
4112 |
|
} |
4113 |
|
} |
4114 |
|
|
4115 |
|
void MainWindow::on_clipboard_clear() { |
4116 |
|
m_serializationArchive.clear(); |
4117 |
|
updateClipboardPasteAvailable(); |
4118 |
|
updateClipboardCopyAvailable(); |
4119 |
|
} |
4120 |
|
|
4121 |
|
//NOTE: Might throw exception !!! |
4122 |
|
void MainWindow::applyMacro(Serialization::Archive& macro) { |
4123 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
4124 |
|
if (!pDimRgn) return; |
4125 |
|
|
4126 |
|
for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin(); |
4127 |
|
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) |
4128 |
|
{ |
4129 |
|
gig::DimensionRegion* pDimRgn = *itDimReg; |
4130 |
|
DimRegionChangeGuard(this, pDimRgn); |
4131 |
|
macro.deserialize(pDimRgn); |
4132 |
|
} |
4133 |
|
//region_changed() |
4134 |
|
file_changed(); |
4135 |
|
dimreg_changed(); |
4136 |
|
} |
4137 |
|
|
4138 |
|
void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { |
4139 |
|
const std::string target = selection_data.get_target(); |
4140 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
4141 |
|
Glib::ustring errorText; |
4142 |
|
try { |
4143 |
|
m_serializationArchive.decode( |
4144 |
|
selection_data.get_data(), selection_data.get_length() |
4145 |
|
); |
4146 |
|
applyMacro(m_serializationArchive); |
4147 |
|
} catch (Serialization::Exception e) { |
4148 |
|
errorText = e.Message; |
4149 |
|
} catch (...) { |
4150 |
|
errorText = _("Unknown exception while pasting DimensionRegion"); |
4151 |
|
} |
4152 |
|
if (!errorText.empty()) { |
4153 |
|
Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; |
4154 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
4155 |
|
msg.run(); |
4156 |
|
} |
4157 |
|
} |
4158 |
|
} |
4159 |
|
|
4160 |
|
void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) { |
4161 |
|
const bool bDimensionRegionPasteIsPossible = |
4162 |
|
std::find(targets.begin(), targets.end(), |
4163 |
|
CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end(); |
4164 |
|
|
4165 |
|
static_cast<Gtk::MenuItem*>( |
4166 |
|
uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn") |
4167 |
|
)->set_sensitive(bDimensionRegionPasteIsPossible); |
4168 |
|
|
4169 |
|
static_cast<Gtk::MenuItem*>( |
4170 |
|
uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard") |
4171 |
|
)->set_sensitive(bDimensionRegionPasteIsPossible); |
4172 |
|
} |
4173 |
|
|
4174 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
4175 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
4176 |
} |
} |