/[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 3460 - (show annotations) (download)
Sat Feb 2 07:48:50 2019 UTC (5 years, 1 month ago) by persson
File size: 211765 byte(s)
* Use GDK Seat API if available to grab pointer
* Improve version checks for pangomm
* Fix the instrument list tooltip handling so it doesn't generate GTK
  assertion error messages
* Use English quotation marks in tooltips instead of German
* Use multiple columns in controller value popups, as tall popup menus
  work really badly in some GTK environments

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

  ViewVC Help
Powered by ViewVC