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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2697 by schoenebeck, Sun Jan 11 16:39:22 2015 UTC revision 3456 by persson, Sun Jan 27 10:07:56 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2019 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #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>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
39  #include <gtkmm/stock.h>  #if HAS_GTKMM_STOCK
40    # include <gtkmm/stock.h>
41    #endif
42  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
43  #include <gtkmm/main.h>  #include <gtkmm/main.h>
44  #include <gtkmm/toggleaction.h>  #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  #if GTKMM_MAJOR_VERSION < 3
49  #include "wrapLabel.hh"  #include "wrapLabel.hh"
50  #endif  #endif
# Line 39  Line 53 
53  #include "compat.h"  #include "compat.h"
54    
55  #include <stdio.h>  #include <stdio.h>
56  #include <sndfile.h>  #ifdef LIBSNDFILE_HEADER_FILE
57    # include LIBSNDFILE_HEADER_FILE(sndfile.h)
58    #else
59    # include <sndfile.h>
60    #endif
61  #include <assert.h>  #include <assert.h>
62    
63  #include "mainwindow.h"  #include "mainwindow.h"
# Line 50  Line 68 
68  #include "ReferencesView.h"  #include "ReferencesView.h"
69  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
70  #include "../../gfx/status_detached.xpm"  #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() :  MainWindow::MainWindow() :
86      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
87      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
88      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
89      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
90      dimreg_stereo(_("both channels"))      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);  //    set_border_width(5);
 //    set_default_size(400, 200);  
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);      add(m_VBox);
113    
# Line 71  MainWindow::MainWindow() : Line 117  MainWindow::MainWindow() :
117    
118      // m_TreeView.set_reorderable();      // 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(      m_TreeView.signal_button_press_event().connect_notify(
125          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
126    #endif
127    
128      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
129      m_ScrolledWindow.add(m_TreeView);      m_ScrolledWindow.add(m_TreeView);
# Line 85  MainWindow::MainWindow() : Line 136  MainWindow::MainWindow() :
136      m_ScrolledWindowScripts.add(m_TreeViewScripts);      m_ScrolledWindowScripts.add(m_TreeViewScripts);
137      m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138    
139    #if GTKMM_MAJOR_VERSION < 3
140      m_TreeViewNotebook.set_size_request(300);      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    
     m_HPaned.add1(m_TreeViewNotebook);  
153      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
154      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
155      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 96  MainWindow::MainWindow() : Line 157  MainWindow::MainWindow() :
157      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
158      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
159      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      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);      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."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 107  MainWindow::MainWindow() : Line 220  MainWindow::MainWindow() :
220      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221      m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));      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();      actionGroup = Gtk::ActionGroup::create();
263    
264      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
# Line 156  MainWindow::MainWindow() : Line 308  MainWindow::MainWindow() :
308          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309      );      );
310      actionGroup->add(      actionGroup->add(
311          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
312          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313      );      );
314      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      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")));      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 =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
440          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
441      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 177  MainWindow::MainWindow() : Line 450  MainWindow::MainWindow() :
450          Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));          Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451      toggle_action->set_active(true);      toggle_action->set_active(true);
452      actionGroup->add(toggle_action);      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      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
471        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
472      toggle_action =      toggle_action =
473          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
474      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 187  MainWindow::MainWindow() : Line 476  MainWindow::MainWindow() :
476                       sigc::mem_fun(                       sigc::mem_fun(
477                           *this, &MainWindow::on_action_view_status_bar));                           *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);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
525      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
526                                           action->property_label()));                                           action->property_label()));
# Line 202  MainWindow::MainWindow() : Line 536  MainWindow::MainWindow() :
536          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
537      );      );
538      actionGroup->add(      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),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
545          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          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")));      actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
564            
565      toggle_action =      toggle_action =
# Line 225  MainWindow::MainWindow() : Line 578  MainWindow::MainWindow() :
578          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          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")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
599    
600      actionGroup->add(      actionGroup->add(
# Line 237  MainWindow::MainWindow() : Line 606  MainWindow::MainWindow() :
606          Gtk::Action::create("MergeFiles", _("_Merge Files...")),          Gtk::Action::create("MergeFiles", _("_Merge Files...")),
607          sigc::mem_fun(*this, &MainWindow::on_action_merge_files)          sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
608      );      );
609    #endif
610    
611      // sample right-click popup actions      // 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(      actionGroup->add(
639          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
640          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
# Line 257  MainWindow::MainWindow() : Line 652  MainWindow::MainWindow() :
652          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
653      );      );
654      actionGroup->add(      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...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
660          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
661      );      );
662      actionGroup->add(      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",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
669                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
670          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
671      );      );
672    #endif
673            
674      // script right-click popup actions      // 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(      actionGroup->add(
690          Gtk::Action::create("AddScriptGroup", _("Add _Group")),          Gtk::Action::create("AddScriptGroup", _("Add _Group")),
691          sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
# Line 283  MainWindow::MainWindow() : Line 702  MainWindow::MainWindow() :
702          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
703          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          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();      uiManager = Gtk::UIManager::create();
1095      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
1096      add_accel_group(uiManager->get_accel_group());      add_accel_group(uiManager->get_accel_group());
# Line 303  MainWindow::MainWindow() : Line 1110  MainWindow::MainWindow() :
1110          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
1111          "    </menu>"          "    </menu>"
1112          "    <menu action='MenuEdit'>"          "    <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'/>"          "      <menuitem action='CopySampleUnity'/>"
1131          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
1132          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
1133          "    </menu>"          "    </menu>"
1134            "    <menu action='MenuMacro'>"
1135            "    </menu>"
1136          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
1137          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
1138          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
1139          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
1140          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
1141            "      <menuitem action='ReplaceSample' />"
1142          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
1143          "      <separator/>"          "      <separator/>"
1144          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
1145            "      <menuitem action='RemoveUnusedSamples'/>"
1146          "    </menu>"          "    </menu>"
1147          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
1148          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 323  MainWindow::MainWindow() : Line 1151  MainWindow::MainWindow() :
1151          "      <menuitem action='InstrProperties'/>"          "      <menuitem action='InstrProperties'/>"
1152          "      <menuitem action='MidiRules'/>"          "      <menuitem action='MidiRules'/>"
1153          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
1154            "      <menu action='AssignScripts'/>"
1155          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
1156          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
1157            "      <menuitem action='CombInstruments'/>"
1158          "      <separator/>"          "      <separator/>"
1159          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
1160          "    </menu>"          "    </menu>"
# Line 337  MainWindow::MainWindow() : Line 1167  MainWindow::MainWindow() :
1167          "    </menu>"          "    </menu>"
1168          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
1169          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
1170            "      <menuitem action='ShowTooltips'/>"
1171            "      <menuitem action='AutoRestoreWinDim'/>"
1172            "      <separator/>"
1173            "      <menuitem action='RefreshAll'/>"
1174          "    </menu>"          "    </menu>"
1175          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
1176          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 1179  MainWindow::MainWindow() :
1179          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
1180          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
1181          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
1182            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
1183            "      <menuitem action='SaveWithTemporaryFile'/>"
1184          "    </menu>"          "    </menu>"
1185          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
1186          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 356  MainWindow::MainWindow() : Line 1192  MainWindow::MainWindow() :
1192          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
1193          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
1194          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
1195            "    <menuitem action='CombInstruments'/>"
1196          "    <separator/>"          "    <separator/>"
1197          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
1198          "  </popup>"          "  </popup>"
# Line 364  MainWindow::MainWindow() : Line 1201  MainWindow::MainWindow() :
1201          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
1202          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
1203          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
1204            "    <menuitem action='ReplaceSample' />"
1205          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
1206          "    <separator/>"          "    <separator/>"
1207          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
1208            "    <menuitem action='RemoveUnusedSamples'/>"
1209          "  </popup>"          "  </popup>"
1210          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
1211          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 377  MainWindow::MainWindow() : Line 1216  MainWindow::MainWindow() :
1216          "  </popup>"          "  </popup>"
1217          "</ui>";          "</ui>";
1218      uiManager->add_ui_from_string(ui_info);      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"));      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      // Set tooltips for menu items (for some reason, setting a tooltip on the
# Line 397  MainWindow::MainWindow() : Line 1254  MainWindow::MainWindow() :
1254      {      {
1255          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1256              uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));              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 informations to be altered by this action."));          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*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
# Line 411  MainWindow::MainWindow() : Line 1268  MainWindow::MainWindow() :
1268      }      }
1269      {      {
1270          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          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"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1296          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1297      }      }
# Line 419  MainWindow::MainWindow() : Line 1300  MainWindow::MainWindow() :
1300              uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));              uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1301          item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));          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*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
1313          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();          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");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1324    #endif
1325    
1326      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1327      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
1328      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
# Line 435  MainWindow::MainWindow() : Line 1333  MainWindow::MainWindow() :
1333      set_file_is_shared(false);      set_file_is_shared(false);
1334    
1335      // Status Bar:      // 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);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1340      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1341    #endif
1342      m_StatusBar.show();      m_StatusBar.show();
1343    
1344      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
# Line 447  MainWindow::MainWindow() : Line 1349  MainWindow::MainWindow() :
1349    
1350      // Create the Tree model:      // Create the Tree model:
1351      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
1352      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1353      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      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(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1364          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1365      );      );
1366    
1367      // Add the TreeView's view columns:      // Add the TreeView's view columns:
1368      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1369      m_TreeView.set_headers_visible(false);      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)      // create samples treeview (including its data model)
1392      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1393      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      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."));      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();      // m_TreeViewSamples.set_reorderable();
1397      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 481  MainWindow::MainWindow() : Line 1413  MainWindow::MainWindow() :
1413          );          );
1414      }      }
1415      m_TreeViewSamples.set_headers_visible(true);      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(      m_TreeViewSamples.signal_button_press_event().connect_notify(
1422          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1423      );      );
1424    #endif
1425      m_refSamplesTreeModel->signal_row_changed().connect(      m_refSamplesTreeModel->signal_row_changed().connect(
1426          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1427      );      );
# Line 500  MainWindow::MainWindow() : Line 1438  MainWindow::MainWindow() :
1438      // m_TreeViewScripts.set_reorderable();      // m_TreeViewScripts.set_reorderable();
1439      m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);      m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1440      m_TreeViewScripts.set_headers_visible(false);      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(      m_TreeViewScripts.signal_button_press_event().connect_notify(
1447          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          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 ?      //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(      m_TreeViewScripts.signal_row_activated().connect(
1452          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
# Line 540  MainWindow::MainWindow() : Line 1484  MainWindow::MainWindow() :
1484          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1485      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
1486          sigc::mem_fun(*this, &MainWindow::file_changed));          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(      m_DimRegionChooser.signal_region_changed().connect(
1490          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1491      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 599  MainWindow::MainWindow() : Line 1545  MainWindow::MainWindow() :
1545      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
1546          sigc::mem_fun(*this, &MainWindow::update_dimregs));          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;      file = 0;
1553      file_is_changed = false;      file_is_changed = false;
1554    
1555    #if HAS_GTKMM_SHOW_ALL_CHILDREN
1556      show_all_children();      show_all_children();
1557    #endif
1558    
1559      // start with a new gig file by default      // start with a new gig file by default
1560      on_action_file_new();      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      // select 'Instruments' tab by default
1567      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
1568      m_TreeViewNotebook.set_current_page(1);      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()  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)  bool MainWindow::on_delete_event(GdkEventAny* event)
1776  {  {
1777      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 635  void MainWindow::region_changed() Line 1791  void MainWindow::region_changed()
1791  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
1792  {  {
1793      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
1794      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1795          m_TreeView.get_selection()->get_selected();      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) {      if (it) {
1799          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1800          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 679  void MainWindow::update_dimregs() Line 1837  void MainWindow::update_dimregs()
1837              add_region_to_dimregs(region, stereo, all_dimregs);              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()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 695  void MainWindow::dimreg_changed() Line 1860  void MainWindow::dimreg_changed()
1860    
1861  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1862  {  {
1863    #if !USE_GTKMM_BUILDER
1864      // select item in instrument menu      // select item in instrument menu
1865      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1866      if (it) {      if (!rows.empty()) {
1867          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1868          int index = path[0];          if (it) {
1869          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1870              instrument_menu->get_children();              int index = path[0];
1871          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              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());      m_RegionChooser.set_instrument(get_instrument());
1881    
# Line 727  void Loader::progress_callback(float fra Line 1899  void Loader::progress_callback(float fra
1899      progress_dispatcher();      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()  void Loader::thread_function()
1907  {  {
1908      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1909               static_cast<void*>(Glib::Threads::Thread::self()));
1910      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1911      try {      try {
1912          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 751  void Loader::thread_function() Line 1928  void Loader::thread_function()
1928  }  }
1929    
1930  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1931      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
1932  {  {
1933  }  }
1934    
# Line 762  void Loader::launch() Line 1939  void Loader::launch()
1939  #else  #else
1940      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1941  #endif  #endif
1942      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1943  }  }
1944    
1945  float Loader::get_progress()  float Loader::get_progress()
# Line 805  void Saver::progress_callback(float frac Line 1982  void Saver::progress_callback(float frac
1982      progress_dispatcher.emit();      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()  void Saver::thread_function()
1990  {  {
1991      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1992               static_cast<void*>(Glib::Threads::Thread::self()));
1993      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1994      try {      try {
1995          gig::progress_t progress;          gig::progress_t progress;
# Line 816  void Saver::thread_function() Line 1998  void Saver::thread_function()
1998    
1999          // if no filename was provided, that means "save", if filename was provided means "save as"          // if no filename was provided, that means "save", if filename was provided means "save as"
2000          if (filename.empty()) {          if (filename.empty()) {
2001              gig->Save(&progress);              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 {          } else {
2030              gig->Save(filename, &progress);              gig->Save(filename, &progress);
2031          }          }
# Line 844  void Saver::launch() Line 2053  void Saver::launch()
2053  #else  #else
2054      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2055  #endif  #endif
2056      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
2057  }  }
2058    
2059  float Saver::get_progress()  float Saver::get_progress()
# Line 875  Glib::Dispatcher& Saver::signal_error() Line 2084  Glib::Dispatcher& Saver::signal_error()
2084  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2085      : Gtk::Dialog(title, parent, true)      : 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);      get_vbox()->pack_start(progressBar);
2091    #endif
2092    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2093      show_all_children();      show_all_children();
2094    #endif
2095      resize(600,50);      resize(600,50);
2096  }  }
2097    
# Line 889  void MainWindow::__clear() { Line 2104  void MainWindow::__clear() {
2104      m_refTreeModel->clear();      m_refTreeModel->clear();
2105      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2106      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2107    #if !USE_GTKMM_BUILDER
2108      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2109      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2110          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2111      }      }
2112    #endif
2113      // free libgig's gig::File instance      // free libgig's gig::File instance
2114      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
2115      file = NULL;      file = NULL;
# Line 904  void MainWindow::__refreshEntireGUI() { Line 2121  void MainWindow::__refreshEntireGUI() {
2121      m_refTreeModel->clear();      m_refTreeModel->clear();
2122      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2123      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2124    #if !USE_GTKMM_BUILDER
2125      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2126      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2127          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2128      }      }
2129    #endif
2130    
2131      if (!this->file) return;      if (!this->file) return;
2132    
# Line 941  bool MainWindow::close_confirmation_dial Line 2160  bool MainWindow::close_confirmation_dial
2160      g_free(msg);      g_free(msg);
2161      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2162      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2163    #if HAS_GTKMM_STOCK
2164      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      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);      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);      dialog.set_default_response(Gtk::RESPONSE_YES);
2171      int response = dialog.run();      int response = dialog.run();
2172      dialog.hide();      dialog.hide();
# Line 973  bool MainWindow::leaving_shared_mode_dia Line 2197  bool MainWindow::leaving_shared_mode_dia
2197            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
2198            "load it."));            "load it."));
2199      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2200    #if HAS_GTKMM_STOCK
2201      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      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);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2206      int response = dialog.run();      int response = dialog.run();
2207      dialog.hide();      dialog.hide();
# Line 987  void MainWindow::on_action_file_open() Line 2215  void MainWindow::on_action_file_open()
2215      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
2216    
2217      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
2218    #if HAS_GTKMM_STOCK
2219      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2220      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      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);      dialog.set_default_response(Gtk::RESPONSE_OK);
2226  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2227      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1004  void MainWindow::on_action_file_open() Line 2237  void MainWindow::on_action_file_open()
2237      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2238          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
2239          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
2240          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
2241                   static_cast<void*>(Glib::Threads::Thread::self()));
2242          load_file(filename.c_str());          load_file(filename.c_str());
2243          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
2244      }      }
# Line 1019  void MainWindow::load_file(const char* n Line 2253  void MainWindow::load_file(const char* n
2253          Glib::filename_display_basename(name) + "' ...",          Glib::filename_display_basename(name) + "' ...",
2254          *this          *this
2255      );      );
2256    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2257      progress_dialog->show_all();      progress_dialog->show_all();
2258    #endif
2259      loader = new Loader(name); //FIXME: memory leak!      loader = new Loader(name); //FIXME: memory leak!
2260      loader->signal_progress().connect(      loader->signal_progress().connect(
2261          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
# Line 1053  void MainWindow::load_instrument(gig::In Line 2289  void MainWindow::load_instrument(gig::In
2289              // make sure the selected item in the "instruments" tree view is              // make sure the selected item in the "instruments" tree view is
2290              // visible (scroll to it)              // visible (scroll to it)
2291              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2292    #if !USE_GTKMM_BUILDER
2293              // select item in instrument menu              // select item in instrument menu
2294              {              {
2295                  const std::vector<Gtk::Widget*> children =                  const std::vector<Gtk::Widget*> children =
2296                      instrument_menu->get_children();                      instrument_menu->get_children();
2297                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2298              }              }
2299    #endif
2300              // update region chooser and dimension region chooser              // update region chooser and dimension region chooser
2301              m_RegionChooser.set_instrument(instr);              m_RegionChooser.set_instrument(instr);
2302              break;              break;
# Line 1074  void MainWindow::on_loader_progress() Line 2312  void MainWindow::on_loader_progress()
2312  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
2313  {  {
2314      printf("Loader finished!\n");      printf("Loader finished!\n");
2315      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
2316               static_cast<void*>(Glib::Threads::Thread::self()));
2317      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
2318      progress_dialog->hide();      progress_dialog->hide();
2319  }  }
# Line 1129  bool MainWindow::file_save() Line 2368  bool MainWindow::file_save()
2368          Glib::filename_display_basename(this->filename) + "' ...",          Glib::filename_display_basename(this->filename) + "' ...",
2369          *this          *this
2370      );      );
2371    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2372      progress_dialog->show_all();      progress_dialog->show_all();
2373    #endif
2374      saver = new Saver(this->file); //FIXME: memory leak!      saver = new Saver(this->file); //FIXME: memory leak!
2375      saver->signal_progress().connect(      saver->signal_progress().connect(
2376          sigc::mem_fun(*this, &MainWindow::on_saver_progress));          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 1182  void MainWindow::on_action_file_save_as( Line 2423  void MainWindow::on_action_file_save_as(
2423  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
2424  {  {
2425      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      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);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2428      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      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);      dialog.set_default_response(Gtk::RESPONSE_OK);
2434      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
2435    
# Line 1212  bool MainWindow::file_save_as() Line 2458  bool MainWindow::file_save_as()
2458      }      }
2459    
2460      // show warning in the dialog      // show warning in the dialog
2461      Gtk::HBox descriptionArea;      HBox descriptionArea;
2462      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
2463      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      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);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2467  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2468      view::WrapLabel description;      view::WrapLabel description;
# Line 1231  bool MainWindow::file_save_as() Line 2479  bool MainWindow::file_save_as()
2479            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
2480      );      );
2481      descriptionArea.pack_start(description);      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);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2486    #endif
2487    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2488      descriptionArea.show_all();      descriptionArea.show_all();
2489    #endif
2490    
2491      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2492          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
# Line 1246  bool MainWindow::file_save_as() Line 2500  bool MainWindow::file_save_as()
2500              Glib::filename_display_basename(filename) + "' ...",              Glib::filename_display_basename(filename) + "' ...",
2501              *this              *this
2502          );          );
2503    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2504          progress_dialog->show_all();          progress_dialog->show_all();
2505    #endif
2506    
2507          saver = new Saver(file, filename); //FIXME: memory leak!          saver = new Saver(file, filename); //FIXME: memory leak!
2508          saver->signal_progress().connect(          saver->signal_progress().connect(
# Line 1266  bool MainWindow::file_save_as() Line 2522  bool MainWindow::file_save_as()
2522  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
2523      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
2524      Glib::ustring error_files;      Glib::ustring error_files;
2525      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2526      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2527           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
2528          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
2529          SF_INFO info;          SF_INFO info;
2530          info.format = 0;          info.format = 0;
2531          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2532          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2533          try {          try {
2534              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1295  void MainWindow::__import_queued_samples Line 2551  void MainWindow::__import_queued_samples
2551                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      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;              const int bufsize = 10000;
2558              switch (bitdepth) {              switch (bitdepth) {
2559                  case 16: {                  case 16: {
# Line 1304  void MainWindow::__import_queued_samples Line 2563  void MainWindow::__import_queued_samples
2563                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
2564                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
2565                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
2566                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
2567                          cnt -= n;                          cnt -= n;
2568                      }                      }
2569                      delete[] buffer;                      delete[] buffer;
# Line 1324  void MainWindow::__import_queued_samples Line 2583  void MainWindow::__import_queued_samples
2583                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
2584                          }                          }
2585                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
2586                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
2587                          cnt -= n;                          cnt -= n;
2588                      }                      }
2589                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1335  void MainWindow::__import_queued_samples Line 2594  void MainWindow::__import_queued_samples
2594              // cleanup              // cleanup
2595              sf_close(hFile);              sf_close(hFile);
2596              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
2597              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
2598              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
2599              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
2600              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2601              ++iter;              ++iter;
2602              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
2603          } catch (std::string what) {          } catch (std::string what) {
2604              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
2605              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
2606              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
2607              ++iter;              ++iter;
2608          }          }
2609      }      }
# Line 1367  void MainWindow::on_action_warn_user_on_ Line 2626  void MainWindow::on_action_warn_user_on_
2626          !Settings::singleton()->warnUserOnExtensions;          !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() {  void MainWindow::on_action_sync_sampler_instrument_selection() {
2654      Settings::singleton()->syncSamplerInstrumentSelection =      Settings::singleton()->syncSamplerInstrumentSelection =
2655          !Settings::singleton()->syncSamplerInstrumentSelection;          !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()  void MainWindow::on_action_help_about()
2664  {  {
2665      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1381  void MainWindow::on_action_help_about() Line 2669  void MainWindow::on_action_help_about()
2669      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
2670  #endif  #endif
2671      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2672      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2673      const std::string sComment =      const std::string sComment =
2674          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
2675          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1397  void MainWindow::on_action_help_about() Line 2685  void MainWindow::on_action_help_about()
2685      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
2686      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
2687      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
2688        dialog.set_position(Gtk::WIN_POS_CENTER);
2689      dialog.run();      dialog.run();
2690  }  }
2691    
# Line 1418  PropDialog::PropDialog() Line 2707  PropDialog::PropDialog()
2707        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
2708        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
2709        eSubject(_("Subject")),        eSubject(_("Subject")),
2710    #if HAS_GTKMM_STOCK
2711        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
2712    #else
2713          quitButton(_("_Close")),
2714    #endif
2715        table(2, 1),        table(2, 1),
2716        m_file(NULL)        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"));      set_title(_("File Properties"));
2724      eName.set_width_chars(50);      eName.set_width_chars(50);
2725    
# Line 1460  PropDialog::PropDialog() Line 2758  PropDialog::PropDialog()
2758      table.add(eCommissioned);      table.add(eCommissioned);
2759      table.add(eSubject);      table.add(eSubject);
2760    
2761    #if USE_GTKMM_GRID
2762        table.set_column_spacing(5);
2763    #else
2764      table.set_col_spacings(5);      table.set_col_spacings(5);
2765    #endif
2766    
2767      add(vbox);      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);      table.set_border_width(5);
2772    #endif
2773      vbox.add(table);      vbox.add(table);
2774      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2775      buttonBox.set_layout(Gtk::BUTTONBOX_END);      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);      buttonBox.set_border_width(5);
2780    #endif
2781      buttonBox.show();      buttonBox.show();
2782      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2783      quitButton.set_can_default();      quitButton.set_can_default();
# Line 1478  PropDialog::PropDialog() Line 2789  PropDialog::PropDialog()
2789    
2790      quitButton.show();      quitButton.show();
2791      vbox.show();      vbox.show();
2792    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2793      show_all_children();      show_all_children();
2794    #endif
2795  }  }
2796    
2797  void PropDialog::set_file(gig::File* file)  void PropDialog::set_file(gig::File* file)
# Line 1491  void PropDialog::set_file(gig::File* fil Line 2804  void PropDialog::set_file(gig::File* fil
2804      std::vector<std::string> txts;      std::vector<std::string> txts;
2805      std::vector<int> values;      std::vector<int> values;
2806      txts.push_back(sGiga + "2"); values.push_back(2);      txts.push_back(sGiga + "2"); values.push_back(2);
2807      txts.push_back(sGiga + "3/v4"); values.push_back(3);      txts.push_back(sGiga + "3"); values.push_back(3);
2808      if (major != 2 && major != 3) {      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);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
2811      }      }
2812      std::vector<const char*> texts;      std::vector<const char*> texts;
# Line 1541  void InstrumentProps::set_MIDIProgram(ui Line 2855  void InstrumentProps::set_MIDIProgram(ui
2855  }  }
2856    
2857  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
2858    #if HAS_GTKMM_STOCK
2859      quitButton(Gtk::Stock::CLOSE),      quitButton(Gtk::Stock::CLOSE),
2860    #else
2861        quitButton(_("_Close")),
2862    #endif
2863      table(2,1),      table(2,1),
2864      eName(_("Name")),      eName(_("Name")),
2865      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1551  InstrumentProps::InstrumentProps() : Line 2869  InstrumentProps::InstrumentProps() :
2869      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2870      eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
2871      eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
2872      ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 48),
2873      ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
2874      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2875      eDimensionKeyRangeHigh(_("Keyswitching range high"))      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"));      set_title(_("Instrument Properties"));
2883    
2884      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1582  InstrumentProps::InstrumentProps() : Line 2905  InstrumentProps::InstrumentProps() :
2905    
2906      eName.signal_value_changed().connect(sig_name_changed.make_slot());      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);      table.set_col_spacings(5);
2912    #endif
2913    
2914      table.add(eName);      table.add(eName);
2915      table.add(eIsDrum);      table.add(eIsDrum);
# Line 1598  InstrumentProps::InstrumentProps() : Line 2925  InstrumentProps::InstrumentProps() :
2925      table.add(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
2926    
2927      add(vbox);      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);      table.set_border_width(5);
2932    #endif
2933      vbox.pack_start(table);      vbox.pack_start(table);
2934      table.show();      table.show();
2935      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2936      buttonBox.set_layout(Gtk::BUTTONBOX_END);      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);      buttonBox.set_border_width(5);
2941    #endif
2942      buttonBox.show();      buttonBox.show();
2943      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2944      quitButton.set_can_default();      quitButton.set_can_default();
# Line 1614  InstrumentProps::InstrumentProps() : Line 2949  InstrumentProps::InstrumentProps() :
2949    
2950      quitButton.show();      quitButton.show();
2951      vbox.show();      vbox.show();
2952    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2953      show_all_children();      show_all_children();
2954    #endif
2955  }  }
2956    
2957  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
# Line 1659  void MainWindow::updateSampleRefCountMap Line 2996  void MainWindow::updateSampleRefCountMap
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        m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter);
3002        Gtk::TreeModel::Path path(iter);
3003        Gtk::TreeModel::Row row = *iter;
3004        Gtk::TreeViewColumn* pointedColumn = NULL;
3005        // resolve the precise table column the mouse points to
3006        {
3007            Gtk::TreeModel::Path path; // unused
3008            int cellX, cellY; // unused
3009            m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
3010        }
3011        Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
3012        if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
3013            // show the script(s) assigned to the hovered instrument as tooltip
3014            tooltip->set_markup( row[m_Columns.m_col_tooltip] );
3015            m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
3016        } else {
3017            // if beginners' tooltips is disabled then don't show the following one
3018            if (!Settings::singleton()->showTooltips)
3019                return false;
3020            // yeah, a beginners tooltip
3021            tooltip->set_text(_(
3022                "Right click here for actions on instruments & MIDI Rules. "
3023                "Drag & drop to change the order of instruments."
3024            ));
3025            m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
3026        }
3027        return true;
3028    }
3029    
3030    static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
3031        Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3032        const int iScriptSlots = instrument->ScriptSlotCount();
3033        Glib::ustring tooltip = "<u>(" + ToString(index) + ") „"  + name + "”</u>\n\n";
3034        if (!iScriptSlots)
3035            tooltip += "<span foreground='red'><i>No script assigned</i></span>";
3036        else {
3037            for (int i = 0; i < iScriptSlots; ++i) {
3038                tooltip += "• " + ToString(i+1) + ". Script:  „<span foreground='#46DEFF'><b>" +
3039                           instrument->GetScriptOfSlot(i)->Name + "</b></span>”";
3040                if (i + 1 < iScriptSlots) tooltip += "\n\n";
3041            }
3042        }
3043        return tooltip;
3044    }
3045    
3046  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
3047  {  {
3048      file = 0;      file = 0;
3049      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
3050    
3051      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
3052            (filename && strlen(filename) > 0) ?
3053                filename : (!gig->GetFileName().empty()) ?
3054                    gig->GetFileName() : _("Unsaved Gig File");
3055      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
3056      file_has_name = filename;      file_has_name = filename;
3057      file_is_changed = false;      file_is_changed = false;
# Line 1673  void MainWindow::load_gig(gig::File* gig Line 3060  void MainWindow::load_gig(gig::File* gig
3060      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
3061    
3062      instrument_name_connection.block();      instrument_name_connection.block();
3063        int index = 0;
3064      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
3065           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
3066          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3067            const int iScriptSlots = instrument->ScriptSlotCount();
3068    
3069          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
3070          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
3071            row[m_Columns.m_col_nr] = index;
3072          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
3073          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
3074            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3075            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3076    
3077    #if !USE_GTKMM_BUILDER
3078          add_instrument_to_menu(name);          add_instrument_to_menu(name);
3079    #endif
3080      }      }
3081      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3082    #if !USE_GTKMM_BUILDER
3083      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
3084    #endif
3085    
3086      updateSampleRefCountMap(gig);      updateSampleRefCountMap(gig);
3087    
# Line 1751  bool MainWindow::instr_props_set_instrum Line 3147  bool MainWindow::instr_props_set_instrum
3147  {  {
3148      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
3149    
3150      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3151          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
3152            instrumentProps.hide();
3153            return false;
3154        }
3155        //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3156        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3157      if (it) {      if (it) {
3158          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3159          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1769  bool MainWindow::instr_props_set_instrum Line 3170  bool MainWindow::instr_props_set_instrum
3170      } else {      } else {
3171          instrumentProps.hide();          instrumentProps.hide();
3172      }      }
3173      return it;      //NOTE: explicit boolean cast required for GTKMM4 development branch here
3174        return it ? true : false;
3175  }  }
3176    
3177  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
# Line 1788  void MainWindow::instr_name_changed_by_i Line 3190  void MainWindow::instr_name_changed_by_i
3190      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3191      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3192      if (gigname != name) {      if (gigname != name) {
3193            Gtk::TreeModel::Path path(*it);
3194            const int index = path[0];
3195          row[m_Columns.m_col_name] = gigname;          row[m_Columns.m_col_name] = gigname;
3196            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3197      }      }
3198  }  }
3199    
# Line 1805  void MainWindow::show_midi_rules() Line 3210  void MainWindow::show_midi_rules()
3210  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
3211      if (!file) return;      if (!file) return;
3212      // get selected instrument      // get selected instrument
3213      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3214      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
3215        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3216      if (!it) return;      if (!it) return;
3217      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3218      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1814  void MainWindow::show_script_slots() { Line 3220  void MainWindow::show_script_slots() {
3220    
3221      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
3222      window->setInstrument(instrument);      window->setInstrument(instrument);
3223        window->signal_script_slots_changed().connect(
3224            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3225        );
3226      //window->reparent(*this);      //window->reparent(*this);
3227      window->show();      window->show();
3228  }  }
3229    
3230    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3231        if (!pInstrument) return;
3232        const int iScriptSlots = pInstrument->ScriptSlotCount();
3233    
3234        //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!
3235        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3236        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3237    
3238        for (int i = 0; i < model->children().size(); ++i) {
3239            Gtk::TreeModel::Row row = model->children()[i];
3240            if (row[m_Columns.m_col_instr] != pInstrument) continue;
3241            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3242            row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3243            break;
3244        }
3245    
3246        // causes the sampler to reload the instrument with the new script
3247        on_sel_change();
3248    }
3249    
3250    void MainWindow::assignScript(gig::Script* pScript) {
3251        if (!pScript) {
3252            printf("assignScript() : !script\n");
3253            return;
3254        }
3255        printf("assignScript('%s')\n", pScript->Name.c_str());
3256    
3257        gig::Instrument* pInstrument = get_instrument();
3258        if (!pInstrument) {
3259            printf("!instrument\n");
3260            return;
3261        }
3262    
3263        pInstrument->AddScriptSlot(pScript);
3264    
3265        onScriptSlotsModified(pInstrument);
3266    }
3267    
3268    void MainWindow::dropAllScriptSlots() {
3269        gig::Instrument* pInstrument = get_instrument();
3270        if (!pInstrument) {
3271            printf("!instrument\n");
3272            return;
3273        }
3274    
3275        const int iScriptSlots = pInstrument->ScriptSlotCount();
3276        for (int i = iScriptSlots - 1; i >= 0; --i)
3277            pInstrument->RemoveScriptSlot(i);
3278    
3279        onScriptSlotsModified(pInstrument);
3280    }
3281    
3282    void MainWindow::on_action_refresh_all() {
3283        __refreshEntireGUI();
3284    }
3285    
3286  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
3287    #if USE_GLIB_ACTION
3288        bool active = false;
3289        m_actionToggleStatusBar->get_state(active);
3290        // for some reason toggle state does not change automatically
3291        active = !active;
3292        m_actionToggleStatusBar->change_state(active);
3293        if (active)
3294            m_StatusBar.show();
3295        else
3296            m_StatusBar.hide();
3297    #else
3298      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3299          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3300      if (!item) {      if (!item) {
# Line 1827  void MainWindow::on_action_view_status_b Line 3303  void MainWindow::on_action_view_status_b
3303      }      }
3304      if (item->get_active()) m_StatusBar.show();      if (item->get_active()) m_StatusBar.show();
3305      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
3306    #endif
3307    }
3308    
3309    void MainWindow::on_auto_restore_win_dim() {
3310    #if USE_GLIB_ACTION
3311        bool active = false;
3312        m_actionToggleRestoreWinDim->get_state(active);
3313        // for some reason toggle state does not change automatically
3314        active = !active;
3315        m_actionToggleRestoreWinDim->change_state(active);
3316        Settings::singleton()->autoRestoreWindowDimension = active;
3317    #else
3318        Gtk::CheckMenuItem* item =
3319            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3320        if (!item) {
3321            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
3322            return;
3323        }
3324        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3325    #endif
3326    }
3327    
3328    void MainWindow::on_save_with_temporary_file() {
3329    #if USE_GLIB_ACTION
3330        bool active = false;
3331        m_actionToggleSaveWithTempFile->get_state(active);
3332        // for some reason toggle state does not change automatically
3333        active = !active;
3334        m_actionToggleSaveWithTempFile->change_state(active);
3335        Settings::singleton()->saveWithTemporaryFile = active;
3336    #else
3337        Gtk::CheckMenuItem* item =
3338            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3339        if (!item) {
3340            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
3341            return;
3342        }
3343        Settings::singleton()->saveWithTemporaryFile = item->get_active();
3344    #endif
3345  }  }
3346    
3347  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
3348    #if USE_GLIB_ACTION
3349        bool active = false;
3350        m_actionToggleCopySampleUnity->get_state(active);
3351        return active;
3352    #else
3353      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3354          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3355      if (!item) {      if (!item) {
# Line 1837  bool MainWindow::is_copy_samples_unity_n Line 3357  bool MainWindow::is_copy_samples_unity_n
3357          return true;          return true;
3358      }      }
3359      return item->get_active();      return item->get_active();
3360    #endif
3361  }  }
3362    
3363  bool MainWindow::is_copy_samples_fine_tune_enabled() const {  bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3364    #if USE_GLIB_ACTION
3365        bool active = false;
3366        m_actionToggleCopySampleTune->get_state(active);
3367        return active;
3368    #else
3369      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3370          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3371      if (!item) {      if (!item) {
# Line 1847  bool MainWindow::is_copy_samples_fine_tu Line 3373  bool MainWindow::is_copy_samples_fine_tu
3373          return true;          return true;
3374      }      }
3375      return item->get_active();      return item->get_active();
3376    #endif
3377  }  }
3378    
3379  bool MainWindow::is_copy_samples_loop_enabled() const {  bool MainWindow::is_copy_samples_loop_enabled() const {
3380    #if USE_GLIB_ACTION
3381        bool active = false;
3382        m_actionToggleCopySampleLoop->get_state(active);
3383        return active;
3384    #else
3385      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3386          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3387      if (!item) {      if (!item) {
# Line 1857  bool MainWindow::is_copy_samples_loop_en Line 3389  bool MainWindow::is_copy_samples_loop_en
3389          return true;          return true;
3390      }      }
3391      return item->get_active();      return item->get_active();
3392    #endif
3393  }  }
3394    
3395  void MainWindow::on_button_release(GdkEventButton* button)  #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
3396  {  bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3397        GdkEventButton* button = _button.gobj();
3398    #else
3399    void MainWindow::on_button_release(GdkEventButton* button) {
3400    #endif
3401      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3402          show_instr_props();          show_instr_props();
3403      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3404          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3405          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3406    #if USE_GTKMM_BUILDER
3407            m_actionMIDIRules->property_enabled() = bEnabled;
3408    #else
3409          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
3410              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3411                  bEnabled                  bEnabled
# Line 1874  void MainWindow::on_button_release(GdkEv Line 3414  void MainWindow::on_button_release(GdkEv
3414              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3415                  bEnabled                  bEnabled
3416              );              );
3417    #endif
3418          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
3419      }      }
3420    #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
3421        return false;
3422    #endif
3423  }  }
3424    
3425    #if !USE_GTKMM_BUILDER
3426  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3427      if (item->get_active()) {      if (item->get_active()) {
3428          const std::vector<Gtk::Widget*> children =          const std::vector<Gtk::Widget*> children =
# Line 1892  void MainWindow::on_instrument_selection Line 3437  void MainWindow::on_instrument_selection
3437          }          }
3438      }      }
3439  }  }
3440    #endif
3441    
3442    void MainWindow::select_instrument(gig::Instrument* instrument) {
3443        if (!instrument) return;
3444    
3445        //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!
3446        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3447        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3448    
3449        for (int i = 0; i < model->children().size(); ++i) {
3450            Gtk::TreeModel::Row row = model->children()[i];
3451            if (row[m_Columns.m_col_instr] == instrument) {
3452                // select and show the respective instrument in the list view
3453                show_intruments_tab();
3454                m_TreeView.get_selection()->unselect_all();
3455                
3456    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3457                auto iterSel = model->children()[i].get_iter();
3458                m_TreeView.get_selection()->select(iterSel);
3459    #else
3460                m_TreeView.get_selection()->select(model->children()[i]);
3461    #endif
3462                std::vector<Gtk::TreeModel::Path> rows =
3463                    m_TreeView.get_selection()->get_selected_rows();
3464                if (!rows.empty())
3465                    m_TreeView.scroll_to_row(rows[0]);
3466                on_sel_change(); // the regular instrument selection change callback
3467            }
3468        }
3469    }
3470    
3471  /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.  /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
3472  bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {  bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
3473      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3474      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3475    
3476        //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!
3477      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3478        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3479    
3480      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
3481          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3482          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
3483              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
3484              show_intruments_tab();              show_intruments_tab();
3485                m_TreeView.get_selection()->unselect_all();
3486    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3487                auto iterSel = model->children()[i].get_iter();
3488                m_TreeView.get_selection()->select(iterSel);
3489    #else
3490              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
3491              Gtk::TreePath path(  #endif
3492                  m_TreeView.get_selection()->get_selected()              std::vector<Gtk::TreeModel::Path> rows =
3493              );                  m_TreeView.get_selection()->get_selected_rows();
3494              m_TreeView.scroll_to_row(path);              if (!rows.empty())
3495                    m_TreeView.scroll_to_row(rows[0]);
3496              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
3497    
3498              // select respective region in the region selector              // select respective region in the region selector
# Line 1934  void MainWindow::select_sample(gig::Samp Line 3518  void MainWindow::select_sample(gig::Samp
3518              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3519              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3520                  show_samples_tab();                  show_samples_tab();
3521                    m_TreeViewSamples.get_selection()->unselect_all();
3522    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3523                    auto iterSel = rowGroup.children()[s].get_iter();
3524                    m_TreeViewSamples.get_selection()->select(iterSel);
3525    #else
3526                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3527                  Gtk::TreePath path(  #endif
3528                      m_TreeViewSamples.get_selection()->get_selected()                  std::vector<Gtk::TreeModel::Path> rows =
3529                  );                      m_TreeViewSamples.get_selection()->get_selected_rows();
3530                  m_TreeViewSamples.scroll_to_row(path);                  if (rows.empty()) return;
3531                    m_TreeViewSamples.scroll_to_row(rows[0]);
3532                  return;                  return;
3533              }              }
3534          }          }
3535      }      }
3536  }  }
3537    
3538    #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
3539    bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3540        GdkEventButton* button = _button.gobj();
3541    #else
3542  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3543    #endif
3544      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3545            // by default if Ctrl keys is pressed down, then a mouse right-click
3546            // does not select the respective row, so we must assure this
3547            // programmatically ...
3548            /*{
3549                Gtk::TreeModel::Path path;
3550                Gtk::TreeViewColumn* pColumn = NULL;
3551                int cellX, cellY;
3552                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
3553                    (int)button->x, (int)button->y,
3554                    path, pColumn, cellX, cellY
3555                );
3556                if (bSuccess) {
3557                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
3558                        printf("not selected !!!\n");
3559                        m_TreeViewSamples.get_selection()->select(path);
3560                    }
3561                }
3562            }*/
3563    
3564    #if !USE_GTKMM_BUILDER
3565          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
3566              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
3567    #endif
3568    
3569          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3570          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3571          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3572          bool group_selected  = false;          const int n = rows.size();
3573          bool sample_selected = false;          int nGroups  = 0;
3574          if (it) {          int nSamples = 0;
3575            for (int r = 0; r < n; ++r) {
3576                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3577                if (!it) continue;
3578              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
3579              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
3580              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
3581          }          }
3582            
3583                #if USE_GTKMM_BUILDER
3584            m_actionSampleProperties->property_enabled() = (n == 1);
3585            m_actionAddSample->property_enabled() = (n);
3586            m_actionAddSampleGroup->property_enabled() = (file);
3587            m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
3588            m_actionRemoveSample->property_enabled() = (n);
3589            m_actionReplaceSample->property_enabled() = (nSamples == 1);
3590    #else
3591          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
3592              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
3593          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
3594              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3595          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
3596              set_sensitive(file);              set_sensitive(file);
3597          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
3598              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
3599          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
3600              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3601    #endif
3602          // show sample popup          // show sample popup
3603          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
3604    
3605    #if !USE_GTKMM_BUILDER
3606          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
3607              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
3608          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
3609              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3610          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
3611              set_sensitive(file);              set_sensitive(file);
3612          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
3613              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
3614          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3615              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3616    #endif
3617      }      }
3618        
3619    #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
3620        return false;
3621    #endif
3622  }  }
3623    
3624    #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
3625    bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3626        GdkEventButton* button = _button.gobj();
3627    #else
3628  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3629    #endif
3630      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3631    #if !USE_GTKMM_BUILDER
3632          Gtk::Menu* script_popup =          Gtk::Menu* script_popup =
3633              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3634    #endif
3635          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3636          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3637          Gtk::TreeModel::iterator it = sel->get_selected();          Gtk::TreeModel::iterator it = sel->get_selected();
# Line 2001  void MainWindow::on_script_treeview_butt Line 3642  void MainWindow::on_script_treeview_butt
3642              group_selected  = row[m_ScriptsModel.m_col_group];              group_selected  = row[m_ScriptsModel.m_col_group];
3643              script_selected = row[m_ScriptsModel.m_col_script];              script_selected = row[m_ScriptsModel.m_col_script];
3644          }          }
3645    #if USE_GTKMM_BUILDER
3646            m_actionAddScript->property_enabled() = (group_selected || script_selected);
3647            m_actionAddScriptGroup->property_enabled() = (file);
3648            m_actionEditScript->property_enabled() = (script_selected);
3649            m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
3650    #else
3651          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
3652              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3653          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
# Line 2009  void MainWindow::on_script_treeview_butt Line 3656  void MainWindow::on_script_treeview_butt
3656              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3657          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3658              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3659    #endif
3660          // show sample popup          // show sample popup
3661          script_popup->popup(button->button, button->time);          script_popup->popup(button->button, button->time);
3662    
3663    #if !USE_GTKMM_BUILDER
3664          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3665              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3666          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
# Line 2020  void MainWindow::on_script_treeview_butt Line 3669  void MainWindow::on_script_treeview_butt
3669              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3670          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3671              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3672    #endif
3673      }      }
3674    #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
3675        return false;
3676    #endif
3677  }  }
3678    
3679    void MainWindow::updateScriptListOfMenu() {
3680        // remove all entries from "Assign Script" menu
3681        {
3682            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
3683            for (int i = 0; i < children.size(); ++i) {
3684                Gtk::Widget* child = children[i];
3685                assign_scripts_menu->remove(*child);
3686                delete child;
3687            }
3688        }
3689    
3690        int iTotalScripts = 0;
3691    
3692        if (!file) goto noScripts;
3693    
3694        // add all configured macros as menu items to the "Macro" menu
3695        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
3696            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
3697            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
3698                gig::Script* pScript = pGroup->GetScript(iScript);
3699                std::string name = pScript->Name;
3700    
3701                Gtk::MenuItem* item = new Gtk::MenuItem(name);
3702                item->signal_activate().connect(
3703                    sigc::bind(
3704                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
3705                    )
3706                );
3707                assign_scripts_menu->append(*item);
3708                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
3709                //item->set_tooltip_text(comment);
3710            }
3711        }
3712    
3713        noScripts:
3714    
3715        // if there are no macros configured at all, then show a dummy entry instead
3716        if (!iTotalScripts) {
3717            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
3718            item->set_sensitive(false);
3719            assign_scripts_menu->append(*item);
3720        }
3721    
3722        // add separator line to menu
3723        assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
3724    
3725        {
3726            Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
3727            item->signal_activate().connect(
3728                sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
3729            );
3730            assign_scripts_menu->append(*item);
3731            item->set_accel_path("<Scripts>/DropAllScriptSlots");
3732        }
3733    
3734    #if HAS_GTKMM_SHOW_ALL_CHILDREN
3735        assign_scripts_menu->show_all_children();
3736    #endif
3737    }
3738    
3739    #if !USE_GTKMM_BUILDER
3740  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
3741      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
3742    
# Line 2046  Gtk::RadioMenuItem* MainWindow::add_inst Line 3760  Gtk::RadioMenuItem* MainWindow::add_inst
3760              item));              item));
3761      return item;      return item;
3762  }  }
3763    #endif
3764    
3765    #if !USE_GTKMM_BUILDER
3766  void MainWindow::remove_instrument_from_menu(int index) {  void MainWindow::remove_instrument_from_menu(int index) {
3767      const std::vector<Gtk::Widget*> children =      const std::vector<Gtk::Widget*> children =
3768          instrument_menu->get_children();          instrument_menu->get_children();
# Line 2054  void MainWindow::remove_instrument_from_ Line 3770  void MainWindow::remove_instrument_from_
3770      instrument_menu->remove(*child);      instrument_menu->remove(*child);
3771      delete child;      delete child;
3772  }  }
3773    #endif
3774    
3775  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
3776      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
# Line 2062  void MainWindow::add_instrument(gig::Ins Line 3779  void MainWindow::add_instrument(gig::Ins
3779      instrument_name_connection.block();      instrument_name_connection.block();
3780      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3781      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
3782        const int index = m_refTreeModel->children().size() - 1;
3783        rowInstr[m_Columns.m_col_nr] = index;
3784      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
3785      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
3786        rowInstr[m_Columns.m_col_scripts] = "";
3787        rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3788      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3789    
3790    #if !USE_GTKMM_BUILDER
3791      add_instrument_to_menu(name);      add_instrument_to_menu(name);
3792    #endif
3793      m_TreeView.get_selection()->select(iterInstr);      select_instrument(instrument);
   
3794      file_changed();      file_changed();
3795  }  }
3796    
# Line 2090  void MainWindow::on_action_duplicate_ins Line 3811  void MainWindow::on_action_duplicate_ins
3811      // retrieve the currently selected instrument      // retrieve the currently selected instrument
3812      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
3813      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3814      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3815      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
3816      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3817      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
3818      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
3819                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
3820      // duplicate the orginal instrument              if (instrOrig) {
3821      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
3822      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
3823          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
3824          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
3825                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
3826    
3827      add_instrument(instrNew);                  add_instrument(instrNew);
3828                }
3829            }
3830        }
3831  }  }
3832    
3833  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2119  void MainWindow::on_action_remove_instru Line 3844  void MainWindow::on_action_remove_instru
3844      }      }
3845    
3846      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3847      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3848      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3849            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3850            if (!it) continue;
3851          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3852          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
3853          try {          try {
# Line 2131  void MainWindow::on_action_remove_instru Line 3858  void MainWindow::on_action_remove_instru
3858              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
3859              file_changed();              file_changed();
3860    
3861    #if !USE_GTKMM_BUILDER
3862              remove_instrument_from_menu(index);              remove_instrument_from_menu(index);
3863    #endif
3864    
3865              // remove row from instruments tree view              // remove row from instruments tree view
3866              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
3867                // update "Nr" column of all instrument rows
3868                {
3869                    int index = 0;
3870                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
3871                         it != m_refTreeModel->children().end(); ++it, ++index)
3872                    {
3873                        Gtk::TreeModel::Row row = *it;
3874                        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3875                        row[m_Columns.m_col_nr] = index;
3876                        row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3877                    }
3878                }
3879    
3880  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3881              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2232  void MainWindow::on_action_edit_script() Line 3973  void MainWindow::on_action_edit_script()
3973      if (!script) return;      if (!script) return;
3974    
3975      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3976        editor->signal_script_to_be_changed.connect(
3977            signal_script_to_be_changed.make_slot()
3978        );
3979        editor->signal_script_changed.connect(
3980            signal_script_changed.make_slot()
3981        );
3982      editor->setScript(script);      editor->setScript(script);
3983      //editor->reparent(*this);      //editor->reparent(*this);
3984      editor->show();      editor->show();
# Line 2297  void MainWindow::on_action_add_group() { Line 4044  void MainWindow::on_action_add_group() {
4044      file_changed();      file_changed();
4045  }  }
4046    
4047    void MainWindow::on_action_replace_sample() {
4048        add_or_replace_sample(true);
4049    }
4050    
4051  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
4052        add_or_replace_sample(false);
4053    }
4054    
4055    void MainWindow::add_or_replace_sample(bool replace) {
4056      if (!file) return;      if (!file) return;
4057      // get selected group  
4058        // get selected group (and probably selected sample)
4059      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4060      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4061        if (rows.empty()) return;
4062        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4063      if (!it) return;      if (!it) return;
4064      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4065        gig::Sample* sample = NULL;
4066      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
4067      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
4068          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
4069          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
4070          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
4071          if (!it) return;          if (!it) return;
4072          row = *it;          if (!replace) row = *it;
4073          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
4074          if (!group) return;          if (!group) return;
4075      }      }
4076        if (replace && !sample) return;
4077    
4078      // show 'browse for file' dialog      // show 'browse for file' dialog
4079      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
4080    #if HAS_GTKMM_STOCK
4081      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4082      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
4083      dialog.set_select_multiple(true);  #else
4084        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4085        dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
4086    #endif
4087        dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
4088    
4089      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
4090  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 2366  void MainWindow::on_action_add_sample() Line 4132  void MainWindow::on_action_add_sample()
4132          for (std::vector<std::string>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
4133               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
4134              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
4135              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file information
4136              SF_INFO info;              SF_INFO info;
4137              info.format = 0;              info.format = 0;
4138              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
# Line 2389  void MainWindow::on_action_add_sample() Line 4155  void MainWindow::on_action_add_sample()
4155                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
4156                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
4157                  }                  }
4158                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
4159                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
4160                  // file name without path                  // file name without path
4161                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
4162                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2441  void MainWindow::on_action_add_sample() Line 4207  void MainWindow::on_action_add_sample()
4207                  // physically when File::Save() is called)                  // physically when File::Save() is called)
4208                  sample->Resize(info.frames);                  sample->Resize(info.frames);
4209                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
4210                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
4211                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
4212                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
4213                  SampleImportItem sched_item;                  SampleImportItem sched_item;
4214                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
4215                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
4216                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
4217                  // add sample to the tree view                  // add sample to the tree view
4218                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
4219                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
4220                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
4221                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
4222                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
4223                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
4224                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
4225                            gig_to_utf8(sample->pInfo->Name);
4226                        rowSample[m_SamplesModel.m_col_sample] = sample;
4227                        rowSample[m_SamplesModel.m_col_group]  = NULL;
4228                    }
4229                  // close sound file                  // close sound file
4230                  sf_close(hFile);                  sf_close(hFile);
4231                  file_changed();                  file_changed();
# Line 2466  void MainWindow::on_action_add_sample() Line 4236  void MainWindow::on_action_add_sample()
4236          }          }
4237          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
4238          if (!error_files.empty()) {          if (!error_files.empty()) {
4239              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
4240                    (replace
4241                        ? _("Failed to replace sample with:\n")
4242                        : _("Could not add the following sample(s):\n"))
4243                    + error_files;
4244              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4245              msg.run();              msg.run();
4246          }          }
# Line 2499  void MainWindow::on_action_replace_all_s Line 4273  void MainWindow::on_action_replace_all_s
4273      Gtk::Label description(str);      Gtk::Label description(str);
4274      description.set_line_wrap();      description.set_line_wrap();
4275  #endif  #endif
4276      Gtk::HBox entryArea;      HBox entryArea;
4277      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4278      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
4279      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
4280      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
4281      entryArea.pack_start(postfixEntryBox);      entryArea.pack_start(postfixEntryBox);
4282    #if USE_GTKMM_BOX
4283        dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4284        dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4285    #else
4286      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4287      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4288    #endif
4289      description.show();      description.show();
4290    
4291    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4292      entryArea.show_all();      entryArea.show_all();
4293    #else
4294        entryArea.show();
4295    #endif
4296    
4297    #if HAS_GTKMM_STOCK
4298      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4299    #else
4300        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4301    #endif
4302      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4303      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
4304      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2533  void MainWindow::on_action_replace_all_s Line 4322  void MainWindow::on_action_replace_all_s
4322              try              try
4323              {              {
4324                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
4325                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
4326                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
4327                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
4328                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
4329                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
4330                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
4331                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
4332                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
4333                          break;                          break;
4334                      default:                      default:
4335                          sf_close(hFile);                          sf_close(hFile);
# Line 2553  void MainWindow::on_action_replace_all_s Line 4338  void MainWindow::on_action_replace_all_s
4338                  SampleImportItem sched_item;                  SampleImportItem sched_item;
4339                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
4340                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
4341                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
4342                  sf_close(hFile);                  sf_close(hFile);
4343                  file_changed();                  file_changed();
4344              }              }
# Line 2577  void MainWindow::on_action_replace_all_s Line 4362  void MainWindow::on_action_replace_all_s
4362  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
4363      if (!file) return;      if (!file) return;
4364      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4365      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4366      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
4367            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4368            if (!it) continue;
4369          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
4370          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
4371          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2603  void MainWindow::on_action_remove_sample Line 4390  void MainWindow::on_action_remove_sample
4390                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
4391                  // them from the import queue                  // them from the import queue
4392                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
4393                       member != members.end(); ++member) {                       member != members.end(); ++member)
4394                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
4395                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
4396                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
4397                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
4398                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
4399                      }                      }
4400                  }                  }
4401                  file_changed();                  file_changed();
# Line 2626  void MainWindow::on_action_remove_sample Line 4410  void MainWindow::on_action_remove_sample
4410                  samples_removed_signal.emit();                  samples_removed_signal.emit();
4411                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
4412                  // the import queue                  // the import queue
4413                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
4414                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
4415                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
4416                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
4417                  }                  }
4418                  dimreg_changed();                  dimreg_changed();
4419                  file_changed();                  file_changed();
# Line 2650  void MainWindow::on_action_remove_sample Line 4430  void MainWindow::on_action_remove_sample
4430      }      }
4431  }  }
4432    
4433    void MainWindow::on_action_remove_unused_samples() {
4434        if (!file) return;
4435    
4436        // collect all samples that are not referenced by any instrument
4437        std::list<gig::Sample*> lsamples;
4438        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
4439            gig::Sample* sample = file->GetSample(iSample);
4440            bool isUsed = false;
4441            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
4442                                  instrument = file->GetNextInstrument())
4443            {
4444                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
4445                                  rgn = instrument->GetNextRegion())
4446                {
4447                    for (int i = 0; i < 256; ++i) {
4448                        if (!rgn->pDimensionRegions[i]) continue;
4449                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
4450                        isUsed = true;
4451                        goto endOfRefSearch;
4452                    }
4453                }
4454            }
4455            endOfRefSearch:
4456            if (!isUsed) lsamples.push_back(sample);
4457        }
4458    
4459        if (lsamples.empty()) return;
4460    
4461        // notify everybody that we're going to remove these samples
4462        samples_to_be_removed_signal.emit(lsamples);
4463    
4464        // remove collected samples
4465        try {
4466            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
4467                 itSample != lsamples.end(); ++itSample)
4468            {
4469                gig::Sample* sample = *itSample;
4470                // remove sample from the .gig file
4471                file->DeleteSample(sample);
4472                // if sample was just previously added, remove it from the import queue
4473                if (m_SampleImportQueue.count(sample)) {
4474                    printf("Removing previously added sample '%s'\n",
4475                           m_SampleImportQueue[sample].sample_path.c_str());
4476                    m_SampleImportQueue.erase(sample);
4477                }
4478            }
4479        } catch (RIFF::Exception e) {
4480            // show error message
4481            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4482            msg.run();
4483        }
4484    
4485        // notify everybody that we're done with removal
4486        samples_removed_signal.emit();
4487    
4488        dimreg_changed();
4489        file_changed();
4490        __refreshEntireGUI();
4491    }
4492    
4493  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
4494  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4495  {  {
# Line 2676  void MainWindow::on_scripts_treeview_dra Line 4516  void MainWindow::on_scripts_treeview_dra
4516                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
4517  }  }
4518    
4519    // see comment on on_sample_treeview_drag_begin()
4520    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4521    {
4522        first_call_to_drag_data_get = true;
4523    }
4524    
4525    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4526                                                           Gtk::SelectionData& selection_data, guint, guint)
4527    {
4528        if (!first_call_to_drag_data_get) return;
4529        first_call_to_drag_data_get = false;
4530    
4531        // get selected source instrument
4532        gig::Instrument* src = NULL;
4533        {
4534            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4535            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4536            if (!rows.empty()) {
4537                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
4538                if (it) {
4539                    Gtk::TreeModel::Row row = *it;
4540                    src = row[m_Columns.m_col_instr];
4541                }
4542            }
4543        }
4544        if (!src) return;
4545    
4546        // pass the source gig::Instrument as pointer
4547        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
4548                           sizeof(src)/*length of data in bytes*/);
4549    }
4550    
4551    void MainWindow::on_instruments_treeview_drop_drag_data_received(
4552        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
4553        const Gtk::SelectionData& selection_data, guint, guint time)
4554    {
4555        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
4556        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
4557            return;
4558    
4559        gig::Instrument* dst = NULL;
4560        {
4561            Gtk::TreeModel::Path path;
4562            const bool found = m_TreeView.get_path_at_pos(x, y, path);
4563            if (!found) return;
4564    
4565            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
4566            if (!iter) return;
4567            Gtk::TreeModel::Row row = *iter;
4568            dst = row[m_Columns.m_col_instr];
4569        }
4570        if (!dst) return;
4571    
4572        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
4573        src->MoveTo(dst);
4574        __refreshEntireGUI();
4575        select_instrument(src);
4576    }
4577    
4578  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
4579  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
4580  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2694  void MainWindow::on_sample_treeview_drag Line 4593  void MainWindow::on_sample_treeview_drag
4593      // get selected sample      // get selected sample
4594      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
4595      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4596      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4597      if (it) {      if (!rows.empty()) {
4598          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4599          sample = row[m_SamplesModel.m_col_sample];          if (it) {
4600                Gtk::TreeModel::Row row = *it;
4601                sample = row[m_SamplesModel.m_col_sample];
4602            }
4603      }      }
4604      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
4605      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 2837  void MainWindow::script_double_clicked(c Line 4739  void MainWindow::script_double_clicked(c
4739      if (!script) return;      if (!script) return;
4740    
4741      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
4742        editor->signal_script_to_be_changed.connect(
4743            signal_script_to_be_changed.make_slot()
4744        );
4745        editor->signal_script_changed.connect(
4746            signal_script_changed.make_slot()
4747        );
4748      editor->setScript(script);      editor->setScript(script);
4749      //editor->reparent(*this);      //editor->reparent(*this);
4750      editor->show();      editor->show();
# Line 2848  void MainWindow::instrument_name_changed Line 4756  void MainWindow::instrument_name_changed
4756      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
4757      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
4758    
4759    #if !USE_GTKMM_BUILDER
4760      // change name in instrument menu      // change name in instrument menu
4761      int index = path[0];      int index = path[0];
4762      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
# Line 2860  void MainWindow::instrument_name_changed Line 4769  void MainWindow::instrument_name_changed
4769          item->set_active();          item->set_active();
4770  #endif  #endif
4771      }      }
4772    #endif
4773    
4774      // change name in gig      // change name in gig
4775      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 2876  void MainWindow::instrument_name_changed Line 4786  void MainWindow::instrument_name_changed
4786      }      }
4787  }  }
4788    
4789    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
4790        if (!iter)
4791            return true;
4792    
4793        Glib::ustring pattern = m_searchText.get_text().lowercase();
4794        trim(pattern);
4795        if (pattern.empty()) return true;
4796    
4797    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4798        //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4799        Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4800    #else
4801        Gtk::TreeModel::Row row = *iter;
4802    #endif
4803        Glib::ustring name = row[m_Columns.m_col_name];
4804        name = name.lowercase();
4805    
4806        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
4807        for (int t = 0; t < tokens.size(); ++t)
4808            if (name.find(tokens[t]) == Glib::ustring::npos)
4809                return false;
4810    
4811        return true;
4812    }
4813    
4814  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
4815      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
4816    
4817        // take over selection from instruments list view for the combine dialog's
4818        // list view as pre-selection
4819        std::set<int> indeces;
4820        {
4821            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4822            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4823            for (int r = 0; r < rows.size(); ++r) {
4824                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4825                if (it) {
4826                    Gtk::TreeModel::Row row = *it;
4827                    int index = row[m_Columns.m_col_nr];
4828                    indeces.insert(index);
4829                }
4830            }
4831        }
4832        d->setSelectedInstruments(indeces);
4833    
4834    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4835      d->show_all();      d->show_all();
4836      d->resize(500, 400);  #else
4837        d->show();
4838    #endif
4839      d->run();      d->run();
4840      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
4841          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 2890  void MainWindow::on_action_combine_instr Line 4846  void MainWindow::on_action_combine_instr
4846    
4847  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
4848      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4849      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4850        if (rows.empty()) return;
4851        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4852      if (!it) return;      if (!it) return;
4853      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4854      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2901  void MainWindow::on_action_view_referenc Line 4859  void MainWindow::on_action_view_referenc
4859      d->dimension_region_selected.connect(      d->dimension_region_selected.connect(
4860          sigc::mem_fun(*this, &MainWindow::select_dimension_region)          sigc::mem_fun(*this, &MainWindow::select_dimension_region)
4861      );      );
4862    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4863      d->show_all();      d->show_all();
4864    #else
4865        d->show();
4866    #endif
4867      d->resize(500, 400);      d->resize(500, 400);
4868      d->run();      d->run();
4869      delete d;      delete d;
# Line 2985  void MainWindow::mergeFiles(const std::v Line 4947  void MainWindow::mergeFiles(const std::v
4947              Glib::filename_display_basename(this->filename) + "' ...",              Glib::filename_display_basename(this->filename) + "' ...",
4948              *this              *this
4949          );          );
4950    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4951          progress_dialog->show_all();          progress_dialog->show_all();
4952    #else
4953            progress_dialog->show();
4954    #endif
4955          saver = new Saver(this->file); //FIXME: memory leak!          saver = new Saver(this->file); //FIXME: memory leak!
4956          saver->signal_progress().connect(          saver->signal_progress().connect(
4957              sigc::mem_fun(*this, &MainWindow::on_saver_progress));              sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 3012  void MainWindow::on_action_merge_files() Line 4978  void MainWindow::on_action_merge_files()
4978      }      }
4979    
4980      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4981    #if HAS_GTKMM_STOCK
4982      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4983    #else
4984        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4985    #endif
4986      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
4987      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4988  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 3029  void MainWindow::on_action_merge_files() Line 4999  void MainWindow::on_action_merge_files()
4999      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
5000    
5001      // show warning in the file picker dialog      // show warning in the file picker dialog
5002      Gtk::HBox descriptionArea;      HBox descriptionArea;
5003      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
5004      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
5005        warningIcon.set_from_icon_name("dialog-warning",
5006                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
5007      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
5008  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
5009      view::WrapLabel description;      view::WrapLabel description;
# Line 3050  void MainWindow::on_action_merge_files() Line 5022  void MainWindow::on_action_merge_files()
5022          "will accordingly be stored separately in the target .gig file!"          "will accordingly be stored separately in the target .gig file!"
5023      ));      ));
5024      descriptionArea.pack_start(description);      descriptionArea.pack_start(description);
5025    #if USE_GTKMM_BOX
5026    # warning No description area implemented for dialog on GTKMM 3
5027    #else
5028      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
5029    #endif
5030    #if HAS_GTKMM_SHOW_ALL_CHILDREN
5031      descriptionArea.show_all();      descriptionArea.show_all();
5032    #else
5033        descriptionArea.show();
5034    #endif
5035    
5036      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
5037          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
5038                   static_cast<void*>(Glib::Threads::Thread::self()));
5039          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
5040    
5041          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3066  void MainWindow::on_action_merge_files() Line 5047  void MainWindow::on_action_merge_files()
5047          }          }
5048    
5049          // update GUI          // update GUI
5050          __refreshEntireGUI();                  __refreshEntireGUI();
5051      }      }
5052  }  }
5053    
# Line 3086  void MainWindow::set_file_is_shared(bool Line 5067  void MainWindow::set_file_is_shared(bool
5067      }      }
5068    
5069      {      {
5070    #if USE_GTKMM_BUILDER
5071            m_actionToggleSyncSamplerSelection->property_enabled() = b;
5072    #else
5073          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
5074              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
5075          if (item) item->set_sensitive(b);          if (item) item->set_sensitive(b);
5076    #endif
5077      }      }
5078  }  }
5079    
# Line 3136  void MainWindow::show_scripts_tab() { Line 5121  void MainWindow::show_scripts_tab() {
5121      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
5122  }  }
5123    
5124    void MainWindow::select_instrument_by_dir(int dir) {
5125        if (!file) return;
5126        gig::Instrument* pInstrument = get_instrument();
5127        if (!pInstrument) {
5128            select_instrument( file->GetInstrument(0) );
5129            return;
5130        }
5131        for (int i = 0; file->GetInstrument(i); ++i) {
5132            if (file->GetInstrument(i) == pInstrument) {
5133                select_instrument( file->GetInstrument(i + dir) );
5134                return;
5135            }
5136        }
5137    }
5138    
5139    void MainWindow::select_prev_instrument() {
5140        select_instrument_by_dir(-1);
5141    }
5142    
5143    void MainWindow::select_next_instrument() {
5144        select_instrument_by_dir(1);
5145    }
5146    
5147    void MainWindow::select_prev_region() {
5148        m_RegionChooser.select_prev_region();
5149    }
5150    
5151    void MainWindow::select_next_region() {
5152        m_RegionChooser.select_next_region();
5153    }
5154    
5155    void MainWindow::select_next_dim_rgn_zone() {
5156        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5157        m_DimRegionChooser.select_next_dimzone();
5158    }
5159    
5160    void MainWindow::select_prev_dim_rgn_zone() {
5161        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5162        m_DimRegionChooser.select_prev_dimzone();
5163    }
5164    
5165    void MainWindow::select_add_next_dim_rgn_zone() {
5166        m_DimRegionChooser.select_next_dimzone(true);
5167    }
5168    
5169    void MainWindow::select_add_prev_dim_rgn_zone() {
5170        m_DimRegionChooser.select_prev_dimzone(true);
5171    }
5172    
5173    void MainWindow::select_prev_dimension() {
5174        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5175        m_DimRegionChooser.select_prev_dimension();
5176    }
5177    
5178    void MainWindow::select_next_dimension() {
5179        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5180        m_DimRegionChooser.select_next_dimension();
5181    }
5182    
5183    #define CLIPBOARD_DIMENSIONREGION_TARGET \
5184        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
5185    
5186    void MainWindow::copy_selected_dimrgn() {
5187        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5188        if (!pDimRgn) {
5189            updateClipboardPasteAvailable();
5190            updateClipboardCopyAvailable();
5191            return;
5192        }
5193    
5194        std::vector<Gtk::TargetEntry> targets;
5195        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
5196    
5197        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5198        clipboard->set(
5199            targets,
5200            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
5201            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
5202        );
5203    
5204        m_serializationArchive.serialize(pDimRgn);
5205    
5206        updateClipboardPasteAvailable();
5207    }
5208    
5209    void MainWindow::paste_copied_dimrgn() {
5210        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5211        clipboard->request_contents(
5212            CLIPBOARD_DIMENSIONREGION_TARGET,
5213            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
5214        );
5215        updateClipboardPasteAvailable();
5216    }
5217    
5218    void MainWindow::adjust_clipboard_content() {
5219        MacroEditor* editor = new MacroEditor();
5220        editor->setMacro(&m_serializationArchive, true);
5221        editor->show();
5222    }
5223    
5224    void MainWindow::updateClipboardPasteAvailable() {
5225        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5226        clipboard->request_targets(
5227            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
5228        );
5229    }
5230    
5231    void MainWindow::updateClipboardCopyAvailable() {
5232        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5233    #if USE_GTKMM_BUILDER
5234        m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5235    #else
5236        static_cast<Gtk::MenuItem*>(
5237            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5238        )->set_sensitive(bDimensionRegionCopyIsPossible);
5239    #endif
5240    }
5241    
5242    #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
5243    void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5244    #else
5245    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5246    #endif
5247        updateClipboardPasteAvailable();
5248    }
5249    
5250    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
5251        const std::string target = selection_data.get_target();
5252        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5253            selection_data.set(
5254                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
5255                &m_serializationArchive.rawData()[0],
5256                m_serializationArchive.rawData().size()
5257            );
5258        } else {
5259            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
5260        }
5261    }
5262    
5263    void MainWindow::on_clipboard_clear() {
5264        m_serializationArchive.clear();
5265        updateClipboardPasteAvailable();
5266        updateClipboardCopyAvailable();
5267    }
5268    
5269    //NOTE: Might throw exception !!!
5270    void MainWindow::applyMacro(Serialization::Archive& macro) {
5271        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5272        if (!pDimRgn) return;
5273    
5274        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5275             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5276        {
5277            gig::DimensionRegion* pDimRgn = *itDimReg;
5278            DimRegionChangeGuard(this, pDimRgn);
5279            macro.deserialize(pDimRgn);
5280        }
5281        //region_changed()
5282        file_changed();
5283        dimreg_changed();
5284    }
5285    
5286    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5287        const std::string target = selection_data.get_target();
5288        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5289            Glib::ustring errorText;
5290            try {
5291                m_serializationArchive.decode(
5292                    selection_data.get_data(), selection_data.get_length()
5293                );
5294                applyMacro(m_serializationArchive);
5295            } catch (Serialization::Exception e) {
5296                errorText = e.Message;
5297            } catch (...) {
5298                errorText = _("Unknown exception while pasting DimensionRegion");
5299            }
5300            if (!errorText.empty()) {
5301                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
5302                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5303                msg.run();
5304            }
5305        }
5306    }
5307    
5308    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
5309        const bool bDimensionRegionPasteIsPossible =
5310            std::find(targets.begin(), targets.end(),
5311                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5312    
5313    #if USE_GTKMM_BUILDER
5314        m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5315        m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5316    #else
5317        static_cast<Gtk::MenuItem*>(
5318            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5319        )->set_sensitive(bDimensionRegionPasteIsPossible);
5320    
5321        static_cast<Gtk::MenuItem*>(
5322            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5323        )->set_sensitive(bDimensionRegionPasteIsPossible);
5324    #endif
5325    }
5326    
5327  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
5328      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
5329  }  }

Legend:
Removed from v.2697  
changed lines
  Added in v.3456

  ViewVC Help
Powered by ViewVC