/[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 3637 - (show annotations) (download)
Thu Oct 24 13:12:52 2019 UTC (4 years, 5 months ago) by schoenebeck
File size: 225026 byte(s)
* Implemented sample property dialog.
* Bumped version (1.1.1.svn6).

1 /*
2 * Copyright (C) 2006-2019 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
25 #include <glibmm/convert.h>
26 #include <glibmm/dispatcher.h>
27 #include <glibmm/miscutils.h>
28 #include <glibmm/stringutils.h>
29 #include <glibmm/regex.h>
30 #include <gtkmm/aboutdialog.h>
31 #include <gtkmm/filechooserdialog.h>
32 #include <gtkmm/messagedialog.h>
33 #if HAS_GTKMM_STOCK
34 # include <gtkmm/stock.h>
35 #endif
36 #include <gtkmm/targetentry.h>
37 #include <gtkmm/main.h>
38 #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89)
39 # include <gtkmm/toggleaction.h>
40 #endif
41 #include <gtkmm/accelmap.h>
42 #if GTKMM_MAJOR_VERSION < 3
43 #include "wrapLabel.hh"
44 #endif
45
46 #include "global.h"
47 #include "compat.h"
48
49 #include <stdio.h>
50 #ifdef LIBSNDFILE_HEADER_FILE
51 # include LIBSNDFILE_HEADER_FILE(sndfile.h)
52 #else
53 # include <sndfile.h>
54 #endif
55 #include <assert.h>
56
57 #include "mainwindow.h"
58 #include "Settings.h"
59 #include "CombineInstrumentsDialog.h"
60 #include "scripteditor.h"
61 #include "scriptslots.h"
62 #include "ReferencesView.h"
63 #include "../../gfx/status_attached.xpm"
64 #include "../../gfx/status_detached.xpm"
65 #include "gfx/builtinpix.h"
66 #include "MacroEditor.h"
67 #include "MacrosSetup.h"
68 #if defined(__APPLE__)
69 # include "MacHelper.h"
70 #endif
71
72 static const Gdk::ModifierType primaryModifierKey =
73 #if defined(__APPLE__)
74 Gdk::META_MASK; // Cmd key on Mac
75 #else
76 Gdk::CONTROL_MASK; // Ctrl key on all other OSs
77 #endif
78
79 MainWindow::MainWindow() :
80 m_DimRegionChooser(*this),
81 dimreg_label(_("Changes apply to:")),
82 dimreg_all_regions(_("all regions")),
83 dimreg_all_dimregs(_("all dimension splits")),
84 dimreg_stereo(_("both channels")),
85 labelLegend(_("Legend:")),
86 labelNoSample(_(" No Sample")),
87 labelMissingSample(_(" Missing some Sample(s)")),
88 labelLooped(_(" Looped")),
89 labelSomeLoops(_(" Some Loop(s)"))
90 {
91 loadBuiltInPix();
92
93 this->file = NULL;
94
95 // set_border_width(5);
96
97 if (!Settings::singleton()->autoRestoreWindowDimension) {
98 #if GTKMM_MAJOR_VERSION >= 3
99 set_default_size(960, 600);
100 #else
101 set_default_size(865, 600);
102 #endif
103 set_position(Gtk::WIN_POS_CENTER);
104 }
105
106 add(m_VBox);
107
108 // Handle selection
109 m_TreeView.get_selection()->signal_changed().connect(
110 sigc::mem_fun(*this, &MainWindow::on_sel_change));
111
112 // m_TreeView.set_reorderable();
113
114 #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
115 m_TreeView.signal_button_press_event().connect(
116 sigc::mem_fun(*this, &MainWindow::on_button_release));
117 #else
118 m_TreeView.signal_button_press_event().connect_notify(
119 sigc::mem_fun(*this, &MainWindow::on_button_release));
120 #endif
121
122 // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
123 m_ScrolledWindow.add(m_TreeView);
124 // m_ScrolledWindow.set_size_request(200, 600);
125 m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
126
127 m_ScrolledWindowSamples.add(m_TreeViewSamples);
128 m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
129
130 m_ScrolledWindowScripts.add(m_TreeViewScripts);
131 m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132
133 #if GTKMM_MAJOR_VERSION < 3
134 m_TreeViewNotebook.set_size_request(300);
135 #endif
136
137 m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
138 m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
139 m_searchField.pack_start(m_searchText);
140 m_searchField.set_spacing(5);
141
142 m_left_vbox.pack_start(m_TreeViewNotebook);
143 m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
144
145 m_HPaned.add1(m_left_vbox);
146
147 dimreg_hbox.add(dimreg_label);
148 dimreg_hbox.add(dimreg_all_regions);
149 dimreg_hbox.add(dimreg_all_dimregs);
150 dimreg_stereo.set_active();
151 dimreg_hbox.add(dimreg_stereo);
152 dimreg_vbox.add(dimreg_edit);
153 dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
154 {
155 legend_hbox.add(labelLegend);
156
157 imageNoSample.set(redDot);
158 #if HAS_GTKMM_ALIGNMENT
159 imageNoSample.set_alignment(Gtk::ALIGN_END);
160 labelNoSample.set_alignment(Gtk::ALIGN_START);
161 #else
162 imageNoSample.set_halign(Gtk::ALIGN_END);
163 labelNoSample.set_halign(Gtk::ALIGN_START);
164 #endif
165 legend_hbox.add(imageNoSample);
166 legend_hbox.add(labelNoSample);
167
168 imageMissingSample.set(yellowDot);
169 #if HAS_GTKMM_ALIGNMENT
170 imageMissingSample.set_alignment(Gtk::ALIGN_END);
171 labelMissingSample.set_alignment(Gtk::ALIGN_START);
172 #else
173 imageMissingSample.set_halign(Gtk::ALIGN_END);
174 labelMissingSample.set_halign(Gtk::ALIGN_START);
175 #endif
176 legend_hbox.add(imageMissingSample);
177 legend_hbox.add(labelMissingSample);
178
179 imageLooped.set(blackLoop);
180 #if HAS_GTKMM_ALIGNMENT
181 imageLooped.set_alignment(Gtk::ALIGN_END);
182 labelLooped.set_alignment(Gtk::ALIGN_START);
183 #else
184 imageLooped.set_halign(Gtk::ALIGN_END);
185 labelLooped.set_halign(Gtk::ALIGN_START);
186 #endif
187 legend_hbox.add(imageLooped);
188 legend_hbox.add(labelLooped);
189
190 imageSomeLoops.set(grayLoop);
191 #if HAS_GTKMM_ALIGNMENT
192 imageSomeLoops.set_alignment(Gtk::ALIGN_END);
193 labelSomeLoops.set_alignment(Gtk::ALIGN_START);
194 #else
195 imageSomeLoops.set_halign(Gtk::ALIGN_END);
196 labelSomeLoops.set_halign(Gtk::ALIGN_START);
197 #endif
198 legend_hbox.add(imageSomeLoops);
199 legend_hbox.add(labelSomeLoops);
200
201 #if HAS_GTKMM_SHOW_ALL_CHILDREN
202 legend_hbox.show_all_children();
203 #endif
204 }
205 dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
206 m_HPaned.add2(dimreg_vbox);
207
208 dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
209 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."));
210 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."));
211 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)."));
212
213 m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
214 m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
215 m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
216
217 #if USE_GLIB_ACTION
218 m_actionGroup = Gio::SimpleActionGroup::create();
219 m_actionGroup->add_action(
220 "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
221 );
222 m_actionGroup->add_action(
223 "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
224 );
225 m_actionGroup->add_action(
226 "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
227 );
228 m_actionGroup->add_action(
229 "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
230 );
231 m_actionGroup->add_action(
232 "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
233 );
234 m_actionGroup->add_action(
235 "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
236 );
237 m_actionMIDIRules = m_actionGroup->add_action(
238 "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
239 );
240 m_actionGroup->add_action(
241 "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
242 );
243 m_actionGroup->add_action(
244 "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
245 );
246 m_actionGroup->add_action(
247 "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
248 );
249 m_actionGroup->add_action(
250 "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
251 );
252 m_actionGroup->add_action(
253 "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
254 );
255 #else
256 actionGroup = Gtk::ActionGroup::create();
257
258 actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
259 actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
260 sigc::mem_fun(
261 *this, &MainWindow::on_action_file_new));
262 Glib::RefPtr<Gtk::Action> action =
263 Gtk::Action::create("Open", Gtk::Stock::OPEN);
264 action->property_label() = action->property_label() + "...";
265 actionGroup->add(action,
266 sigc::mem_fun(
267 *this, &MainWindow::on_action_file_open));
268 actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
269 sigc::mem_fun(
270 *this, &MainWindow::on_action_file_save));
271 action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
272 action->property_label() = action->property_label() + "...";
273 actionGroup->add(action,
274 Gtk::AccelKey("<shift><control>s"),
275 sigc::mem_fun(
276 *this, &MainWindow::on_action_file_save_as));
277 actionGroup->add(Gtk::Action::create("Properties",
278 Gtk::Stock::PROPERTIES),
279 sigc::mem_fun(
280 *this, &MainWindow::on_action_file_properties));
281 actionGroup->add(Gtk::Action::create("InstrProperties",
282 Gtk::Stock::PROPERTIES),
283 sigc::mem_fun(
284 *this, &MainWindow::show_instr_props));
285 actionGroup->add(Gtk::Action::create("MidiRules",
286 _("_Midi Rules...")),
287 sigc::mem_fun(
288 *this, &MainWindow::show_midi_rules));
289 actionGroup->add(Gtk::Action::create("ScriptSlots",
290 _("_Script Slots...")),
291 sigc::mem_fun(
292 *this, &MainWindow::show_script_slots));
293 actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
294 sigc::mem_fun(
295 *this, &MainWindow::on_action_quit));
296 actionGroup->add(
297 Gtk::Action::create("MenuSample", _("_Sample")),
298 sigc::mem_fun(*this, &MainWindow::show_samples_tab)
299 );
300 actionGroup->add(
301 Gtk::Action::create("MenuInstrument", _("_Instrument")),
302 sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
303 );
304 actionGroup->add(
305 Gtk::Action::create("MenuScript", _("Scr_ipt")),
306 sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
307 );
308 actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
309 actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
310
311 actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
312 #endif
313
314 const Gdk::ModifierType primaryModifierKey =
315 #if defined(__APPLE__)
316 Gdk::META_MASK; // Cmd key on Mac
317 #else
318 Gdk::CONTROL_MASK; // Ctrl key on all other OSs
319 #endif
320
321 #if USE_GLIB_ACTION
322 m_actionCopyDimRgn = m_actionGroup->add_action(
323 "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)
324 );
325 m_actionPasteDimRgn = m_actionGroup->add_action(
326 "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)
327 );
328 m_actionAdjustClipboard = m_actionGroup->add_action(
329 "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)
330 );
331 m_actionGroup->add_action(
332 "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument)
333 );
334 m_actionGroup->add_action(
335 "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument)
336 );
337 m_actionGroup->add_action(
338 "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region)
339 );
340 m_actionGroup->add_action(
341 "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region)
342 );
343 m_actionGroup->add_action(
344 "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)
345 );
346 m_actionGroup->add_action(
347 "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)
348 );
349 m_actionGroup->add_action(
350 "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension)
351 );
352 m_actionGroup->add_action(
353 "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension)
354 );
355 m_actionGroup->add_action(
356 "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)
357 );
358 m_actionGroup->add_action(
359 "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)
360 );
361 #else
362 actionGroup->add(Gtk::Action::create("CopyDimRgn",
363 _("Copy selected dimension region")),
364 Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
365 sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
366
367 actionGroup->add(Gtk::Action::create("PasteDimRgn",
368 _("Paste dimension region")),
369 Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
370 sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
371
372 actionGroup->add(Gtk::Action::create("AdjustClipboard",
373 _("Adjust Clipboard Content")),
374 Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
375 sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
376
377 actionGroup->add(Gtk::Action::create("SelectPrevInstr",
378 _("Select Previous Instrument")),
379 Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
380 sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
381
382 actionGroup->add(Gtk::Action::create("SelectNextInstr",
383 _("Select Next Instrument")),
384 Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
385 sigc::mem_fun(*this, &MainWindow::select_next_instrument));
386
387 actionGroup->add(Gtk::Action::create("SelectPrevRegion",
388 _("Select Previous Region")),
389 Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
390 sigc::mem_fun(*this, &MainWindow::select_prev_region));
391
392 actionGroup->add(Gtk::Action::create("SelectNextRegion",
393 _("Select Next Region")),
394 Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
395 sigc::mem_fun(*this, &MainWindow::select_next_region));
396
397 actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
398 _("Select Previous Dimension Region Zone")),
399 Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
400 sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
401
402 actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
403 _("Select Next Dimension Region Zone")),
404 Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
405 sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
406
407 actionGroup->add(Gtk::Action::create("SelectPrevDimension",
408 _("Select Previous Dimension")),
409 Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
410 sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
411
412 actionGroup->add(Gtk::Action::create("SelectNextDimension",
413 _("Select Next Dimension")),
414 Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
415 sigc::mem_fun(*this, &MainWindow::select_next_dimension));
416
417 actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
418 _("Add Previous Dimension Region Zone to Selection")),
419 Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
420 sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
421
422 actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
423 _("Add Next Dimension Region Zone to Selection")),
424 Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
425 sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
426 #endif
427
428 #if USE_GLIB_ACTION
429 m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true);
430 m_actionToggleCopySampleTune = m_actionGroup->add_action_bool("CopySampleTune", true);
431 m_actionToggleCopySampleLoop = m_actionGroup->add_action_bool("CopySampleLoop", true);
432 #else
433 Glib::RefPtr<Gtk::ToggleAction> toggle_action =
434 Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
435 toggle_action->set_active(true);
436 actionGroup->add(toggle_action);
437
438 toggle_action =
439 Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
440 toggle_action->set_active(true);
441 actionGroup->add(toggle_action);
442
443 toggle_action =
444 Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
445 toggle_action->set_active(true);
446 actionGroup->add(toggle_action);
447 #endif
448
449 #if USE_GLIB_ACTION
450 m_actionToggleStatusBar =
451 m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
452 m_actionToggleRestoreWinDim =
453 m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
454 m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
455 "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
456 Settings::singleton()->showTooltips
457 );
458 m_actionToggleSaveWithTempFile =
459 m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
460 m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
461 #else
462 actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
463
464
465 actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
466 toggle_action =
467 Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
468 toggle_action->set_active(true);
469 actionGroup->add(toggle_action,
470 sigc::mem_fun(
471 *this, &MainWindow::on_action_view_status_bar));
472
473 toggle_action =
474 Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
475 toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
476 actionGroup->add(toggle_action,
477 sigc::mem_fun(
478 *this, &MainWindow::on_auto_restore_win_dim));
479
480 toggle_action =
481 Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
482 toggle_action->set_active(Settings::singleton()->showTooltips);
483 actionGroup->add(
484 toggle_action,
485 sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips)
486 );
487
488 toggle_action =
489 Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
490 toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
491 actionGroup->add(toggle_action,
492 sigc::mem_fun(
493 *this, &MainWindow::on_save_with_temporary_file));
494
495 actionGroup->add(
496 Gtk::Action::create("RefreshAll", _("_Refresh All")),
497 sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
498 );
499 #endif
500
501 #if USE_GLIB_ACTION
502 m_actionGroup->add_action(
503 "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
504 );
505 m_actionGroup->add_action(
506 "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
507 );
508 m_actionGroup->add_action(
509 "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
510 );
511 m_actionGroup->add_action(
512 "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
513 );
514 m_actionGroup->add_action(
515 "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
516 );
517 #else
518 action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
519 actionGroup->add(Gtk::Action::create("MenuHelp",
520 action->property_label()));
521 actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
522 sigc::mem_fun(
523 *this, &MainWindow::on_action_help_about));
524 actionGroup->add(
525 Gtk::Action::create("AddInstrument", _("Add _Instrument")),
526 sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
527 );
528 actionGroup->add(
529 Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
530 sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
531 );
532 actionGroup->add(
533 Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
534 Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
535 sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
536 );
537 actionGroup->add(
538 Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
539 sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
540 );
541 #endif
542
543 #if USE_GLIB_ACTION
544 m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool(
545 "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions),
546 Settings::singleton()->warnUserOnExtensions
547 );
548 m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool(
549 "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection),
550 Settings::singleton()->syncSamplerInstrumentSelection
551 );
552 m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool(
553 "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved),
554 Settings::singleton()->moveRootNoteWithRegionMoved
555 );
556 #else
557 actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
558
559 toggle_action =
560 Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
561 toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
562 actionGroup->add(
563 toggle_action,
564 sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
565 );
566
567 toggle_action =
568 Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
569 toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
570 actionGroup->add(
571 toggle_action,
572 sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
573 );
574
575 toggle_action =
576 Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
577 toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
578 actionGroup->add(
579 toggle_action,
580 sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
581 );
582 #endif
583
584 #if USE_GLIB_ACTION
585 m_actionGroup->add_action(
586 "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
587 );
588 m_actionGroup->add_action(
589 "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
590 );
591 #else
592 actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
593
594 actionGroup->add(
595 Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
596 sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
597 );
598
599 actionGroup->add(
600 Gtk::Action::create("MergeFiles", _("_Merge Files...")),
601 sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
602 );
603 #endif
604
605 // sample right-click popup actions
606 #if USE_GLIB_ACTION
607 m_actionSampleProperties = m_actionGroup->add_action(
608 "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
609 );
610 m_actionAddSampleGroup = m_actionGroup->add_action(
611 "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group)
612 );
613 m_actionAddSample = m_actionGroup->add_action(
614 "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
615 );
616 m_actionRemoveSample = m_actionGroup->add_action(
617 "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
618 );
619 m_actionGroup->add_action(
620 "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
621 );
622 m_actionViewSampleRefs = m_actionGroup->add_action(
623 "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references)
624 );
625 m_actionReplaceSample = m_actionGroup->add_action(
626 "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
627 );
628 m_actionGroup->add_action(
629 "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
630 );
631 #else
632 actionGroup->add(
633 Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
634 sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
635 );
636 actionGroup->add(
637 Gtk::Action::create("AddGroup", _("Add _Group")),
638 sigc::mem_fun(*this, &MainWindow::on_action_add_group)
639 );
640 actionGroup->add(
641 Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
642 sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
643 );
644 actionGroup->add(
645 Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
646 sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
647 );
648 actionGroup->add(
649 Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
650 sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
651 );
652 actionGroup->add(
653 Gtk::Action::create("ShowSampleRefs", _("Show References...")),
654 sigc::mem_fun(*this, &MainWindow::on_action_view_references)
655 );
656 actionGroup->add(
657 Gtk::Action::create("ReplaceSample",
658 _("Replace Sample...")),
659 sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
660 );
661 actionGroup->add(
662 Gtk::Action::create("ReplaceAllSamplesInAllGroups",
663 _("Replace All Samples in All Groups...")),
664 sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
665 );
666 #endif
667
668 // script right-click popup actions
669 #if USE_GLIB_ACTION
670 m_actionAddScriptGroup = m_actionGroup->add_action(
671 "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
672 );
673 m_actionAddScript = m_actionGroup->add_action(
674 "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script)
675 );
676 m_actionEditScript = m_actionGroup->add_action(
677 "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
678 );
679 m_actionRemoveScript = m_actionGroup->add_action(
680 "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
681 );
682 #else
683 actionGroup->add(
684 Gtk::Action::create("AddScriptGroup", _("Add _Group")),
685 sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
686 );
687 actionGroup->add(
688 Gtk::Action::create("AddScript", _("Add _Script")),
689 sigc::mem_fun(*this, &MainWindow::on_action_add_script)
690 );
691 actionGroup->add(
692 Gtk::Action::create("EditScript", _("_Edit Script...")),
693 sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
694 );
695 actionGroup->add(
696 Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
697 sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
698 );
699 #endif
700
701 #if USE_GTKMM_BUILDER
702 insert_action_group("AppMenu", m_actionGroup);
703
704 m_uiManager = Gtk::Builder::create();
705 Glib::ustring ui_info =
706 "<interface>"
707 " <menubar id='MenuBar'>"
708 " <menu id='MenuFile'>"
709 " <attribute name='label' translatable='yes'>_File</attribute>"
710 " <section>"
711 " <item id='New'>"
712 " <attribute name='label' translatable='yes'>New</attribute>"
713 " <attribute name='action'>AppMenu.New</attribute>"
714 " </item>"
715 " <item id='Open'>"
716 " <attribute name='label' translatable='yes'>Open</attribute>"
717 " <attribute name='action'>AppMenu.Open</attribute>"
718 " </item>"
719 " </section>"
720 " <section>"
721 " <item id='Save'>"
722 " <attribute name='label' translatable='yes'>Save</attribute>"
723 " <attribute name='action'>AppMenu.Save</attribute>"
724 " </item>"
725 " <item id='SaveAs'>"
726 " <attribute name='label' translatable='yes'>Save As</attribute>"
727 " <attribute name='action'>AppMenu.SaveAs</attribute>"
728 " </item>"
729 " </section>"
730 " <section>"
731 " <item id='Properties'>"
732 " <attribute name='label' translatable='yes'>Properties</attribute>"
733 " <attribute name='action'>AppMenu.Properties</attribute>"
734 " </item>"
735 " </section>"
736 " <section>"
737 " <item id='Quit'>"
738 " <attribute name='label' translatable='yes'>Quit</attribute>"
739 " <attribute name='action'>AppMenu.Quit</attribute>"
740 " </item>"
741 " </section>"
742 " </menu>"
743 " <menu id='MenuEdit'>"
744 " <attribute name='label' translatable='yes'>Edit</attribute>"
745 " <section>"
746 " <item id='CopyDimRgn'>"
747 " <attribute name='label' translatable='yes'>Copy Dimension Region</attribute>"
748 " <attribute name='action'>AppMenu.CopyDimRgn</attribute>"
749 " </item>"
750 " <item id='AdjustClipboard'>"
751 " <attribute name='label' translatable='yes'>Adjust Clipboard</attribute>"
752 " <attribute name='action'>AppMenu.AdjustClipboard</attribute>"
753 " </item>"
754 " <item id='PasteDimRgn'>"
755 " <attribute name='label' translatable='yes'>Paste Dimension Region</attribute>"
756 " <attribute name='action'>AppMenu.PasteDimRgn</attribute>"
757 " </item>"
758 " </section>"
759 " <item id='SelectPrevInstr'>"
760 " <attribute name='label' translatable='yes'>Previous Instrument</attribute>"
761 " <attribute name='action'>AppMenu.SelectPrevInstr</attribute>"
762 " </item>"
763 " <item id='SelectNextInstr'>"
764 " <attribute name='label' translatable='yes'>Next Instrument</attribute>"
765 " <attribute name='action'>AppMenu.SelectNextInstr</attribute>"
766 " </item>"
767 " <section>"
768 " <item id='SelectPrevRegion'>"
769 " <attribute name='label' translatable='yes'>Previous Region</attribute>"
770 " <attribute name='action'>AppMenu.SelectPrevRegion</attribute>"
771 " </item>"
772 " <item id='SelectNextRegion'>"
773 " <attribute name='label' translatable='yes'>Next Region</attribute>"
774 " <attribute name='action'>AppMenu.SelectNextRegion</attribute>"
775 " </item>"
776 " </section>"
777 " <item id='SelectPrevDimension'>"
778 " <attribute name='label' translatable='yes'>Previous Dimension</attribute>"
779 " <attribute name='action'>AppMenu.SelectPrevDimension</attribute>"
780 " </item>"
781 " <item id='SelectNextDimension'>"
782 " <attribute name='label' translatable='yes'>Next Dimension</attribute>"
783 " <attribute name='action'>AppMenu.SelectNextDimension</attribute>"
784 " </item>"
785 " <item id='SelectPrevDimRgnZone'>"
786 " <attribute name='label' translatable='yes'>Previous Dimension Region Zone</attribute>"
787 " <attribute name='action'>AppMenu.SelectPrevDimRgnZone</attribute>"
788 " </item>"
789 " <item id='SelectNextDimRgnZone'>"
790 " <attribute name='label' translatable='yes'>Next Dimension Region Zone</attribute>"
791 " <attribute name='action'>AppMenu.SelectNextDimRgnZone</attribute>"
792 " </item>"
793 " <item id='SelectAddPrevDimRgnZone'>"
794 " <attribute name='label' translatable='yes'>Add Previous Dimension Region Zone</attribute>"
795 " <attribute name='action'>AppMenu.SelectAddPrevDimRgnZone</attribute>"
796 " </item>"
797 " <item id='SelectAddNextDimRgnZone'>"
798 " <attribute name='label' translatable='yes'>Add Next Dimension Region Zone</attribute>"
799 " <attribute name='action'>AppMenu.SelectAddNextDimRgnZone</attribute>"
800 " </item>"
801 " <section>"
802 " <item id='CopySampleUnity'>"
803 " <attribute name='label' translatable='yes'>Copy Sample Unity</attribute>"
804 " <attribute name='action'>AppMenu.CopySampleUnity</attribute>"
805 " </item>"
806 " <item id='CopySampleTune'>"
807 " <attribute name='label' translatable='yes'>Copy Sample Tune</attribute>"
808 " <attribute name='action'>AppMenu.CopySampleTune</attribute>"
809 " </item>"
810 " <item id='CopySampleLoop'>"
811 " <attribute name='label' translatable='yes'>Copy Sample Loop</attribute>"
812 " <attribute name='action'>AppMenu.CopySampleLoop</attribute>"
813 " </item>"
814 " </section>"
815 " </menu>"
816 " <menu id='MenuMacro'>"
817 " <attribute name='label' translatable='yes'>Macro</attribute>"
818 " <section>"
819 " </section>"
820 " </menu>"
821 " <menu id='MenuSample'>"
822 " <attribute name='label' translatable='yes'>Sample</attribute>"
823 " <section>"
824 " <item id='SampleProperties'>"
825 " <attribute name='label' translatable='yes'>Properties</attribute>"
826 " <attribute name='action'>AppMenu.SampleProperties</attribute>"
827 " </item>"
828 " <item id='AddGroup'>"
829 " <attribute name='label' translatable='yes'>Add Group</attribute>"
830 " <attribute name='action'>AppMenu.AddGroup</attribute>"
831 " </item>"
832 " <item id='AddSample'>"
833 " <attribute name='label' translatable='yes'>Add Sample</attribute>"
834 " <attribute name='action'>AppMenu.AddSample</attribute>"
835 " </item>"
836 " <item id='ShowSampleRefs'>"
837 " <attribute name='label' translatable='yes'>Show Sample References</attribute>"
838 " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
839 " </item>"
840 " <item id='ReplaceSample'>"
841 " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
842 " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
843 " </item>"
844 " <item id='ReplaceAllSamplesInAllGroups'>"
845 " <attribute name='label' translatable='yes'>Replace all Samples in all Groups</attribute>"
846 " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
847 " </item>"
848 " </section>"
849 " <section>"
850 " <item id='RemoveSample'>"
851 " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
852 " <attribute name='action'>AppMenu.RemoveSample</attribute>"
853 " </item>"
854 " <item id='RemoveUnusedSamples'>"
855 " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
856 " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
857 " </item>"
858 " </section>"
859 " </menu>"
860 " <menu id='MenuInstrument'>"
861 " <attribute name='label' translatable='yes'>Instrument</attribute>"
862 " <section>"
863 " <item id='InstrProperties'>"
864 " <attribute name='label' translatable='yes'>Properties</attribute>"
865 " <attribute name='action'>AppMenu.InstrProperties</attribute>"
866 " </item>"
867 " <item id='MidiRules'>"
868 " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
869 " <attribute name='action'>AppMenu.MidiRules</attribute>"
870 " </item>"
871 " <item id='ScriptSlots'>"
872 " <attribute name='label' translatable='yes'>Script Slots</attribute>"
873 " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
874 " </item>"
875 " </section>"
876 " <submenu id='AssignScripts'>"
877 " <attribute name='label' translatable='yes'>Assign Scripts</attribute>"
878 " </submenu>"
879 " <section>"
880 " <item id='AddInstrument'>"
881 " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
882 " <attribute name='action'>AppMenu.AddInstrument</attribute>"
883 " </item>"
884 " <item id='DupInstrument'>"
885 " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
886 " <attribute name='action'>AppMenu.DupInstrument</attribute>"
887 " </item>"
888 " <item id='CombInstruments'>"
889 " <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
890 " <attribute name='action'>AppMenu.CombInstruments</attribute>"
891 " </item>"
892 " </section>"
893 " <section>"
894 " <item id='RemoveInstrument'>"
895 " <attribute name='label' translatable='yes'>Remove Instrument</attribute>"
896 " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
897 " </item>"
898 " </section>"
899 " </menu>"
900 " <menu id='MenuScript'>"
901 " <attribute name='label' translatable='yes'>Script</attribute>"
902 " <section>"
903 " <item id='AddScriptGroup'>"
904 " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
905 " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
906 " </item>"
907 " <item id='AddScript'>"
908 " <attribute name='label' translatable='yes'>Add Script</attribute>"
909 " <attribute name='action'>AppMenu.AddScript</attribute>"
910 " </item>"
911 " <item id='EditScript'>"
912 " <attribute name='label' translatable='yes'>Edit Script</attribute>"
913 " <attribute name='action'>AppMenu.EditScript</attribute>"
914 " </item>"
915 " </section>"
916 " <section>"
917 " <item id='RemoveScript'>"
918 " <attribute name='label' translatable='yes'>Remove Script</attribute>"
919 " <attribute name='action'>AppMenu.RemoveScript</attribute>"
920 " </item>"
921 " </section>"
922 " </menu>"
923 " <menu id='MenuView'>"
924 " <attribute name='label' translatable='yes'>View</attribute>"
925 " <section>"
926 " <item id='Statusbar'>"
927 " <attribute name='label' translatable='yes'>Statusbar</attribute>"
928 " <attribute name='action'>AppMenu.Statusbar</attribute>"
929 " </item>"
930 " <item id='ShowTooltips'>"
931 " <attribute name='label' translatable='yes'>Tooltips for Beginners</attribute>"
932 " <attribute name='action'>AppMenu.ShowTooltips</attribute>"
933 " </item>"
934 " <item id='AutoRestoreWinDim'>"
935 " <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
936 " <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
937 " </item>"
938 " </section>"
939 " <section>"
940 " <item id='RefreshAll'>"
941 " <attribute name='label' translatable='yes'>Refresh All</attribute>"
942 " <attribute name='action'>AppMenu.RefreshAll</attribute>"
943 " </item>"
944 " </section>"
945 " </menu>"
946 " <menu id='MenuTools'>"
947 " <attribute name='label' translatable='yes'>Tools</attribute>"
948 " <section>"
949 " <item id='CombineInstruments'>"
950 " <attribute name='label' translatable='yes'>Combine Instruments ...</attribute>"
951 " <attribute name='action'>AppMenu.CombineInstruments</attribute>"
952 " </item>"
953 " <item id='MergeFiles'>"
954 " <attribute name='label' translatable='yes'>Merge Files ...</attribute>"
955 " <attribute name='action'>AppMenu.MergeFiles</attribute>"
956 " </item>"
957 " </section>"
958 " </menu>"
959 " <menu id='MenuSettings'>"
960 " <attribute name='label' translatable='yes'>Settings</attribute>"
961 " <section>"
962 " <item id='WarnUserOnExtensions'>"
963 " <attribute name='label' translatable='yes'>Warning on Format Extensions</attribute>"
964 " <attribute name='action'>AppMenu.WarnUserOnExtensions</attribute>"
965 " </item>"
966 " <item id='SyncSamplerInstrumentSelection'>"
967 " <attribute name='label' translatable='yes'>Synchronize Sampler Selection</attribute>"
968 " <attribute name='action'>AppMenu.SyncSamplerInstrumentSelection</attribute>"
969 " </item>"
970 " <item id='MoveRootNoteWithRegionMoved'>"
971 " <attribute name='label' translatable='yes'>Move Root Note with Region moved</attribute>"
972 " <attribute name='action'>AppMenu.MoveRootNoteWithRegionMoved</attribute>"
973 " </item>"
974 " <item id='SaveWithTemporaryFile'>"
975 " <attribute name='label' translatable='yes'>Save with temporary file</attribute>"
976 " <attribute name='action'>AppMenu.SaveWithTemporaryFile</attribute>"
977 " </item>"
978 " </section>"
979 " </menu>"
980 " <menu id='MenuHelp'>"
981 " <attribute name='label' translatable='yes'>Help</attribute>"
982 " <section>"
983 " <item id='About'>"
984 " <attribute name='label' translatable='yes'>About ...</attribute>"
985 " <attribute name='action'>AppMenu.About</attribute>"
986 " </item>"
987 " </section>"
988 " </menu>"
989 " </menubar>"
990 // popups
991 " <menu id='PopupMenu'>"
992 " <section>"
993 " <item id='InstrProperties'>"
994 " <attribute name='label' translatable='yes'>Instrument Properties</attribute>"
995 " <attribute name='action'>AppMenu.InstrProperties</attribute>"
996 " </item>"
997 " <item id='MidiRules'>"
998 " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
999 " <attribute name='action'>AppMenu.MidiRules</attribute>"
1000 " </item>"
1001 " <item id='ScriptSlots'>"
1002 " <attribute name='label' translatable='yes'>Script Slots</attribute>"
1003 " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
1004 " </item>"
1005 " <item id='AddInstrument'>"
1006 " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
1007 " <attribute name='action'>AppMenu.AddInstrument</attribute>"
1008 " </item>"
1009 " <item id='DupInstrument'>"
1010 " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1011 " <attribute name='action'>AppMenu.DupInstrument</attribute>"
1012 " </item>"
1013 " <item id='CombInstruments'>"
1014 " <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1015 " <attribute name='action'>AppMenu.CombInstruments</attribute>"
1016 " </item>"
1017 " </section>"
1018 " <section>"
1019 " <item id='RemoveInstrument'>"
1020 " <attribute name='label' translatable='yes'>Remove Instruments</attribute>"
1021 " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
1022 " </item>"
1023 " </section>"
1024 " </menu>"
1025 " <menu id='SamplePopupMenu'>"
1026 " <section>"
1027 " <item id='SampleProperties'>"
1028 " <attribute name='label' translatable='yes'>Sample Properties</attribute>"
1029 " <attribute name='action'>AppMenu.SampleProperties</attribute>"
1030 " </item>"
1031 " <item id='AddGroup'>"
1032 " <attribute name='label' translatable='yes'>Add Sample Group</attribute>"
1033 " <attribute name='action'>AppMenu.AddGroup</attribute>"
1034 " </item>"
1035 " <item id='AddSample'>"
1036 " <attribute name='label' translatable='yes'>Add Sample</attribute>"
1037 " <attribute name='action'>AppMenu.AddSample</attribute>"
1038 " </item>"
1039 " <item id='ShowSampleRefs'>"
1040 " <attribute name='label' translatable='yes'>Show Sample References ...</attribute>"
1041 " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
1042 " </item>"
1043 " <item id='ReplaceSample'>"
1044 " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
1045 " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
1046 " </item>"
1047 " <item id='ReplaceAllSamplesInAllGroups'>"
1048 " <attribute name='label' translatable='yes'>Replace all Samples ...</attribute>"
1049 " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
1050 " </item>"
1051 " </section>"
1052 " <section>"
1053 " <item id='RemoveSample'>"
1054 " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
1055 " <attribute name='action'>AppMenu.RemoveSample</attribute>"
1056 " </item>"
1057 " <item id='RemoveUnusedSamples'>"
1058 " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
1059 " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
1060 " </item>"
1061 " </section>"
1062 " </menu>"
1063 " <menu id='ScriptPopupMenu'>"
1064 " <section>"
1065 " <item id='AddScriptGroup'>"
1066 " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
1067 " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
1068 " </item>"
1069 " <item id='AddScript'>"
1070 " <attribute name='label' translatable='yes'>Add Script</attribute>"
1071 " <attribute name='action'>AppMenu.AddScript</attribute>"
1072 " </item>"
1073 " <item id='EditScript'>"
1074 " <attribute name='label' translatable='yes'>Edit Script</attribute>"
1075 " <attribute name='action'>AppMenu.EditScript</attribute>"
1076 " </item>"
1077 " </section>"
1078 " <section>"
1079 " <item id='RemoveScript'>"
1080 " <attribute name='label' translatable='yes'>Remove Script</attribute>"
1081 " <attribute name='action'>AppMenu.RemoveScript</attribute>"
1082 " </item>"
1083 " </section>"
1084 " </menu>"
1085 "</interface>";
1086 m_uiManager->add_from_string(ui_info);
1087 #else
1088 uiManager = Gtk::UIManager::create();
1089 uiManager->insert_action_group(actionGroup);
1090 add_accel_group(uiManager->get_accel_group());
1091
1092 Glib::ustring ui_info =
1093 "<ui>"
1094 " <menubar name='MenuBar'>"
1095 " <menu action='MenuFile'>"
1096 " <menuitem action='New'/>"
1097 " <menuitem action='Open'/>"
1098 " <separator/>"
1099 " <menuitem action='Save'/>"
1100 " <menuitem action='SaveAs'/>"
1101 " <separator/>"
1102 " <menuitem action='Properties'/>"
1103 " <separator/>"
1104 " <menuitem action='Quit'/>"
1105 " </menu>"
1106 " <menu action='MenuEdit'>"
1107 " <menuitem action='CopyDimRgn'/>"
1108 " <menuitem action='AdjustClipboard'/>"
1109 " <menuitem action='PasteDimRgn'/>"
1110 " <separator/>"
1111 " <menuitem action='SelectPrevInstr'/>"
1112 " <menuitem action='SelectNextInstr'/>"
1113 " <separator/>"
1114 " <menuitem action='SelectPrevRegion'/>"
1115 " <menuitem action='SelectNextRegion'/>"
1116 " <separator/>"
1117 " <menuitem action='SelectPrevDimension'/>"
1118 " <menuitem action='SelectNextDimension'/>"
1119 " <menuitem action='SelectPrevDimRgnZone'/>"
1120 " <menuitem action='SelectNextDimRgnZone'/>"
1121 " <menuitem action='SelectAddPrevDimRgnZone'/>"
1122 " <menuitem action='SelectAddNextDimRgnZone'/>"
1123 " <separator/>"
1124 " <menuitem action='CopySampleUnity'/>"
1125 " <menuitem action='CopySampleTune'/>"
1126 " <menuitem action='CopySampleLoop'/>"
1127 " </menu>"
1128 " <menu action='MenuMacro'>"
1129 " </menu>"
1130 " <menu action='MenuSample'>"
1131 " <menuitem action='SampleProperties'/>"
1132 " <menuitem action='AddGroup'/>"
1133 " <menuitem action='AddSample'/>"
1134 " <menuitem action='ShowSampleRefs'/>"
1135 " <menuitem action='ReplaceSample' />"
1136 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1137 " <separator/>"
1138 " <menuitem action='RemoveSample'/>"
1139 " <menuitem action='RemoveUnusedSamples'/>"
1140 " </menu>"
1141 " <menu action='MenuInstrument'>"
1142 " <menu action='AllInstruments'>"
1143 " </menu>"
1144 " <separator/>"
1145 " <menuitem action='InstrProperties'/>"
1146 " <menuitem action='MidiRules'/>"
1147 " <menuitem action='ScriptSlots'/>"
1148 " <menu action='AssignScripts'/>"
1149 " <menuitem action='AddInstrument'/>"
1150 " <menuitem action='DupInstrument'/>"
1151 " <menuitem action='CombInstruments'/>"
1152 " <separator/>"
1153 " <menuitem action='RemoveInstrument'/>"
1154 " </menu>"
1155 " <menu action='MenuScript'>"
1156 " <menuitem action='AddScriptGroup'/>"
1157 " <menuitem action='AddScript'/>"
1158 " <menuitem action='EditScript'/>"
1159 " <separator/>"
1160 " <menuitem action='RemoveScript'/>"
1161 " </menu>"
1162 " <menu action='MenuView'>"
1163 " <menuitem action='Statusbar'/>"
1164 " <menuitem action='ShowTooltips'/>"
1165 " <menuitem action='AutoRestoreWinDim'/>"
1166 " <separator/>"
1167 " <menuitem action='RefreshAll'/>"
1168 " </menu>"
1169 " <menu action='MenuTools'>"
1170 " <menuitem action='CombineInstruments'/>"
1171 " <menuitem action='MergeFiles'/>"
1172 " </menu>"
1173 " <menu action='MenuSettings'>"
1174 " <menuitem action='WarnUserOnExtensions'/>"
1175 " <menuitem action='SyncSamplerInstrumentSelection'/>"
1176 " <menuitem action='MoveRootNoteWithRegionMoved'/>"
1177 " <menuitem action='SaveWithTemporaryFile'/>"
1178 " </menu>"
1179 " <menu action='MenuHelp'>"
1180 " <menuitem action='About'/>"
1181 " </menu>"
1182 " </menubar>"
1183 " <popup name='PopupMenu'>"
1184 " <menuitem action='InstrProperties'/>"
1185 " <menuitem action='MidiRules'/>"
1186 " <menuitem action='ScriptSlots'/>"
1187 " <menuitem action='AddInstrument'/>"
1188 " <menuitem action='DupInstrument'/>"
1189 " <menuitem action='CombInstruments'/>"
1190 " <separator/>"
1191 " <menuitem action='RemoveInstrument'/>"
1192 " </popup>"
1193 " <popup name='SamplePopupMenu'>"
1194 " <menuitem action='SampleProperties'/>"
1195 " <menuitem action='AddGroup'/>"
1196 " <menuitem action='AddSample'/>"
1197 " <menuitem action='ShowSampleRefs'/>"
1198 " <menuitem action='ReplaceSample' />"
1199 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1200 " <separator/>"
1201 " <menuitem action='RemoveSample'/>"
1202 " <menuitem action='RemoveUnusedSamples'/>"
1203 " </popup>"
1204 " <popup name='ScriptPopupMenu'>"
1205 " <menuitem action='AddScriptGroup'/>"
1206 " <menuitem action='AddScript'/>"
1207 " <menuitem action='EditScript'/>"
1208 " <separator/>"
1209 " <menuitem action='RemoveScript'/>"
1210 " </popup>"
1211 "</ui>";
1212 uiManager->add_ui_from_string(ui_info);
1213 #endif
1214
1215 #if USE_GTKMM_BUILDER
1216 popup_menu = new Gtk::Menu(
1217 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1218 m_uiManager->get_object("PopupMenu")
1219 )
1220 );
1221 sample_popup = new Gtk::Menu(
1222 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1223 m_uiManager->get_object("SamplePopupMenu")
1224 )
1225 );
1226 script_popup = new Gtk::Menu(
1227 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1228 m_uiManager->get_object("ScriptPopupMenu")
1229 )
1230 );
1231 #else
1232 popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
1233
1234 // Set tooltips for menu items (for some reason, setting a tooltip on the
1235 // respective Gtk::Action objects above will simply be ignored, no matter
1236 // if using Gtk::Action::set_tooltip() or passing the tooltip string on
1237 // Gtk::Action::create()).
1238 {
1239 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1240 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1241 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."));
1242 }
1243 {
1244 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1245 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1246 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."));
1247 }
1248 {
1249 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1250 uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1251 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 information to be altered by this action."));
1252 }
1253 {
1254 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1255 uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
1256 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."));
1257 }
1258 {
1259 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1260 uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
1261 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)."));
1262 }
1263 {
1264 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1265 uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
1266 item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keyboard position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
1267 }
1268 {
1269 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1270 uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
1271 item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
1272 // copy tooltip to popup menu
1273 Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
1274 uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
1275 item2->set_tooltip_text(item->get_tooltip_text());
1276 }
1277 {
1278 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1279 uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
1280 item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
1281 }
1282 {
1283 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1284 uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1285 item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
1286 }
1287 {
1288 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1289 uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1290 item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1291 }
1292 {
1293 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1294 uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1295 item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
1296 }
1297 #endif
1298
1299 #if USE_GTKMM_BUILDER
1300 assign_scripts_menu = new Gtk::Menu(
1301 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1302 m_uiManager->get_object("AssignScripts")
1303 )
1304 );
1305 #else
1306 instrument_menu = static_cast<Gtk::MenuItem*>(
1307 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
1308
1309 assign_scripts_menu = static_cast<Gtk::MenuItem*>(
1310 uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
1311 #endif
1312
1313 #if USE_GTKMM_BUILDER
1314 Gtk::Widget* menuBar = NULL;
1315 m_uiManager->get_widget("MenuBar", menuBar);
1316 #else
1317 Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1318 #endif
1319
1320 m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1321 m_VBox.pack_start(m_HPaned);
1322 m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
1323 m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
1324 m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
1325 m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
1326
1327 set_file_is_shared(false);
1328
1329 // Status Bar:
1330 #if USE_GTKMM_BOX
1331 # warning No status bar layout for GTKMM 4 yet
1332 #else
1333 m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1334 m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1335 #endif
1336 m_StatusBar.show();
1337
1338 m_RegionChooser.signal_region_selected().connect(
1339 sigc::mem_fun(*this, &MainWindow::region_changed) );
1340 m_DimRegionChooser.signal_dimregion_selected().connect(
1341 sigc::mem_fun(*this, &MainWindow::dimreg_changed) );
1342
1343
1344 // Create the Tree model:
1345 m_refTreeModel = Gtk::ListStore::create(m_Columns);
1346 m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1347 m_refTreeModelFilter->set_visible_func(
1348 sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1349 );
1350 m_TreeView.set_model(m_refTreeModelFilter);
1351
1352 m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1353 m_TreeView.set_has_tooltip(true);
1354 m_TreeView.signal_query_tooltip().connect(
1355 sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1356 );
1357 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1358 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1359 );
1360
1361 // Add the TreeView's view columns:
1362 m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1363 m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1364 m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1365 m_TreeView.set_headers_visible(true);
1366
1367 // establish drag&drop within the instrument tree view, allowing to reorder
1368 // the sequence of instruments within the gig file
1369 {
1370 std::vector<Gtk::TargetEntry> drag_target_instrument;
1371 drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1372 m_TreeView.drag_source_set(drag_target_instrument);
1373 m_TreeView.drag_dest_set(drag_target_instrument);
1374 m_TreeView.signal_drag_begin().connect(
1375 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1376 );
1377 m_TreeView.signal_drag_data_get().connect(
1378 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1379 );
1380 m_TreeView.signal_drag_data_received().connect(
1381 sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1382 );
1383 }
1384
1385 // create samples treeview (including its data model)
1386 m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1387 m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1388 m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1389 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."));
1390 // m_TreeViewSamples.set_reorderable();
1391 m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1392 m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1393 {
1394 Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1395 Gtk::CellRendererText* cellrenderer =
1396 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1397 column->add_attribute(
1398 cellrenderer->property_foreground(), m_SamplesModel.m_color
1399 );
1400 }
1401 {
1402 Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1403 Gtk::CellRendererText* cellrenderer =
1404 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1405 column->add_attribute(
1406 cellrenderer->property_foreground(), m_SamplesModel.m_color
1407 );
1408 }
1409 m_TreeViewSamples.set_headers_visible(true);
1410 #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
1411 m_TreeViewSamples.signal_button_press_event().connect(
1412 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1413 );
1414 #else
1415 m_TreeViewSamples.signal_button_press_event().connect_notify(
1416 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1417 );
1418 #endif
1419 m_refSamplesTreeModel->signal_row_changed().connect(
1420 sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1421 );
1422
1423 // create scripts treeview (including its data model)
1424 m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1425 m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1426 m_TreeViewScripts.set_tooltip_text(_(
1427 "Use CTRL + double click for editing a script."
1428 "\n\n"
1429 "Note: instrument scripts are a LinuxSampler extension of the gig "
1430 "format. This feature will not work with the GigaStudio software!"
1431 ));
1432 // m_TreeViewScripts.set_reorderable();
1433 m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1434 m_TreeViewScripts.set_headers_visible(false);
1435 #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
1436 m_TreeViewScripts.signal_button_press_event().connect(
1437 sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1438 );
1439 #else
1440 m_TreeViewScripts.signal_button_press_event().connect_notify(
1441 sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1442 );
1443 #endif
1444 //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1445 m_TreeViewScripts.signal_row_activated().connect(
1446 sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1447 );
1448 m_refScriptsTreeModel->signal_row_changed().connect(
1449 sigc::mem_fun(*this, &MainWindow::script_name_changed)
1450 );
1451
1452 // establish drag&drop between scripts tree view and ScriptSlots window
1453 std::vector<Gtk::TargetEntry> drag_target_gig_script;
1454 drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1455 m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1456 m_TreeViewScripts.signal_drag_begin().connect(
1457 sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1458 );
1459 m_TreeViewScripts.signal_drag_data_get().connect(
1460 sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1461 );
1462
1463 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1464 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1465 drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1466 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1467 m_TreeViewSamples.signal_drag_begin().connect(
1468 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
1469 );
1470 m_TreeViewSamples.signal_drag_data_get().connect(
1471 sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
1472 );
1473 dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
1474 dimreg_edit.wSample->signal_drag_data_received().connect(
1475 sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
1476 );
1477 dimreg_edit.signal_dimreg_changed().connect(
1478 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1479 m_RegionChooser.signal_instrument_changed().connect(
1480 sigc::mem_fun(*this, &MainWindow::file_changed));
1481 m_RegionChooser.signal_instrument_changed().connect(
1482 sigc::mem_fun(*this, &MainWindow::region_changed));
1483 m_DimRegionChooser.signal_region_changed().connect(
1484 sigc::mem_fun(*this, &MainWindow::file_changed));
1485 instrumentProps.signal_changed().connect(
1486 sigc::mem_fun(*this, &MainWindow::file_changed));
1487 sampleProps.signal_changed().connect(
1488 sigc::mem_fun(*this, &MainWindow::file_changed));
1489 fileProps.signal_changed().connect(
1490 sigc::mem_fun(*this, &MainWindow::file_changed));
1491 midiRules.signal_changed().connect(
1492 sigc::mem_fun(*this, &MainWindow::file_changed));
1493
1494 dimreg_edit.signal_dimreg_to_be_changed().connect(
1495 dimreg_to_be_changed_signal.make_slot());
1496 dimreg_edit.signal_dimreg_changed().connect(
1497 dimreg_changed_signal.make_slot());
1498 dimreg_edit.signal_sample_ref_changed().connect(
1499 sample_ref_changed_signal.make_slot());
1500 sample_ref_changed_signal.connect(
1501 sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1502 );
1503 samples_to_be_removed_signal.connect(
1504 sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1505 );
1506
1507 dimreg_edit.signal_select_sample().connect(
1508 sigc::mem_fun(*this, &MainWindow::select_sample)
1509 );
1510
1511 m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1512 sigc::hide(
1513 sigc::bind(
1514 file_structure_to_be_changed_signal.make_slot(),
1515 #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1516 std::ref(this->file)
1517 #else
1518 sigc::ref(this->file)
1519 #endif
1520 )
1521 )
1522 );
1523 m_RegionChooser.signal_instrument_struct_changed().connect(
1524 sigc::hide(
1525 sigc::bind(
1526 file_structure_changed_signal.make_slot(),
1527 #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1528 std::ref(this->file)
1529 #else
1530 sigc::ref(this->file)
1531 #endif
1532 )
1533 )
1534 );
1535 m_RegionChooser.signal_region_to_be_changed().connect(
1536 region_to_be_changed_signal.make_slot());
1537 m_RegionChooser.signal_region_changed_signal().connect(
1538 region_changed_signal.make_slot());
1539
1540 note_on_signal.connect(
1541 sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
1542 note_off_signal.connect(
1543 sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
1544
1545 dimreg_all_regions.signal_toggled().connect(
1546 sigc::mem_fun(*this, &MainWindow::update_dimregs));
1547 dimreg_all_dimregs.signal_toggled().connect(
1548 sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
1549 dimreg_stereo.signal_toggled().connect(
1550 sigc::mem_fun(*this, &MainWindow::update_dimregs));
1551
1552 m_searchText.signal_changed().connect(
1553 sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1554 );
1555
1556 file = 0;
1557 file_is_changed = false;
1558
1559 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1560 show_all_children();
1561 #endif
1562
1563 // start with a new gig file by default
1564 on_action_file_new();
1565
1566 m_TreeViewNotebook.signal_switch_page().connect(
1567 sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1568 );
1569
1570 // select 'Instruments' tab by default
1571 // (gtk allows this only if the tab childs are visible, thats why it's here)
1572 m_TreeViewNotebook.set_current_page(1);
1573
1574 Gtk::Clipboard::get()->signal_owner_change().connect(
1575 sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1576 );
1577 updateClipboardPasteAvailable();
1578 updateClipboardCopyAvailable();
1579
1580 // setup macros and their keyboard accelerators
1581 {
1582 #if USE_GTKMM_BUILDER
1583 menuMacro = new Gtk::Menu(
1584 Glib::RefPtr<Gio::Menu>::cast_dynamic(
1585 m_uiManager->get_object("MenuMacro")
1586 )
1587 );
1588 #else
1589 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1590 uiManager->get_widget("/MenuBar/MenuMacro")
1591 )->get_submenu();
1592 #endif
1593
1594 const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1595 Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1596 Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1597 Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1598 Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1599 Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1600 Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1601 Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1602 Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1603 Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1604 Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1605 Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1606 Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1607 Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1608 Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1609 Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1610 Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1611 Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1612 Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1613 Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1614 Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1615
1616 Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1617 menuMacro->set_accel_group(accelGroup);
1618
1619 updateMacroMenu();
1620 }
1621
1622 // setup "Assign Scripts" keyboard accelerators
1623 {
1624 Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1625 Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1626 Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1627 Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1628 Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1629 Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1630 Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1631 Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1632 Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1633 Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1634 Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1635 Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1636 Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1637 Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1638 Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1639 Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1640 Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1641 Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1642 Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1643 Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1644
1645 Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1646 assign_scripts_menu->set_accel_group(accelGroup);
1647 }
1648
1649 on_show_tooltips_changed();
1650
1651 Glib::signal_idle().connect_once(
1652 sigc::mem_fun(*this, &MainWindow::bringToFront),
1653 200
1654 );
1655 }
1656
1657 MainWindow::~MainWindow()
1658 {
1659 }
1660
1661 void MainWindow::bringToFront() {
1662 #if defined(__APPLE__)
1663 macRaiseAppWindow();
1664 #endif
1665 raise();
1666 present();
1667 }
1668
1669 void MainWindow::updateMacroMenu() {
1670 #if !USE_GTKMM_BUILDER
1671 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1672 uiManager->get_widget("/MenuBar/MenuMacro")
1673 )->get_submenu();
1674 #endif
1675
1676 // remove all entries from "Macro" menu
1677 {
1678 const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1679 for (int i = 0; i < children.size(); ++i) {
1680 Gtk::Widget* child = children[i];
1681 menuMacro->remove(*child);
1682 delete child;
1683 }
1684 }
1685
1686 // (re)load all macros from config file
1687 try {
1688 Settings::singleton()->loadMacros(m_macros);
1689 } catch (Serialization::Exception e) {
1690 std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1691 } catch (...) {
1692 std::cerr << "Unknown exception while loading macros!" << std::endl;
1693 }
1694
1695 // add all configured macros as menu items to the "Macro" menu
1696 for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1697 const Serialization::Archive& macro = m_macros[iMacro];
1698 std::string name =
1699 macro.name().empty() ?
1700 (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1701 Gtk::MenuItem* item = new Gtk::MenuItem(name);
1702 item->signal_activate().connect(
1703 sigc::bind(
1704 sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1705 )
1706 );
1707 menuMacro->append(*item);
1708 item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1709 Glib::ustring comment = macro.comment();
1710 if (!comment.empty())
1711 item->set_tooltip_text(comment);
1712 }
1713 // if there are no macros configured at all, then show a dummy entry instead
1714 if (m_macros.empty()) {
1715 Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1716 item->set_sensitive(false);
1717 menuMacro->append(*item);
1718 }
1719
1720 // add separator line to menu
1721 menuMacro->append(*new Gtk::SeparatorMenuItem);
1722
1723 {
1724 Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1725 item->signal_activate().connect(
1726 sigc::mem_fun(*this, &MainWindow::setupMacros)
1727 );
1728 menuMacro->append(*item);
1729 item->set_accel_path("<Macros>/SetupMacros");
1730 }
1731
1732 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1733 menuMacro->show_all_children();
1734 #endif
1735 }
1736
1737 void MainWindow::onMacroSelected(int iMacro) {
1738 printf("onMacroSelected(%d)\n", iMacro);
1739 if (iMacro < 0 || iMacro >= m_macros.size()) return;
1740 Glib::ustring errorText;
1741 try {
1742 applyMacro(m_macros[iMacro]);
1743 } catch (Serialization::Exception e) {
1744 errorText = e.Message;
1745 } catch (...) {
1746 errorText = _("Unknown exception while applying macro");
1747 }
1748 if (!errorText.empty()) {
1749 Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1750 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1751 msg.run();
1752 }
1753 }
1754
1755 void MainWindow::setupMacros() {
1756 MacrosSetup* setup = new MacrosSetup();
1757 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1758 setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1759 setup->signal_macros_changed().connect(
1760 sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1761 );
1762 setup->show();
1763 }
1764
1765 void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1766 m_macros = macros;
1767 Settings::singleton()->saveMacros(m_macros);
1768 updateMacroMenu();
1769 }
1770
1771 //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.
1772 void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1773 bool isInstrumentsPage = (page_num == 1);
1774 // so far we only support filtering for the instruments list, so hide the
1775 // filter text entry field if another tab is selected
1776 m_searchField.set_visible(isInstrumentsPage);
1777 }
1778
1779 bool MainWindow::on_delete_event(GdkEventAny* event)
1780 {
1781 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
1782 }
1783
1784 void MainWindow::on_action_quit()
1785 {
1786 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
1787 hide();
1788 }
1789
1790 void MainWindow::region_changed()
1791 {
1792 m_DimRegionChooser.set_region(m_RegionChooser.get_region());
1793 }
1794
1795 gig::Instrument* MainWindow::get_instrument()
1796 {
1797 gig::Instrument* instrument = 0;
1798 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1799 if (rows.empty()) return NULL;
1800 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1801 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1802 if (it) {
1803 Gtk::TreeModel::Row row = *it;
1804 instrument = row[m_Columns.m_col_instr];
1805 }
1806 return instrument;
1807 }
1808
1809 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
1810 {
1811 if (all_dimregs) {
1812 for (int i = 0 ; i < region->DimensionRegions ; i++) {
1813 if (region->pDimensionRegions[i]) {
1814 dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
1815 }
1816 }
1817 } else {
1818 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
1819 }
1820 }
1821
1822 void MainWindow::update_dimregs()
1823 {
1824 dimreg_edit.dimregs.clear();
1825 bool all_regions = dimreg_all_regions.get_active();
1826 bool stereo = dimreg_stereo.get_active();
1827 bool all_dimregs = dimreg_all_dimregs.get_active();
1828
1829 if (all_regions) {
1830 gig::Instrument* instrument = get_instrument();
1831 if (instrument) {
1832 for (gig::Region* region = instrument->GetFirstRegion() ;
1833 region ;
1834 region = instrument->GetNextRegion()) {
1835 add_region_to_dimregs(region, stereo, all_dimregs);
1836 }
1837 }
1838 } else {
1839 gig::Region* region = m_RegionChooser.get_region();
1840 if (region) {
1841 add_region_to_dimregs(region, stereo, all_dimregs);
1842 }
1843 }
1844
1845 m_RegionChooser.setModifyAllRegions(all_regions);
1846 m_DimRegionChooser.setModifyAllRegions(all_regions);
1847 m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1848 m_DimRegionChooser.setModifyBothChannels(stereo);
1849
1850 updateClipboardCopyAvailable();
1851 }
1852
1853 void MainWindow::dimreg_all_dimregs_toggled()
1854 {
1855 dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
1856 update_dimregs();
1857 }
1858
1859 void MainWindow::dimreg_changed()
1860 {
1861 update_dimregs();
1862 dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1863 }
1864
1865 void MainWindow::on_sel_change()
1866 {
1867 #if !USE_GTKMM_BUILDER
1868 // select item in instrument menu
1869 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1870 if (!rows.empty()) {
1871 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1872 if (it) {
1873 Gtk::TreePath path(it);
1874 int index = path[0];
1875 const std::vector<Gtk::Widget*> children =
1876 instrument_menu->get_children();
1877 static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1878 }
1879 }
1880 #endif
1881
1882 updateScriptListOfMenu();
1883
1884 m_RegionChooser.set_instrument(get_instrument());
1885
1886 if (Settings::singleton()->syncSamplerInstrumentSelection) {
1887 switch_sampler_instrument_signal.emit(get_instrument());
1888 }
1889 }
1890
1891
1892 LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :
1893 filename(filename), gig(gig),
1894 #ifdef GLIB_THREADS
1895 thread(0),
1896 #endif
1897 progress(0.f)
1898 {
1899 }
1900
1901 void loader_progress_callback(gig::progress_t* progress)
1902 {
1903 LoaderSaverBase* loader = static_cast<LoaderSaverBase*>(progress->custom);
1904 loader->progress_callback(progress->factor);
1905 }
1906
1907 void LoaderSaverBase::progress_callback(float fraction)
1908 {
1909 {
1910 #ifdef GLIB_THREADS
1911 Glib::Threads::Mutex::Lock lock(progressMutex);
1912 #else
1913 std::lock_guard<std::mutex> lock(progressMutex);
1914 #endif
1915 progress = fraction;
1916 }
1917 progress_dispatcher();
1918 }
1919
1920 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1921 // make sure stack is 16-byte aligned for SSE instructions
1922 __attribute__((force_align_arg_pointer))
1923 #endif
1924 void LoaderSaverBase::thread_function()
1925 {
1926 #ifdef GLIB_THREADS
1927 printf("thread_function self=%p\n",
1928 static_cast<void*>(Glib::Threads::Thread::self()));
1929 #else
1930 std::cout << "thread_function self=" << std::this_thread::get_id() << "\n";
1931 #endif
1932 printf("Start %s\n", filename.c_str());
1933 try {
1934 gig::progress_t progress;
1935 progress.callback = loader_progress_callback;
1936 progress.custom = this;
1937
1938 thread_function_sub(progress);
1939 printf("End\n");
1940 finished_dispatcher();
1941 } catch (RIFF::Exception e) {
1942 error_message = e.Message;
1943 error_dispatcher.emit();
1944 } catch (...) {
1945 error_message = _("Unknown exception occurred");
1946 error_dispatcher.emit();
1947 }
1948 }
1949
1950 void LoaderSaverBase::launch()
1951 {
1952 #ifdef GLIB_THREADS
1953 #ifdef OLD_THREADS
1954 thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);
1955 #else
1956 thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));
1957 #endif
1958 printf("launch thread=%p\n", static_cast<void*>(thread));
1959 #else
1960 thread = std::thread([this](){ thread_function(); });
1961 std::cout << "launch thread=" << thread.get_id() << "\n";
1962 #endif
1963 }
1964
1965 float LoaderSaverBase::get_progress()
1966 {
1967 #ifdef GLIB_THREADS
1968 Glib::Threads::Mutex::Lock lock(progressMutex);
1969 #else
1970 std::lock_guard<std::mutex> lock(progressMutex);
1971 #endif
1972 return progress;
1973 }
1974
1975 Glib::Dispatcher& LoaderSaverBase::signal_progress()
1976 {
1977 return progress_dispatcher;
1978 }
1979
1980 Glib::Dispatcher& LoaderSaverBase::signal_finished()
1981 {
1982 return finished_dispatcher;
1983 }
1984
1985 Glib::Dispatcher& LoaderSaverBase::signal_error()
1986 {
1987 return error_dispatcher;
1988 }
1989
1990 void LoaderSaverBase::join() {
1991 #ifdef GLIB_THREADS
1992 thread->join();
1993 #else
1994 thread.join();
1995 #endif
1996 }
1997
1998
1999 Loader::Loader(const char* filename) :
2000 LoaderSaverBase(filename, 0)
2001 {
2002 }
2003
2004 void Loader::thread_function_sub(gig::progress_t& progress)
2005 {
2006 RIFF::File* riff = new RIFF::File(filename);
2007 gig = new gig::File(riff);
2008
2009 gig->GetInstrument(0, &progress);
2010 }
2011
2012
2013 Saver::Saver(gig::File* file, Glib::ustring filename) :
2014 LoaderSaverBase(filename, file)
2015 {
2016 }
2017
2018 void Saver::thread_function_sub(gig::progress_t& progress)
2019 {
2020 // if no filename was provided, that means "save", if filename was provided means "save as"
2021 if (filename.empty()) {
2022 if (!Settings::singleton()->saveWithTemporaryFile) {
2023 // save directly over the existing .gig file
2024 // (requires less disk space than solution below
2025 // but may be slower)
2026 gig->Save(&progress);
2027 } else {
2028 // save the file as separate temporary file first,
2029 // then move the saved file over the old file
2030 // (may result in performance speedup during save)
2031 gig::String tmpname = filename + ".TMP";
2032 gig->Save(tmpname, &progress);
2033 #if defined(WIN32)
2034 if (!DeleteFile(filename.c_str())) {
2035 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
2036 }
2037 #else // POSIX ...
2038 if (unlink(filename.c_str())) {
2039 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2040 }
2041 #endif
2042 if (rename(tmpname.c_str(), filename.c_str())) {
2043 #if defined(WIN32)
2044 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
2045 #else
2046 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2047 #endif
2048 }
2049 }
2050 } else {
2051 gig->Save(filename, &progress);
2052 }
2053 }
2054
2055
2056 ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2057 : Gtk::Dialog(title, parent, true)
2058 {
2059 #if USE_GTKMM_BOX
2060 get_content_area()->pack_start(progressBar);
2061 #else
2062 get_vbox()->pack_start(progressBar);
2063 #endif
2064 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2065 show_all_children();
2066 #endif
2067 resize(600,50);
2068 }
2069
2070 // Clear all GUI elements / controls. This method is typically called
2071 // before a new .gig file is to be created or to be loaded.
2072 void MainWindow::__clear() {
2073 // forget all samples that ought to be imported
2074 m_SampleImportQueue.clear();
2075 // clear the samples and instruments tree views
2076 m_refTreeModel->clear();
2077 m_refSamplesTreeModel->clear();
2078 m_refScriptsTreeModel->clear();
2079 #if !USE_GTKMM_BUILDER
2080 // remove all entries from "Instrument" menu
2081 while (!instrument_menu->get_children().empty()) {
2082 remove_instrument_from_menu(0);
2083 }
2084 #endif
2085 // free libgig's gig::File instance
2086 if (file && !file_is_shared) delete file;
2087 file = NULL;
2088 set_file_is_shared(false);
2089 }
2090
2091 void MainWindow::__refreshEntireGUI() {
2092 // clear the samples and instruments tree views
2093 m_refTreeModel->clear();
2094 m_refSamplesTreeModel->clear();
2095 m_refScriptsTreeModel->clear();
2096 #if !USE_GTKMM_BUILDER
2097 // remove all entries from "Instrument" menu
2098 while (!instrument_menu->get_children().empty()) {
2099 remove_instrument_from_menu(0);
2100 }
2101 #endif
2102
2103 if (!this->file) return;
2104
2105 load_gig(
2106 this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2107 );
2108 }
2109
2110 void MainWindow::on_action_file_new()
2111 {
2112 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2113
2114 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2115
2116 // clear all GUI elements
2117 __clear();
2118 // create a new .gig file (virtually yet)
2119 gig::File* pFile = new gig::File;
2120 // already add one new instrument by default
2121 gig::Instrument* pInstrument = pFile->AddInstrument();
2122 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2123 // update GUI with that new gig::File
2124 load_gig(pFile, 0 /*no file name yet*/);
2125 }
2126
2127 bool MainWindow::close_confirmation_dialog()
2128 {
2129 gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
2130 Glib::filename_display_basename(filename).c_str());
2131 Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2132 g_free(msg);
2133 dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2134 dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2135 #if HAS_GTKMM_STOCK
2136 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2137 dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2138 #else
2139 dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2140 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2141 #endif
2142 dialog.set_default_response(Gtk::RESPONSE_YES);
2143 int response = dialog.run();
2144 dialog.hide();
2145
2146 // user decided to exit app without saving
2147 if (response == Gtk::RESPONSE_NO) return true;
2148
2149 // user cancelled dialog, thus don't close app
2150 if (response == Gtk::RESPONSE_CANCEL) return false;
2151
2152 // TODO: the following return valid is disabled and hard coded instead for
2153 // now, due to the fact that saving with progress bar is now implemented
2154 // asynchronously, as a result the app does not close automatically anymore
2155 // after saving the file has completed
2156 //
2157 // if (response == Gtk::RESPONSE_YES) return file_save();
2158 // return response != Gtk::RESPONSE_CANCEL;
2159 //
2160 if (response == Gtk::RESPONSE_YES) file_save();
2161 return false; // always prevent closing the app for now (see comment above)
2162 }
2163
2164 bool MainWindow::leaving_shared_mode_dialog() {
2165 Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2166 Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2167 dialog.set_secondary_text(
2168 _("If you proceed to work on another instrument file, it won't be "
2169 "used by the sampler until you tell the sampler explicitly to "
2170 "load it."));
2171 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2172 #if HAS_GTKMM_STOCK
2173 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2174 #else
2175 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2176 #endif
2177 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2178 int response = dialog.run();
2179 dialog.hide();
2180 return response == Gtk::RESPONSE_YES;
2181 }
2182
2183 void MainWindow::on_action_file_open()
2184 {
2185 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2186
2187 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2188
2189 Gtk::FileChooserDialog dialog(*this, _("Open file"));
2190 #if HAS_GTKMM_STOCK
2191 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2192 dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2193 #else
2194 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2195 dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2196 #endif
2197 dialog.set_default_response(Gtk::RESPONSE_OK);
2198 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2199 Gtk::FileFilter filter;
2200 filter.add_pattern("*.gig");
2201 #else
2202 Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2203 filter->add_pattern("*.gig");
2204 #endif
2205 dialog.set_filter(filter);
2206 if (current_gig_dir != "") {
2207 dialog.set_current_folder(current_gig_dir);
2208 }
2209 if (dialog.run() == Gtk::RESPONSE_OK) {
2210 dialog.hide();
2211 std::string filename = dialog.get_filename();
2212 printf("filename=%s\n", filename.c_str());
2213 #ifdef GLIB_THREADS
2214 printf("on_action_file_open self=%p\n",
2215 static_cast<void*>(Glib::Threads::Thread::self()));
2216 #else
2217 std::cout << "on_action_file_open self=" <<
2218 std::this_thread::get_id() << "\n";
2219 #endif
2220 load_file(filename.c_str());
2221 current_gig_dir = Glib::path_get_dirname(filename);
2222 }
2223 }
2224
2225 void MainWindow::load_file(const char* name)
2226 {
2227 __clear();
2228
2229 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2230 _("Loading") + Glib::ustring(" '") +
2231 Glib::filename_display_basename(name) + "' ...",
2232 *this
2233 );
2234 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2235 progress_dialog->show_all();
2236 #endif
2237 loader = new Loader(name); //FIXME: memory leak!
2238 loader->signal_progress().connect(
2239 sigc::mem_fun(*this, &MainWindow::on_loader_progress));
2240 loader->signal_finished().connect(
2241 sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2242 loader->signal_error().connect(
2243 sigc::mem_fun(*this, &MainWindow::on_loader_error));
2244 loader->launch();
2245 }
2246
2247 void MainWindow::load_instrument(gig::Instrument* instr) {
2248 if (!instr) {
2249 Glib::ustring txt = "Provided instrument is NULL!\n";
2250 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2251 msg.run();
2252 Gtk::Main::quit();
2253 }
2254 // clear all GUI elements
2255 __clear();
2256 // load the instrument
2257 gig::File* pFile = (gig::File*) instr->GetParent();
2258 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2259 // automatically select the given instrument
2260 int i = 0;
2261 for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2262 instrument = pFile->GetNextInstrument(), ++i)
2263 {
2264 if (instrument == instr) {
2265 // select item in "instruments" tree view
2266 m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2267 // make sure the selected item in the "instruments" tree view is
2268 // visible (scroll to it)
2269 m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2270 #if !USE_GTKMM_BUILDER
2271 // select item in instrument menu
2272 {
2273 const std::vector<Gtk::Widget*> children =
2274 instrument_menu->get_children();
2275 static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2276 }
2277 #endif
2278 // update region chooser and dimension region chooser
2279 m_RegionChooser.set_instrument(instr);
2280 break;
2281 }
2282 }
2283 }
2284
2285 void MainWindow::on_loader_progress()
2286 {
2287 progress_dialog->set_fraction(loader->get_progress());
2288 }
2289
2290 void MainWindow::on_loader_finished()
2291 {
2292 loader->join();
2293 printf("Loader finished!\n");
2294 #ifdef GLIB_THREADS
2295 printf("on_loader_finished self=%p\n",
2296 static_cast<void*>(Glib::Threads::Thread::self()));
2297 #else
2298 std::cout << "on_loader_finished self=" <<
2299 std::this_thread::get_id() << "\n";
2300 #endif
2301 load_gig(loader->gig, loader->filename.c_str());
2302 progress_dialog->hide();
2303 }
2304
2305 void MainWindow::on_loader_error()
2306 {
2307 loader->join();
2308 Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2309 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2310 msg.run();
2311 progress_dialog->hide();
2312 }
2313
2314 void MainWindow::on_action_file_save()
2315 {
2316 file_save();
2317 }
2318
2319 bool MainWindow::check_if_savable()
2320 {
2321 if (!file) return false;
2322
2323 if (!file->GetFirstSample()) {
2324 Gtk::MessageDialog(*this, _("The file could not be saved "
2325 "because it contains no samples"),
2326 false, Gtk::MESSAGE_ERROR).run();
2327 return false;
2328 }
2329
2330 for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
2331 instrument = file->GetNextInstrument()) {
2332 if (!instrument->GetFirstRegion()) {
2333 Gtk::MessageDialog(*this, _("The file could not be saved "
2334 "because there are instruments "
2335 "that have no regions"),
2336 false, Gtk::MESSAGE_ERROR).run();
2337 return false;
2338 }
2339 }
2340 return true;
2341 }
2342
2343 bool MainWindow::file_save()
2344 {
2345 if (!check_if_savable()) return false;
2346 if (!file_is_shared && !file_has_name) return file_save_as();
2347
2348 std::cout << "Saving file\n" << std::flush;
2349 file_structure_to_be_changed_signal.emit(this->file);
2350
2351 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2352 _("Saving") + Glib::ustring(" '") +
2353 Glib::filename_display_basename(this->filename) + "' ...",
2354 *this
2355 );
2356 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2357 progress_dialog->show_all();
2358 #endif
2359 saver = new Saver(this->file); //FIXME: memory leak!
2360 saver->signal_progress().connect(
2361 sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2362 saver->signal_finished().connect(
2363 sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2364 saver->signal_error().connect(
2365 sigc::mem_fun(*this, &MainWindow::on_saver_error));
2366 saver->launch();
2367
2368 return true;
2369 }
2370
2371 void MainWindow::on_saver_progress()
2372 {
2373 progress_dialog->set_fraction(saver->get_progress());
2374 }
2375
2376 void MainWindow::on_saver_error()
2377 {
2378 saver->join();
2379 file_structure_changed_signal.emit(this->file);
2380 Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2381 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2382 msg.run();
2383 }
2384
2385 void MainWindow::on_saver_finished()
2386 {
2387 saver->join();
2388 this->file = saver->gig;
2389 this->filename = saver->filename;
2390 current_gig_dir = Glib::path_get_dirname(filename);
2391 set_title(Glib::filename_display_basename(filename));
2392 file_has_name = true;
2393 file_is_changed = false;
2394 std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
2395 __import_queued_samples();
2396 std::cout << "Importing queued samples done.\n" << std::flush;
2397
2398 file_structure_changed_signal.emit(this->file);
2399
2400 __refreshEntireGUI();
2401 progress_dialog->hide();
2402 }
2403
2404 void MainWindow::on_action_file_save_as()
2405 {
2406 if (!check_if_savable()) return;
2407 file_save_as();
2408 }
2409
2410 bool MainWindow::file_save_as()
2411 {
2412 Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2413 #if HAS_GTKMM_STOCK
2414 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2415 dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2416 #else
2417 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2418 dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2419 #endif
2420 dialog.set_default_response(Gtk::RESPONSE_OK);
2421 dialog.set_do_overwrite_confirmation();
2422
2423 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2424 Gtk::FileFilter filter;
2425 filter.add_pattern("*.gig");
2426 #else
2427 Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2428 filter->add_pattern("*.gig");
2429 #endif
2430 dialog.set_filter(filter);
2431
2432 // set initial dir and filename of the Save As dialog
2433 // and prepare that initial filename as a copy of the gig
2434 {
2435 std::string basename = Glib::path_get_basename(filename);
2436 std::string dir = Glib::path_get_dirname(filename);
2437 basename = std::string(_("copy_of_")) + basename;
2438 Glib::ustring copyFileName = Glib::build_filename(dir, basename);
2439 if (Glib::path_is_absolute(filename)) {
2440 dialog.set_filename(copyFileName);
2441 } else {
2442 if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
2443 }
2444 dialog.set_current_name(Glib::filename_display_basename(copyFileName));
2445 }
2446
2447 // show warning in the dialog
2448 HBox descriptionArea;
2449 descriptionArea.set_spacing(15);
2450 Gtk::Image warningIcon;
2451 warningIcon.set_from_icon_name("dialog-warning",
2452 Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2453 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2454 #if GTKMM_MAJOR_VERSION < 3
2455 view::WrapLabel description;
2456 #else
2457 Gtk::Label description;
2458 description.set_line_wrap();
2459 #endif
2460 description.set_markup(
2461 _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
2462 "<span style=\"italic\">\"Save\"</span> dialog instead of "
2463 "<span style=\"italic\">\"Save As...\"</span> if you want to save "
2464 "to the same .gig file. Using "
2465 "<span style=\"italic\">\"Save As...\"</span> for writing to the "
2466 "same .gig file will end up in corrupted sample wave data!\n")
2467 );
2468 descriptionArea.pack_start(description);
2469 #if USE_GTKMM_BOX
2470 dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2471 #else
2472 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2473 #endif
2474 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2475 descriptionArea.show_all();
2476 #endif
2477
2478 if (dialog.run() == Gtk::RESPONSE_OK) {
2479 dialog.hide();
2480 std::string filename = dialog.get_filename();
2481 if (!Glib::str_has_suffix(filename, ".gig")) {
2482 filename += ".gig";
2483 }
2484 printf("filename=%s\n", filename.c_str());
2485
2486 progress_dialog = new ProgressDialog( //FIXME: memory leak!
2487 _("Saving") + Glib::ustring(" '") +
2488 Glib::filename_display_basename(filename) + "' ...",
2489 *this
2490 );
2491 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2492 progress_dialog->show_all();
2493 #endif
2494
2495 saver = new Saver(file, filename); //FIXME: memory leak!
2496 saver->signal_progress().connect(
2497 sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2498 saver->signal_finished().connect(
2499 sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2500 saver->signal_error().connect(
2501 sigc::mem_fun(*this, &MainWindow::on_saver_error));
2502 saver->launch();
2503
2504 return true;
2505 }
2506 return false;
2507 }
2508
2509 // actually write the sample(s)' data to the gig file
2510 void MainWindow::__import_queued_samples() {
2511 std::cout << "Starting sample import\n" << std::flush;
2512 Glib::ustring error_files;
2513 printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2514 for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2515 iter != m_SampleImportQueue.end(); ) {
2516 printf("Importing sample %s\n",iter->second.sample_path.c_str());
2517 SF_INFO info;
2518 info.format = 0;
2519 SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2520 sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2521 try {
2522 if (!hFile) throw std::string(_("could not open file"));
2523 // determine sample's bit depth
2524 int bitdepth;
2525 switch (info.format & 0xff) {
2526 case SF_FORMAT_PCM_S8:
2527 case SF_FORMAT_PCM_16:
2528 case SF_FORMAT_PCM_U8:
2529 bitdepth = 16;
2530 break;
2531 case SF_FORMAT_PCM_24:
2532 case SF_FORMAT_PCM_32:
2533 case SF_FORMAT_FLOAT:
2534 case SF_FORMAT_DOUBLE:
2535 bitdepth = 24;
2536 break;
2537 default:
2538 sf_close(hFile); // close sound file
2539 throw std::string(_("format not supported")); // unsupported subformat (yet?)
2540 }
2541
2542 // reset write position for sample
2543 iter->first->SetPos(0);
2544
2545 const int bufsize = 10000;
2546 switch (bitdepth) {
2547 case 16: {
2548 short* buffer = new short[bufsize * info.channels];
2549 sf_count_t cnt = info.frames;
2550 while (cnt) {
2551 // libsndfile does the conversion for us (if needed)
2552 int n = sf_readf_short(hFile, buffer, bufsize);
2553 // write from buffer directly (physically) into .gig file
2554 iter->first->Write(buffer, n);
2555 cnt -= n;
2556 }
2557 delete[] buffer;
2558 break;
2559 }
2560 case 24: {
2561 int* srcbuf = new int[bufsize * info.channels];
2562 uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
2563 sf_count_t cnt = info.frames;
2564 while (cnt) {
2565 // libsndfile returns 32 bits, convert to 24
2566 int n = sf_readf_int(hFile, srcbuf, bufsize);
2567 int j = 0;
2568 for (int i = 0 ; i < n * info.channels ; i++) {
2569 dstbuf[j++] = srcbuf[i] >> 8;
2570 dstbuf[j++] = srcbuf[i] >> 16;
2571 dstbuf[j++] = srcbuf[i] >> 24;
2572 }
2573 // write from buffer directly (physically) into .gig file
2574 iter->first->Write(dstbuf, n);
2575 cnt -= n;
2576 }
2577 delete[] srcbuf;
2578 delete[] dstbuf;
2579 break;
2580 }
2581 }
2582 // cleanup
2583 sf_close(hFile);
2584 // let the sampler re-cache the sample if needed
2585 sample_changed_signal.emit(iter->first);
2586 // on success we remove the sample from the import queue,
2587 // otherwise keep it, maybe it works the next time ?
2588 std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2589 ++iter;
2590 m_SampleImportQueue.erase(cur);
2591 } catch (std::string what) {
2592 // remember the files that made trouble (and their cause)
2593 if (!error_files.empty()) error_files += "\n";
2594 error_files += iter->second.sample_path += " (" + what + ")";
2595 ++iter;
2596 }
2597 }
2598 // show error message box when some sample(s) could not be imported
2599 if (!error_files.empty()) {
2600 Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
2601 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2602 msg.run();
2603 }
2604 }
2605
2606 void MainWindow::on_action_file_properties()
2607 {
2608 fileProps.show();
2609 fileProps.deiconify();
2610 }
2611
2612 void MainWindow::on_action_warn_user_on_extensions() {
2613 Settings::singleton()->warnUserOnExtensions =
2614 !Settings::singleton()->warnUserOnExtensions;
2615 }
2616
2617 void MainWindow::on_action_show_tooltips() {
2618 Settings::singleton()->showTooltips =
2619 !Settings::singleton()->showTooltips;
2620
2621 on_show_tooltips_changed();
2622 }
2623
2624 void MainWindow::on_show_tooltips_changed() {
2625 const bool b = Settings::singleton()->showTooltips;
2626
2627 dimreg_label.set_has_tooltip(b);
2628 dimreg_all_regions.set_has_tooltip(b);
2629 dimreg_all_dimregs.set_has_tooltip(b);
2630 dimreg_stereo.set_has_tooltip(b);
2631
2632 // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2633 //m_TreeView.set_has_tooltip(b);
2634
2635 m_TreeViewSamples.set_has_tooltip(b);
2636 m_TreeViewScripts.set_has_tooltip(b);
2637
2638 set_has_tooltip(b);
2639 }
2640
2641 void MainWindow::on_action_sync_sampler_instrument_selection() {
2642 Settings::singleton()->syncSamplerInstrumentSelection =
2643 !Settings::singleton()->syncSamplerInstrumentSelection;
2644 }
2645
2646 void MainWindow::on_action_move_root_note_with_region_moved() {
2647 Settings::singleton()->moveRootNoteWithRegionMoved =
2648 !Settings::singleton()->moveRootNoteWithRegionMoved;
2649 }
2650
2651 void MainWindow::on_action_help_about()
2652 {
2653 Gtk::AboutDialog dialog;
2654 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
2655 dialog.set_program_name("Gigedit");
2656 #else
2657 dialog.set_name("Gigedit");
2658 #endif
2659 dialog.set_version(VERSION);
2660 dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2661 const std::string sComment =
2662 _("Built " __DATE__ "\nUsing ") +
2663 ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
2664 _(
2665 "Gigedit is released under the GNU General Public License.\n"
2666 "\n"
2667 "This program is distributed WITHOUT ANY WARRANTY; So better "
2668 "backup your Gigasampler/GigaStudio files before editing them with "
2669 "this application.\n"
2670 "\n"
2671 "Please report bugs to: https://bugs.linuxsampler.org"
2672 );
2673 dialog.set_comments(sComment.c_str());
2674 dialog.set_website("https://www.linuxsampler.org");
2675 dialog.set_website_label("https://www.linuxsampler.org");
2676 dialog.set_position(Gtk::WIN_POS_CENTER);
2677 dialog.run();
2678 }
2679
2680 FilePropDialog::FilePropDialog()
2681 : eFileFormat(_("File Format")),
2682 eName(_("Name")),
2683 eCreationDate(_("Creation date")),
2684 eComments(_("Comments")),
2685 eProduct(_("Product")),
2686 eCopyright(_("Copyright")),
2687 eArtists(_("Artists")),
2688 eGenre(_("Genre")),
2689 eKeywords(_("Keywords")),
2690 eEngineer(_("Engineer")),
2691 eTechnician(_("Technician")),
2692 eSoftware(_("Software")),
2693 eMedium(_("Medium")),
2694 eSource(_("Source")),
2695 eSourceForm(_("Source form")),
2696 eCommissioned(_("Commissioned")),
2697 eSubject(_("Subject")),
2698 #if HAS_GTKMM_STOCK
2699 quitButton(Gtk::Stock::CLOSE),
2700 #else
2701 quitButton(_("_Close")),
2702 #endif
2703 table(2, 1),
2704 m_file(NULL)
2705 {
2706 if (!Settings::singleton()->autoRestoreWindowDimension) {
2707 set_default_size(470, 390);
2708 set_position(Gtk::WIN_POS_MOUSE);
2709 }
2710
2711 set_title(_("File Properties"));
2712 eName.set_width_chars(50);
2713
2714 connect(eFileFormat, &FilePropDialog::set_FileFormat);
2715 connect(eName, &DLS::Info::Name);
2716 connect(eCreationDate, &DLS::Info::CreationDate);
2717 connect(eComments, &DLS::Info::Comments);
2718 connect(eProduct, &DLS::Info::Product);
2719 connect(eCopyright, &DLS::Info::Copyright);
2720 connect(eArtists, &DLS::Info::Artists);
2721 connect(eGenre, &DLS::Info::Genre);
2722 connect(eKeywords, &DLS::Info::Keywords);
2723 connect(eEngineer, &DLS::Info::Engineer);
2724 connect(eTechnician, &DLS::Info::Technician);
2725 connect(eSoftware, &DLS::Info::Software);
2726 connect(eMedium, &DLS::Info::Medium);
2727 connect(eSource, &DLS::Info::Source);
2728 connect(eSourceForm, &DLS::Info::SourceForm);
2729 connect(eCommissioned, &DLS::Info::Commissioned);
2730 connect(eSubject, &DLS::Info::Subject);
2731
2732 table.add(eFileFormat);
2733 table.add(eName);
2734 table.add(eCreationDate);
2735 table.add(eComments);
2736 table.add(eProduct);
2737 table.add(eCopyright);
2738 table.add(eArtists);
2739 table.add(eGenre);
2740 table.add(eKeywords);
2741 table.add(eEngineer);
2742 table.add(eTechnician);
2743 table.add(eSoftware);
2744 table.add(eMedium);
2745 table.add(eSource);
2746 table.add(eSourceForm);
2747 table.add(eCommissioned);
2748 table.add(eSubject);
2749
2750 #if USE_GTKMM_GRID
2751 table.set_column_spacing(5);
2752 #else
2753 table.set_col_spacings(5);
2754 #endif
2755
2756 add(vbox);
2757 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2758 table.set_margin(5);
2759 #else
2760 table.set_border_width(5);
2761 #endif
2762 vbox.add(table);
2763 vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2764 buttonBox.set_layout(Gtk::BUTTONBOX_END);
2765 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2766 buttonBox.set_margin(5);
2767 #else
2768 buttonBox.set_border_width(5);
2769 #endif
2770 buttonBox.show();
2771 buttonBox.pack_start(quitButton);
2772 quitButton.set_can_default();
2773 quitButton.grab_focus();
2774 quitButton.signal_clicked().connect(
2775 sigc::mem_fun(*this, &FilePropDialog::hide));
2776
2777 quitButton.show();
2778 vbox.show();
2779 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2780 show_all_children();
2781 #endif
2782 }
2783
2784 void FilePropDialog::set_file(gig::File* file)
2785 {
2786 m_file = file;
2787 update(file->pInfo);
2788
2789 // update file format version combo box
2790 const std::string sGiga = "Gigasampler/GigaStudio v";
2791 const int major = file->pVersion->major;
2792 std::vector<std::string> txts;
2793 std::vector<int> values;
2794 txts.push_back(sGiga + "2"); values.push_back(2);
2795 txts.push_back(sGiga + "3"); values.push_back(3);
2796 txts.push_back(sGiga + "4"); values.push_back(4);
2797 if (major < 2 || major > 4) {
2798 txts.push_back(sGiga + ToString(major)); values.push_back(major);
2799 }
2800 std::vector<const char*> texts;
2801 for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2802 texts.push_back(NULL); values.push_back(0);
2803
2804 update_model++;
2805 eFileFormat.set_choices(&texts[0], &values[0]);
2806 eFileFormat.set_value(major);
2807 update_model--;
2808 }
2809
2810 void FilePropDialog::set_FileFormat(int value)
2811 {
2812 m_file->pVersion->major = value;
2813 }
2814
2815
2816 void InstrumentProps::set_Name(const gig::String& name)
2817 {
2818 m->pInfo->Name = name;
2819 }
2820
2821 void InstrumentProps::update_name()
2822 {
2823 update_model++;
2824 eName.set_value(m->pInfo->Name);
2825 update_model--;
2826 }
2827
2828 void InstrumentProps::set_IsDrum(bool value)
2829 {
2830 m->IsDrum = value;
2831 }
2832
2833 void InstrumentProps::set_MIDIBank(uint16_t value)
2834 {
2835 m->MIDIBank = value;
2836 }
2837
2838 void InstrumentProps::set_MIDIProgram(uint32_t value)
2839 {
2840 m->MIDIProgram = value;
2841 }
2842
2843 InstrumentProps::InstrumentProps() :
2844 #if HAS_GTKMM_STOCK
2845 quitButton(Gtk::Stock::CLOSE),
2846 #else
2847 quitButton(_("_Close")),
2848 #endif
2849 table(2,1),
2850 eName(_("Name")),
2851 eIsDrum(_("Is drum")),
2852 eMIDIBank(_("MIDI bank"), 0, 16383),
2853 eMIDIProgram(_("MIDI program")),
2854 eAttenuation(_("Attenuation"), 0, 96, 0, 1),
2855 eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2856 eEffectSend(_("Effect send"), 0, 65535),
2857 eFineTune(_("Fine tune"), -8400, 8400),
2858 ePitchbendRange(_("Pitchbend range"), 0, 48),
2859 ePianoReleaseMode(_("Piano release mode")),
2860 eDimensionKeyRangeLow(_("Keyswitching range low")),
2861 eDimensionKeyRangeHigh(_("Keyswitching range high")),
2862 table2(2,1),
2863 eName2(_("Name")),
2864 eCreationDate(_("Creation date")),
2865 eComments(_("Comments")),
2866 eProduct(_("Product")),
2867 eCopyright(_("Copyright")),
2868 eArtists(_("Artists")),
2869 eGenre(_("Genre")),
2870 eKeywords(_("Keywords")),
2871 eEngineer(_("Engineer")),
2872 eTechnician(_("Technician")),
2873 eSoftware(_("Software")),
2874 eMedium(_("Medium")),
2875 eSource(_("Source")),
2876 eSourceForm(_("Source form")),
2877 eCommissioned(_("Commissioned")),
2878 eSubject(_("Subject"))
2879 {
2880 if (!Settings::singleton()->autoRestoreWindowDimension) {
2881 //set_default_size(470, 390);
2882 set_position(Gtk::WIN_POS_MOUSE);
2883 }
2884
2885 set_title(_("Instrument Properties"));
2886
2887 tabs.append_page(vbox[1], _("Settings"));
2888 tabs.append_page(vbox[2], _("Info"));
2889
2890 eDimensionKeyRangeLow.set_tip(
2891 _("start of the keyboard area which should switch the "
2892 "\"keyswitching\" dimension")
2893 );
2894 eDimensionKeyRangeHigh.set_tip(
2895 _("end of the keyboard area which should switch the "
2896 "\"keyswitching\" dimension")
2897 );
2898
2899 connect(eName, &InstrumentProps::set_Name);
2900 connect(eIsDrum, &InstrumentProps::set_IsDrum);
2901 connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2902 connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
2903 connect(eAttenuation, &gig::Instrument::Attenuation);
2904 connect(eGainPlus6, &gig::Instrument::Attenuation);
2905 connect(eEffectSend, &gig::Instrument::EffectSend);
2906 connect(eFineTune, &gig::Instrument::FineTune);
2907 connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
2908 connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
2909 connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
2910 &gig::Instrument::DimensionKeyRange);
2911
2912 eName.signal_value_changed().connect(sig_name_changed.make_slot());
2913
2914 connect(eName2, &InstrumentProps::set_Name);
2915 connectLambda(eCreationDate, [this](gig::String s) {
2916 m->pInfo->CreationDate = s;
2917 });
2918 connectLambda(eComments, [this](gig::String s) {
2919 m->pInfo->Comments = s;
2920 });
2921 connectLambda(eProduct, [this](gig::String s) {
2922 m->pInfo->Product = s;
2923 });
2924 connectLambda(eCopyright, [this](gig::String s) {
2925 m->pInfo->Copyright = s;
2926 });
2927 connectLambda(eArtists, [this](gig::String s) {
2928 m->pInfo->Artists = s;
2929 });
2930 connectLambda(eGenre, [this](gig::String s) {
2931 m->pInfo->Genre = s;
2932 });
2933 connectLambda(eKeywords, [this](gig::String s) {
2934 m->pInfo->Keywords = s;
2935 });
2936 connectLambda(eEngineer, [this](gig::String s) {
2937 m->pInfo->Engineer = s;
2938 });
2939 connectLambda(eTechnician, [this](gig::String s) {
2940 m->pInfo->Technician = s;
2941 });
2942 connectLambda(eSoftware, [this](gig::String s) {
2943 m->pInfo->Software = s;
2944 });
2945 connectLambda(eMedium, [this](gig::String s) {
2946 m->pInfo->Medium = s;
2947 });
2948 connectLambda(eSource, [this](gig::String s) {
2949 m->pInfo->Source = s;
2950 });
2951 connectLambda(eSourceForm, [this](gig::String s) {
2952 m->pInfo->SourceForm = s;
2953 });
2954 connectLambda(eCommissioned, [this](gig::String s) {
2955 m->pInfo->Commissioned = s;
2956 });
2957 connectLambda(eSubject, [this](gig::String s) {
2958 m->pInfo->Subject = s;
2959 });
2960
2961 // tab 1
2962 #if USE_GTKMM_GRID
2963 table.set_column_spacing(5);
2964 #else
2965 table.set_col_spacings(5);
2966 #endif
2967 table.add(eName);
2968 table.add(eIsDrum);
2969 table.add(eMIDIBank);
2970 table.add(eMIDIProgram);
2971 table.add(eAttenuation);
2972 table.add(eGainPlus6);
2973 table.add(eEffectSend);
2974 table.add(eFineTune);
2975 table.add(ePitchbendRange);
2976 table.add(ePianoReleaseMode);
2977 table.add(eDimensionKeyRangeLow);
2978 table.add(eDimensionKeyRangeHigh);
2979
2980 // tab 2
2981 #if USE_GTKMM_GRID
2982 table2.set_column_spacing(5);
2983 #else
2984 table2.set_col_spacings(5);
2985 #endif
2986 table2.add(eName2);
2987 table2.add(eCreationDate);
2988 table2.add(eComments);
2989 table2.add(eProduct);
2990 table2.add(eCopyright);
2991 table2.add(eArtists);
2992 table2.add(eGenre);
2993 table2.add(eKeywords);
2994 table2.add(eEngineer);
2995 table2.add(eTechnician);
2996 table2.add(eSoftware);
2997 table2.add(eMedium);
2998 table2.add(eSource);
2999 table2.add(eSourceForm);
3000 table2.add(eCommissioned);
3001 table2.add(eSubject);
3002
3003 add(vbox[0]);
3004 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3005 table.set_margin(5);
3006 #else
3007 table.set_border_width(5);
3008 #endif
3009 vbox[1].pack_start(table);
3010 vbox[2].pack_start(table2);
3011 table.show();
3012 table2.show();
3013 vbox[0].pack_start(tabs);
3014 vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK);
3015 buttonBox.set_layout(Gtk::BUTTONBOX_END);
3016 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3017 buttonBox.set_margin(5);
3018 #else
3019 buttonBox.set_border_width(5);
3020 #endif
3021 buttonBox.show();
3022 buttonBox.pack_start(quitButton);
3023 quitButton.set_can_default();
3024 quitButton.grab_focus();
3025
3026 quitButton.signal_clicked().connect(
3027 sigc::mem_fun(*this, &InstrumentProps::hide));
3028
3029 quitButton.show();
3030 vbox[0].show();
3031 #if HAS_GTKMM_SHOW_ALL_CHILDREN
3032 show_all_children();
3033 #endif
3034 }
3035
3036 void InstrumentProps::set_instrument(gig::Instrument* instrument)
3037 {
3038 update(instrument);
3039
3040 update_model++;
3041
3042 // tab 1
3043 eName.set_value(instrument->pInfo->Name);
3044 eIsDrum.set_value(instrument->IsDrum);
3045 eMIDIBank.set_value(instrument->MIDIBank);
3046 eMIDIProgram.set_value(instrument->MIDIProgram);
3047 // tab 2
3048 eName2.set_value(instrument->pInfo->Name);
3049 eCreationDate.set_value(instrument->pInfo->CreationDate);
3050 eComments.set_value(instrument->pInfo->Comments);
3051 eProduct.set_value(instrument->pInfo->Product);
3052 eCopyright.set_value(instrument->pInfo->Copyright);
3053 eArtists.set_value(instrument->pInfo->Artists);
3054 eGenre.set_value(instrument->pInfo->Genre);
3055 eKeywords.set_value(instrument->pInfo->Keywords);
3056 eEngineer.set_value(instrument->pInfo->Engineer);
3057 eTechnician.set_value(instrument->pInfo->Technician);
3058 eSoftware.set_value(instrument->pInfo->Software);
3059 eMedium.set_value(instrument->pInfo->Medium);
3060 eSource.set_value(instrument->pInfo->Source);
3061 eSourceForm.set_value(instrument->pInfo->SourceForm);
3062 eCommissioned.set_value(instrument->pInfo->Commissioned);
3063 eSubject.set_value(instrument->pInfo->Subject);
3064
3065 update_model--;
3066 }
3067
3068
3069 SampleProps::SampleProps() :
3070 #if HAS_GTKMM_STOCK
3071 quitButton(Gtk::Stock::CLOSE),
3072 #else
3073 quitButton(_("_Close")),
3074 #endif
3075 table(2,1),
3076 eName(_("Name")),
3077 eUnityNote(_("Unity Note")),
3078 eSampleGroup(_("Sample Group")),
3079 eSampleFormatInfo(_("Sample Format")),
3080 eSampleID("Sample ID"),
3081 eChecksum("Wave Data CRC-32"),
3082 eLoopsCount(_("Loops"), 0, 1), // we might support more than 1 loop in future
3083 eLoopStart(_("Loop start position"), 0, 9999999),
3084 eLoopLength(_("Loop size"), 0, 9999999),
3085 eLoopType(_("Loop type")),
3086 eLoopPlayCount(_("Playback count")),
3087 table2(2,1),
3088 eName2(_("Name")),
3089 eCreationDate(_("Creation date")),
3090 eComments(_("Comments")),
3091 eProduct(_("Product")),
3092 eCopyright(_("Copyright")),
3093 eArtists(_("Artists")),
3094 eGenre(_("Genre")),
3095 eKeywords(_("Keywords")),
3096 eEngineer(_("Engineer")),
3097 eTechnician(_("Technician")),
3098 eSoftware(_("Software")),
3099 eMedium(_("Medium")),
3100 eSource(_("Source")),
3101 eSourceForm(_("Source form")),
3102 eCommissioned(_("Commissioned")),
3103 eSubject(_("Subject"))
3104 {
3105 if (!Settings::singleton()->autoRestoreWindowDimension) {
3106 //set_default_size(470, 390);
3107 set_position(Gtk::WIN_POS_MOUSE);
3108 }
3109
3110 set_title(_("Sample Properties"));
3111
3112 tabs.append_page(vbox[1], _("Settings"));
3113 tabs.append_page(vbox[2], _("Info"));
3114
3115 connect(eName, &SampleProps::set_Name);
3116 connect(eUnityNote, &gig::Sample::MIDIUnityNote);
3117 connect(eLoopsCount, &gig::Sample::Loops);
3118 connectLambda(eLoopStart, [this](uint32_t start){
3119 m->LoopStart = start;
3120 m->LoopEnd = start + m->LoopSize;
3121 });
3122 connectLambda(eLoopLength, [this](uint32_t length){
3123 m->LoopSize = length;
3124 m->LoopEnd = m->LoopStart + length;
3125 });
3126 {
3127 const char* choices[] = { _("normal"), _("bidirectional"), _("backward"), 0 };
3128 static const gig::loop_type_t values[] = {
3129 gig::loop_type_normal,
3130 gig::loop_type_bidirectional,
3131 gig::loop_type_backward
3132 };
3133 eLoopType.set_choices(choices, values);
3134 }
3135 connect(eLoopType, &gig::Sample::LoopType);
3136 connect(eLoopPlayCount, &gig::Sample::LoopPlayCount);
3137
3138 eName.signal_value_changed().connect(sig_name_changed.make_slot());
3139
3140 connect(eName2, &SampleProps::set_Name);
3141 connectLambda(eCreationDate, [this](gig::String s) {
3142 m->pInfo->CreationDate = s;
3143 });
3144 connectLambda(eComments, [this](gig::String s) {
3145 m->pInfo->Comments = s;
3146 });
3147 connectLambda(eProduct, [this](gig::String s) {
3148 m->pInfo->Product = s;
3149 });
3150 connectLambda(eCopyright, [this](gig::String s) {
3151 m->pInfo->Copyright = s;
3152 });
3153 connectLambda(eArtists, [this](gig::String s) {
3154 m->pInfo->Artists = s;
3155 });
3156 connectLambda(eGenre, [this](gig::String s) {
3157 m->pInfo->Genre = s;
3158 });
3159 connectLambda(eKeywords, [this](gig::String s) {
3160 m->pInfo->Keywords = s;
3161 });
3162 connectLambda(eEngineer, [this](gig::String s) {
3163 m->pInfo->Engineer = s;
3164 });
3165 connectLambda(eTechnician, [this](gig::String s) {
3166 m->pInfo->Technician = s;
3167 });
3168 connectLambda(eSoftware, [this](gig::String s) {
3169 m->pInfo->Software = s;
3170 });
3171 connectLambda(eMedium, [this](gig::String s) {
3172 m->pInfo->Medium = s;
3173 });
3174 connectLambda(eSource, [this](gig::String s) {
3175 m->pInfo->Source = s;
3176 });
3177 connectLambda(eSourceForm, [this](gig::String s) {
3178 m->pInfo->SourceForm = s;
3179 });
3180 connectLambda(eCommissioned, [this](gig::String s) {
3181 m->pInfo->Commissioned = s;
3182 });
3183 connectLambda(eSubject, [this](gig::String s) {
3184 m->pInfo->Subject = s;
3185 });
3186
3187 // tab 1
3188 #if USE_GTKMM_GRID
3189 table.set_column_spacing(5);
3190 #else
3191 table.set_col_spacings(5);
3192 #endif
3193 table.add(eName);
3194 table.add(eUnityNote);
3195 table.add(eSampleGroup);
3196 table.add(eSampleFormatInfo);
3197 table.add(eSampleID);
3198 table.add(eChecksum);
3199 table.add(eLoopsCount);
3200 table.add(eLoopStart);
3201 table.add(eLoopLength);
3202 table.add(eLoopType);
3203 table.add(eLoopPlayCount);
3204
3205 // tab 2
3206 #if USE_GTKMM_GRID
3207 table2.set_column_spacing(5);
3208 #else
3209 table2.set_col_spacings(5);
3210 #endif
3211 table2.add(eName2);
3212 table2.add(eCreationDate);
3213 table2.add(eComments);
3214 table2.add(eProduct);
3215 table2.add(eCopyright);
3216 table2.add(eArtists);
3217 table2.add(eGenre);
3218 table2.add(eKeywords);
3219 table2.add(eEngineer);
3220 table2.add(eTechnician);
3221 table2.add(eSoftware);
3222 table2.add(eMedium);
3223 table2.add(eSource);
3224 table2.add(eSourceForm);
3225 table2.add(eCommissioned);
3226 table2.add(eSubject);
3227
3228 add(vbox[0]);
3229 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3230 table.set_margin(5);
3231 #else
3232 table.set_border_width(5);
3233 #endif
3234 vbox[1].pack_start(table);
3235 vbox[2].pack_start(table2);
3236 table.show();
3237 table2.show();
3238 vbox[0].pack_start(tabs);
3239 vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK);
3240 buttonBox.set_layout(Gtk::BUTTONBOX_END);
3241 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3242 buttonBox.set_margin(5);
3243 #else
3244 buttonBox.set_border_width(5);
3245 #endif
3246 buttonBox.show();
3247 buttonBox.pack_start(quitButton);
3248 quitButton.set_can_default();
3249 quitButton.grab_focus();
3250
3251 quitButton.signal_clicked().connect(
3252 sigc::mem_fun(*this, &SampleProps::hide));
3253
3254 quitButton.show();
3255 vbox[0].show();
3256 #if HAS_GTKMM_SHOW_ALL_CHILDREN
3257 show_all_children();
3258 #endif
3259 }
3260
3261 void SampleProps::set_sample(gig::Sample* sample)
3262 {
3263 update(sample);
3264
3265 update_model++;
3266
3267 // tab 1
3268 eName.set_value(sample->pInfo->Name);
3269 eUnityNote.set_value(sample->MIDIUnityNote);
3270 // show sample group name
3271 {
3272 Glib::ustring s = "---";
3273 if (sample && sample->GetGroup())
3274 s = sample->GetGroup()->Name;
3275 eSampleGroup.text.set_text(s);
3276 }
3277 // assemble sample format info string
3278 {
3279 Glib::ustring s;
3280 if (sample) {
3281 switch (sample->Channels) {
3282 case 1: s = _("Mono"); break;
3283 case 2: s = _("Stereo"); break;
3284 default:
3285 s = ToString(sample->Channels) + _(" audio channels");
3286 break;
3287 }
3288 s += " " + ToString(sample->BitDepth) + " Bits";
3289 s += " " + ToString(sample->SamplesPerSecond/1000) + "."
3290 + ToString((sample->SamplesPerSecond%1000)/100) + " kHz";
3291 } else {
3292 s = _("No sample assigned to this dimension region.");
3293 }
3294 eSampleFormatInfo.text.set_text(s);
3295 }
3296 // generate sample's memory address pointer string
3297 {
3298 Glib::ustring s;
3299 if (sample) {
3300 char buf[64] = {};
3301 snprintf(buf, sizeof(buf), "%p", sample);
3302 s = buf;
3303 } else {
3304 s = "---";
3305 }
3306 eSampleID.text.set_text(s);
3307 }
3308 // generate raw wave form data CRC-32 checksum string
3309 {
3310 Glib::ustring s = "---";
3311 if (sample) {
3312 char buf[64] = {};
3313 snprintf(buf, sizeof(buf), "%x", sample->GetWaveDataCRC32Checksum());
3314 s = buf;
3315 }
3316 eChecksum.text.set_text(s);
3317 }
3318 eLoopsCount.set_value(sample->Loops);
3319 eLoopStart.set_value(sample->LoopStart);
3320 eLoopLength.set_value(sample->LoopSize);
3321 eLoopType.set_value(sample->LoopType);
3322 eLoopPlayCount.set_value(sample->LoopPlayCount);
3323 // tab 2
3324 eName2.set_value(sample->pInfo->Name);
3325 eCreationDate.set_value(sample->pInfo->CreationDate);
3326 eComments.set_value(sample->pInfo->Comments);
3327 eProduct.set_value(sample->pInfo->Product);
3328 eCopyright.set_value(sample->pInfo->Copyright);
3329 eArtists.set_value(sample->pInfo->Artists);
3330 eGenre.set_value(sample->pInfo->Genre);
3331 eKeywords.set_value(sample->pInfo->Keywords);
3332 eEngineer.set_value(sample->pInfo->Engineer);
3333 eTechnician.set_value(sample->pInfo->Technician);
3334 eSoftware.set_value(sample->pInfo->Software);
3335 eMedium.set_value(sample->pInfo->Medium);
3336 eSource.set_value(sample->pInfo->Source);
3337 eSourceForm.set_value(sample->pInfo->SourceForm);
3338 eCommissioned.set_value(sample->pInfo->Commissioned);
3339 eSubject.set_value(sample->pInfo->Subject);
3340
3341 update_model--;
3342 }
3343
3344 void SampleProps::set_Name(const gig::String& name)
3345 {
3346 m->pInfo->Name = name;
3347 }
3348
3349 void SampleProps::update_name()
3350 {
3351 update_model++;
3352 eName.set_value(m->pInfo->Name);
3353 update_model--;
3354 }
3355
3356
3357 void MainWindow::file_changed()
3358 {
3359 if (file && !file_is_changed) {
3360 set_title("*" + get_title());
3361 file_is_changed = true;
3362 }
3363 }
3364
3365 void MainWindow::updateSampleRefCountMap(gig::File* gig) {
3366 sample_ref_count.clear();
3367
3368 if (!gig) return;
3369
3370 for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
3371 instrument = gig->GetNextInstrument())
3372 {
3373 for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
3374 rgn = instrument->GetNextRegion())
3375 {
3376 for (int i = 0; i < 256; ++i) {
3377 if (!rgn->pDimensionRegions[i]) continue;
3378 if (rgn->pDimensionRegions[i]->pSample) {
3379 sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
3380 }
3381 }
3382 }
3383 }
3384 }
3385
3386 bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
3387 Gtk::TreeModel::iterator iter;
3388 if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
3389 return false;
3390 }
3391 Gtk::TreeModel::Path path(iter);
3392 Gtk::TreeModel::Row row = *iter;
3393 Gtk::TreeViewColumn* pointedColumn = NULL;
3394 // resolve the precise table column the mouse points to
3395 {
3396 Gtk::TreeModel::Path path; // unused
3397 int cellX, cellY; // unused
3398 m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
3399 }
3400 Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
3401 if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
3402 // show the script(s) assigned to the hovered instrument as tooltip
3403 tooltip->set_markup( row[m_Columns.m_col_tooltip] );
3404 m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
3405 } else {
3406 // if beginners' tooltips is disabled then don't show the following one
3407 if (!Settings::singleton()->showTooltips)
3408 return false;
3409 // yeah, a beginners tooltip
3410 tooltip->set_text(_(
3411 "Right click here for actions on instruments & MIDI Rules. "
3412 "Drag & drop to change the order of instruments."
3413 ));
3414 m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
3415 }
3416 return true;
3417 }
3418
3419 static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
3420 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3421 const int iScriptSlots = instrument->ScriptSlotCount();
3422 Glib::ustring tooltip = "<u>(" + ToString(index) + ") ���" + name + "���</u>\n\n";
3423 if (!iScriptSlots)
3424 tooltip += "<span foreground='red'><i>No script assigned</i></span>";
3425 else {
3426 for (int i = 0; i < iScriptSlots; ++i) {
3427 tooltip += "��� " + ToString(i+1) + ". Script: ���<span foreground='#46DEFF'><b>" +
3428 instrument->GetScriptOfSlot(i)->Name + "</b></span>���";
3429 if (i + 1 < iScriptSlots) tooltip += "\n\n";
3430 }
3431 }
3432 return tooltip;
3433 }
3434
3435 void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
3436 {
3437 file = 0;
3438 set_file_is_shared(isSharedInstrument);
3439
3440 this->filename =
3441 (filename && strlen(filename) > 0) ?
3442 filename : (!gig->GetFileName().empty()) ?
3443 gig->GetFileName() : _("Unsaved Gig File");
3444 set_title(Glib::filename_display_basename(this->filename));
3445 file_has_name = filename;
3446 file_is_changed = false;
3447
3448 fileProps.set_file(gig);
3449
3450 instrument_name_connection.block();
3451 int index = 0;
3452 for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
3453 instrument = gig->GetNextInstrument(), ++index) {
3454 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3455 const int iScriptSlots = instrument->ScriptSlotCount();
3456
3457 Gtk::TreeModel::iterator iter = m_refTreeModel->append();
3458 Gtk::TreeModel::Row row = *iter;
3459 row[m_Columns.m_col_nr] = index;
3460 row[m_Columns.m_col_name] = name;
3461 row[m_Columns.m_col_instr] = instrument;
3462 row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3463 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3464
3465 #if !USE_GTKMM_BUILDER
3466 add_instrument_to_menu(name);
3467 #endif
3468 }
3469 instrument_name_connection.unblock();
3470 #if !USE_GTKMM_BUILDER
3471 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
3472 #endif
3473
3474 updateSampleRefCountMap(gig);
3475
3476 for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
3477 if (group->Name != "") {
3478 Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3479 Gtk::TreeModel::Row rowGroup = *iterGroup;
3480 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3481 rowGroup[m_SamplesModel.m_col_group] = group;
3482 rowGroup[m_SamplesModel.m_col_sample] = NULL;
3483 for (gig::Sample* sample = group->GetFirstSample();
3484 sample; sample = group->GetNextSample()) {
3485 Gtk::TreeModel::iterator iterSample =
3486 m_refSamplesTreeModel->append(rowGroup.children());
3487 Gtk::TreeModel::Row rowSample = *iterSample;
3488 rowSample[m_SamplesModel.m_col_name] =
3489 gig_to_utf8(sample->pInfo->Name);
3490 rowSample[m_SamplesModel.m_col_sample] = sample;
3491 rowSample[m_SamplesModel.m_col_group] = NULL;
3492 int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
3493 rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3494 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3495 }
3496 }
3497 }
3498
3499 for (int i = 0; gig->GetScriptGroup(i); ++i) {
3500 gig::ScriptGroup* group = gig->GetScriptGroup(i);
3501
3502 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3503 Gtk::TreeModel::Row rowGroup = *iterGroup;
3504 rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3505 rowGroup[m_ScriptsModel.m_col_group] = group;
3506 rowGroup[m_ScriptsModel.m_col_script] = NULL;
3507 for (int s = 0; group->GetScript(s); ++s) {
3508 gig::Script* script = group->GetScript(s);
3509
3510 Gtk::TreeModel::iterator iterScript =
3511 m_refScriptsTreeModel->append(rowGroup.children());
3512 Gtk::TreeModel::Row rowScript = *iterScript;
3513 rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
3514 rowScript[m_ScriptsModel.m_col_script] = script;
3515 rowScript[m_ScriptsModel.m_col_group] = NULL;
3516 }
3517 }
3518 // unfold all sample groups & script groups by default
3519 m_TreeViewSamples.expand_all();
3520 m_TreeViewScripts.expand_all();
3521
3522 file = gig;
3523
3524 // select the first instrument
3525 m_TreeView.get_selection()->select(Gtk::TreePath("0"));
3526
3527 instr_props_set_instrument();
3528 gig::Instrument* instrument = get_instrument();
3529 if (instrument) {
3530 midiRules.set_instrument(instrument);
3531 }
3532 }
3533
3534 bool MainWindow::instr_props_set_instrument()
3535 {
3536 instrumentProps.signal_name_changed().clear();
3537
3538 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3539 if (rows.empty()) {
3540 instrumentProps.hide();
3541 return false;
3542 }
3543 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3544 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3545 if (it) {
3546 Gtk::TreeModel::Row row = *it;
3547 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3548
3549 instrumentProps.set_instrument(instrument);
3550
3551 // make sure instrument tree is updated when user changes the
3552 // instrument name in instrument properties window
3553 instrumentProps.signal_name_changed().connect(
3554 sigc::bind(
3555 sigc::mem_fun(*this,
3556 &MainWindow::instr_name_changed_by_instr_props),
3557 it));
3558 } else {
3559 instrumentProps.hide();
3560 }
3561 //NOTE: explicit boolean cast required for GTKMM4 development branch here
3562 return it ? true : false;
3563 }
3564
3565 void MainWindow::show_instr_props()
3566 {
3567 if (instr_props_set_instrument()) {
3568 instrumentProps.show();
3569 instrumentProps.deiconify();
3570 }
3571 }
3572
3573 void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3574 {
3575 Gtk::TreeModel::Row row = *it;
3576 Glib::ustring name = row[m_Columns.m_col_name];
3577
3578 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3579 Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3580 if (gigname != name) {
3581 Gtk::TreeModel::Path path(*it);
3582 const int index = path[0];
3583 row[m_Columns.m_col_name] = gigname;
3584 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3585 }
3586 }
3587
3588 bool MainWindow::sample_props_set_sample()
3589 {
3590 sampleProps.signal_name_changed().clear();
3591
3592 std::vector<Gtk::TreeModel::Path> rows = m_TreeViewSamples.get_selection()->get_selected_rows();
3593 if (rows.empty()) {
3594 sampleProps.hide();
3595 return false;
3596 }
3597 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3598 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3599 if (it) {
3600 Gtk::TreeModel::Row row = *it;
3601 gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3602
3603 sampleProps.set_sample(sample);
3604
3605 // make sure sample tree is updated when user changes the
3606 // sample name in sample properties window
3607 sampleProps.signal_name_changed().connect(
3608 sigc::bind(
3609 sigc::mem_fun(*this,
3610 &MainWindow::sample_name_changed_by_sample_props
3611 ), it
3612 )
3613 );
3614 } else {
3615 sampleProps.hide();
3616 }
3617 //NOTE: explicit boolean cast required for GTKMM4 development branch here
3618 return it ? true : false;
3619 }
3620
3621 void MainWindow::show_sample_props()
3622 {
3623 if (sample_props_set_sample()) {
3624 sampleProps.show();
3625 sampleProps.deiconify();
3626 }
3627 }
3628
3629 void MainWindow::sample_name_changed_by_sample_props(Gtk::TreeModel::iterator& it)
3630 {
3631 Gtk::TreeModel::Row row = *it;
3632 Glib::ustring name = row[m_SamplesModel.m_col_name];
3633
3634 gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3635 Glib::ustring gigname(gig_to_utf8(sample->pInfo->Name));
3636 if (gigname != name) {
3637 Gtk::TreeModel::Path path(*it);
3638 row[m_SamplesModel.m_col_name] = gigname;
3639 }
3640 }
3641
3642 void MainWindow::show_midi_rules()
3643 {
3644 if (gig::Instrument* instrument = get_instrument())
3645 {
3646 midiRules.set_instrument(instrument);
3647 midiRules.show();
3648 midiRules.deiconify();
3649 }
3650 }
3651
3652 void MainWindow::show_script_slots() {
3653 if (!file) return;
3654 // get selected instrument
3655 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3656 if (rows.empty()) return;
3657 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3658 if (!it) return;
3659 Gtk::TreeModel::Row row = *it;
3660 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3661 if (!instrument) return;
3662
3663 ScriptSlots* window = new ScriptSlots;
3664 window->setInstrument(instrument);
3665 window->signal_script_slots_changed().connect(
3666 sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3667 );
3668 //window->reparent(*this);
3669 window->show();
3670 }
3671
3672 void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3673 if (!pInstrument) return;
3674 const int iScriptSlots = pInstrument->ScriptSlotCount();
3675
3676 //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
3677 //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3678 Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3679
3680 for (int i = 0; i < model->children().size(); ++i) {
3681 Gtk::TreeModel::Row row = model->children()[i];
3682 if (row[m_Columns.m_col_instr] != pInstrument) continue;
3683 row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3684 row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3685 break;
3686 }
3687
3688 // causes the sampler to reload the instrument with the new script
3689 on_sel_change();
3690 }
3691
3692 void MainWindow::assignScript(gig::Script* pScript) {
3693 if (!pScript) {
3694 printf("assignScript() : !script\n");
3695 return;
3696 }
3697 printf("assignScript('%s')\n", pScript->Name.c_str());
3698
3699 gig::Instrument* pInstrument = get_instrument();
3700 if (!pInstrument) {
3701 printf("!instrument\n");
3702 return;
3703 }
3704
3705 pInstrument->AddScriptSlot(pScript);
3706
3707 onScriptSlotsModified(pInstrument);
3708 }
3709
3710 void MainWindow::dropAllScriptSlots() {
3711 gig::Instrument* pInstrument = get_instrument();
3712 if (!pInstrument) {
3713 printf("!instrument\n");
3714 return;
3715 }
3716
3717 const int iScriptSlots = pInstrument->ScriptSlotCount();
3718 for (int i = iScriptSlots - 1; i >= 0; --i)
3719 pInstrument->RemoveScriptSlot(i);
3720
3721 onScriptSlotsModified(pInstrument);
3722 }
3723
3724 void MainWindow::on_action_refresh_all() {
3725 __refreshEntireGUI();
3726 }
3727
3728 void MainWindow::on_action_view_status_bar() {
3729 #if USE_GLIB_ACTION
3730 bool active = false;
3731 m_actionToggleStatusBar->get_state(active);
3732 // for some reason toggle state does not change automatically
3733 active = !active;
3734 m_actionToggleStatusBar->change_state(active);
3735 if (active)
3736 m_StatusBar.show();
3737 else
3738 m_StatusBar.hide();
3739 #else
3740 Gtk::CheckMenuItem* item =
3741 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3742 if (!item) {
3743 std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
3744 return;
3745 }
3746 if (item->get_active()) m_StatusBar.show();
3747 else m_StatusBar.hide();
3748 #endif
3749 }
3750
3751 void MainWindow::on_auto_restore_win_dim() {
3752 #if USE_GLIB_ACTION
3753 bool active = false;
3754 m_actionToggleRestoreWinDim->get_state(active);
3755 // for some reason toggle state does not change automatically
3756 active = !active;
3757 m_actionToggleRestoreWinDim->change_state(active);
3758 Settings::singleton()->autoRestoreWindowDimension = active;
3759 #else
3760 Gtk::CheckMenuItem* item =
3761 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3762 if (!item) {
3763 std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
3764 return;
3765 }
3766 Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3767 #endif
3768 }
3769
3770 void MainWindow::on_save_with_temporary_file() {
3771 #if USE_GLIB_ACTION
3772 bool active = false;
3773 m_actionToggleSaveWithTempFile->get_state(active);
3774 // for some reason toggle state does not change automatically
3775 active = !active;
3776 m_actionToggleSaveWithTempFile->change_state(active);
3777 Settings::singleton()->saveWithTemporaryFile = active;
3778 #else
3779 Gtk::CheckMenuItem* item =
3780 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3781 if (!item) {
3782 std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
3783 return;
3784 }
3785 Settings::singleton()->saveWithTemporaryFile = item->get_active();
3786 #endif
3787 }
3788
3789 bool MainWindow::is_copy_samples_unity_note_enabled() const {
3790 #if USE_GLIB_ACTION
3791 bool active = false;
3792 m_actionToggleCopySampleUnity->get_state(active);
3793 return active;
3794 #else
3795 Gtk::CheckMenuItem* item =
3796 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3797 if (!item) {
3798 std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
3799 return true;
3800 }
3801 return item->get_active();
3802 #endif
3803 }
3804
3805 bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3806 #if USE_GLIB_ACTION
3807 bool active = false;
3808 m_actionToggleCopySampleTune->get_state(active);
3809 return active;
3810 #else
3811 Gtk::CheckMenuItem* item =
3812 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3813 if (!item) {
3814 std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
3815 return true;
3816 }
3817 return item->get_active();
3818 #endif
3819 }
3820
3821 bool MainWindow::is_copy_samples_loop_enabled() const {
3822 #if USE_GLIB_ACTION
3823 bool active = false;
3824 m_actionToggleCopySampleLoop->get_state(active);
3825 return active;
3826 #else
3827 Gtk::CheckMenuItem* item =
3828 dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3829 if (!item) {
3830 std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
3831 return true;
3832 }
3833 return item->get_active();
3834 #endif
3835 }
3836
3837 #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
3838 bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3839 GdkEventButton* button = _button.gobj();
3840 #else
3841 void MainWindow::on_button_release(GdkEventButton* button) {
3842 #endif
3843 if (button->type == GDK_2BUTTON_PRESS) {
3844 show_instr_props();
3845 } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3846 // gig v2 files have no midi rules
3847 const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3848 #if USE_GTKMM_BUILDER
3849 m_actionMIDIRules->property_enabled() = bEnabled;
3850 #else
3851 static_cast<Gtk::MenuItem*>(
3852 uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3853 bEnabled
3854 );
3855 static_cast<Gtk::MenuItem*>(
3856 uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3857 bEnabled
3858 );
3859 #endif
3860 popup_menu->popup(button->button, button->time);
3861 }
3862 #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
3863 return false;
3864 #endif
3865 }
3866
3867 #if !USE_GTKMM_BUILDER
3868 void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3869 if (item->get_active()) {
3870 const std::vector<Gtk::Widget*> children =
3871 instrument_menu->get_children();
3872 std::vector<Gtk::Widget*>::const_iterator it =
3873 find(children.begin(), children.end(), item);
3874 if (it != children.end()) {
3875 int index = it - children.begin();
3876 m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
3877
3878 m_RegionChooser.set_instrument(file->GetInstrument(index));
3879 }
3880 }
3881 }
3882 #endif
3883
3884 void MainWindow::select_instrument(gig::Instrument* instrument) {
3885 if (!instrument) return;
3886
3887 //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
3888 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3889 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3890
3891 for (int i = 0; i < model->children().size(); ++i) {
3892 Gtk::TreeModel::Row row = model->children()[i];
3893 if (row[m_Columns.m_col_instr] == instrument) {
3894 // select and show the respective instrument in the list view
3895 show_intruments_tab();
3896 m_TreeView.get_selection()->unselect_all();
3897
3898 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3899 auto iterSel = model->children()[i].get_iter();
3900 m_TreeView.get_selection()->select(iterSel);
3901 #else
3902 m_TreeView.get_selection()->select(model->children()[i]);
3903 #endif
3904 std::vector<Gtk::TreeModel::Path> rows =
3905 m_TreeView.get_selection()->get_selected_rows();
3906 if (!rows.empty())
3907 m_TreeView.scroll_to_row(rows[0]);
3908 on_sel_change(); // the regular instrument selection change callback
3909 }
3910 }
3911 }
3912
3913 /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
3914 bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
3915 gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3916 gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3917
3918 //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
3919 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3920 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3921
3922 for (int i = 0; i < model->children().size(); ++i) {
3923 Gtk::TreeModel::Row row = model->children()[i];
3924 if (row[m_Columns.m_col_instr] == pInstrument) {
3925 // select and show the respective instrument in the list view
3926 show_intruments_tab();
3927 m_TreeView.get_selection()->unselect_all();
3928 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3929 auto iterSel = model->children()[i].get_iter();
3930 m_TreeView.get_selection()->select(iterSel);
3931 #else
3932 m_TreeView.get_selection()->select(model->children()[i]);
3933 #endif
3934 std::vector<Gtk::TreeModel::Path> rows =
3935 m_TreeView.get_selection()->get_selected_rows();
3936 if (!rows.empty())
3937 m_TreeView.scroll_to_row(rows[0]);
3938 on_sel_change(); // the regular instrument selection change callback
3939
3940 // select respective region in the region selector
3941 m_RegionChooser.set_region(pRegion);
3942
3943 // select and show the respective dimension region in the editor
3944 //update_dimregs();
3945 if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
3946 //dimreg_edit.set_dim_region(dimRgn);
3947
3948 return true;
3949 }
3950 }
3951
3952 return false;
3953 }
3954
3955 void MainWindow::select_sample(gig::Sample* sample) {
3956 Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3957 for (int g = 0; g < model->children().size(); ++g) {
3958 Gtk::TreeModel::Row rowGroup = model->children()[g];
3959 for (int s = 0; s < rowGroup.children().size(); ++s) {
3960 Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3961 if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3962 show_samples_tab();
3963 m_TreeViewSamples.get_selection()->unselect_all();
3964 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3965 auto iterSel = rowGroup.children()[s].get_iter();
3966 m_TreeViewSamples.get_selection()->select(iterSel);
3967 #else
3968 m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3969 #endif
3970 std::vector<Gtk::TreeModel::Path> rows =
3971 m_TreeViewSamples.get_selection()->get_selected_rows();
3972 if (rows.empty()) return;
3973 m_TreeViewSamples.scroll_to_row(rows[0]);
3974 return;
3975 }
3976 }
3977 }
3978 }
3979
3980 #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
3981 bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3982 GdkEventButton* button = _button.gobj();
3983 #else
3984 void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3985 #endif
3986 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3987 // by default if Ctrl keys is pressed down, then a mouse right-click
3988 // does not select the respective row, so we must assure this
3989 // programmatically ...
3990 /*{
3991 Gtk::TreeModel::Path path;
3992 Gtk::TreeViewColumn* pColumn = NULL;
3993 int cellX, cellY;
3994 bool bSuccess = m_TreeViewSamples.get_path_at_pos(
3995 (int)button->x, (int)button->y,
3996 path, pColumn, cellX, cellY
3997 );
3998 if (bSuccess) {
3999 if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
4000 printf("not selected !!!\n");
4001 m_TreeViewSamples.get_selection()->select(path);
4002 }
4003 }
4004 }*/
4005
4006 #if !USE_GTKMM_BUILDER
4007 Gtk::Menu* sample_popup =
4008 dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
4009 #endif
4010
4011 // update enabled/disabled state of sample popup items
4012 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4013 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4014 const int n = rows.size();
4015 int nGroups = 0;
4016 int nSamples = 0;
4017 for (int r = 0; r < n; ++r) {
4018 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4019 if (!it) continue;
4020 Gtk::TreeModel::Row row = *it;
4021 if (row[m_SamplesModel.m_col_group]) nGroups++;
4022 if (row[m_SamplesModel.m_col_sample]) nSamples++;
4023 }
4024
4025 #if USE_GTKMM_BUILDER
4026 m_actionSampleProperties->property_enabled() = (n == 1);
4027 m_actionAddSample->property_enabled() = (n);
4028 m_actionAddSampleGroup->property_enabled() = (file);
4029 m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
4030 m_actionRemoveSample->property_enabled() = (n);
4031 m_actionReplaceSample->property_enabled() = (nSamples == 1);
4032 #else
4033 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
4034 set_sensitive(n == 1);
4035 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
4036 set_sensitive(n);
4037 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
4038 set_sensitive(file);
4039 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
4040 set_sensitive(nSamples == 1);
4041 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
4042 set_sensitive(n);
4043 #endif
4044 // show sample popup
4045 sample_popup->popup(button->button, button->time);
4046
4047 #if !USE_GTKMM_BUILDER
4048 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
4049 set_sensitive(n == 1);
4050 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
4051 set_sensitive(n);
4052 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
4053 set_sensitive(file);
4054 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
4055 set_sensitive(nSamples == 1);
4056 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
4057 set_sensitive(n);
4058 #endif
4059 }
4060
4061 #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
4062 return false;
4063 #endif
4064 }
4065
4066 #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
4067 bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
4068 GdkEventButton* button = _button.gobj();
4069 #else
4070 void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
4071 #endif
4072 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
4073 #if !USE_GTKMM_BUILDER
4074 Gtk::Menu* script_popup =
4075 dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
4076 #endif
4077 // update enabled/disabled state of sample popup items
4078 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4079 Gtk::TreeModel::iterator it = sel->get_selected();
4080 bool group_selected = false;
4081 bool script_selected = false;
4082 if (it) {
4083 Gtk::TreeModel::Row row = *it;
4084 group_selected = row[m_ScriptsModel.m_col_group];
4085 script_selected = row[m_ScriptsModel.m_col_script];
4086 }
4087 #if USE_GTKMM_BUILDER
4088 m_actionAddScript->property_enabled() = (group_selected || script_selected);
4089 m_actionAddScriptGroup->property_enabled() = (file);
4090 m_actionEditScript->property_enabled() = (script_selected);
4091 m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
4092 #else
4093 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
4094 set_sensitive(group_selected || script_selected);
4095 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
4096 set_sensitive(file);
4097 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
4098 set_sensitive(script_selected);
4099 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
4100 set_sensitive(group_selected || script_selected);
4101 #endif
4102 // show sample popup
4103 script_popup->popup(button->button, button->time);
4104
4105 #if !USE_GTKMM_BUILDER
4106 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
4107 set_sensitive(group_selected || script_selected);
4108 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
4109 set_sensitive(file);
4110 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
4111 set_sensitive(script_selected);
4112 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
4113 set_sensitive(group_selected || script_selected);
4114 #endif
4115 }
4116 #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
4117 return false;
4118 #endif
4119 }
4120
4121 void MainWindow::updateScriptListOfMenu() {
4122 // remove all entries from "Assign Script" menu
4123 {
4124 const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
4125 for (int i = 0; i < children.size(); ++i) {
4126 Gtk::Widget* child = children[i];
4127 assign_scripts_menu->remove(*child);
4128 delete child;
4129 }
4130 }
4131
4132 int iTotalScripts = 0;
4133
4134 if (!file) goto noScripts;
4135
4136 // add all configured macros as menu items to the "Macro" menu
4137 for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
4138 gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
4139 for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
4140 gig::Script* pScript = pGroup->GetScript(iScript);
4141 std::string name = pScript->Name;
4142
4143 Gtk::MenuItem* item = new Gtk::MenuItem(name);
4144 item->signal_activate().connect(
4145 sigc::bind(
4146 sigc::mem_fun(*this, &MainWindow::assignScript), pScript
4147 )
4148 );
4149 assign_scripts_menu->append(*item);
4150 item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
4151 //item->set_tooltip_text(comment);
4152 }
4153 }
4154
4155 noScripts:
4156
4157 // if there are no macros configured at all, then show a dummy entry instead
4158 if (!iTotalScripts) {
4159 Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
4160 item->set_sensitive(false);
4161 assign_scripts_menu->append(*item);
4162 }
4163
4164 // add separator line to menu
4165 assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
4166
4167 {
4168 Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
4169 item->signal_activate().connect(
4170 sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
4171 );
4172 assign_scripts_menu->append(*item);
4173 item->set_accel_path("<Scripts>/DropAllScriptSlots");
4174 }
4175
4176 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4177 assign_scripts_menu->show_all_children();
4178 #endif
4179 }
4180
4181 #if !USE_GTKMM_BUILDER
4182 Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
4183 const Glib::ustring& name, int position) {
4184
4185 Gtk::RadioMenuItem::Group instrument_group;
4186 const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
4187 if (!children.empty()) {
4188 instrument_group =
4189 static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
4190 }
4191 Gtk::RadioMenuItem* item =
4192 new Gtk::RadioMenuItem(instrument_group, name);
4193 if (position < 0) {
4194 instrument_menu->append(*item);
4195 } else {
4196 instrument_menu->insert(*item, position);
4197 }
4198 item->show();
4199 item->signal_activate().connect(
4200 sigc::bind(
4201 sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
4202 item));
4203 return item;
4204 }
4205 #endif
4206
4207 #if !USE_GTKMM_BUILDER
4208 void MainWindow::remove_instrument_from_menu(int index) {
4209 const std::vector<Gtk::Widget*> children =
4210 instrument_menu->get_children();
4211 Gtk::Widget* child = children[index];
4212 instrument_menu->remove(*child);
4213 delete child;
4214 }
4215 #endif
4216
4217 void MainWindow::add_instrument(gig::Instrument* instrument) {
4218 const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
4219
4220 // update instrument tree view
4221 instrument_name_connection.block();
4222 Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
4223 Gtk::TreeModel::Row rowInstr = *iterInstr;
4224 const int index = m_refTreeModel->children().size() - 1;
4225 rowInstr[m_Columns.m_col_nr] = index;
4226 rowInstr[m_Columns.m_col_name] = name;
4227 rowInstr[m_Columns.m_col_instr] = instrument;
4228 rowInstr[m_Columns.m_col_scripts] = "";
4229 rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
4230 instrument_name_connection.unblock();
4231
4232 #if !USE_GTKMM_BUILDER
4233 add_instrument_to_menu(name);
4234 #endif
4235 select_instrument(instrument);
4236 file_changed();
4237 }
4238
4239 void MainWindow::on_action_add_instrument() {
4240 static int __instrument_indexer = 0;
4241 if (!file) return;
4242 gig::Instrument* instrument = file->AddInstrument();
4243 __instrument_indexer++;
4244 instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
4245 ToString(__instrument_indexer));
4246
4247 add_instrument(instrument);
4248 }
4249
4250 void MainWindow::on_action_duplicate_instrument() {
4251 if (!file) return;
4252
4253 // retrieve the currently selected instrument
4254 // (being the original instrument to be duplicated)
4255 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4256 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4257 for (int r = 0; r < rows.size(); ++r) {
4258 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4259 if (it) {
4260 Gtk::TreeModel::Row row = *it;
4261 gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
4262 if (instrOrig) {
4263 // duplicate the orginal instrument
4264 gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
4265 instrNew->pInfo->Name =
4266 instrOrig->pInfo->Name +
4267 gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
4268
4269 add_instrument(instrNew);
4270 }
4271 }
4272 }
4273 }
4274
4275 void MainWindow::on_action_remove_instrument() {
4276 if (!file) return;
4277 if (file_is_shared) {
4278 Gtk::MessageDialog msg(
4279 *this,
4280 _("You cannot delete an instrument from this file, since it's "
4281 "currently used by the sampler."),
4282 false, Gtk::MESSAGE_INFO
4283 );
4284 msg.run();
4285 return;
4286 }
4287
4288 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4289 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4290 for (int r = rows.size() - 1; r >= 0; --r) {
4291 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4292 if (!it) continue;
4293 Gtk::TreeModel::Row row = *it;
4294 gig::Instrument* instr = row[m_Columns.m_col_instr];
4295 try {
4296 Gtk::TreePath path(it);
4297 int index = path[0];
4298
4299 // remove instrument from the gig file
4300 if (instr) file->DeleteInstrument(instr);
4301 file_changed();
4302
4303 #if !USE_GTKMM_BUILDER
4304 remove_instrument_from_menu(index);
4305 #endif
4306
4307 // remove row from instruments tree view
4308 m_refTreeModel->erase(it);
4309 // update "Nr" column of all instrument rows
4310 {
4311 int index = 0;
4312 for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
4313 it != m_refTreeModel->children().end(); ++it, ++index)
4314 {
4315 Gtk::TreeModel::Row row = *it;
4316 gig::Instrument* instrument = row[m_Columns.m_col_instr];
4317 row[m_Columns.m_col_nr] = index;
4318 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
4319 }
4320 }
4321
4322 #if GTKMM_MAJOR_VERSION < 3
4323 // select another instrument (in gtk3 this is done
4324 // automatically)
4325 if (!m_refTreeModel->children().empty()) {
4326 if (index == m_refTreeModel->children().size()) {
4327 index--;
4328 }
4329 m_TreeView.get_selection()->select(
4330 Gtk::TreePath(ToString(index)));
4331 }
4332 #endif
4333 instr_props_set_instrument();
4334 instr = get_instrument();
4335 if (instr) {
4336 midiRules.set_instrument(instr);
4337 } else {
4338 midiRules.hide();
4339 }
4340 } catch (RIFF::Exception e) {
4341 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4342 msg.run();
4343 }
4344 }
4345 }
4346
4347 void MainWindow::on_action_sample_properties() {
4348 show_sample_props();
4349 }
4350
4351 void MainWindow::on_action_add_script_group() {
4352 static int __script_indexer = 0;
4353 if (!file) return;
4354 gig::ScriptGroup* group = file->AddScriptGroup();
4355 group->Name = gig_from_utf8(_("Unnamed Group"));
4356 if (__script_indexer) group->Name += " " + ToString(__script_indexer);
4357 __script_indexer++;
4358 // update sample tree view
4359 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
4360 Gtk::TreeModel::Row rowGroup = *iterGroup;
4361 rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
4362 rowGroup[m_ScriptsModel.m_col_script] = NULL;
4363 rowGroup[m_ScriptsModel.m_col_group] = group;
4364 file_changed();
4365 }
4366
4367 void MainWindow::on_action_add_script() {
4368 if (!file) return;
4369 // get selected group
4370 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4371 Gtk::TreeModel::iterator it = sel->get_selected();
4372 if (!it) return;
4373 Gtk::TreeModel::Row row = *it;
4374 gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
4375 if (!group) { // not a group, but a script is selected (probably)
4376 gig::Script* script = row[m_ScriptsModel.m_col_script];
4377 if (!script) return;
4378 it = row.parent(); // resolve parent (that is the script's group)
4379 if (!it) return;
4380 row = *it;
4381 group = row[m_ScriptsModel.m_col_group];
4382 if (!group) return;
4383 }
4384
4385 // add a new script to the .gig file
4386 gig::Script* script = group->AddScript();
4387 Glib::ustring name = _("Unnamed Script");
4388 script->Name = gig_from_utf8(name);
4389
4390 // add script to the tree view
4391 Gtk::TreeModel::iterator iterScript =
4392 m_refScriptsTreeModel->append(row.children());
4393 Gtk::TreeModel::Row rowScript = *iterScript;
4394 rowScript[m_ScriptsModel.m_col_name] = name;
4395 rowScript[m_ScriptsModel.m_col_script] = script;
4396 rowScript[m_ScriptsModel.m_col_group] = NULL;
4397
4398 // unfold group of new script item in treeview
4399 Gtk::TreeModel::Path path(iterScript);
4400 m_TreeViewScripts.expand_to_path(path);
4401 }
4402
4403 void MainWindow::on_action_edit_script() {
4404 if (!file) return;
4405 // get selected script
4406 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4407 Gtk::TreeModel::iterator it = sel->get_selected();
4408 if (!it) return;
4409 Gtk::TreeModel::Row row = *it;
4410 gig::Script* script = row[m_ScriptsModel.m_col_script];
4411 if (!script) return;
4412
4413 ScriptEditor* editor = new ScriptEditor;
4414 editor->signal_script_to_be_changed.connect(
4415 signal_script_to_be_changed.make_slot()
4416 );
4417 editor->signal_script_changed.connect(
4418 signal_script_changed.make_slot()
4419 );
4420 editor->setScript(script);
4421 //editor->reparent(*this);
4422 editor->show();
4423 }
4424
4425 void MainWindow::on_action_remove_script() {
4426 if (!file) return;
4427 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4428 Gtk::TreeModel::iterator it = sel->get_selected();
4429 if (it) {
4430 Gtk::TreeModel::Row row = *it;
4431 gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
4432 gig::Script* script = row[m_ScriptsModel.m_col_script];
4433 Glib::ustring name = row[m_ScriptsModel.m_col_name];
4434 try {
4435 // remove script group or script from the gig file
4436 if (group) {
4437 // notify everybody that we're going to remove these samples
4438 //TODO: scripts_to_be_removed_signal.emit(members);
4439 // delete the group in the .gig file including the
4440 // samples that belong to the group
4441 file->DeleteScriptGroup(group);
4442 // notify that we're done with removal
4443 //TODO: scripts_removed_signal.emit();
4444 file_changed();
4445 } else if (script) {
4446 // notify everybody that we're going to remove this sample
4447 //TODO: std::list<gig::Script*> lscripts;
4448 //TODO: lscripts.push_back(script);
4449 //TODO: scripts_to_be_removed_signal.emit(lscripts);
4450 // remove sample from the .gig file
4451 script->GetGroup()->DeleteScript(script);
4452 // notify that we're done with removal
4453 //TODO: scripts_removed_signal.emit();
4454 dimreg_changed();
4455 file_changed();
4456 }
4457 // remove respective row(s) from samples tree view
4458 m_refScriptsTreeModel->erase(it);
4459 } catch (RIFF::Exception e) {
4460 // pretend we're done with removal (i.e. to avoid dead locks)
4461 //TODO: scripts_removed_signal.emit();
4462 // show error message
4463 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4464 msg.run();
4465 }
4466 }
4467 }
4468
4469 void MainWindow::on_action_add_group() {
4470 static int __sample_indexer = 0;
4471 if (!file) return;
4472 gig::Group* group = file->AddGroup();
4473 group->Name = gig_from_utf8(_("Unnamed Group"));
4474 if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
4475 __sample_indexer++;
4476 // update sample tree view
4477 Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
4478 Gtk::TreeModel::Row rowGroup = *iterGroup;
4479 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
4480 rowGroup[m_SamplesModel.m_col_sample] = NULL;
4481 rowGroup[m_SamplesModel.m_col_group] = group;
4482 file_changed();
4483 }
4484
4485 void MainWindow::on_action_replace_sample() {
4486 add_or_replace_sample(true);
4487 }
4488
4489 void MainWindow::on_action_add_sample() {
4490 add_or_replace_sample(false);
4491 }
4492
4493 void MainWindow::add_or_replace_sample(bool replace) {
4494 if (!file) return;
4495
4496 // get selected group (and probably selected sample)
4497 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4498 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4499 if (rows.empty()) return;
4500 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4501 if (!it) return;
4502 Gtk::TreeModel::Row row = *it;
4503 gig::Sample* sample = NULL;
4504 gig::Group* group = row[m_SamplesModel.m_col_group];
4505 if (!group) { // not a group, but a sample is selected (probably)
4506 if (replace) sample = row[m_SamplesModel.m_col_sample];
4507 if (!row[m_SamplesModel.m_col_sample]) return;
4508 it = row.parent(); // resolve parent (that is the sample's group)
4509 if (!it) return;
4510 if (!replace) row = *it;
4511 group = (*it)[m_SamplesModel.m_col_group];
4512 if (!group) return;
4513 }
4514 if (replace && !sample) return;
4515
4516 // show 'browse for file' dialog
4517 Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
4518 #if HAS_GTKMM_STOCK
4519 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4520 dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
4521 #else
4522 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4523 dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
4524 #endif
4525 dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
4526
4527 // matches all file types supported by libsndfile
4528 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4529 Gtk::FileFilter soundfilter;
4530 #else
4531 Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
4532 #endif
4533 const char* const supportedFileTypes[] = {
4534 "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
4535 "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
4536 "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
4537 "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
4538 "*.caf", "*.CAF", NULL
4539 };
4540 const char* soundfiles = _("Sound Files");
4541 const char* allfiles = _("All Files");
4542 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4543 for (int i = 0; supportedFileTypes[i]; i++)
4544 soundfilter.add_pattern(supportedFileTypes[i]);
4545 soundfilter.set_name(soundfiles);
4546
4547 // matches every file
4548 Gtk::FileFilter allpassfilter;
4549 allpassfilter.add_pattern("*.*");
4550 allpassfilter.set_name(allfiles);
4551 #else
4552 for (int i = 0; supportedFileTypes[i]; i++)
4553 soundfilter->add_pattern(supportedFileTypes[i]);
4554 soundfilter->set_name(soundfiles);
4555
4556 // matches every file
4557 Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
4558 allpassfilter->add_pattern("*.*");
4559 allpassfilter->set_name(allfiles);
4560 #endif
4561 dialog.add_filter(soundfilter);
4562 dialog.add_filter(allpassfilter);
4563 if (current_sample_dir != "") {
4564 dialog.set_current_folder(current_sample_dir);
4565 }
4566 if (dialog.run() == Gtk::RESPONSE_OK) {
4567 dialog.hide();
4568 current_sample_dir = dialog.get_current_folder();
4569 Glib::ustring error_files;
4570 std::vector<std::string> filenames = dialog.get_filenames();
4571 for (std::vector<std::string>::iterator iter = filenames.begin();
4572 iter != filenames.end(); ++iter) {
4573 printf("Adding sample %s\n",(*iter).c_str());
4574 // use libsndfile to retrieve file information
4575 SF_INFO info;
4576 info.format = 0;
4577 SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
4578 try {
4579 if (!hFile) throw std::string(_("could not open file"));
4580 int bitdepth;
4581 switch (info.format & 0xff) {
4582 case SF_FORMAT_PCM_S8:
4583 case SF_FORMAT_PCM_16:
4584 case SF_FORMAT_PCM_U8:
4585 bitdepth = 16;
4586 break;
4587 case SF_FORMAT_PCM_24:
4588 case SF_FORMAT_PCM_32:
4589 case SF_FORMAT_FLOAT:
4590 case SF_FORMAT_DOUBLE:
4591 bitdepth = 24;
4592 break;
4593 default:
4594 sf_close(hFile); // close sound file
4595 throw std::string(_("format not supported")); // unsupported subformat (yet?)
4596 }
4597 // add a new sample to the .gig file (if adding is requested actually)
4598 if (!replace) sample = file->AddSample();
4599 // file name without path
4600 Glib::ustring filename = Glib::filename_display_basename(*iter);
4601 // remove file extension if there is one
4602 for (int i = 0; supportedFileTypes[i]; i++) {
4603 if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) {
4604 filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1));
4605 break;
4606 }
4607 }
4608 sample->pInfo->Name = gig_from_utf8(filename);
4609 sample->Channels = info.channels;
4610 sample->BitDepth = bitdepth;
4611 sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
4612 sample->SamplesPerSecond = info.samplerate;
4613 sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond;
4614 sample->BlockAlign = sample->FrameSize;
4615 sample->SamplesTotal = info.frames;
4616
4617 SF_INSTRUMENT instrument;
4618 if (sf_command(hFile, SFC_GET_INSTRUMENT,
4619 &instrument, sizeof(instrument)) != SF_FALSE)
4620 {
4621 sample->MIDIUnityNote = instrument.basenote;
4622 sample->FineTune = instrument.detune;
4623
4624 if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
4625 sample->Loops = 1;
4626
4627 switch (instrument.loops[0].mode) {
4628 case SF_LOOP_FORWARD:
4629 sample->LoopType = gig::loop_type_normal;
4630 break;
4631 case SF_LOOP_BACKWARD:
4632 sample->LoopType = gig::loop_type_backward;
4633 break;
4634 case SF_LOOP_ALTERNATING:
4635 sample->LoopType = gig::loop_type_bidirectional;
4636 break;
4637 }
4638 sample->LoopStart = instrument.loops[0].start;
4639 sample->LoopEnd = instrument.loops[0].end;
4640 sample->LoopPlayCount = instrument.loops[0].count;
4641 sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
4642 }
4643 }
4644
4645 // schedule resizing the sample (which will be done
4646 // physically when File::Save() is called)
4647 sample->Resize(info.frames);
4648 // make sure sample is part of the selected group
4649 if (!replace) group->AddSample(sample);
4650 // schedule that physical resize and sample import
4651 // (data copying), performed when "Save" is requested
4652 SampleImportItem sched_item;
4653 sched_item.gig_sample = sample;
4654 sched_item.sample_path = *iter;
4655 m_SampleImportQueue[sample] = sched_item;
4656 // add sample to the tree view
4657 if (replace) {
4658 row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
4659 } else {
4660 Gtk::TreeModel::iterator iterSample =
4661 m_refSamplesTreeModel->append(row.children());
4662 Gtk::TreeModel::Row rowSample = *iterSample;
4663 rowSample[m_SamplesModel.m_col_name] =
4664 gig_to_utf8(sample->pInfo->Name);
4665 rowSample[m_SamplesModel.m_col_sample] = sample;
4666 rowSample[m_SamplesModel.m_col_group] = NULL;
4667 }
4668 // close sound file
4669 sf_close(hFile);
4670 file_changed();
4671 } catch (std::string what) { // remember the files that made trouble (and their cause)
4672 if (!error_files.empty()) error_files += "\n";
4673 error_files += *iter += " (" + what + ")";
4674 }
4675 }
4676 // show error message box when some file(s) could not be opened / added
4677 if (!error_files.empty()) {
4678 Glib::ustring txt =
4679 (replace
4680 ? _("Failed to replace sample with:\n")
4681 : _("Could not add the following sample(s):\n"))
4682 + error_files;
4683 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4684 msg.run();
4685 }
4686 }
4687 }
4688
4689 void MainWindow::on_action_replace_all_samples_in_all_groups()
4690 {
4691 if (!file) return;
4692 Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
4693 Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
4694 const char* str =
4695 _("This is a very specific function. It tries to replace all samples "
4696 "in the current gig file by samples located in the chosen "
4697 "directory.\n\n"
4698 "It works like this: For each sample in the gig file, it tries to "
4699 "find a sample file in the selected directory with the same name as "
4700 "the sample in the gig file. Optionally, you can add a filename "
4701 "extension below, which will be added to the filename expected to be "
4702 "found. That is, assume you have a gig file with a sample called "
4703 "'Snare', if you enter '.wav' below (like it's done by default), it "
4704 "expects to find a sample file called 'Snare.wav' and will replace "
4705 "the sample in the gig file accordingly. If you don't need an "
4706 "extension, blank the field below. Any gig sample where no "
4707 "appropriate sample file could be found will be reported and left "
4708 "untouched.\n");
4709 #if GTKMM_MAJOR_VERSION < 3
4710 view::WrapLabel description(str);
4711 #else
4712 Gtk::Label description(str);
4713 description.set_line_wrap();
4714 #endif
4715 HBox entryArea;
4716 Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4717 Gtk::Entry postfixEntryBox;
4718 postfixEntryBox.set_text(".wav");
4719 entryArea.pack_start(entryLabel);
4720 entryArea.pack_start(postfixEntryBox);
4721 #if USE_GTKMM_BOX
4722 dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4723 dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4724 #else
4725 dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4726 dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4727 #endif
4728 description.show();
4729
4730 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4731 entryArea.show_all();
4732 #else
4733 entryArea.show();
4734 #endif
4735
4736 #if HAS_GTKMM_STOCK
4737 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4738 #else
4739 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4740 #endif
4741 dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4742 dialog.set_select_multiple(false);
4743 if (current_sample_dir != "") {
4744 dialog.set_current_folder(current_sample_dir);
4745 }
4746 if (dialog.run() == Gtk::RESPONSE_OK)
4747 {
4748 dialog.hide();
4749 current_sample_dir = dialog.get_current_folder();
4750 Glib::ustring error_files;
4751 std::string folder = dialog.get_filename();
4752 for (gig::Sample* sample = file->GetFirstSample();
4753 sample; sample = file->GetNextSample())
4754 {
4755 std::string filename =
4756 folder + G_DIR_SEPARATOR_S +
4757 Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
4758 postfixEntryBox.get_text());
4759 SF_INFO info;
4760 info.format = 0;
4761 SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
4762 try
4763 {
4764 if (!hFile) throw std::string(_("could not open file"));
4765 switch (info.format & 0xff) {
4766 case SF_FORMAT_PCM_S8:
4767 case SF_FORMAT_PCM_16:
4768 case SF_FORMAT_PCM_U8:
4769 case SF_FORMAT_PCM_24:
4770 case SF_FORMAT_PCM_32:
4771 case SF_FORMAT_FLOAT:
4772 case SF_FORMAT_DOUBLE:
4773 break;
4774 default:
4775 sf_close(hFile);
4776 throw std::string(_("format not supported"));
4777 }
4778 SampleImportItem sched_item;
4779 sched_item.gig_sample = sample;
4780 sched_item.sample_path = filename;
4781 m_SampleImportQueue[sample] = sched_item;
4782 sf_close(hFile);
4783 file_changed();
4784 }
4785 catch (std::string what)
4786 {
4787 if (!error_files.empty()) error_files += "\n";
4788 error_files += Glib::filename_to_utf8(filename) +
4789 " (" + what + ")";
4790 }
4791 }
4792 // show error message box when some file(s) could not be opened / added
4793 if (!error_files.empty()) {
4794 Glib::ustring txt =
4795 _("Could not replace the following sample(s):\n") + error_files;
4796 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4797 msg.run();
4798 }
4799 }
4800 }
4801
4802 void MainWindow::on_action_remove_sample() {
4803 if (!file) return;
4804 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4805 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4806 for (int r = rows.size() - 1; r >= 0; --r) {
4807 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4808 if (!it) continue;
4809 Gtk::TreeModel::Row row = *it;
4810 gig::Group* group = row[m_SamplesModel.m_col_group];
4811 gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4812 Glib::ustring name = row[m_SamplesModel.m_col_name];
4813 try {
4814 // remove group or sample from the gig file
4815 if (group) {
4816 // temporarily remember the samples that belong to
4817 // that group (we need that to clean the queue)
4818 std::list<gig::Sample*> members;
4819 for (gig::Sample* pSample = group->GetFirstSample();
4820 pSample; pSample = group->GetNextSample()) {
4821 members.push_back(pSample);
4822 }
4823 // notify everybody that we're going to remove these samples
4824 samples_to_be_removed_signal.emit(members);
4825 // delete the group in the .gig file including the
4826 // samples that belong to the group
4827 file->DeleteGroup(group);
4828 // notify that we're done with removal
4829 samples_removed_signal.emit();
4830 // if sample(s) were just previously added, remove
4831 // them from the import queue
4832 for (std::list<gig::Sample*>::iterator member = members.begin();
4833 member != members.end(); ++member)
4834 {
4835 if (m_SampleImportQueue.count(*member)) {
4836 printf("Removing previously added sample '%s' from group '%s'\n",
4837 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
4838 m_SampleImportQueue.erase(*member);
4839 }
4840 }
4841 file_changed();
4842 } else if (sample) {
4843 // notify everybody that we're going to remove this sample
4844 std::list<gig::Sample*> lsamples;
4845 lsamples.push_back(sample);
4846 samples_to_be_removed_signal.emit(lsamples);
4847 // remove sample from the .gig file
4848 file->DeleteSample(sample);
4849 // notify that we're done with removal
4850 samples_removed_signal.emit();
4851 // if sample was just previously added, remove it from
4852 // the import queue
4853 if (m_SampleImportQueue.count(sample)) {
4854 printf("Removing previously added sample '%s'\n",
4855 m_SampleImportQueue[sample].sample_path.c_str());
4856 m_SampleImportQueue.erase(sample);
4857 }
4858 dimreg_changed();
4859 file_changed();
4860 }
4861 // remove respective row(s) from samples tree view
4862 m_refSamplesTreeModel->erase(it);
4863 } catch (RIFF::Exception e) {
4864 // pretend we're done with removal (i.e. to avoid dead locks)
4865 samples_removed_signal.emit();
4866 // show error message
4867 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4868 msg.run();
4869 }
4870 }
4871 }
4872
4873 void MainWindow::on_action_remove_unused_samples() {
4874 if (!file) return;
4875
4876 // collect all samples that are not referenced by any instrument
4877 std::list<gig::Sample*> lsamples;
4878 for (int iSample = 0; file->GetSample(iSample); ++iSample) {
4879 gig::Sample* sample = file->GetSample(iSample);
4880 bool isUsed = false;
4881 for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
4882 instrument = file->GetNextInstrument())
4883 {
4884 for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
4885 rgn = instrument->GetNextRegion())
4886 {
4887 for (int i = 0; i < 256; ++i) {
4888 if (!rgn->pDimensionRegions[i]) continue;
4889 if (rgn->pDimensionRegions[i]->pSample != sample) continue;
4890 isUsed = true;
4891 goto endOfRefSearch;
4892 }
4893 }
4894 }
4895 endOfRefSearch:
4896 if (!isUsed) lsamples.push_back(sample);
4897 }
4898
4899 if (lsamples.empty()) return;
4900
4901 // notify everybody that we're going to remove these samples
4902 samples_to_be_removed_signal.emit(lsamples);
4903
4904 // remove collected samples
4905 try {
4906 for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
4907 itSample != lsamples.end(); ++itSample)
4908 {
4909 gig::Sample* sample = *itSample;
4910 // remove sample from the .gig file
4911 file->DeleteSample(sample);
4912 // if sample was just previously added, remove it from the import queue
4913 if (m_SampleImportQueue.count(sample)) {
4914 printf("Removing previously added sample '%s'\n",
4915 m_SampleImportQueue[sample].sample_path.c_str());
4916 m_SampleImportQueue.erase(sample);
4917 }
4918 }
4919 } catch (RIFF::Exception e) {
4920 // show error message
4921 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4922 msg.run();
4923 }
4924
4925 // notify everybody that we're done with removal
4926 samples_removed_signal.emit();
4927
4928 dimreg_changed();
4929 file_changed();
4930 __refreshEntireGUI();
4931 }
4932
4933 // see comment on on_sample_treeview_drag_begin()
4934 void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4935 {
4936 first_call_to_drag_data_get = true;
4937 }
4938
4939 void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4940 Gtk::SelectionData& selection_data, guint, guint)
4941 {
4942 if (!first_call_to_drag_data_get) return;
4943 first_call_to_drag_data_get = false;
4944
4945 // get selected script
4946 gig::Script* script = NULL;
4947 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4948 Gtk::TreeModel::iterator it = sel->get_selected();
4949 if (it) {
4950 Gtk::TreeModel::Row row = *it;
4951 script = row[m_ScriptsModel.m_col_script];
4952 }
4953 // pass the gig::Script as pointer
4954 selection_data.set(selection_data.get_target(), 0/*unused*/,
4955 (const guchar*)&script,
4956 sizeof(script)/*length of data in bytes*/);
4957 }
4958
4959 // see comment on on_sample_treeview_drag_begin()
4960 void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4961 {
4962 first_call_to_drag_data_get = true;
4963 }
4964
4965 void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4966 Gtk::SelectionData& selection_data, guint, guint)
4967 {
4968 if (!first_call_to_drag_data_get) return;
4969 first_call_to_drag_data_get = false;
4970
4971 // get selected source instrument
4972 gig::Instrument* src = NULL;
4973 {
4974 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4975 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4976 if (!rows.empty()) {
4977 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
4978 if (it) {
4979 Gtk::TreeModel::Row row = *it;
4980 src = row[m_Columns.m_col_instr];
4981 }
4982 }
4983 }
4984 if (!src) return;
4985
4986 // pass the source gig::Instrument as pointer
4987 selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
4988 sizeof(src)/*length of data in bytes*/);
4989 }
4990
4991 void MainWindow::on_instruments_treeview_drop_drag_data_received(
4992 const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
4993 const Gtk::SelectionData& selection_data, guint, guint time)
4994 {
4995 gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
4996 if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
4997 return;
4998
4999 gig::Instrument* dst = NULL;
5000 {
5001 Gtk::TreeModel::Path path;
5002 const bool found = m_TreeView.get_path_at_pos(x, y, path);
5003 if (!found) return;
5004
5005 Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
5006 if (!iter) return;
5007 Gtk::TreeModel::Row row = *iter;
5008 dst = row[m_Columns.m_col_instr];
5009 }
5010 if (!dst) return;
5011
5012 //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
5013 src->MoveTo(dst);
5014 __refreshEntireGUI();
5015 select_instrument(src);
5016 }
5017
5018 // For some reason drag_data_get gets called two times for each
5019 // drag'n'drop (at least when target is an Entry). This work-around
5020 // makes sure the code in drag_data_get and drop_drag_data_received is
5021 // only executed once, as drag_begin only gets called once.
5022 void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
5023 {
5024 first_call_to_drag_data_get = true;
5025 }
5026
5027 void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
5028 Gtk::SelectionData& selection_data, guint, guint)
5029 {
5030 if (!first_call_to_drag_data_get) return;
5031 first_call_to_drag_data_get = false;
5032
5033 // get selected sample
5034 gig::Sample* sample = NULL;
5035 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
5036 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
5037 if (!rows.empty()) {
5038 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
5039 if (it) {
5040 Gtk::TreeModel::Row row = *it;
5041 sample = row[m_SamplesModel.m_col_sample];
5042 }
5043 }
5044 // pass the gig::Sample as pointer
5045 selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
5046 sizeof(sample)/*length of data in bytes*/);
5047 }
5048
5049 void MainWindow::on_sample_label_drop_drag_data_received(
5050 const Glib::RefPtr<Gdk::DragContext>& context, int, int,
5051 const Gtk::SelectionData& selection_data, guint, guint time)
5052 {
5053 gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
5054
5055 if (sample && selection_data.get_length() == sizeof(gig::Sample*)) {
5056 std::cout << "Drop received sample \"" <<
5057 sample->pInfo->Name << "\"" << std::endl;
5058 // drop success
5059 context->drop_reply(true, time);
5060
5061 //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
5062
5063 // notify everybody that we're going to alter the region
5064 gig::Region* region = m_RegionChooser.get_region();
5065 region_to_be_changed_signal.emit(region);
5066
5067 // find the samplechannel dimension
5068 gig::dimension_def_t* stereo_dimension = 0;
5069 for (int i = 0 ; i < region->Dimensions ; i++) {
5070 if (region->pDimensionDefinitions[i].dimension ==
5071 gig::dimension_samplechannel) {
5072 stereo_dimension = &region->pDimensionDefinitions[i];
5073 break;
5074 }
5075 }
5076 bool channels_changed = false;
5077 if (sample->Channels == 1 && stereo_dimension) {
5078 // remove the samplechannel dimension
5079 /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
5080 region->DeleteDimension(stereo_dimension);
5081 channels_changed = true;
5082 region_changed();
5083 */
5084 }
5085 dimreg_edit.set_sample(
5086 sample,
5087 is_copy_samples_unity_note_enabled(),
5088 is_copy_samples_fine_tune_enabled(),
5089 is_copy_samples_loop_enabled()
5090 );
5091
5092 if (sample->Channels == 2 && !stereo_dimension) {
5093 // add samplechannel dimension
5094 gig::dimension_def_t dim;
5095 dim.dimension = gig::dimension_samplechannel;
5096 dim.bits = 1;
5097 dim.zones = 2;
5098 region->AddDimension(&dim);
5099 channels_changed = true;
5100 region_changed();
5101 }
5102 if (channels_changed) {
5103 // unmap all samples with wrong number of channels
5104 // TODO: maybe there should be a warning dialog for this
5105 for (int i = 0 ; i < region->DimensionRegions ; i++) {
5106 gig::DimensionRegion* d = region->pDimensionRegions[i];
5107 if (d->pSample && d->pSample->Channels != sample->Channels) {
5108 gig::Sample* oldref = d->pSample;
5109 d->pSample = NULL;
5110 sample_ref_changed_signal.emit(oldref, NULL);
5111 }
5112 }
5113 }
5114
5115 // notify we're done with altering
5116 region_changed_signal.emit(region);
5117
5118 file_changed();
5119
5120 return;
5121 }
5122 // drop failed
5123 context->drop_reply(false, time);
5124 }
5125
5126 void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path,
5127 const Gtk::TreeModel::iterator& iter) {
5128 if (!iter) return;
5129 Gtk::TreeModel::Row row = *iter;
5130 Glib::ustring name = row[m_SamplesModel.m_col_name];
5131 gig::Group* group = row[m_SamplesModel.m_col_group];
5132 gig::Sample* sample = row[m_SamplesModel.m_col_sample];
5133 gig::String gigname(gig_from_utf8(name));
5134 if (group) {
5135 if (group->Name != gigname) {
5136 group->Name = gigname;
5137 printf("group name changed\n");
5138 file_changed();
5139 }
5140 } else if (sample) {
5141 if (sample->pInfo->Name != gigname) {
5142 sample->pInfo->Name = gigname;
5143 printf("sample name changed\n");
5144 file_changed();
5145 }
5146 }
5147 // change name in the sample properties window
5148 if (sampleProps.get_sample() == sample && sample) {
5149 sampleProps.set_sample(sample);
5150 }
5151 }
5152
5153 void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
5154 const Gtk::TreeModel::iterator& iter) {
5155 if (!iter) return;
5156 Gtk::TreeModel::Row row = *iter;
5157 Glib::ustring name = row[m_ScriptsModel.m_col_name];
5158 gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
5159 gig::Script* script = row[m_ScriptsModel.m_col_script];
5160 gig::String gigname(gig_from_utf8(name));
5161 if (group) {
5162 if (group->Name != gigname) {
5163 group->Name = gigname;
5164 printf("script group name changed\n");
5165 file_changed();
5166 }
5167 } else if (script) {
5168 if (script->Name != gigname) {
5169 script->Name = gigname;
5170 printf("script name changed\n");
5171 file_changed();
5172 }
5173 }
5174 }
5175
5176 void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
5177 Gtk::TreeViewColumn* column)
5178 {
5179 Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
5180 if (!iter) return;
5181 Gtk::TreeModel::Row row = *iter;
5182 gig::Script* script = row[m_ScriptsModel.m_col_script];
5183 if (!script) return;
5184
5185 ScriptEditor* editor = new ScriptEditor;
5186 editor->signal_script_to_be_changed.connect(
5187 signal_script_to_be_changed.make_slot()
5188 );
5189 editor->signal_script_changed.connect(
5190 signal_script_changed.make_slot()
5191 );
5192 editor->setScript(script);
5193 //editor->reparent(*this);
5194 editor->show();
5195 }
5196
5197 void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
5198 const Gtk::TreeModel::iterator& iter) {
5199 if (!iter) return;
5200 Gtk::TreeModel::Row row = *iter;
5201 Glib::ustring name = row[m_Columns.m_col_name];
5202
5203 #if !USE_GTKMM_BUILDER
5204 // change name in instrument menu
5205 int index = path[0];
5206 const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
5207 if (index < children.size()) {
5208 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
5209 static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
5210 #else
5211 remove_instrument_from_menu(index);
5212 Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
5213 item->set_active();
5214 #endif
5215 }
5216 #endif
5217
5218 // change name in gig
5219 gig::Instrument* instrument = row[m_Columns.m_col_instr];
5220 gig::String gigname(gig_from_utf8(name));
5221 if (instrument && instrument->pInfo->Name != gigname) {
5222 instrument->pInfo->Name = gigname;
5223
5224 // change name in the instrument properties window
5225 if (instrumentProps.get_instrument() == instrument) {
5226 instrumentProps.update_name();
5227 }
5228
5229 file_changed();
5230 }
5231 }
5232
5233 bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
5234 if (!iter)
5235 return true;
5236
5237 Glib::ustring pattern = m_searchText.get_text().lowercase();
5238 trim(pattern);
5239 if (pattern.empty()) return true;
5240
5241 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
5242 //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
5243 Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
5244 #else
5245 Gtk::TreeModel::Row row = *iter;
5246 #endif
5247 Glib::ustring name = row[m_Columns.m_col_name];
5248 name = name.lowercase();
5249
5250 std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
5251 for (int t = 0; t < tokens.size(); ++t)
5252 if (name.find(tokens[t]) == Glib::ustring::npos)
5253 return false;
5254
5255 return true;
5256 }
5257
5258 void MainWindow::on_action_combine_instruments() {
5259 CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
5260
5261 // take over selection from instruments list view for the combine dialog's
5262 // list view as pre-selection
5263 std::set<int> indeces;
5264 {
5265 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
5266 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
5267 for (int r = 0; r < rows.size(); ++r) {
5268 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
5269 if (it) {
5270 Gtk::TreeModel::Row row = *it;
5271 int index = row[m_Columns.m_col_nr];
5272 indeces.insert(index);
5273 }
5274 }
5275 }
5276 d->setSelectedInstruments(indeces);
5277
5278 #if HAS_GTKMM_SHOW_ALL_CHILDREN
5279 d->show_all();
5280 #else
5281 d->show();
5282 #endif
5283 d->run();
5284 if (d->fileWasChanged()) {
5285 // update GUI with new instrument just created
5286 add_instrument(d->newCombinedInstrument());
5287 }
5288 delete d;
5289 }
5290
5291 void MainWindow::on_action_view_references() {
5292 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
5293 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
5294 if (rows.empty()) return;
5295 Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
5296 if (!it) return;
5297 Gtk::TreeModel::Row row = *it;
5298 gig::Sample* sample = row[m_SamplesModel.m_col_sample];
5299 if (!sample) return;
5300
5301 ReferencesView* d = new ReferencesView(*this);
5302 d->setSample(sample);
5303 d->dimension_region_selected.connect(
5304 sigc::mem_fun(*this, &MainWindow::select_dimension_region)
5305 );
5306 #if HAS_GTKMM_SHOW_ALL_CHILDREN
5307 d->show_all();
5308 #else
5309 d->show();
5310 #endif
5311 d->resize(500, 400);
5312 d->run();
5313 delete d;
5314 }
5315
5316 void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
5317 struct _Source {
5318 std::vector<RIFF::File*> riffs;
5319 std::vector<gig::File*> gigs;
5320
5321 ~_Source() {
5322 for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
5323 for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
5324 riffs.clear();
5325 gigs.clear();
5326 }
5327 } sources;
5328
5329 if (filenames.empty())
5330 throw RIFF::Exception(_("No files selected, so nothing done."));
5331
5332 // first open all input files (to avoid output file corruption)
5333 int i;
5334 try {
5335 for (i = 0; i < filenames.size(); ++i) {
5336 const std::string& filename = filenames[i];
5337 printf("opening file=%s\n", filename.c_str());
5338
5339 RIFF::File* riff = new RIFF::File(filename);
5340 sources.riffs.push_back(riff);
5341
5342 gig::File* gig = new gig::File(riff);
5343 sources.gigs.push_back(gig);
5344 }
5345 } catch (RIFF::Exception e) {
5346 throw RIFF::Exception(
5347 _("Error occurred while opening '") +
5348 filenames[i] +
5349 "': " +
5350 e.Message
5351 );
5352 } catch (...) {
5353 throw RIFF::Exception(
5354 _("Unknown exception occurred while opening '") +
5355 filenames[i] + "'"
5356 );
5357 }
5358
5359 // now merge the opened .gig files to the main .gig file currently being
5360 // open in gigedit
5361 try {
5362 for (i = 0; i < filenames.size(); ++i) {
5363 const std::string& filename = filenames[i];
5364 printf("merging file=%s\n", filename.c_str());
5365 assert(i < sources.gigs.size());
5366
5367 this->file->AddContentOf(sources.gigs[i]);
5368 }
5369 } catch (RIFF::Exception e) {
5370 throw RIFF::Exception(
5371 _("Error occurred while merging '") +
5372 filenames[i] +
5373 "': " +
5374 e.Message
5375 );
5376 } catch (...) {
5377 throw RIFF::Exception(
5378 _("Unknown exception occurred while merging '") +
5379 filenames[i] + "'"
5380 );
5381 }
5382
5383 // Finally save gig file persistently to disk ...
5384 //NOTE: requires that this gig file already has a filename !
5385 {
5386 std::cout << "Saving file\n" << std::flush;
5387 file_structure_to_be_changed_signal.emit(this->file);
5388
5389 progress_dialog = new ProgressDialog( //FIXME: memory leak!
5390 _("Saving") + Glib::ustring(" '") +
5391 Glib::filename_display_basename(this->filename) + "' ...",
5392 *this
5393 );
5394 #if HAS_GTKMM_SHOW_ALL_CHILDREN
5395 progress_dialog->show_all();
5396 #else
5397 progress_dialog->show();
5398 #endif
5399 saver = new Saver(this->file); //FIXME: memory leak!
5400 saver->signal_progress().connect(
5401 sigc::mem_fun(*this, &MainWindow::on_saver_progress));
5402 saver->signal_finished().connect(
5403 sigc::mem_fun(*this, &MainWindow::on_saver_finished));
5404 saver->signal_error().connect(
5405 sigc::mem_fun(*this, &MainWindow::on_saver_error));
5406 saver->launch();
5407 }
5408 }
5409
5410 void MainWindow::on_action_merge_files() {
5411 if (this->file->GetFileName().empty()) {
5412 Glib::ustring txt = _(
5413 "You seem to have a new .gig file open that has not been saved "
5414 "yet. You must save it somewhere before starting to merge it with "
5415 "other .gig files though, because during the merge operation the "
5416 "other files' sample data must be written on file level to the "
5417 "target .gig file."
5418 );
5419 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5420 msg.run();
5421 return;
5422 }
5423
5424 Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
5425 #if HAS_GTKMM_STOCK
5426 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
5427 #else
5428 dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
5429 #endif
5430 dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
5431 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
5432 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
5433 Gtk::FileFilter filter;
5434 filter.add_pattern("*.gig");
5435 #else
5436 Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
5437 filter->add_pattern("*.gig");
5438 #endif
5439 dialog.set_filter(filter);
5440 if (current_gig_dir != "") {
5441 dialog.set_current_folder(current_gig_dir);
5442 }
5443 dialog.set_select_multiple(true);
5444
5445 // show warning in the file picker dialog
5446 HBox descriptionArea;
5447 descriptionArea.set_spacing(15);
5448 Gtk::Image warningIcon;
5449 warningIcon.set_from_icon_name("dialog-warning",
5450 Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
5451 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
5452 #if GTKMM_MAJOR_VERSION < 3
5453 view::WrapLabel description;
5454 #else
5455 Gtk::Label description;
5456 description.set_line_wrap();
5457 #endif
5458 description.set_markup(_(
5459 "\nSelect at least one .gig file that shall be merged to the .gig file "
5460 "currently being open in gigedit.\n\n"
5461 "<b>Please Note:</b> Merging with other files will modify your "
5462 "currently open .gig file on file level! And be aware that the current "
5463 "merge algorithm does not detect duplicate samples yet. So if you are "
5464 "merging files which are using equivalent sample data, those "
5465 "equivalent samples will currently be treated as separate samples and "
5466 "will accordingly be stored separately in the target .gig file!"
5467 ));
5468 descriptionArea.pack_start(description);
5469 #if USE_GTKMM_BOX
5470 # warning No description area implemented for dialog on GTKMM 3
5471 #else
5472 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
5473 #endif
5474 #if HAS_GTKMM_SHOW_ALL_CHILDREN
5475 descriptionArea.show_all();
5476 #else
5477 descriptionArea.show();
5478 #endif
5479
5480 if (dialog.run() == Gtk::RESPONSE_OK) {
5481 dialog.hide();
5482 #ifdef GLIB_THREADS
5483 printf("on_action_merge_files self=%p\n",
5484 static_cast<void*>(Glib::Threads::Thread::self()));
5485 #else
5486 std::cout << "on_action_merge_files self=" <<
5487 std::this_thread::get_id() << "\n";
5488 #endif
5489 std::vector<std::string> filenames = dialog.get_filenames();
5490
5491 // merge the selected files to the currently open .gig file
5492 try {
5493 mergeFiles(filenames);
5494 } catch (RIFF::Exception e) {
5495 Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
5496 msg.run();
5497 }
5498
5499 // update GUI
5500 __refreshEntireGUI();
5501 }
5502 }
5503
5504 void MainWindow::set_file_is_shared(bool b) {
5505 this->file_is_shared = b;
5506
5507 if (file_is_shared) {
5508 m_AttachedStateLabel.set_label(_("live-mode"));
5509 m_AttachedStateImage.set(
5510 Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
5511 );
5512 } else {
5513 m_AttachedStateLabel.set_label(_("stand-alone"));
5514 m_AttachedStateImage.set(
5515 Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
5516 );
5517 }
5518
5519 {
5520 #if USE_GTKMM_BUILDER
5521 m_actionToggleSyncSamplerSelection->property_enabled() = b;
5522 #else
5523 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
5524 uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
5525 if (item) item->set_sensitive(b);
5526 #endif
5527 }
5528 }
5529
5530 void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
5531 if (!sample) return;
5532 sample_ref_count[sample] += offset;
5533 const int refcount = sample_ref_count[sample];
5534
5535 Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
5536 for (int g = 0; g < model->children().size(); ++g) {
5537 Gtk::TreeModel::Row rowGroup = model->children()[g];
5538 for (int s = 0; s < rowGroup.children().size(); ++s) {
5539 Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
5540 if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
5541 rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
5542 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
5543 }
5544 }
5545 }
5546
5547 void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
5548 on_sample_ref_count_incremented(oldSample, -1);
5549 on_sample_ref_count_incremented(newSample, +1);
5550 }
5551
5552 void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
5553 // just in case a new sample is added later with exactly the same memory
5554 // address, which would lead to incorrect refcount if not deleted here
5555 for (std::list<gig::Sample*>::const_iterator it = samples.begin();
5556 it != samples.end(); ++it)
5557 {
5558 sample_ref_count.erase(*it);
5559 }
5560 }
5561
5562 void MainWindow::show_samples_tab() {
5563 m_TreeViewNotebook.set_current_page(0);
5564 }
5565
5566 void MainWindow::show_intruments_tab() {
5567 m_TreeViewNotebook.set_current_page(1);
5568 }
5569
5570 void MainWindow::show_scripts_tab() {
5571 m_TreeViewNotebook.set_current_page(2);
5572 }
5573
5574 void MainWindow::select_instrument_by_dir(int dir) {
5575 if (!file) return;
5576 gig::Instrument* pInstrument = get_instrument();
5577 if (!pInstrument) {
5578 select_instrument( file->GetInstrument(0) );
5579 return;
5580 }
5581 for (int i = 0; file->GetInstrument(i); ++i) {
5582 if (file->GetInstrument(i) == pInstrument) {
5583 select_instrument( file->GetInstrument(i + dir) );
5584 return;
5585 }
5586 }
5587 }
5588
5589 void MainWindow::select_prev_instrument() {
5590 select_instrument_by_dir(-1);
5591 }
5592
5593 void MainWindow::select_next_instrument() {
5594 select_instrument_by_dir(1);
5595 }
5596
5597 void MainWindow::select_prev_region() {
5598 m_RegionChooser.select_prev_region();
5599 }
5600
5601 void MainWindow::select_next_region() {
5602 m_RegionChooser.select_next_region();
5603 }
5604
5605 void MainWindow::select_next_dim_rgn_zone() {
5606 if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5607 m_DimRegionChooser.select_next_dimzone();
5608 }
5609
5610 void MainWindow::select_prev_dim_rgn_zone() {
5611 if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5612 m_DimRegionChooser.select_prev_dimzone();
5613 }
5614
5615 void MainWindow::select_add_next_dim_rgn_zone() {
5616 m_DimRegionChooser.select_next_dimzone(true);
5617 }
5618
5619 void MainWindow::select_add_prev_dim_rgn_zone() {
5620 m_DimRegionChooser.select_prev_dimzone(true);
5621 }
5622
5623 void MainWindow::select_prev_dimension() {
5624 if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5625 m_DimRegionChooser.select_prev_dimension();
5626 }
5627
5628 void MainWindow::select_next_dimension() {
5629 if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5630 m_DimRegionChooser.select_next_dimension();
5631 }
5632
5633 #define CLIPBOARD_DIMENSIONREGION_TARGET \
5634 ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
5635
5636 void MainWindow::copy_selected_dimrgn() {
5637 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5638 if (!pDimRgn) {
5639 updateClipboardPasteAvailable();
5640 updateClipboardCopyAvailable();
5641 return;
5642 }
5643
5644 std::vector<Gtk::TargetEntry> targets;
5645 targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
5646
5647 Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5648 clipboard->set(
5649 targets,
5650 sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
5651 sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
5652 );
5653
5654 m_serializationArchive.serialize(pDimRgn);
5655
5656 updateClipboardPasteAvailable();
5657 }
5658
5659 void MainWindow::paste_copied_dimrgn() {
5660 Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5661 clipboard->request_contents(
5662 CLIPBOARD_DIMENSIONREGION_TARGET,
5663 sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
5664 );
5665 updateClipboardPasteAvailable();
5666 }
5667
5668 void MainWindow::adjust_clipboard_content() {
5669 MacroEditor* editor = new MacroEditor();
5670 editor->setMacro(&m_serializationArchive, true);
5671 editor->show();
5672 }
5673
5674 void MainWindow::updateClipboardPasteAvailable() {
5675 Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5676 clipboard->request_targets(
5677 sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
5678 );
5679 }
5680
5681 void MainWindow::updateClipboardCopyAvailable() {
5682 bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5683 #if USE_GTKMM_BUILDER
5684 m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5685 #else
5686 static_cast<Gtk::MenuItem*>(
5687 uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5688 )->set_sensitive(bDimensionRegionCopyIsPossible);
5689 #endif
5690 }
5691
5692 #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
5693 void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5694 #else
5695 void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5696 #endif
5697 updateClipboardPasteAvailable();
5698 }
5699
5700 void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
5701 const std::string target = selection_data.get_target();
5702 if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5703 selection_data.set(
5704 CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
5705 &m_serializationArchive.rawData()[0],
5706 m_serializationArchive.rawData().size()
5707 );
5708 } else {
5709 std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
5710 }
5711 }
5712
5713 void MainWindow::on_clipboard_clear() {
5714 m_serializationArchive.clear();
5715 updateClipboardPasteAvailable();
5716 updateClipboardCopyAvailable();
5717 }
5718
5719 //NOTE: Might throw exception !!!
5720 void MainWindow::applyMacro(Serialization::Archive& macro) {
5721 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5722 if (!pDimRgn) return;
5723
5724 for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5725 itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5726 {
5727 gig::DimensionRegion* pDimRgn = *itDimReg;
5728 DimRegionChangeGuard(this, pDimRgn);
5729 macro.deserialize(pDimRgn);
5730 }
5731 //region_changed()
5732 file_changed();
5733 dimreg_changed();
5734 }
5735
5736 void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5737 const std::string target = selection_data.get_target();
5738 if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5739 Glib::ustring errorText;
5740 try {
5741 m_serializationArchive.decode(
5742 selection_data.get_data(), selection_data.get_length()
5743 );
5744 applyMacro(m_serializationArchive);
5745 } catch (Serialization::Exception e) {
5746 errorText = e.Message;
5747 } catch (...) {
5748 errorText = _("Unknown exception while pasting DimensionRegion");
5749 }
5750 if (!errorText.empty()) {
5751 Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
5752 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5753 msg.run();
5754 }
5755 }
5756 }
5757
5758 void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
5759 const bool bDimensionRegionPasteIsPossible =
5760 std::find(targets.begin(), targets.end(),
5761 CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5762
5763 #if USE_GTKMM_BUILDER
5764 m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5765 m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5766 #else
5767 static_cast<Gtk::MenuItem*>(
5768 uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5769 )->set_sensitive(bDimensionRegionPasteIsPossible);
5770
5771 static_cast<Gtk::MenuItem*>(
5772 uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5773 )->set_sensitive(bDimensionRegionPasteIsPossible);
5774 #endif
5775 }
5776
5777 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
5778 return file_structure_to_be_changed_signal;
5779 }
5780
5781 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
5782 return file_structure_changed_signal;
5783 }
5784
5785 sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
5786 return samples_to_be_removed_signal;
5787 }
5788
5789 sigc::signal<void>& MainWindow::signal_samples_removed() {
5790 return samples_removed_signal;
5791 }
5792
5793 sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
5794 return region_to_be_changed_signal;
5795 }
5796
5797 sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
5798 return region_changed_signal;
5799 }
5800
5801 sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
5802 return sample_changed_signal;
5803 }
5804
5805 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
5806 return sample_ref_changed_signal;
5807 }
5808
5809 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
5810 return dimreg_to_be_changed_signal;
5811 }
5812
5813 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
5814 return dimreg_changed_signal;
5815 }
5816
5817 sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
5818 return note_on_signal;
5819 }
5820
5821 sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
5822 return note_off_signal;
5823 }
5824
5825 sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
5826 return m_RegionChooser.signal_keyboard_key_hit();
5827 }
5828
5829 sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
5830 return m_RegionChooser.signal_keyboard_key_released();
5831 }
5832
5833 sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
5834 return switch_sampler_instrument_signal;
5835 }

  ViewVC Help
Powered by ViewVC