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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3368 - (show annotations) (download)
Thu Nov 16 19:18:42 2017 UTC (2 years, 4 months ago) by schoenebeck
File size: 205438 byte(s)
* Visual cosmetics on Gtk 3.
* Script Editor: Use consistent font size on all screens and DPI settings.
* Bumped version (1.0.0.svn65).

1 /*
2 * Copyright (C) 2006-2017 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 #include <iostream>
21 #include <cstring>
22
23 #include "compat.h"
24 // threads.h must be included first to be able to build with
25 // G_DISABLE_DEPRECATED
26 #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27 (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28 #include <glibmm/threads.h>
29 #endif
30
31 #include <glibmm/convert.h>
32 #include <glibmm/dispatcher.h>
33 #include <glibmm/miscutils.h>
34 #include <glibmm/stringutils.h>
35 #include <glibmm/regex.h>
36 #include <gtkmm/aboutdialog.h>
37 #include <gtkmm/filechooserdialog.h>
38 #include <gtkmm/messagedialog.h>
39 #if HAS_GTKMM_STOCK
40 # include <gtkmm/stock.h>
41 #endif
42 #include <gtkmm/targetentry.h>
43 #include <gtkmm/main.h>
44 #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89)
45 # include <gtkmm/toggleaction.h>
46 #endif
47 #include <gtkmm/accelmap.h>
48 #if GTKMM_MAJOR_VERSION < 3
49 #include "wrapLabel.hh"
50 #endif
51
52 #include "global.h"
53 #include "compat.h"
54
55 #include <stdio.h>
56 #ifdef LIBSNDFILE_HEADER_FILE
57 # include LIBSNDFILE_HEADER_FILE(sndfile.h)
58 #else
59 # include <sndfile.h>
60 #endif
61 #include <assert.h>
62
63 #include "mainwindow.h"
64 #include "Settings.h"
65 #include "CombineInstrumentsDialog.h"
66 #include "scripteditor.h"
67 #include "scriptslots.h"
68 #include "ReferencesView.h"
69 #include "../../gfx/status_attached.xpm"
70 #include "../../gfx/status_detached.xpm"
71 #include "gfx/builtinpix.h"
72 #include "MacroEditor.h"
73 #include "MacrosSetup.h"
74 #if defined(__APPLE__)
75 # include "MacHelper.h"
76 #endif
77
78 static const Gdk::ModifierType primaryModifierKey =
79 #if defined(__APPLE__)
80 Gdk::META_MASK; // Cmd key on Mac
81 #else
82 Gdk::CONTROL_MASK; // Ctrl key on all other OSs
83 #endif
84
85 MainWindow::MainWindow() :
86 m_DimRegionChooser(*this),
87 dimreg_label(_("Changes apply to:")),
88 dimreg_all_regions(_("all regions")),
89 dimreg_all_dimregs(_("all dimension splits")),
90 dimreg_stereo(_("both channels")),
91 labelLegend(_("Legend:")),
92 labelNoSample(_(" No Sample")),
93 labelMissingSample(_(" Missing some Sample(s)")),
94 labelLooped(_(" Looped")),
95 labelSomeLoops(_(" Some Loop(s)"))
96 {
97 loadBuiltInPix();
98
99 this->file = NULL;
100
101 // set_border_width(5);
102
103 if (!Settings::singleton()->autoRestoreWindowDimension) {
104 #if GTKMM_MAJOR_VERSION >= 3
105 set_default_size(895, 600);
106 #else
107 set_default_size(800, 600);
108 #endif
109 set_position(Gtk::WIN_POS_CENTER);
110 }
111
112 add(m_VBox);
113
114 // Handle selection
115 m_TreeView.get_selection()->signal_changed().connect(
116 sigc::mem_fun(*this, &MainWindow::on_sel_change));
117
118 // m_TreeView.set_reorderable();
119
120 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
121 m_TreeView.signal_button_press_event().connect(
122 sigc::mem_fun(*this, &MainWindow::on_button_release));
123 #else
124 m_TreeView.signal_button_press_event().connect_notify(
125 sigc::mem_fun(*this, &MainWindow::on_button_release));
126 #endif
127
128 // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
129 m_ScrolledWindow.add(m_TreeView);
130 // m_ScrolledWindow.set_size_request(200, 600);
131 m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132
133 m_ScrolledWindowSamples.add(m_TreeViewSamples);
134 m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
135
136 m_ScrolledWindowScripts.add(m_TreeViewScripts);
137 m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138
139 #if GTKMM_MAJOR_VERSION < 3
140 m_TreeViewNotebook.set_size_request(300);
141 #endif
142
143 m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
144 m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
145 m_searchField.pack_start(m_searchText);
146 m_searchField.set_spacing(5);
147
148 m_left_vbox.pack_start(m_TreeViewNotebook);
149 m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
150
151 m_HPaned.add1(m_left_vbox);
152
153 dimreg_hbox.add(dimreg_label);
154 dimreg_hbox.add(dimreg_all_regions);
155 dimreg_hbox.add(dimreg_all_dimregs);
156 dimreg_stereo.set_active();
157 dimreg_hbox.add(dimreg_stereo);
158 dimreg_vbox.add(dimreg_edit);
159 dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
160 {
161 legend_hbox.add(labelLegend);
162
163 imageNoSample.set(redDot);
164 #if HAS_GTKMM_ALIGNMENT
165 imageNoSample.set_alignment(Gtk::ALIGN_END);
166 labelNoSample.set_alignment(Gtk::ALIGN_START);
167 #else
168 imageNoSample.set_halign(Gtk::ALIGN_END);
169 labelNoSample.set_halign(Gtk::ALIGN_START);
170 #endif
171 legend_hbox.add(imageNoSample);
172 legend_hbox.add(labelNoSample);
173
174 imageMissingSample.set(yellowDot);
175 #if HAS_GTKMM_ALIGNMENT
176 imageMissingSample.set_alignment(Gtk::ALIGN_END);
177 labelMissingSample.set_alignment(Gtk::ALIGN_START);
178 #else
179 imageMissingSample.set_halign(Gtk::ALIGN_END);
180 labelMissingSample.set_halign(Gtk::ALIGN_START);
181 #endif
182 legend_hbox.add(imageMissingSample);
183 legend_hbox.add(labelMissingSample);
184
185 imageLooped.set(blackLoop);
186 #if HAS_GTKMM_ALIGNMENT
187 imageLooped.set_alignment(Gtk::ALIGN_END);
188 labelLooped.set_alignment(Gtk::ALIGN_START);
189 #else
190 imageLooped.set_halign(Gtk::ALIGN_END);
191 labelLooped.set_halign(Gtk::ALIGN_START);
192 #endif
193 legend_hbox.add(imageLooped);
194 legend_hbox.add(labelLooped);
195
196 imageSomeLoops.set(grayLoop);
197 #if HAS_GTKMM_ALIGNMENT
198 imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199 labelSomeLoops.set_alignment(Gtk::ALIGN_START);
200 #else
201 imageSomeLoops.set_halign(Gtk::ALIGN_END);
202 labelSomeLoops.set_halign(Gtk::ALIGN_START);
203 #endif
204 legend_hbox.add(imageSomeLoops);
205 legend_hbox.add(labelSomeLoops);
206
207 #if HAS_GTKMM_SHOW_ALL_CHILDREN
208 legend_hbox.show_all_children();
209 #endif
210 }
211 dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212 m_HPaned.add2(dimreg_vbox);
213
214 dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
215 dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
216 dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
217 dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
218
219 m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
220 m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221 m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
222
223 #if USE_GLIB_ACTION
224 m_actionGroup = Gio::SimpleActionGroup::create();
225 m_actionGroup->add_action(
226 "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
227 );
228 m_actionGroup->add_action(
229 "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
230 );
231 m_actionGroup->add_action(
232 "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
233 );
234 m_actionGroup->add_action(
235 "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
236 );
237 m_actionGroup->add_action(
238 "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
239 );
240 m_actionGroup->add_action(
241 "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
242 );
243 m_actionMIDIRules = m_actionGroup->add_action(
244 "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
245 );
246 m_actionGroup->add_action(
247 "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
248 );
249 m_actionGroup->add_action(
250 "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
251 );
252 m_actionGroup->add_action(
253 "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
254 );
255 m_actionGroup->add_action(
256 "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
257 );
258 m_actionGroup->add_action(
259 "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
260 );
261 #else
262 actionGroup = Gtk::ActionGroup::create();
263
264 actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
265 actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
266 sigc::mem_fun(
267 *this, &MainWindow::on_action_file_new));
268 Glib::RefPtr<Gtk::Action> action =
269 Gtk::Action::create("Open", Gtk::Stock::OPEN);
270 action->property_label() = action->property_label() + "...";
271 actionGroup->add(action,
272 sigc::mem_fun(
273 *this, &MainWindow::on_action_file_open));
274 actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
275 sigc::mem_fun(
276 *this, &MainWindow::on_action_file_save));
277 action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
278 action->property_label() = action->property_label() + "...";
279 actionGroup->add(action,
280 Gtk::AccelKey("<shift><control>s"),
281 sigc::mem_fun(
282 *this, &MainWindow::on_action_file_save_as));
283 actionGroup->add(Gtk::Action::create("Properties",
284 Gtk::Stock::PROPERTIES),
285 sigc::mem_fun(
286 *this, &MainWindow::on_action_file_properties));
287 actionGroup->add(Gtk::Action::create("InstrProperties",
288 Gtk::Stock::PROPERTIES),
289 sigc::mem_fun(
290 *this, &MainWindow::show_instr_props));
291 actionGroup->add(Gtk::Action::create("MidiRules",
292 _("_Midi Rules...")),
293 sigc::mem_fun(
294 *this, &MainWindow::show_midi_rules));
295 actionGroup->add(Gtk::Action::create("ScriptSlots",
296 _("_Script Slots...")),
297 sigc::mem_fun(
298 *this, &MainWindow::show_script_slots));
299 actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
300 sigc::mem_fun(
301 *this, &MainWindow::on_action_quit));
302 actionGroup->add(
303 Gtk::Action::create("MenuSample", _("_Sample")),
304 sigc::mem_fun(*this, &MainWindow::show_samples_tab)
305 );
306 actionGroup->add(
307 Gtk::Action::create("MenuInstrument", _("_Instrument")),
308 sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309 );
310 actionGroup->add(
311 Gtk::Action::create("MenuScript", _("Scr_ipt")),
312 sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313 );
314 actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
315 actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
316
317 actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
318 #endif
319
320 const Gdk::ModifierType primaryModifierKey =
321 #if defined(__APPLE__)
322 Gdk::META_MASK; // Cmd key on Mac
323 #else
324 Gdk::CONTROL_MASK; // Ctrl key on all other OSs
325 #endif
326
327 #if USE_GLIB_ACTION
328 m_actionCopyDimRgn = m_actionGroup->add_action(
329 "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)
330 );
331 m_actionPasteDimRgn = m_actionGroup->add_action(
332 "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)
333 );
334 m_actionAdjustClipboard = m_actionGroup->add_action(
335 "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)
336 );
337 m_actionGroup->add_action(
338 "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument)
339 );
340 m_actionGroup->add_action(
341 "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument)
342 );
343 m_actionGroup->add_action(
344 "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region)
345 );
346 m_actionGroup->add_action(
347 "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region)
348 );
349 m_actionGroup->add_action(
350 "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)
351 );
352 m_actionGroup->add_action(
353 "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)
354 );
355 m_actionGroup->add_action(
356 "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension)
357 );
358 m_actionGroup->add_action(
359 "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension)
360 );
361 m_actionGroup->add_action(
362 "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)
363 );
364 m_actionGroup->add_action(
365 "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)
366 );
367 #else
368 actionGroup->add(Gtk::Action::create("CopyDimRgn",
369 _("Copy selected dimension region")),
370 Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
371 sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
372
373 actionGroup->add(Gtk::Action::create("PasteDimRgn",
374 _("Paste dimension region")),
375 Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
376 sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
377
378 actionGroup->add(Gtk::Action::create("AdjustClipboard",
379 _("Adjust Clipboard Content")),
380 Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
381 sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
382
383 actionGroup->add(Gtk::Action::create("SelectPrevInstr",
384 _("Select Previous Instrument")),
385 Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
386 sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
387
388 actionGroup->add(Gtk::Action::create("SelectNextInstr",
389 _("Select Next Instrument")),
390 Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
391 sigc::mem_fun(*this, &MainWindow::select_next_instrument));
392
393 actionGroup->add(Gtk::Action::create("SelectPrevRegion",
394 _("Select Previous Region")),
395 Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
396 sigc::mem_fun(*this, &MainWindow::select_prev_region));
397
398 actionGroup->add(Gtk::Action::create("SelectNextRegion",
399 _("Select Next Region")),
400 Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
401 sigc::mem_fun(*this, &MainWindow::select_next_region));
402
403 actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
404 _("Select Previous Dimension Region Zone")),
405 Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
406 sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
407
408 actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
409 _("Select Next Dimension Region Zone")),
410 Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
411 sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
412
413 actionGroup->add(Gtk::Action::create("SelectPrevDimension",
414 _("Select Previous Dimension")),
415 Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
416 sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
417
418 actionGroup->add(Gtk::Action::create("SelectNextDimension",
419 _("Select Next Dimension")),
420 Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
421 sigc::mem_fun(*this, &MainWindow::select_next_dimension));
422
423 actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
424 _("Add Previous Dimension Region Zone to Selection")),
425 Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
426 sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
427
428 actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
429 _("Add Next Dimension Region Zone to Selection")),
430 Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
431 sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
432 #endif
433
434 #if USE_GLIB_ACTION
435 m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true);
436 m_actionToggleCopySampleTune = m_actionGroup->add_action_bool("CopySampleTune", true);
437 m_actionToggleCopySampleLoop = m_actionGroup->add_action_bool("CopySampleLoop", true);
438 #else
439 Glib::RefPtr<Gtk::ToggleAction> toggle_action =
440 Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
441 toggle_action->set_active(true);
442 actionGroup->add(toggle_action);
443
444 toggle_action =
445 Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
446 toggle_action->set_active(true);
447 actionGroup->add(toggle_action);
448
449 toggle_action =
450 Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451 toggle_action->set_active(true);
452 actionGroup->add(toggle_action);
453 #endif
454
455 #if USE_GLIB_ACTION
456 m_actionToggleStatusBar =
457 m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458 m_actionToggleRestoreWinDim =
459 m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460 m_actionToggleSaveWithTempFile =
461 m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
462 m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
463 #else
464 actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
465
466
467 actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
468 toggle_action =
469 Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
470 toggle_action->set_active(true);
471 actionGroup->add(toggle_action,
472 sigc::mem_fun(
473 *this, &MainWindow::on_action_view_status_bar));
474
475 toggle_action =
476 Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
477 toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
478 actionGroup->add(toggle_action,
479 sigc::mem_fun(
480 *this, &MainWindow::on_auto_restore_win_dim));
481
482 toggle_action =
483 Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
484 toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
485 actionGroup->add(toggle_action,
486 sigc::mem_fun(
487 *this, &MainWindow::on_save_with_temporary_file));
488
489 actionGroup->add(
490 Gtk::Action::create("RefreshAll", _("_Refresh All")),
491 sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
492 );
493 #endif
494
495 #if USE_GLIB_ACTION
496 m_actionGroup->add_action(
497 "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
498 );
499 m_actionGroup->add_action(
500 "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
501 );
502 m_actionGroup->add_action(
503 "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
504 );
505 m_actionGroup->add_action(
506 "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
507 );
508 m_actionGroup->add_action(
509 "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
510 );
511 #else
512 action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
513 actionGroup->add(Gtk::Action::create("MenuHelp",
514 action->property_label()));
515 actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
516 sigc::mem_fun(
517 *this, &MainWindow::on_action_help_about));
518 actionGroup->add(
519 Gtk::Action::create("AddInstrument", _("Add _Instrument")),
520 sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
521 );
522 actionGroup->add(
523 Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
524 sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
525 );
526 actionGroup->add(
527 Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
528 Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
529 sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
530 );
531 actionGroup->add(
532 Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
533 sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
534 );
535 #endif
536
537 #if USE_GLIB_ACTION
538 m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool(
539 "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions),
540 Settings::singleton()->warnUserOnExtensions
541 );
542 m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool(
543 "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection),
544 Settings::singleton()->syncSamplerInstrumentSelection
545 );
546 m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool(
547 "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved),
548 Settings::singleton()->moveRootNoteWithRegionMoved
549 );
550 #else
551 actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
552
553 toggle_action =
554 Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
555 toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
556 actionGroup->add(
557 toggle_action,
558 sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
559 );
560
561 toggle_action =
562 Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
563 toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
564 actionGroup->add(
565 toggle_action,
566 sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
567 );
568
569 toggle_action =
570 Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
571 toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
572 actionGroup->add(
573 toggle_action,
574 sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
575 );
576 #endif
577
578 #if USE_GLIB_ACTION
579 m_actionGroup->add_action(
580 "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
581 );
582 m_actionGroup->add_action(
583 "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
584 );
585 #else
586 actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
587
588 actionGroup->add(
589 Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
590 sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
591 );
592
593 actionGroup->add(
594 Gtk::Action::create("MergeFiles", _("_Merge Files...")),
595 sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
596 );
597 #endif
598
599 // sample right-click popup actions
600 #if USE_GLIB_ACTION
601 m_actionSampleProperties = m_actionGroup->add_action(
602 "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
603 );
604 m_actionAddSampleGroup = m_actionGroup->add_action(
605 "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group)
606 );
607 m_actionAddSample = m_actionGroup->add_action(
608 "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
609 );
610 m_actionRemoveSample = m_actionGroup->add_action(
611 "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
612 );
613 m_actionGroup->add_action(
614 "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
615 );
616 m_actionViewSampleRefs = m_actionGroup->add_action(
617 "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references)
618 );
619 m_actionReplaceSample = m_actionGroup->add_action(
620 "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
621 );
622 m_actionGroup->add_action(
623 "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
624 );
625 #else
626 actionGroup->add(
627 Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
628 sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
629 );
630 actionGroup->add(
631 Gtk::Action::create("AddGroup", _("Add _Group")),
632 sigc::mem_fun(*this, &MainWindow::on_action_add_group)
633 );
634 actionGroup->add(
635 Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
636 sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
637 );
638 actionGroup->add(
639 Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
640 sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
641 );
642 actionGroup->add(
643 Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
644 sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
645 );
646 actionGroup->add(
647 Gtk::Action::create("ShowSampleRefs", _("Show References...")),
648 sigc::mem_fun(*this, &MainWindow::on_action_view_references)
649 );
650 actionGroup->add(
651 Gtk::Action::create("ReplaceSample",
652 _("Replace Sample...")),
653 sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
654 );
655 actionGroup->add(
656 Gtk::Action::create("ReplaceAllSamplesInAllGroups",
657 _("Replace All Samples in All Groups...")),
658 sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
659 );
660 #endif
661
662 // script right-click popup actions
663 #if USE_GLIB_ACTION
664 m_actionAddScriptGroup = m_actionGroup->add_action(
665 "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
666 );
667 m_actionAddScript = m_actionGroup->add_action(
668 "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script)
669 );
670 m_actionEditScript = m_actionGroup->add_action(
671 "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
672 );
673 m_actionRemoveScript = m_actionGroup->add_action(
674 "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
675 );
676 #else
677 actionGroup->add(
678 Gtk::Action::create("AddScriptGroup", _("Add _Group")),
679 sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
680 );
681 actionGroup->add(
682 Gtk::Action::create("AddScript", _("Add _Script")),
683 sigc::mem_fun(*this, &MainWindow::on_action_add_script)
684 );
685 actionGroup->add(
686 Gtk::Action::create("EditScript", _("_Edit Script...")),
687 sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
688 );
689 actionGroup->add(
690 Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
691 sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
692 );
693 #endif
694
695 #if USE_GTKMM_BUILDER
696 insert_action_group("AppMenu", m_actionGroup);
697
698 m_uiManager = Gtk::Builder::create();
699 Glib::ustring ui_info =
700 "<interface>"
701 " <menubar id='MenuBar'>"
702 " <menu id='MenuFile'>"
703 " <attribute name='label' translatable='yes'>_File</attribute>"
704 " <section>"
705 " <item id='New'>"
706 " <attribute name='label' translatable='yes'>New</attribute>"
707 " <attribute name='action'>AppMenu.New</attribute>"
708 " </item>"
709 " <item id='Open'>"
710 " <attribute name='label' translatable='yes'>Open</attribute>"
711 " <attribute name='action'>AppMenu.Open</attribute>"
712 " </item>"
713 " </section>"
714 " <section>"
715 " <item id='Save'>"
716 " <attribute name='label' translatable='yes'>Save</attribute>"
717 " <attribute name='action'>AppMenu.Save</attribute>"
718 " </item>"
719 " <item id='SaveAs'>"
720 " <attribute name='label' translatable='yes'>Save As</attribute>"
721 " <attribute name='action'>AppMenu.SaveAs</attribute>"
722 " </item>"
723 " </section>"
724 " <section>"
725 " <item id='Properties'>"
726 " <attribute name='label' translatable='yes'>Properties</attribute>"
727 " <attribute name='action'>AppMenu.Properties</attribute>"
728 " </item>"
729 " </section>"
730 " <section>"
731 " <item id='Quit'>"
732 " <attribute name='label' translatable='yes'>Quit</attribute>"
733 " <attribute name='action'>AppMenu.Quit</attribute>"
734 " </item>"
735 " </section>"
736 " </menu>"
737 " <menu id='MenuEdit'>"
738 " <attribute name='label' translatable='yes'>Edit</attribute>"
739 " <section>"
740 " <item id='CopyDimRgn'>"
741 " <attribute name='label' translatable='yes'>Copy Dimension Region</attribute>"
742 " <attribute name='action'>AppMenu.CopyDimRgn</attribute>"
743 " </item>"
744 " <item id='AdjustClipboard'>"
745 " <attribute name='label' translatable='yes'>Adjust Clipboard</attribute>"
746 " <attribute name='action'>AppMenu.AdjustClipboard</attribute>"
747 " </item>"
748 " <item id='PasteDimRgn'>"
749 " <attribute name='label' translatable='yes'>Paste Dimension Region</attribute>"
750 " <attribute name='action'>AppMenu.PasteDimRgn</attribute>"
751 " </item>"
752 " </section>"
753 " <item id='SelectPrevInstr'>"
754 " <attribute name='label' translatable='yes'>Previous Instrument</attribute>"
755 " <attribute name='action'>AppMenu.SelectPrevInstr</attribute>"
756 " </item>"
757 " <item id='SelectNextInstr'>"
758 " <attribute name='label' translatable='yes'>Next Instrument</attribute>"
759 " <attribute name='action'>AppMenu.SelectNextInstr</attribute>"
760 " </item>"
761 " <section>"
762 " <item id='SelectPrevRegion'>"
763 " <attribute name='label' translatable='yes'>Previous Region</attribute>"
764 " <attribute name='action'>AppMenu.SelectPrevRegion</attribute>"
765 " </item>"
766 " <item id='SelectNextRegion'>"
767 " <attribute name='label' translatable='yes'>Next Region</attribute>"
768 " <attribute name='action'>AppMenu.SelectNextRegion</attribute>"
769 " </item>"
770 " </section>"
771 " <item id='SelectPrevDimension'>"
772 " <attribute name='label' translatable='yes'>Previous Dimension</attribute>"
773 " <attribute name='action'>AppMenu.SelectPrevDimension</attribute>"
774 " </item>"
775 " <item id='SelectNextDimension'>"
776 " <attribute name='label' translatable='yes'>Next Dimension</attribute>"
777 " <attribute name='action'>AppMenu.SelectNextDimension</attribute>"
778 " </item>"
779 " <item id='SelectPrevDimRgnZone'>"
780 " <attribute name='label' translatable='yes'>Previous Dimension Region Zone</attribute>"
781 " <attribute name='action'>AppMenu.SelectPrevDimRgnZone</attribute>"
782 " </item>"
783 " <item id='SelectNextDimRgnZone'>"
784 " <attribute name='label' translatable='yes'>Next Dimension Region Zone</attribute>"
785 " <attribute name='action'>AppMenu.SelectNextDimRgnZone</attribute>"
786 " </item>"
787 " <item id='SelectAddPrevDimRgnZone'>"
788 " <attribute name='label' translatable='yes'>Add Previous Dimension Region Zone</attribute>"
789 " <attribute name='action'>AppMenu.SelectAddPrevDimRgnZone</attribute>"
790 " </item>"
791 " <item id='SelectAddNextDimRgnZone'>"
792 " <attribute name='label' translatable='yes'>Add Next Dimension Region Zone</attribute>"
793 " <attribute name='action'>AppMenu.SelectAddNextDimRgnZone</attribute>"
794 " </item>"
795 " <section>"
796 " <item id='CopySampleUnity'>"
797 " <attribute name='label' translatable='yes'>Copy Sample Unity</attribute>"
798 " <attribute name='action'>AppMenu.CopySampleUnity</attribute>"
799 " </item>"
800 " <item id='CopySampleTune'>"
801 " <attribute name='label' translatable='yes'>Copy Sample Tune</attribute>"
802 " <attribute name='action'>AppMenu.CopySampleTune</attribute>"
803 " </item>"
804 " <item id='CopySampleLoop'>"
805 " <attribute name='label' translatable='yes'>Copy Sample Loop</attribute>"
806 " <attribute name='action'>AppMenu.CopySampleLoop</attribute>"
807 " </item>"
808 " </section>"
809 " </menu>"
810 " <menu id='MenuMacro'>"
811 " <attribute name='label' translatable='yes'>Macro</attribute>"
812 " <section>"
813 " </section>"
814 " </menu>"
815 " <menu id='MenuSample'>"
816 " <attribute name='label' translatable='yes'>Sample</attribute>"
817 " <section>"
818 " <item id='SampleProperties'>"
819 " <attribute name='label' translatable='yes'>Properties</attribute>"
820 " <attribute name='action'>AppMenu.SampleProperties</attribute>"
821 " </item>"
822 " <item id='AddGroup'>"
823 " <attribute name='label' translatable='yes'>Add Group</attribute>"
824 " <attribute name='action'>AppMenu.AddGroup</attribute>"
825 " </item>"
826 " <item id='AddSample'>"
827 " <attribute name='label' translatable='yes'>Add Sample</attribute>"
828 " <attribute name='action'>AppMenu.AddSample</attribute>"
829 " </item>"
830 " <item id='ShowSampleRefs'>"
831 " <attribute name='label' translatable='yes'>Show Sample References</attribute>"
832 " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
833 " </item>"
834 " <item id='ReplaceSample'>"
835 " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
836 " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
837 " </item>"
838 " <item id='ReplaceAllSamplesInAllGroups'>"
839 " <attribute name='label' translatable='yes'>Replace all Samples in all Groups</attribute>"
840 " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
841 " </item>"
842 " </section>"
843 " <section>"
844 " <item id='RemoveSample'>"
845 " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
846 " <attribute name='action'>AppMenu.RemoveSample</attribute>"
847 " </item>"
848 " <item id='RemoveUnusedSamples'>"
849 " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
850 " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
851 " </item>"
852 " </section>"
853 " </menu>"
854 " <menu id='MenuInstrument'>"
855 " <attribute name='label' translatable='yes'>Instrument</attribute>"
856 " <section>"
857 " <item id='InstrProperties'>"
858 " <attribute name='label' translatable='yes'>Properties</attribute>"
859 " <attribute name='action'>AppMenu.InstrProperties</attribute>"
860 " </item>"
861 " <item id='MidiRules'>"
862 " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
863 " <attribute name='action'>AppMenu.MidiRules</attribute>"
864 " </item>"
865 " <item id='ScriptSlots'>"
866 " <attribute name='label' translatable='yes'>Script Slots</attribute>"
867 " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
868 " </item>"
869 " </section>"
870 " <submenu id='AssignScripts'>"
871 " <attribute name='label' translatable='yes'>Assign Scripts</attribute>"
872 " </submenu>"
873 " <section>"
874 " <item id='AddInstrument'>"
875 " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
876 " <attribute name='action'>AppMenu.AddInstrument</attribute>"
877 " </item>"
878 " <item id='DupInstrument'>"
879 " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
880 " <attribute name='action'>AppMenu.DupInstrument</attribute>"
881 " </item>"
882 " <item id='CombInstruments'>"
883 " <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
884 " <attribute name='action'>AppMenu.CombInstruments</attribute>"
885 " </item>"
886 " </section>"
887 " <section>"
888 " <item id='RemoveInstrument'>"
889 " <attribute name='label' translatable='yes'>Remove Instrument</attribute>"
890 " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
891 " </item>"
892 " </section>"
893 " </menu>"
894 " <menu id='MenuScript'>"
895 " <attribute name='label' translatable='yes'>Script</attribute>"
896 " <section>"
897 " <item id='AddScriptGroup'>"
898 " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
899 " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
900 " </item>"
901 " <item id='AddScript'>"
902 " <attribute name='label' translatable='yes'>Add Script</attribute>"
903 " <attribute name='action'>AppMenu.AddScript</attribute>"
904 " </item>"
905 " <item id='EditScript'>"
906 " <attribute name='label' translatable='yes'>Edit Script</attribute>"
907 " <attribute name='action'>AppMenu.EditScript</attribute>"
908 " </item>"
909 " </section>"
910 " <section>"
911 " <item id='RemoveScript'>"
912 " <attribute name='label' translatable='yes'>Remove Script</attribute>"
913 " <attribute name='action'>AppMenu.RemoveScript</attribute>"
914 " </item>"
915 " </section>"
916 " </menu>"
917 " <menu id='MenuView'>"
918 " <attribute name='label' translatable='yes'>View</attribute>"
919 " <section>"
920 " <item id='Statusbar'>"
921 " <attribute name='label' translatable='yes'>Statusbar</attribute>"
922 " <attribute name='action'>AppMenu.Statusbar</attribute>"
923 " </item>"
924 " <item id='AutoRestoreWinDim'>"
925 " <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
926 " <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
927 " </item>"
928 " </section>"
929 " <section>"
930 " <item id='RefreshAll'>"
931 " <attribute name='label' translatable='yes'>Refresh All</attribute>"
932 " <attribute name='action'>AppMenu.RefreshAll</attribute>"
933 " </item>"
934 " </section>"
935 " </menu>"
936 " <menu id='MenuTools'>"
937 " <attribute name='label' translatable='yes'>Tools</attribute>"
938 " <section>"
939 " <item id='CombineInstruments'>"
940 " <attribute name='label' translatable='yes'>Combine Instruments ...</attribute>"
941 " <attribute name='action'>AppMenu.CombineInstruments</attribute>"
942 " </item>"
943 " <item id='MergeFiles'>"
944 " <attribute name='label' translatable='yes'>Merge Files ...</attribute>"
945 " <attribute name='action'>AppMenu.MergeFiles</attribute>"
946 " </item>"
947 " </section>"
948 " </menu>"
949 " <menu id='MenuSettings'>"
950 " <attribute name='label' translatable='yes'>Settings</attribute>"
951 " <section>"
952 " <item id='WarnUserOnExtensions'>"
953 " <attribute name='label' translatable='yes'>Warning on Format Extensions</attribute>"
954 " <attribute name='action'>AppMenu.WarnUserOnExtensions</attribute>"
955 " </item>"
956 " <item id='SyncSamplerInstrumentSelection'>"
957 " <attribute name='label' translatable='yes'>Synchronize Sampler Selection</attribute>"
958 " <attribute name='action'>AppMenu.SyncSamplerInstrumentSelection</attribute>"
959 " </item>"
960 " <item id='MoveRootNoteWithRegionMoved'>"
961 " <attribute name='label' translatable='yes'>Move Root Note with Region moved</attribute>"
962 " <attribute name='action'>AppMenu.MoveRootNoteWithRegionMoved</attribute>"
963 " </item>"
964 " <item id='SaveWithTemporaryFile'>"
965 " <attribute name='label' translatable='yes'>Save with temporary file</attribute>"
966 " <attribute name='action'>AppMenu.SaveWithTemporaryFile</attribute>"
967 " </item>"
968 " </section>"
969 " </menu>"
970 " <menu id='MenuHelp'>"
971 " <attribute name='label' translatable='yes'>Help</attribute>"
972 " <section>"
973 " <item id='About'>"
974 " <attribute name='label' translatable='yes'>About ...</attribute>"
975 " <attribute name='action'>AppMenu.About</attribute>"
976 " </item>"
977 " </section>"
978 " </menu>"
979 " </menubar>"
980 // popups
981 " <menu id='PopupMenu'>"
982 " <section>"
983 " <item id='InstrProperties'>"
984 " <attribute name='label' translatable='yes'>Instrument Properties</attribute>"
985 " <attribute name='action'>AppMenu.InstrProperties</attribute>"
986 " </item>"
987 " <item id='MidiRules'>"
988 " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
989 " <attribute name='action'>AppMenu.MidiRules</attribute>"
990 " </item>"
991 " <item id='ScriptSlots'>"
992 " <attribute name='label' translatable='yes'>Script Slots</attribute>"
993 " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
994 " </item>"
995 " <item id='AddInstrument'>"
996 " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
997 " <attribute name='action'>AppMenu.AddInstrument</attribute>"
998 " </item>"
999 " <item id='DupInstrument'>"
1000 " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1001 " <attribute name='action'>AppMenu.DupInstrument</attribute>"
1002 " </item>"
1003 " <item id='CombInstruments'>"
1004 " <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1005 " <attribute name='action'>AppMenu.CombInstruments</attribute>"
1006 " </item>"
1007 " </section>"
1008 " <section>"
1009 " <item id='RemoveInstrument'>"
1010 " <attribute name='label' translatable='yes'>Remove Instruments</attribute>"
1011 " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
1012 " </item>"
1013 " </section>"
1014 " </menu>"
1015 " <menu id='SamplePopupMenu'>"
1016 " <section>"
1017 " <item id='SampleProperties'>"
1018 " <attribute name='label' translatable='yes'>Sample Properties</attribute>"
1019 " <attribute name='action'>AppMenu.SampleProperties</attribute>"
1020 " </item>"
1021 " <item id='AddGroup'>"
1022 " <attribute name='label' translatable='yes'>Add Sample Group</attribute>"
1023 " <attribute name='action'>AppMenu.AddGroup</attribute>"
1024 " </item>"
1025 " <item id='AddSample'>"
1026 " <attribute name='label' translatable='yes'>Add Sample</attribute>"
1027 " <attribute name='action'>AppMenu.AddSample</attribute>"
1028 " </item>"
1029 " <item id='ShowSampleRefs'>"
1030 " <attribute name='label' translatable='yes'>Show Sample References ...</attribute>"
1031 " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
1032 " </item>"
1033 " <item id='ReplaceSample'>"
1034 " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
1035 " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
1036 " </item>"
1037 " <item id='ReplaceAllSamplesInAllGroups'>"
1038 " <attribute name='label' translatable='yes'>Replace all Samples ...</attribute>"
1039 " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
1040 " </item>"
1041 " </section>"
1042 " <section>"
1043 " <item id='RemoveSample'>"
1044 " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
1045 " <attribute name='action'>AppMenu.RemoveSample</attribute>"
1046 " </item>"
1047 " <item id='RemoveUnusedSamples'>"
1048 " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
1049 " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
1050 " </item>"
1051 " </section>"
1052 " </menu>"
1053 " <menu id='ScriptPopupMenu'>"
1054 " <section>"
1055 " <item id='AddScriptGroup'>"
1056 " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
1057 " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
1058 " </item>"
1059 " <item id='AddScript'>"
1060 " <attribute name='label' translatable='yes'>Add Script</attribute>"
1061 " <attribute name='action'>AppMenu.AddScript</attribute>"
1062 " </item>"
1063 " <item id='EditScript'>"
1064 " <attribute name='label' translatable='yes'>Edit Script</attribute>"
1065 " <attribute name='action'>AppMenu.EditScript</attribute>"
1066 " </item>"
1067 " </section>"
1068 " <section>"
1069 " <item id='RemoveScript'>"
1070 " <attribute name='label' translatable='yes'>Remove Script</attribute>"
1071 " <attribute name='action'>AppMenu.RemoveScript</attribute>"
1072 " </item>"
1073 " </section>"
1074 " </menu>"
1075 "</interface>";
1076 m_uiManager->add_from_string(ui_info);
1077 #else
1078 uiManager = Gtk::UIManager::create();
1079 uiManager->insert_action_group(actionGroup);
1080 add_accel_group(uiManager->get_accel_group());
1081
1082 Glib::ustring ui_info =
1083 "<ui>"
1084 " <menubar name='MenuBar'>"
1085 " <menu action='MenuFile'>"
1086 " <menuitem action='New'/>"
1087 " <menuitem action='Open'/>"
1088 " <separator/>"
1089 " <menuitem action='Save'/>"
1090 " <menuitem action='SaveAs'/>"
1091 " <separator/>"
1092 " <menuitem action='Properties'/>"
1093 " <separator/>"
1094 " <menuitem action='Quit'/>"
1095 " </menu>"
1096 " <menu action='MenuEdit'>"
1097 " <menuitem action='CopyDimRgn'/>"
1098 " <menuitem action='AdjustClipboard'/>"
1099 " <menuitem action='PasteDimRgn'/>"
1100 " <separator/>"
1101 " <menuitem action='SelectPrevInstr'/>"
1102 " <menuitem action='SelectNextInstr'/>"
1103 " <separator/>"
1104 " <menuitem action='SelectPrevRegion'/>"
1105 " <menuitem action='SelectNextRegion'/>"
1106 " <separator/>"
1107 " <menuitem action='SelectPrevDimension'/>"
1108 " <menuitem action='SelectNextDimension'/>"
1109 " <menuitem action='SelectPrevDimRgnZone'/>"
1110 " <menuitem action='SelectNextDimRgnZone'/>"
1111 " <menuitem action='SelectAddPrevDimRgnZone'/>"
1112 " <menuitem action='SelectAddNextDimRgnZone'/>"
1113 " <separator/>"
1114 " <menuitem action='CopySampleUnity'/>"
1115 " <menuitem action='CopySampleTune'/>"
1116 " <menuitem action='CopySampleLoop'/>"
1117 " </menu>"
1118 " <menu action='MenuMacro'>"
1119 " </menu>"
1120 " <menu action='MenuSample'>"
1121 " <menuitem action='SampleProperties'/>"
1122 " <menuitem action='AddGroup'/>"
1123 " <menuitem action='AddSample'/>"
1124 " <menuitem action='ShowSampleRefs'/>"
1125 " <menuitem action='ReplaceSample' />"
1126 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1127 " <separator/>"
1128 " <menuitem action='RemoveSample'/>"
1129 " <menuitem action='RemoveUnusedSamples'/>"
1130 " </menu>"
1131 " <menu action='MenuInstrument'>"
1132 " <menu action='AllInstruments'>"
1133 " </menu>"
1134 " <separator/>"
1135 " <menuitem action='InstrProperties'/>"
1136 " <menuitem action='MidiRules'/>"
1137 " <menuitem action='ScriptSlots'/>"
1138 " <menu action='AssignScripts'/>"
1139 " <menuitem action='AddInstrument'/>"
1140 " <menuitem action='DupInstrument'/>"
1141 " <menuitem action='CombInstruments'/>"
1142 " <separator/>"
1143 " <menuitem action='RemoveInstrument'/>"
1144 " </menu>"
1145 " <menu action='MenuScript'>"
1146 " <menuitem action='AddScriptGroup'/>"
1147 " <menuitem action='AddScript'/>"
1148 " <menuitem action='EditScript'/>"
1149 " <separator/>"
1150 " <menuitem action='RemoveScript'/>"
1151 " </menu>"
1152 " <menu action='MenuView'>"
1153 " <menuitem action='Statusbar'/>"
1154 " <menuitem action='AutoRestoreWinDim'/>"
1155 " <separator/>"
1156 " <menuitem action='RefreshAll'/>"
1157 " </menu>"
1158 " <menu action='MenuTools'>"
1159 " <menuitem action='CombineInstruments'/>"
1160 " <menuitem action='MergeFiles'/>"
1161 " </menu>"
1162 " <menu action='MenuSettings'>"
1163 " <menuitem action='WarnUserOnExtensions'/>"
1164 " <menuitem action='SyncSamplerInstrumentSelection'/>"
1165 " <menuitem action='MoveRootNoteWithRegionMoved'/>"
1166 " <menuitem action='SaveWithTemporaryFile'/>"
1167 " </menu>"
1168 " <menu action='MenuHelp'>"
1169 " <menuitem action='About'/>"
1170 " </menu>"
1171 " </menubar>"
1172 " <popup name='PopupMenu'>"
1173 " <menuitem action='InstrProperties'/>"
1174 " <menuitem action='MidiRules'/>"
1175 " <menuitem action='ScriptSlots'/>"
1176 " <menuitem action='AddInstrument'/>"
1177 " <menuitem action='DupInstrument'/>"
1178 " <menuitem action='CombInstruments'/>"
1179 " <separator/>"
1180 " <menuitem action='RemoveInstrument'/>"
1181 " </popup>"
1182 " <popup name='SamplePopupMenu'>"
1183 " <menuitem action='SampleProperties'/>"
1184 " <menuitem action='AddGroup'/>"
1185 " <menuitem action='AddSample'/>"
1186 " <menuitem action='ShowSampleRefs'/>"
1187 " <menuitem action='ReplaceSample' />"
1188 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1189 " <separator/>"
1190 " <menuitem action='RemoveSample'/>"
1191 " <menuitem action='RemoveUnusedSamples'/>"
1192 " </popup>"
1193 " <popup name='ScriptPopupMenu'>"
1194 " <menuitem action='AddScriptGroup'/>"
1195 " <menuitem action='AddScript'/>"
1196 " <menuitem action='EditScript'/>"
1197 " <separator/>"
1198 " <menuitem action='RemoveScript'/>"
1199 " </popup>"
1200 "</ui>";
1201 uiManager->add_ui_from_string(ui_info);
1202 #endif
1203
1204 #if USE_GTKMM_BUILDER
1205 popup_menu = new Gtk::Menu(
1206 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1207 m_uiManager->get_object("PopupMenu")
1208 )
1209 );
1210 sample_popup = new Gtk::Menu(
1211 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1212 m_uiManager->get_object("SamplePopupMenu")
1213 )
1214 );
1215 script_popup = new Gtk::Menu(
1216 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1217 m_uiManager->get_object("ScriptPopupMenu")
1218 )
1219 );
1220 #else
1221 popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
1222
1223 // Set tooltips for menu items (for some reason, setting a tooltip on the
1224 // respective Gtk::Action objects above will simply be ignored, no matter
1225 // if using Gtk::Action::set_tooltip() or passing the tooltip string on
1226 // Gtk::Action::create()).
1227 {
1228 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1229 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1230 item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
1231 }
1232 {
1233 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1234 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1235 item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
1236 }
1237 {
1238 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1239 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1240 item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action."));
1241 }
1242 {
1243 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1244 uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
1245 item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
1246 }
1247 {
1248 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1249 uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
1250 item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
1251 }
1252 {
1253 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1254 uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
1255 item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
1256 }
1257 {
1258 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1259 uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
1260 item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
1261 // copy tooltip to popup menu
1262 Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
1263 uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
1264 item2->set_tooltip_text(item->get_tooltip_text());
1265 }
1266 {
1267 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1268 uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
1269 item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
1270 }
1271 {
1272 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1273 uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1274 item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
1275 }
1276 {
1277 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1278 uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1279 item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1280 }
1281 {
1282 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1283 uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1284 item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
1285 }
1286 #endif
1287
1288 #if USE_GTKMM_BUILDER
1289 assign_scripts_menu = new Gtk::Menu(
1290 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1291 m_uiManager->get_object("AssignScripts")
1292 )
1293 );
1294 #else
1295 instrument_menu = static_cast<Gtk::MenuItem*>(
1296 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
1297
1298 assign_scripts_menu = static_cast<Gtk::MenuItem*>(
1299 uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
1300 #endif
1301
1302 #if USE_GTKMM_BUILDER
1303 Gtk::Widget* menuBar = NULL;
1304 m_uiManager->get_widget("MenuBar", menuBar);
1305 #else
1306 Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1307 #endif
1308
1309 m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1310 m_VBox.pack_start(m_HPaned);
1311 m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
1312 m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
1313 m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
1314 m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
1315
1316 set_file_is_shared(false);
1317
1318 // Status Bar:
1319 #if USE_GTKMM_BOX
1320 # warning No status bar layout for GTKMM 4 yet
1321 #else
1322 m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1323 m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1324 #endif
1325 m_StatusBar.show();
1326
1327 m_RegionChooser.signal_region_selected().connect(
1328 sigc::mem_fun(*this, &MainWindow::region_changed) );
1329 m_DimRegionChooser.signal_dimregion_selected().connect(
1330 sigc::mem_fun(*this, &MainWindow::dimreg_changed) );
1331
1332
1333 // Create the Tree model:
1334 m_refTreeModel = Gtk::ListStore::create(m_Columns);
1335 m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1336 m_refTreeModelFilter->set_visible_func(
1337 sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1338 );
1339 m_TreeView.set_model(m_refTreeModelFilter);
1340
1341 m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1342 m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
1343 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1344 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1345 );
1346
1347 // Add the TreeView's view columns:
1348 m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1349 m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1350 m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1351 m_TreeView.set_headers_visible(true);
1352
1353 // establish drag&drop within the instrument tree view, allowing to reorder
1354 // the sequence of instruments within the gig file
1355 {
1356 std::vector<Gtk::TargetEntry> drag_target_instrument;
1357 drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1358 m_TreeView.drag_source_set(drag_target_instrument);
1359 m_TreeView.drag_dest_set(drag_target_instrument);
1360 m_TreeView.signal_drag_begin().connect(
1361 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1362 );
1363 m_TreeView.signal_drag_data_get().connect(
1364 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1365 );
1366 m_TreeView.signal_drag_data_received().connect(
1367 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1368 );
1369 }
1370
1371 // create samples treeview (including its data model)
1372 m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1373 m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1374 m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1375 m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
1376 // m_TreeViewSamples.set_reorderable();
1377 m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1378 m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1379 {
1380 Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1381 Gtk::CellRendererText* cellrenderer =
1382 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1383 column->add_attribute(
1384 cellrenderer->property_foreground(), m_SamplesModel.m_color
1385 );
1386 }
1387 {
1388 Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1389 Gtk::CellRendererText* cellrenderer =
1390 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1391 column->add_attribute(
1392 cellrenderer->property_foreground(), m_SamplesModel.m_color
1393 );
1394 }
1395 m_TreeViewSamples.set_headers_visible(true);
1396 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1397 m_TreeViewSamples.signal_button_press_event().connect(
1398 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1399 );
1400 #else
1401 m_TreeViewSamples.signal_button_press_event().connect_notify(
1402 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1403 );
1404 #endif
1405 m_refSamplesTreeModel->signal_row_changed().connect(
1406 sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1407 );
1408
1409 // create scripts treeview (including its data model)
1410 m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1411 m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1412 m_TreeViewScripts.set_tooltip_text(_(
1413 "Use CTRL + double click for editing a script."
1414 "\n\n"
1415 "Note: instrument scripts are a LinuxSampler extension of the gig "
1416 "format. This feature will not work with the GigaStudio software!"
1417 ));
1418 // m_TreeViewScripts.set_reorderable();
1419 m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1420 m_TreeViewScripts.set_headers_visible(false);
1421 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1422 m_TreeViewScripts.signal_button_press_event().connect(
1423 sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1424 );
1425 #else
1426 m_TreeViewScripts.signal_button_press_event().connect_notify(
1427 sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1428 );
1429 #endif
1430 //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1431 m_TreeViewScripts.signal_row_activated().connect(
1432 sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1433 );
1434 m_refScriptsTreeModel->signal_row_changed().connect(
1435 sigc::mem_fun(*this, &MainWindow::script_name_changed)
1436 );
1437
1438 // establish drag&drop between scripts tree view and ScriptSlots window
1439 std::vector<Gtk::TargetEntry> drag_target_gig_script;
1440 drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1441 m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1442 m_TreeViewScripts.signal_drag_begin().connect(
1443 sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1444 );
1445 m_TreeViewScripts.signal_drag_data_get().connect(
1446 sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1447 );
1448
1449 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1450 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1451 drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1452 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1453 m_TreeViewSamples.signal_drag_begin().connect(
1454 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
1455 );
1456 m_TreeViewSamples.signal_drag_data_get().connect(
1457 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
1458 );
1459 dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
1460 dimreg_edit.wSample->signal_drag_data_received().connect(
1461 sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
1462 );
1463 dimreg_edit.signal_dimreg_changed().connect(
1464 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1465 m_RegionChooser.signal_instrument_changed().connect(
1466 sigc::mem_fun(*this, &MainWindow::file_changed));
1467 m_RegionChooser.signal_instrument_changed().connect(
1468 sigc::mem_fun(*this, &MainWindow::region_changed));
1469 m_DimRegionChooser.signal_region_changed().connect(
1470 sigc::mem_fun(*this, &MainWindow::file_changed));
1471 instrumentProps.signal_changed().connect(
1472 sigc::mem_fun(*this, &MainWindow::file_changed));
1473 propDialog.signal_changed().connect(
1474 sigc::mem_fun(*this, &MainWindow::file_changed));
1475 midiRules.signal_changed().connect(
1476 sigc::mem_fun(*this, &MainWindow::file_changed));
1477
1478 dimreg_edit.signal_dimreg_to_be_changed().connect(
1479 dimreg_to_be_changed_signal.make_slot());
1480 dimreg_edit.signal_dimreg_changed().connect(
1481 dimreg_changed_signal.make_slot());
1482 dimreg_edit.signal_sample_ref_changed().connect(
1483 sample_ref_changed_signal.make_slot());
1484 sample_ref_changed_signal.connect(
1485 sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1486 );
1487 samples_to_be_removed_signal.connect(
1488 sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1489 );
1490
1491 dimreg_edit.signal_select_sample().connect(
1492 sigc::mem_fun(*this, &MainWindow::select_sample)
1493 );
1494
1495 m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1496 sigc::hide(
1497 sigc::bind(
1498 file_structure_to_be_changed_signal.make_slot(),
1499 sigc::ref(this->file)
1500 )
1501 )
1502 );
1503 m_RegionChooser.signal_instrument_struct_changed().connect(
1504 sigc::hide(
1505 sigc::bind(
1506 file_structure_changed_signal.make_slot(),
1507 sigc::ref(this->file)
1508 )
1509 )
1510 );
1511 m_RegionChooser.signal_region_to_be_changed().connect(
1512 region_to_be_changed_signal.make_slot());
1513 m_RegionChooser.signal_region_changed_signal().connect(
1514 region_changed_signal.make_slot());
1515
1516 note_on_signal.connect(
1517 sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
1518 note_off_signal.connect(
1519 sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
1520
1521 dimreg_all_regions.signal_toggled().connect(
1522 sigc::mem_fun(*this, &MainWindow::update_dimregs));
1523 dimreg_all_dimregs.signal_toggled().connect(
1524 sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
1525 dimreg_stereo.signal_toggled().connect(
1526 sigc::mem_fun(*this, &MainWindow::update_dimregs));
1527
1528 m_searchText.signal_changed().connect(
1529 sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1530 );
1531
1532 file = 0;
1533 file_is_changed = false;
1534
1535 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1536 show_all_children();
1537 #endif
1538
1539 // start with a new gig file by default
1540 on_action_file_new();
1541
1542 m_TreeViewNotebook.signal_switch_page().connect(
1543 sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1544 );
1545
1546 // select 'Instruments' tab by default
1547 // (gtk allows this only if the tab childs are visible, thats why it's here)
1548 m_TreeViewNotebook.set_current_page(1);
1549
1550 Gtk::Clipboard::get()->signal_owner_change().connect(
1551 sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1552 );
1553 updateClipboardPasteAvailable();
1554 updateClipboardCopyAvailable();
1555
1556 // setup macros and their keyboard accelerators
1557 {
1558 #if USE_GTKMM_BUILDER
1559 menuMacro = new Gtk::Menu(
1560 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1561 m_uiManager->get_object("MenuMacro")
1562 )
1563 );
1564 #else
1565 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1566 uiManager->get_widget("/MenuBar/MenuMacro")
1567 )->get_submenu();
1568 #endif
1569
1570 const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1571 Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1572 Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1573 Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1574 Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1575 Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1576 Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1577 Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1578 Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1579 Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1580 Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1581 Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1582 Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1583 Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1584
1585 Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1586 menuMacro->set_accel_group(accelGroup);
1587
1588 updateMacroMenu();
1589 }
1590
1591 // setup "Assign Scripts" keyboard accelerators
1592 {
1593 Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1594 Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1595 Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1596 Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1597 Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1598 Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1599 Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1600 Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1601 Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1602 Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1603 Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1604 Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1605
1606 Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1607 assign_scripts_menu->set_accel_group(accelGroup);
1608 }
1609
1610 Glib::signal_idle().connect_once(
1611 sigc::mem_fun(*this, &MainWindow::bringToFront),
1612 200
1613 );
1614 }
1615
1616 MainWindow::~MainWindow()
1617 {
1618 }
1619
1620 void MainWindow::bringToFront() {
1621 #if defined(__APPLE__)
1622 macRaiseAppWindow();
1623 #endif
1624 raise();
1625 present();
1626 }
1627
1628 void MainWindow::updateMacroMenu() {
1629 #if !USE_GTKMM_BUILDER
1630 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1631 uiManager->get_widget("/MenuBar/MenuMacro")
1632 )->get_submenu();
1633 #endif
1634
1635 // remove all entries from "Macro" menu
1636 {
1637 const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1638 for (int i = 0; i < children.size(); ++i) {
1639 Gtk::Widget* child = children[i];
1640 menuMacro->remove(*child);
1641 delete child;
1642 }
1643 }
1644
1645 // (re)load all macros from config file
1646 try {
1647 Settings::singleton()->loadMacros(m_macros);
1648 } catch (Serialization::Exception e) {
1649 std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1650 } catch (...) {
1651 std::cerr << "Unknown exception while loading macros!" << std::endl;
1652 }
1653
1654 // add all configured macros as menu items to the "Macro" menu
1655 for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1656 const Serialization::Archive& macro = m_macros[iMacro];
1657 std::string name =
1658 macro.name().empty() ?
1659 (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1660 Gtk::MenuItem* item = new Gtk::MenuItem(name);
1661 item->signal_activate().connect(
1662 sigc::bind(
1663 sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1664 )
1665 );
1666 menuMacro->append(*item);
1667 item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1668 Glib::ustring comment = macro.comment();
1669 if (!comment.empty())
1670 item->set_tooltip_text(comment);
1671 }
1672 // if there are no macros configured at all, then show a dummy entry instead
1673 if (m_macros.empty()) {
1674 Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1675 item->set_sensitive(false);
1676 menuMacro->append(*item);
1677 }
1678
1679 // add separator line to menu
1680 menuMacro->append(*new Gtk::SeparatorMenuItem);
1681
1682 {
1683 Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1684 item->signal_activate().connect(
1685 sigc::mem_fun(*this, &MainWindow::setupMacros)
1686 );
1687 menuMacro->append(*item);
1688 item->set_accel_path("<Macros>/SetupMacros");
1689 }
1690
1691 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1692 menuMacro->show_all_children();
1693 #endif
1694 }
1695
1696 void MainWindow::onMacroSelected(int iMacro) {
1697 printf("onMacroSelected(%d)\n", iMacro);
1698 if (iMacro < 0 || iMacro >= m_macros.size()) return;
1699 Glib::ustring errorText;
1700 try {
1701 applyMacro(m_macros[iMacro]);
1702 } catch (Serialization::Exception e) {
1703 errorText = e.Message;
1704 } catch (...) {
1705 errorText = _("Unknown exception while applying macro");
1706 }
1707 if (!errorText.empty()) {
1708 Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1709 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1710 msg.run();
1711 }
1712 }
1713
1714 void MainWindow::setupMacros() {
1715 MacrosSetup* setup = new MacrosSetup();
1716 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1717 setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1718 setup->signal_macros_changed().connect(
1719 sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1720 );
1721 setup->show();
1722 }
1723
1724 void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1725 m_macros = macros;
1726 Settings::singleton()->saveMacros(m_macros);
1727 updateMacroMenu();
1728 }
1729
1730 //NOTE: the actual signal's first argument for argument 'page' is on some gtkmm version GtkNotebookPage* and on some Gtk::Widget*. Since we don't need that argument, it is simply void* here for now.
1731 void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1732 bool isInstrumentsPage = (page_num == 1);
1733 // so far we only support filtering for the instruments list, so hide the
1734 // filter text entry field if another tab is selected
1735 m_searchField.set_visible(isInstrumentsPage);
1736 }
1737
1738 bool MainWindow::on_delete_event(GdkEventAny* event)
1739 {
1740 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
1741 }
1742
1743 void MainWindow::on_action_quit()
1744 {
1745 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
1746 hide();
1747 }
1748
1749 void MainWindow::region_changed()
1750 {
1751 m_DimRegionChooser.set_region(m_RegionChooser.get_region());
1752 }
1753
1754 gig::Instrument* MainWindow::get_instrument()
1755 {
1756 gig::Instrument* instrument = 0;
1757 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1758 if (rows.empty()) return NULL;
1759 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1760 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1761 if (it) {
1762 Gtk::TreeModel::Row row = *it;
1763 instrument = row[m_Columns.m_col_instr];
1764 }
1765 return instrument;
1766 }
1767
1768 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
1769 {
1770 if (all_dimregs) {
1771 for (int i = 0 ; i < region->DimensionRegions ; i++) {
1772 if (region->pDimensionRegions[i]) {
1773 dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
1774 }
1775 }
1776 } else {
1777 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
1778 }
1779 }
1780
1781 void MainWindow::update_dimregs()
1782 {
1783 dimreg_edit.dimregs.clear();
1784 bool all_regions = dimreg_all_regions.get_active();
1785 bool stereo = dimreg_stereo.get_active();
1786 bool all_dimregs = dimreg_all_dimregs.get_active();
1787
1788 if (all_regions) {
1789 gig::Instrument* instrument = get_instrument();
1790 if (instrument) {
1791 for (gig::Region* region = instrument->GetFirstRegion() ;
1792 region ;
1793 region = instrument->GetNextRegion()) {
1794 add_region_to_dimregs(region, stereo, all_dimregs);
1795 }
1796 }
1797 } else {
1798 gig::Region* region = m_RegionChooser.get_region();
1799 if (region) {
1800 add_region_to_dimregs(region, stereo, all_dimregs);
1801 }
1802 }
1803
1804 m_RegionChooser.setModifyAllRegions(all_regions);
1805 m_DimRegionChooser.setModifyAllRegions(all_regions);
1806 m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1807 m_DimRegionChooser.setModifyBothChannels(stereo);
1808
1809 updateClipboardCopyAvailable();
1810 }
1811
1812 void MainWindow::dimreg_all_dimregs_toggled()
1813 {
1814 dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
1815 update_dimregs();
1816 }
1817
1818 void MainWindow::dimreg_changed()
1819 {
1820 update_dimregs();
1821 dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1822 }
1823
1824 void MainWindow::on_sel_change()
1825 {
1826 #if !USE_GTKMM_BUILDER
1827 // select item in instrument menu
1828 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1829 if (!rows.empty()) {
1830 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1831 if (it) {
1832 Gtk::TreePath path(it);
1833 int index = path[0];
1834 const std::vector<Gtk::Widget*> children =
1835 instrument_menu->get_children();
1836 static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1837 }
1838 }
1839 #endif
1840
1841 updateScriptListOfMenu();
1842
1843 m_RegionChooser.set_instrument(get_instrument());
1844
1845 if (Settings::singleton()->syncSamplerInstrumentSelection) {
1846 switch_sampler_instrument_signal.emit(get_instrument());
1847 }
1848 }
1849
1850 void loader_progress_callback(gig::progress_t* progress)
1851 {
1852 Loader* loader = static_cast<Loader*>(progress->custom);
1853 loader->progress_callback(progress->factor);
1854 }
1855
1856 void Loader::progress_callback(float fraction)
1857 {
1858 {
1859 Glib::Threads::Mutex::Lock lock(progressMutex);
1860 progress = fraction;
1861 }
1862 progress_dispatcher();
1863 }
1864
1865 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1866 // make sure stack is 16-byte aligned for SSE instructions
1867 __attribute__((force_align_arg_pointer))
1868 #endif
1869 void Loader::thread_function()
1870 {
1871 printf("thread_function self=%p\n",
1872 static_cast<void*>(Glib::Threads::Thread::self()));
1873 printf("Start %s\n", filename.c_str());
1874 try {
1875 RIFF::File* riff = new RIFF::File(filename);
1876 gig = new gig::File(riff);
1877 gig::progress_t progress;
1878 progress.callback = loader_progress_callback;
1879 progress.custom = this;
1880
1881 gig->GetInstrument(0, &progress);
1882 printf("End\n");
1883 finished_dispatcher();
1884 } catch (RIFF::Exception e) {
1885 error_message = e.Message;
1886 error_dispatcher.emit();
1887 } catch (...) {
1888 error_message = _("Unknown exception occurred");
1889 error_dispatcher.emit();
1890 }
1891 }
1892
1893 Loader::Loader(const char* filename)
1894 : filename(filename), gig(0), thread(0), progress(0.f)
1895 {
1896 }
1897
1898 void Loader::launch()
1899 {
1900 #ifdef OLD_THREADS
1901 thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
1902 #else
1903 thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1904 #endif
1905 printf("launch thread=%p\n", static_cast<void*>(thread));
1906 }
1907
1908 float Loader::get_progress()
1909 {
1910 float res;
1911 {
1912 Glib::Threads::Mutex::Lock lock(progressMutex);
1913 res = progress;
1914 }
1915 return res;
1916 }
1917
1918 Glib::Dispatcher& Loader::signal_progress()
1919 {
1920 return progress_dispatcher;
1921 }
1922
1923 Glib::Dispatcher& Loader::signal_finished()
1924 {
1925 return finished_dispatcher;
1926 }
1927
1928 Glib::Dispatcher& Loader::signal_error()
1929 {
1930 return error_dispatcher;
1931 }
1932
1933 void saver_progress_callback(gig::progress_t* progress)
1934 {
1935 Saver* saver = static_cast<Saver*>(progress->custom);
1936 saver->progress_callback(progress->factor);
1937 }
1938
1939 void Saver::progress_callback(float fraction)
1940 {
1941 {
1942 Glib::Threads::Mutex::Lock lock(progressMutex);
1943 progress = fraction;
1944 }
1945 progress_dispatcher.emit();
1946 }
1947
1948 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1949 // make sure stack is 16-byte aligned for SSE instructions
1950 __attribute__((force_align_arg_pointer))
1951 #endif
1952 void Saver::thread_function()
1953 {
1954 printf("thread_function self=%p\n",
1955 static_cast<void*>(Glib::Threads::Thread::self()));
1956 printf("Start %s\n", filename.c_str());
1957 try {
1958 gig::progress_t progress;
1959 progress.callback = saver_progress_callback;
1960 progress.custom = this;
1961
1962 // if no filename was provided, that means "save", if filename was provided means "save as"
1963 if (filename.empty()) {
1964 if (!Settings::singleton()->saveWithTemporaryFile) {
1965 // save directly over the existing .gig file
1966 // (requires less disk space than solution below
1967 // but may be slower)
1968 gig->Save(&progress);
1969 } else {
1970 // save the file as separate temporary file first,
1971 // then move the saved file over the old file
1972 // (may result in performance speedup during save)
1973 gig::String tmpname = filename + ".TMP";
1974 gig->Save(tmpname, &progress);
1975 #if defined(WIN32)
1976 if (!DeleteFile(filename.c_str())) {
1977 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1978 }
1979 #else // POSIX ...
1980 if (unlink(filename.c_str())) {
1981 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1982 }
1983 #endif
1984 if (rename(tmpname.c_str(), filename.c_str())) {
1985 #if defined(WIN32)
1986 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1987 #else
1988 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1989 #endif
1990 }
1991 }
1992 } else {
1993 gig->Save(filename, &progress);
1994 }
1995
1996 printf("End\n");
1997 finished_dispatcher.emit();
1998 } catch (RIFF::Exception e) {
1999 error_message = e.Message;
2000 error_dispatcher.emit();
2001 } catch (...) {
2002 error_message = _("Unknown exception occurred");
2003 error_dispatcher.emit();
2004 }
2005 }
2006
2007 Saver::Saver(gig::File* file, Glib::ustring filename)
2008 : gig(file), filename(filename), thread(0), progress(0.f)
2009 {
2010 }
2011
2012 void Saver::launch()
2013 {
2014 #ifdef OLD_THREADS
2015 thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
2016 #else
2017 thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2018 #endif
2019 printf("launch thread=%p\n", static_cast<void*>(thread));
2020 }
2021
2022 float Saver::get_progress()
2023 {
2024 float res;
2025 {
2026 Glib::Threads::Mutex::Lock lock(progressMutex);
2027 res = progress;
2028 }
2029 return res;
2030 }
2031
2032 Glib::Dispatcher& Saver::signal_progress()
2033 {
2034 return progress_dispatcher;
2035 }
2036
2037 Glib::Dispatcher& Saver::signal_finished()
2038 {
2039 return finished_dispatcher;
2040 }
2041
2042 Glib::Dispatcher& Saver::signal_error()
2043 {
2044 return error_dispatcher;
2045 }
2046
2047 ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2048 : Gtk::Dialog(title, parent, true)
2049 {
2050 #if USE_GTKMM_BOX
2051 get_content_area()->pack_start(progressBar);
2052 #else
2053 get_vbox()->pack_start(progressBar);
2054 #endif
2055 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2056 show_all_children();
2057 #endif
2058 resize(600,50);
2059 }
2060
2061 // Clear all GUI elements / controls. This method is typically called
2062 // before a new .gig file is to be created or to be loaded.
2063 void MainWindow::__clear() {
2064 // forget all samples that ought to be imported
2065 m_SampleImportQueue.clear();
2066 // clear the samples and instruments tree views
2067 m_refTreeModel->clear();
2068 m_refSamplesTreeModel->clear();
2069 m_refScriptsTreeModel->clear();
2070 #if !USE_GTKMM_BUILDER
2071 // remove all entries from "Instrument" menu
2072 while (!instrument_menu->get_children().empty()) {
2073 remove_instrument_from_menu(0);
2074 }
2075 #endif
2076 // free libgig's gig::File instance
2077 if (file && !file_is_shared) delete file;
2078 file = NULL;
2079 set_file_is_shared(false);
2080 }
2081
2082 void MainWindow::__refreshEntireGUI() {
2083 // clear the samples and instruments tree views
2084 m_refTreeModel->clear();
2085 m_refSamplesTreeModel->clear();
2086 m_refScriptsTreeModel->clear();
2087 #if !USE_GTKMM_BUILDER
2088 // remove all entries from "Instrument" menu
2089 while (!instrument_menu->get_children().empty()) {
2090 remove_instrument_from_menu(0);
2091 }
2092 #endif
2093
2094 if (!this->file) return;
2095
2096 load_gig(
2097 this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2098 );
2099 }
2100
2101 void MainWindow::on_action_file_new()
2102 {
2103 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2104
2105 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2106
2107 // clear all GUI elements
2108 __clear();
2109 // create a new .gig file (virtually yet)
2110 gig::File* pFile = new gig::File;
2111 // already add one new instrument by default
2112 gig::Instrument* pInstrument = pFile->AddInstrument();
2113 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2114 // update GUI with that new gig::File
2115 load_gig(pFile, 0 /*no file name yet*/);
2116 }
2117
2118 bool MainWindow::close_confirmation_dialog()
2119 {
2120 gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
2121 Glib::filename_display_basename(filename).c_str());
2122 Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2123 g_free(msg);
2124 dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2125 dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2126 #if HAS_GTKMM_STOCK
2127 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2128 dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2129 #else
2130 dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2131 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2132 #endif
2133 dialog.set_default_response(Gtk::RESPONSE_YES);
2134 int response = dialog.run();
2135 dialog.hide();
2136
2137 // user decided to exit app without saving
2138 if (response == Gtk::RESPONSE_NO) return true;
2139
2140 // user cancelled dialog, thus don't close app
2141 if (response == Gtk::RESPONSE_CANCEL) return false;
2142
2143 // TODO: the following return valid is disabled and hard coded instead for
2144 // now, due to the fact that saving with progress bar is now implemented
2145 // asynchronously, as a result the app does not close automatically anymore
2146 // after saving the file has completed
2147 //
2148 // if (response == Gtk::RESPONSE_YES) return file_save();
2149 // return response != Gtk::RESPONSE_CANCEL;
2150 //
2151 if (response == Gtk::RESPONSE_YES) file_save();
2152 return false; // always prevent closing the app for now (see comment above)
2153 }
2154
2155 bool MainWindow::leaving_shared_mode_dialog() {
2156 Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2157 Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2158 dialog.set_secondary_text(
2159 _("If you proceed to work on another instrument file, it won't be "
2160 "used by the sampler until you tell the sampler explicitly to "
2161 "load it."));
2162 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2163 #if HAS_GTKMM_STOCK
2164 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2165 #else
2166 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2167 #endif
2168 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2169 int response = dialog.run();
2170 dialog.hide();
2171 return response == Gtk::RESPONSE_YES;
2172 }
2173
2174 void MainWindow::on_action_file_open()
2175 {
2176 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2177
2178 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2179
2180 Gtk::FileChooserDialog dialog(*this, _("Open file"));
2181 #if HAS_GTKMM_STOCK
2182 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2183 dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2184 #else
2185 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2186 dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2187 #endif
2188 dialog.set_default_response(Gtk::RESPONSE_OK);
2189 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2190 Gtk::FileFilter filter;
2191 filter.add_pattern("*.gig");
2192 #else
2193 Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2194 filter->add_pattern("*.gig");
2195 #endif
2196 dialog.set_filter(filter);
2197 if (current_gig_dir != "") {
2198 dialog.set_current_folder(current_gig_dir);
2199 }
2200 if (dialog.run() == Gtk::RESPONSE_OK) {
2201 std::string filename = dialog.get_filename();
2202 printf("filename=%s\n", filename.c_str());
2203 printf("on_action_file_open self=%p\n",
2204 static_cast<void*>(Glib::Threads::Thread::self()));
2205 load_file(filename.c_str());
2206 current_gig_dir = Glib::path_get_dirname(filename);
2207 }
2208 }
2209
2210 void MainWindow::load_file(const char* name)
2211 {
2212 __clear();
2213
2214 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2215 _("Loading") + Glib::ustring(" '") +
2216 Glib::filename_display_basename(name) + "' ...",
2217 *this
2218 );
2219 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2220 progress_dialog->show_all();
2221 #endif
2222 loader = new Loader(name); //FIXME: memory leak!
2223 loader->signal_progress().connect(
2224 sigc::mem_fun(*this, &MainWindow::on_loader_progress));
2225 loader->signal_finished().connect(
2226 sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2227 loader->signal_error().connect(
2228 sigc::mem_fun(*this, &MainWindow::on_loader_error));
2229 loader->launch();
2230 }
2231
2232 void MainWindow::load_instrument(gig::Instrument* instr) {
2233 if (!instr) {
2234 Glib::ustring txt = "Provided instrument is NULL!\n";
2235 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2236 msg.run();
2237 Gtk::Main::quit();
2238 }
2239 // clear all GUI elements
2240 __clear();
2241 // load the instrument
2242 gig::File* pFile = (gig::File*) instr->GetParent();
2243 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2244 // automatically select the given instrument
2245 int i = 0;
2246 for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2247 instrument = pFile->GetNextInstrument(), ++i)
2248 {
2249 if (instrument == instr) {
2250 // select item in "instruments" tree view
2251 m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2252 // make sure the selected item in the "instruments" tree view is
2253 // visible (scroll to it)
2254 m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2255 #if !USE_GTKMM_BUILDER
2256 // select item in instrument menu
2257 {
2258 const std::vector<Gtk::Widget*> children =
2259 instrument_menu->get_children();
2260 static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2261 }
2262 #endif
2263 // update region chooser and dimension region chooser
2264 m_RegionChooser.set_instrument(instr);
2265 break;
2266 }
2267 }
2268 }
2269
2270 void MainWindow::on_loader_progress()
2271 {
2272 progress_dialog->set_fraction(loader->get_progress());
2273 }
2274
2275 void MainWindow::on_loader_finished()
2276 {
2277 printf("Loader finished!\n");
2278 printf("on_loader_finished self=%p\n",
2279 static_cast<void*>(Glib::Threads::Thread::self()));
2280 load_gig(loader->gig, loader->filename.c_str());
2281 progress_dialog->hide();
2282 }
2283
2284 void MainWindow::on_loader_error()
2285 {
2286 Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2287 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2288 msg.run();
2289 progress_dialog->hide();
2290 }
2291
2292 void MainWindow::on_action_file_save()
2293 {
2294 file_save();
2295 }
2296
2297 bool MainWindow::check_if_savable()
2298 {
2299 if (!file) return false;
2300
2301 if (!file->GetFirstSample()) {
2302 Gtk::MessageDialog(*this, _("The file could not be saved "
2303 "because it contains no samples"),
2304 false, Gtk::MESSAGE_ERROR).run();
2305 return false;
2306 }
2307
2308 for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
2309 instrument = file->GetNextInstrument()) {
2310 if (!instrument->GetFirstRegion()) {
2311 Gtk::MessageDialog(*this, _("The file could not be saved "
2312 "because there are instruments "
2313 "that have no regions"),
2314 false, Gtk::MESSAGE_ERROR).run();
2315 return false;
2316 }
2317 }
2318 return true;
2319 }
2320
2321 bool MainWindow::file_save()
2322 {
2323 if (!check_if_savable()) return false;
2324 if (!file_is_shared && !file_has_name) return file_save_as();
2325
2326 std::cout << "Saving file\n" << std::flush;
2327 file_structure_to_be_changed_signal.emit(this->file);
2328
2329 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2330 _("Saving") + Glib::ustring(" '") +
2331 Glib::filename_display_basename(this->filename) + "' ...",
2332 *this
2333 );
2334 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2335 progress_dialog->show_all();
2336 #endif
2337 saver = new Saver(this->file); //FIXME: memory leak!
2338 saver->signal_progress().connect(
2339 sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2340 saver->signal_finished().connect(
2341 sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2342 saver->signal_error().connect(
2343 sigc::mem_fun(*this, &MainWindow::on_saver_error));
2344 saver->launch();
2345
2346 return true;
2347 }
2348
2349 void MainWindow::on_saver_progress()
2350 {
2351 progress_dialog->set_fraction(saver->get_progress());
2352 }
2353
2354 void MainWindow::on_saver_error()
2355 {
2356 file_structure_changed_signal.emit(this->file);
2357 Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2358 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2359 msg.run();
2360 }
2361
2362 void MainWindow::on_saver_finished()
2363 {
2364 this->file = saver->gig;
2365 this->filename = saver->filename;
2366 current_gig_dir = Glib::path_get_dirname(filename);
2367 set_title(Glib::filename_display_basename(filename));
2368 file_has_name = true;
2369 file_is_changed = false;
2370 std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
2371 __import_queued_samples();
2372 std::cout << "Importing queued samples done.\n" << std::flush;
2373
2374 file_structure_changed_signal.emit(this->file);
2375
2376 __refreshEntireGUI();
2377 progress_dialog->hide();
2378 }
2379
2380 void MainWindow::on_action_file_save_as()
2381 {
2382 if (!check_if_savable()) return;
2383 file_save_as();
2384 }
2385
2386 bool MainWindow::file_save_as()
2387 {
2388 Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2389 #if HAS_GTKMM_STOCK
2390 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2391 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2392 #else
2393 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2394 dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2395 #endif
2396 dialog.set_default_response(Gtk::RESPONSE_OK);
2397 dialog.set_do_overwrite_confirmation();
2398
2399 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2400 Gtk::FileFilter filter;
2401 filter.add_pattern("*.gig");
2402 #else
2403 Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2404 filter->add_pattern("*.gig");
2405 #endif
2406 dialog.set_filter(filter);
2407
2408 // set initial dir and filename of the Save As dialog
2409 // and prepare that initial filename as a copy of the gig
2410 {
2411 std::string basename = Glib::path_get_basename(filename);
2412 std::string dir = Glib::path_get_dirname(filename);
2413 basename = std::string(_("copy_of_")) + basename;
2414 Glib::ustring copyFileName = Glib::build_filename(dir, basename);
2415 if (Glib::path_is_absolute(filename)) {
2416 dialog.set_filename(copyFileName);
2417 } else {
2418 if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
2419 }
2420 dialog.set_current_name(Glib::filename_display_basename(copyFileName));
2421 }
2422
2423 // show warning in the dialog
2424 HBox descriptionArea;
2425 descriptionArea.set_spacing(15);
2426 Gtk::Image warningIcon;
2427 warningIcon.set_from_icon_name("dialog-warning",
2428 Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2429 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2430 #if GTKMM_MAJOR_VERSION < 3
2431 view::WrapLabel description;
2432 #else
2433 Gtk::Label description;
2434 description.set_line_wrap();
2435 #endif
2436 description.set_markup(
2437 _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
2438 "<span style=\"italic\">\"Save\"</span> dialog instead of "
2439 "<span style=\"italic\">\"Save As...\"</span> if you want to save "
2440 "to the same .gig file. Using "
2441 "<span style=\"italic\">\"Save As...\"</span> for writing to the "
2442 "same .gig file will end up in corrupted sample wave data!\n")
2443 );
2444 descriptionArea.pack_start(description);
2445 #if USE_GTKMM_BOX
2446 dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2447 #else
2448 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2449 #endif
2450 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2451 descriptionArea.show_all();
2452 #endif
2453
2454 if (dialog.run() == Gtk::RESPONSE_OK) {
2455 std::string filename = dialog.get_filename();
2456 if (!Glib::str_has_suffix(filename, ".gig")) {
2457 filename += ".gig";
2458 }
2459 printf("filename=%s\n", filename.c_str());
2460
2461 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2462 _("Saving") + Glib::ustring(" '") +
2463 Glib::filename_display_basename(filename) + "' ...",
2464 *this
2465 );
2466 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2467 progress_dialog->show_all();
2468 #endif
2469
2470 saver = new Saver(file, filename); //FIXME: memory leak!
2471 saver->signal_progress().connect(
2472 sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2473 saver->signal_finished().connect(
2474 sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2475 saver->signal_error().connect(
2476 sigc::mem_fun(*this, &MainWindow::on_saver_error));
2477 saver->launch();
2478
2479 return true;
2480 }
2481 return false;
2482 }
2483
2484 // actually write the sample(s)' data to the gig file
2485 void MainWindow::__import_queued_samples() {
2486 std::cout << "Starting sample import\n" << std::flush;
2487 Glib::ustring error_files;
2488 printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2489 for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2490 iter != m_SampleImportQueue.end(); ) {
2491 printf("Importing sample %s\n",iter->second.sample_path.c_str());
2492 SF_INFO info;
2493 info.format = 0;
2494 SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2495 sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2496 try {
2497 if (!hFile) throw std::string(_("could not open file"));
2498 // determine sample's bit depth
2499 int bitdepth;
2500 switch (info.format & 0xff) {
2501 case SF_FORMAT_PCM_S8:
2502 case SF_FORMAT_PCM_16:
2503 case SF_FORMAT_PCM_U8:
2504 bitdepth = 16;
2505 break;
2506 case SF_FORMAT_PCM_24:
2507 case SF_FORMAT_PCM_32:
2508 case SF_FORMAT_FLOAT:
2509 case SF_FORMAT_DOUBLE:
2510 bitdepth = 24;
2511 break;
2512 default:
2513 sf_close(hFile); // close sound file
2514 throw std::string(_("format not supported")); // unsupported subformat (yet?)
2515 }
2516
2517 // reset write position for sample
2518 iter->first->SetPos(0);
2519
2520 const int bufsize = 10000;
2521 switch (bitdepth) {
2522 case 16: {
2523 short* buffer = new short[bufsize * info.channels];
2524 sf_count_t cnt = info.frames;
2525 while (cnt) {
2526 // libsndfile does the conversion for us (if needed)
2527 int n = sf_readf_short(hFile, buffer, bufsize);
2528 // write from buffer directly (physically) into .gig file
2529 iter->first->Write(buffer, n);
2530 cnt -= n;
2531 }
2532 delete[] buffer;
2533 break;
2534 }
2535 case 24: {
2536 int* srcbuf = new int[bufsize * info.channels];
2537 uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
2538 sf_count_t cnt = info.frames;
2539 while (cnt) {
2540 // libsndfile returns 32 bits, convert to 24
2541 int n = sf_readf_int(hFile, srcbuf, bufsize);
2542 int j = 0;
2543 for (int i = 0 ; i < n * info.channels ; i++) {
2544 dstbuf[j++] = srcbuf[i] >> 8;
2545 dstbuf[j++] = srcbuf[i] >> 16;
2546 dstbuf[j++] = srcbuf[i] >> 24;
2547 }
2548 // write from buffer directly (physically) into .gig file
2549 iter->first->Write(dstbuf, n);
2550 cnt -= n;
2551 }
2552 delete[] srcbuf;
2553 delete[] dstbuf;
2554 break;
2555 }
2556 }
2557 // cleanup
2558 sf_close(hFile);
2559 // let the sampler re-cache the sample if needed
2560 sample_changed_signal.emit(iter->first);
2561 // on success we remove the sample from the import queue,
2562 // otherwise keep it, maybe it works the next time ?
2563 std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2564 ++iter;
2565 m_SampleImportQueue.erase(cur);
2566 } catch (std::string what) {
2567 // remember the files that made trouble (and their cause)
2568 if (!error_files.empty()) error_files += "\n";
2569 error_files += iter->second.sample_path += " (" + what + ")";
2570 ++iter;
2571 }
2572 }
2573 // show error message box when some sample(s) could not be imported
2574 if (!error_files.empty()) {
2575 Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
2576 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2577 msg.run();
2578 }
2579 }
2580
2581 void MainWindow::on_action_file_properties()
2582 {
2583 propDialog.show();
2584 propDialog.deiconify();
2585 }
2586
2587 void MainWindow::on_action_warn_user_on_extensions() {
2588 Settings::singleton()->warnUserOnExtensions =
2589 !Settings::singleton()->warnUserOnExtensions;
2590 }
2591
2592 void MainWindow::on_action_sync_sampler_instrument_selection() {
2593 Settings::singleton()->syncSamplerInstrumentSelection =
2594 !Settings::singleton()->syncSamplerInstrumentSelection;
2595 }
2596
2597 void MainWindow::on_action_move_root_note_with_region_moved() {
2598 Settings::singleton()->moveRootNoteWithRegionMoved =
2599 !Settings::singleton()->moveRootNoteWithRegionMoved;
2600 }
2601
2602 void MainWindow::on_action_help_about()
2603 {
2604 Gtk::AboutDialog dialog;
2605 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
2606 dialog.set_program_name("Gigedit");
2607 #else
2608 dialog.set_name("Gigedit");
2609 #endif
2610 dialog.set_version(VERSION);
2611 dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
2612 const std::string sComment =
2613 _("Built " __DATE__ "\nUsing ") +
2614 ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
2615 _(
2616 "Gigedit is released under the GNU General Public License.\n"
2617 "\n"
2618 "This program is distributed WITHOUT ANY WARRANTY; So better "
2619 "backup your Gigasampler/GigaStudio files before editing them with "
2620 "this application.\n"
2621 "\n"
2622 "Please report bugs to: http://bugs.linuxsampler.org"
2623 );
2624 dialog.set_comments(sComment.c_str());
2625 dialog.set_website("http://www.linuxsampler.org");
2626 dialog.set_website_label("http://www.linuxsampler.org");
2627 dialog.set_position(Gtk::WIN_POS_CENTER);
2628 dialog.run();
2629 }
2630
2631 PropDialog::PropDialog()
2632 : eFileFormat(_("File Format")),
2633 eName(_("Name")),
2634 eCreationDate(_("Creation date")),
2635 eComments(_("Comments")),
2636 eProduct(_("Product")),
2637 eCopyright(_("Copyright")),
2638 eArtists(_("Artists")),
2639 eGenre(_("Genre")),
2640 eKeywords(_("Keywords")),
2641 eEngineer(_("Engineer")),
2642 eTechnician(_("Technician")),
2643 eSoftware(_("Software")),
2644 eMedium(_("Medium")),
2645 eSource(_("Source")),
2646 eSourceForm(_("Source form")),
2647 eCommissioned(_("Commissioned")),
2648 eSubject(_("Subject")),
2649 #if HAS_GTKMM_STOCK
2650 quitButton(Gtk::Stock::CLOSE),
2651 #else
2652 quitButton(_("_Close")),
2653 #endif
2654 table(2, 1),
2655 m_file(NULL)
2656 {
2657 if (!Settings::singleton()->autoRestoreWindowDimension) {
2658 set_default_size(470, 390);
2659 set_position(Gtk::WIN_POS_MOUSE);
2660 }
2661
2662 set_title(_("File Properties"));
2663 eName.set_width_chars(50);
2664
2665 connect(eName, &DLS::Info::Name);
2666 connect(eCreationDate, &DLS::Info::CreationDate);
2667 connect(eComments, &DLS::Info::Comments);
2668 connect(eProduct, &DLS::Info::Product);
2669 connect(eCopyright, &DLS::Info::Copyright);
2670 connect(eArtists, &DLS::Info::Artists);
2671 connect(eGenre, &DLS::Info::Genre);
2672 connect(eKeywords, &DLS::Info::Keywords);
2673 connect(eEngineer, &DLS::Info::Engineer);
2674 connect(eTechnician, &DLS::Info::Technician);
2675 connect(eSoftware, &DLS::Info::Software);
2676 connect(eMedium, &DLS::Info::Medium);
2677 connect(eSource, &DLS::Info::Source);
2678 connect(eSourceForm, &DLS::Info::SourceForm);
2679 connect(eCommissioned, &DLS::Info::Commissioned);
2680 connect(eSubject, &DLS::Info::Subject);
2681
2682 table.add(eFileFormat);
2683 table.add(eName);
2684 table.add(eCreationDate);
2685 table.add(eComments);
2686 table.add(eProduct);
2687 table.add(eCopyright);
2688 table.add(eArtists);
2689 table.add(eGenre);
2690 table.add(eKeywords);
2691 table.add(eEngineer);
2692 table.add(eTechnician);
2693 table.add(eSoftware);
2694 table.add(eMedium);
2695 table.add(eSource);
2696 table.add(eSourceForm);
2697 table.add(eCommissioned);
2698 table.add(eSubject);
2699
2700 #if USE_GTKMM_GRID
2701 table.set_column_spacing(5);
2702 #else
2703 table.set_col_spacings(5);
2704 #endif
2705
2706 add(vbox);
2707 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2708 table.set_margin(5);
2709 #else
2710 table.set_border_width(5);
2711 #endif
2712 vbox.add(table);
2713 vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2714 buttonBox.set_layout(Gtk::BUTTONBOX_END);
2715 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2716 buttonBox.set_margin(5);
2717 #else
2718 buttonBox.set_border_width(5);
2719 #endif
2720 buttonBox.show();
2721 buttonBox.pack_start(quitButton);
2722 quitButton.set_can_default();
2723 quitButton.grab_focus();
2724 quitButton.signal_clicked().connect(
2725 sigc::mem_fun(*this, &PropDialog::hide));
2726 eFileFormat.signal_value_changed().connect(
2727 sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
2728
2729 quitButton.show();
2730 vbox.show();
2731 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2732 show_all_children();
2733 #endif
2734 }
2735
2736 void PropDialog::set_file(gig::File* file)
2737 {
2738 m_file = file;
2739
2740 // update file format version combo box
2741 const std::string sGiga = "Gigasampler/GigaStudio v";
2742 const int major = file->pVersion->major;
2743 std::vector<std::string> txts;
2744 std::vector<int> values;
2745 txts.push_back(sGiga + "2"); values.push_back(2);
2746 txts.push_back(sGiga + "3/v4"); values.push_back(3);
2747 if (major != 2 && major != 3) {
2748 txts.push_back(sGiga + ToString(major)); values.push_back(major);
2749 }
2750 std::vector<const char*> texts;
2751 for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2752 texts.push_back(NULL); values.push_back(0);
2753 eFileFormat.set_choices(&texts[0], &values[0]);
2754 eFileFormat.set_value(major);
2755 }
2756
2757 void PropDialog::onFileFormatChanged() {
2758 const int major = eFileFormat.get_value();
2759 if (m_file) m_file->pVersion->major = major;
2760 }
2761
2762 void PropDialog::set_info(DLS::Info* info)
2763 {
2764 update(info);
2765 }
2766
2767
2768 void InstrumentProps::set_Name(const gig::String& name)
2769 {
2770 m->pInfo->Name = name;
2771 }
2772
2773 void InstrumentProps::update_name()
2774 {
2775 update_model++;
2776 eName.set_value(m->pInfo->Name);
2777 update_model--;
2778 }
2779
2780 void InstrumentProps::set_IsDrum(bool value)
2781 {
2782 m->IsDrum = value;
2783 }
2784
2785 void InstrumentProps::set_MIDIBank(uint16_t value)
2786 {
2787 m->MIDIBank = value;
2788 }
2789
2790 void InstrumentProps::set_MIDIProgram(uint32_t value)
2791 {
2792 m->MIDIProgram = value;
2793 }
2794
2795 InstrumentProps::InstrumentProps() :
2796 #if HAS_GTKMM_STOCK
2797 quitButton(Gtk::Stock::CLOSE),
2798 #else
2799 quitButton(_("_Close")),
2800 #endif
2801 table(2,1),
2802 eName(_("Name")),
2803 eIsDrum(_("Is drum")),
2804 eMIDIBank(_("MIDI bank"), 0, 16383),
2805 eMIDIProgram(_("MIDI program")),
2806 eAttenuation(_("Attenuation"), 0, 96, 0, 1),
2807 eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2808 eEffectSend(_("Effect send"), 0, 65535),
2809 eFineTune(_("Fine tune"), -8400, 8400),
2810 ePitchbendRange(_("Pitchbend range"), 0, 48),
2811 ePianoReleaseMode(_("Piano release mode")),
2812 eDimensionKeyRangeLow(_("Keyswitching range low")),
2813 eDimensionKeyRangeHigh(_("Keyswitching range high"))
2814 {
2815 if (!Settings::singleton()->autoRestoreWindowDimension) {
2816 //set_default_size(470, 390);
2817 set_position(Gtk::WIN_POS_MOUSE);
2818 }
2819
2820 set_title(_("Instrument Properties"));
2821
2822 eDimensionKeyRangeLow.set_tip(
2823 _("start of the keyboard area which should switch the "
2824 "\"keyswitching\" dimension")
2825 );
2826 eDimensionKeyRangeHigh.set_tip(
2827 _("end of the keyboard area which should switch the "
2828 "\"keyswitching\" dimension")
2829 );
2830
2831 connect(eName, &InstrumentProps::set_Name);
2832 connect(eIsDrum, &InstrumentProps::set_IsDrum);
2833 connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2834 connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
2835 connect(eAttenuation, &gig::Instrument::Attenuation);
2836 connect(eGainPlus6, &gig::Instrument::Attenuation);
2837 connect(eEffectSend, &gig::Instrument::EffectSend);
2838 connect(eFineTune, &gig::Instrument::FineTune);
2839 connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
2840 connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
2841 connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
2842 &gig::Instrument::DimensionKeyRange);
2843
2844 eName.signal_value_changed().connect(sig_name_changed.make_slot());
2845
2846 #if USE_GTKMM_GRID
2847 table.set_column_spacing(5);
2848 #else
2849 table.set_col_spacings(5);
2850 #endif
2851
2852 table.add(eName);
2853 table.add(eIsDrum);
2854 table.add(eMIDIBank);
2855 table.add(eMIDIProgram);
2856 table.add(eAttenuation);
2857 table.add(eGainPlus6);
2858 table.add(eEffectSend);
2859 table.add(eFineTune);
2860 table.add(ePitchbendRange);
2861 table.add(ePianoReleaseMode);
2862 table.add(eDimensionKeyRangeLow);
2863 table.add(eDimensionKeyRangeHigh);
2864
2865 add(vbox);
2866 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2867 table.set_margin(5);
2868 #else
2869 table.set_border_width(5);
2870 #endif
2871 vbox.pack_start(table);
2872 table.show();
2873 vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2874 buttonBox.set_layout(Gtk::BUTTONBOX_END);
2875 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2876 buttonBox.set_margin(5);
2877 #else
2878 buttonBox.set_border_width(5);
2879 #endif
2880 buttonBox.show();
2881 buttonBox.pack_start(quitButton);
2882 quitButton.set_can_default();
2883 quitButton.grab_focus();
2884
2885 quitButton.signal_clicked().connect(
2886 sigc::mem_fun(*this, &InstrumentProps::hide));
2887
2888 quitButton.show();
2889 vbox.show();
2890 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2891 show_all_children();
2892 #endif
2893 }
2894
2895 void InstrumentProps::set_instrument(gig::Instrument* instrument)
2896 {
2897 update(instrument);
2898
2899 update_model++;
2900 eName.set_value(instrument->pInfo->Name);
2901 eIsDrum.set_value(instrument->IsDrum);
2902 eMIDIBank.set_value(instrument->MIDIBank);
2903 eMIDIProgram.set_value(instrument->MIDIProgram);
2904 update_model--;
2905 }
2906
2907
2908 void MainWindow::file_changed()
2909 {
2910 if (file && !file_is_changed) {
2911 set_title("*" + get_title());
2912 file_is_changed = true;
2913 }
2914 }
2915
2916 void MainWindow::updateSampleRefCountMap(gig::File* gig) {
2917 sample_ref_count.clear();
2918
2919 if (!gig) return;
2920
2921 for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
2922 instrument = gig->GetNextInstrument())
2923 {
2924 for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2925 rgn = instrument->GetNextRegion())
2926 {
2927 for (int i = 0; i < 256; ++i) {
2928 if (!rgn->pDimensionRegions[i]) continue;
2929 if (rgn->pDimensionRegions[i]->pSample) {
2930 sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
2931 }
2932 }
2933 }
2934 }
2935 }
2936
2937 void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
2938 {
2939 file = 0;
2940 set_file_is_shared(isSharedInstrument);
2941
2942 this->filename =
2943 (filename && strlen(filename) > 0) ?
2944 filename : (!gig->GetFileName().empty()) ?
2945 gig->GetFileName() : _("Unsaved Gig File");
2946 set_title(Glib::filename_display_basename(this->filename));
2947 file_has_name = filename;
2948 file_is_changed = false;
2949
2950 propDialog.set_file(gig);
2951 propDialog.set_info(gig->pInfo);
2952
2953 instrument_name_connection.block();
2954 int index = 0;
2955 for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2956 instrument = gig->GetNextInstrument(), ++index) {
2957 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2958 const int iScriptSlots = instrument->ScriptSlotCount();
2959
2960 Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2961 Gtk::TreeModel::Row row = *iter;
2962 row[m_Columns.m_col_nr] = index;
2963 row[m_Columns.m_col_name] = name;
2964 row[m_Columns.m_col_instr] = instrument;
2965 row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2966
2967 #if !USE_GTKMM_BUILDER
2968 add_instrument_to_menu(name);
2969 #endif
2970 }
2971 instrument_name_connection.unblock();
2972 #if !USE_GTKMM_BUILDER
2973 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
2974 #endif
2975
2976 updateSampleRefCountMap(gig);
2977
2978 for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
2979 if (group->Name != "") {
2980 Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2981 Gtk::TreeModel::Row rowGroup = *iterGroup;
2982 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
2983 rowGroup[m_SamplesModel.m_col_group] = group;
2984 rowGroup[m_SamplesModel.m_col_sample] = NULL;
2985 for (gig::Sample* sample = group->GetFirstSample();
2986 sample; sample = group->GetNextSample()) {
2987 Gtk::TreeModel::iterator iterSample =
2988 m_refSamplesTreeModel->append(rowGroup.children());
2989 Gtk::TreeModel::Row rowSample = *iterSample;
2990 rowSample[m_SamplesModel.m_col_name] =
2991 gig_to_utf8(sample->pInfo->Name);
2992 rowSample[m_SamplesModel.m_col_sample] = sample;
2993 rowSample[m_SamplesModel.m_col_group] = NULL;
2994 int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
2995 rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2996 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2997 }
2998 }
2999 }
3000
3001 for (int i = 0; gig->GetScriptGroup(i); ++i) {
3002 gig::ScriptGroup* group = gig->GetScriptGroup(i);
3003
3004 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3005 Gtk::TreeModel::Row rowGroup = *iterGroup;
3006 rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3007 rowGroup[m_ScriptsModel.m_col_group] = group;
3008 rowGroup[m_ScriptsModel.m_col_script] = NULL;
3009 for (int s = 0; group->GetScript(s); ++s) {
3010 gig::Script* script = group->GetScript(s);
3011
3012 Gtk::TreeModel::iterator iterScript =
3013 m_refScriptsTreeModel->append(rowGroup.children());
3014 Gtk::TreeModel::Row rowScript = *iterScript;
3015 rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
3016 rowScript[m_ScriptsModel.m_col_script] = script;
3017 rowScript[m_ScriptsModel.m_col_group] = NULL;
3018 }
3019 }
3020 // unfold all sample groups & script groups by default
3021 m_TreeViewSamples.expand_all();
3022 m_TreeViewScripts.expand_all();
3023
3024 file = gig;
3025
3026 // select the first instrument
3027 m_TreeView.get_selection()->select(Gtk::TreePath("0"));
3028
3029 instr_props_set_instrument();
3030 gig::Instrument* instrument = get_instrument();
3031 if (instrument) {
3032 midiRules.set_instrument(instrument);
3033 }
3034 }
3035
3036 bool MainWindow::instr_props_set_instrument()
3037 {
3038 instrumentProps.signal_name_changed().clear();
3039
3040 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3041 if (rows.empty()) {
3042 instrumentProps.hide();
3043 return false;
3044 }
3045 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3046 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3047 if (it) {
3048 Gtk::TreeModel::Row row = *it;
3049 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3050
3051 instrumentProps.set_instrument(instrument);
3052
3053 // make sure instrument tree is updated when user changes the
3054 // instrument name in instrument properties window
3055 instrumentProps.signal_name_changed().connect(
3056 sigc::bind(
3057 sigc::mem_fun(*this,
3058 &MainWindow::instr_name_changed_by_instr_props),
3059 it));
3060 } else {
3061 instrumentProps.hide();
3062 }
3063 //NOTE: explicit boolean cast required for GTKMM4 development branch here
3064 return it ? true : false;
3065 }
3066
3067 void MainWindow::show_instr_props()
3068 {
3069 if (instr_props_set_instrument()) {
3070 instrumentProps.show();
3071 instrumentProps.deiconify();
3072 }
3073 }
3074
3075 void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3076 {
3077 Gtk::TreeModel::Row row = *it;
3078 Glib::ustring name = row[m_Columns.m_col_name];
3079
3080 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3081 Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3082 if (gigname != name) {
3083 row[m_Columns.m_col_name] = gigname;
3084 }
3085 }
3086
3087 void MainWindow::show_midi_rules()
3088 {
3089 if (gig::Instrument* instrument = get_instrument())
3090 {
3091 midiRules.set_instrument(instrument);
3092 midiRules.show();
3093 midiRules.deiconify();
3094 }
3095 }
3096
3097 void MainWindow::show_script_slots() {
3098 if (!file) return;
3099 // get selected instrument