/[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 3144 by schoenebeck, Wed May 3 19:00:11 2017 UTC revision 3470 by persson, Thu Feb 14 19:10:49 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2017 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 <glibmmconfig.h>  #include "compat.h"
24  // threads.h must be included first to be able to build with  // threads.h must be included first to be able to build with
25  // G_DISABLE_DEPRECATED  // G_DISABLE_DEPRECATED
26  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
# Line 32  Line 32 
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    #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 46  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 58  Line 69 
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"  #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),
# Line 73  MainWindow::MainWindow() : Line 96  MainWindow::MainWindow() :
96  {  {
97      loadBuiltInPix();      loadBuiltInPix();
98    
99        this->file = NULL;
100    
101  //    set_border_width(5);  //    set_border_width(5);
102  //    set_default_size(400, 200);  
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 84  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 98  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 113  MainWindow::MainWindow() : Line 161  MainWindow::MainWindow() :
161          legend_hbox.add(labelLegend);          legend_hbox.add(labelLegend);
162    
163          imageNoSample.set(redDot);          imageNoSample.set(redDot);
164    #if HAS_GTKMM_ALIGNMENT
165          imageNoSample.set_alignment(Gtk::ALIGN_END);          imageNoSample.set_alignment(Gtk::ALIGN_END);
166          labelNoSample.set_alignment(Gtk::ALIGN_START);          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);          legend_hbox.add(imageNoSample);
172          legend_hbox.add(labelNoSample);          legend_hbox.add(labelNoSample);
173    
174          imageMissingSample.set(yellowDot);          imageMissingSample.set(yellowDot);
175    #if HAS_GTKMM_ALIGNMENT
176          imageMissingSample.set_alignment(Gtk::ALIGN_END);          imageMissingSample.set_alignment(Gtk::ALIGN_END);
177          labelMissingSample.set_alignment(Gtk::ALIGN_START);          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);          legend_hbox.add(imageMissingSample);
183          legend_hbox.add(labelMissingSample);          legend_hbox.add(labelMissingSample);
184    
185          imageLooped.set(blackLoop);          imageLooped.set(blackLoop);
186    #if HAS_GTKMM_ALIGNMENT
187          imageLooped.set_alignment(Gtk::ALIGN_END);          imageLooped.set_alignment(Gtk::ALIGN_END);
188          labelLooped.set_alignment(Gtk::ALIGN_START);          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);          legend_hbox.add(imageLooped);
194          legend_hbox.add(labelLooped);          legend_hbox.add(labelLooped);
195    
196          imageSomeLoops.set(grayLoop);          imageSomeLoops.set(grayLoop);
197    #if HAS_GTKMM_ALIGNMENT
198          imageSomeLoops.set_alignment(Gtk::ALIGN_END);          imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199          labelSomeLoops.set_alignment(Gtk::ALIGN_START);          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);          legend_hbox.add(imageSomeLoops);
205          legend_hbox.add(labelSomeLoops);          legend_hbox.add(labelSomeLoops);
206    
207    #if HAS_GTKMM_SHOW_ALL_CHILDREN
208          legend_hbox.show_all_children();          legend_hbox.show_all_children();
209    #endif
210      }      }
211      dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
# Line 150  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")));
265      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
266                       sigc::mem_fun(                       sigc::mem_fun(
267                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
268      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
269                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
270        action->property_label() = action->property_label() + "...";
271        actionGroup->add(action,
272                       sigc::mem_fun(                       sigc::mem_fun(
273                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
274      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
275                       sigc::mem_fun(                       sigc::mem_fun(
276                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
277      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
278        action->property_label() = action->property_label() + "...";
279        actionGroup->add(action,
280                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
281                       sigc::mem_fun(                       sigc::mem_fun(
282                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
283      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
284                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
285                       sigc::mem_fun(                       sigc::mem_fun(
286                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
287      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
288                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
289                       sigc::mem_fun(                       sigc::mem_fun(
290                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
291      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 185  MainWindow::MainWindow() : Line 296  MainWindow::MainWindow() :
296                                           _("_Script Slots...")),                                           _("_Script Slots...")),
297                       sigc::mem_fun(                       sigc::mem_fun(
298                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
299      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
300                       sigc::mem_fun(                       sigc::mem_fun(
301                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
302      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 312  MainWindow::MainWindow() :
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 =      const Gdk::ModifierType primaryModifierKey =
321  #if defined(__APPLE__)  #if defined(__APPLE__)
# Line 212  MainWindow::MainWindow() : Line 324  MainWindow::MainWindow() :
324      Gdk::CONTROL_MASK; // Ctrl key on all other OSs      Gdk::CONTROL_MASK; // Ctrl key on all other OSs
325  #endif  #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",      actionGroup->add(Gtk::Action::create("CopyDimRgn",
369                                           _("Copy selected dimension region")),                                           _("Copy selected dimension region")),
370                       Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),                       Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
# Line 222  MainWindow::MainWindow() : Line 375  MainWindow::MainWindow() :
375                       Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),                       Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
376                       sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));                       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",      actionGroup->add(Gtk::Action::create("SelectPrevRegion",
394                                           _("Select Previous Region")),                                           _("Select Previous Region")),
395                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
# Line 261  MainWindow::MainWindow() : Line 429  MainWindow::MainWindow() :
429                                           _("Add Next Dimension Region Zone to Selection")),                                           _("Add Next Dimension Region Zone to Selection")),
430                       Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),                       Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
431                       sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));                       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 276  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    
471      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
# Line 294  MainWindow::MainWindow() : Line 484  MainWindow::MainWindow() :
484                           *this, &MainWindow::on_auto_restore_win_dim));                           *this, &MainWindow::on_auto_restore_win_dim));
485    
486      toggle_action =      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"));          Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
496      toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);      toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
497      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 304  MainWindow::MainWindow() : Line 502  MainWindow::MainWindow() :
502          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
503          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
504      );                      );                
505    #endif
506    
507      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));  #if USE_GLIB_ACTION
508      actionGroup->add(Gtk::Action::create("About", _("_About")),      m_actionGroup->add_action(
509            "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
510        );
511        m_actionGroup->add_action(
512            "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
513        );
514        m_actionGroup->add_action(
515            "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
516        );
517        m_actionGroup->add_action(
518            "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
519        );
520        m_actionGroup->add_action(
521            "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
522        );
523    #else
524        action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
525        actionGroup->add(Gtk::Action::create("MenuHelp",
526                                             action->property_label()));
527        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
528                       sigc::mem_fun(                       sigc::mem_fun(
529                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
530      actionGroup->add(      actionGroup->add(
# Line 318  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("RemoveInstrument", _("_Remove")),          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
540            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
541            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
542        );
543        actionGroup->add(
544            Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
545          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          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 348  MainWindow::MainWindow() : Line 585  MainWindow::MainWindow() :
585          toggle_action,          toggle_action,
586          sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)          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 361  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", _("_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)
641      );      );
642      actionGroup->add(      actionGroup->add(
# Line 377  MainWindow::MainWindow() : Line 648  MainWindow::MainWindow() :
648          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
649      );      );
650      actionGroup->add(      actionGroup->add(
651          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
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(
# Line 398  MainWindow::MainWindow() : Line 669  MainWindow::MainWindow() :
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 413  MainWindow::MainWindow() : Line 699  MainWindow::MainWindow() :
699          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
700      );      );
701      actionGroup->add(      actionGroup->add(
702          Gtk::Action::create("RemoveScript", _("_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 437  MainWindow::MainWindow() : Line 1111  MainWindow::MainWindow() :
1111          "    </menu>"          "    </menu>"
1112          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
1113          "      <menuitem action='CopyDimRgn'/>"          "      <menuitem action='CopyDimRgn'/>"
1114            "      <menuitem action='AdjustClipboard'/>"
1115          "      <menuitem action='PasteDimRgn'/>"          "      <menuitem action='PasteDimRgn'/>"
1116          "      <separator/>"          "      <separator/>"
1117            "      <menuitem action='SelectPrevInstr'/>"
1118            "      <menuitem action='SelectNextInstr'/>"
1119            "      <separator/>"
1120          "      <menuitem action='SelectPrevRegion'/>"          "      <menuitem action='SelectPrevRegion'/>"
1121          "      <menuitem action='SelectNextRegion'/>"          "      <menuitem action='SelectNextRegion'/>"
1122          "      <separator/>"          "      <separator/>"
# Line 453  MainWindow::MainWindow() : Line 1131  MainWindow::MainWindow() :
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'/>"
# Line 471  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 485  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'/>"          "      <menuitem action='AutoRestoreWinDim'/>"
1172          "      <separator/>"          "      <separator/>"
1173          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
# Line 509  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 532  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 552  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 567  MainWindow::MainWindow() : Line 1269  MainWindow::MainWindow() :
1269      {      {
1270          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1271              uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));              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 keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));          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*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
# Line 598  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 614  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 626  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_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);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1359      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      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      );      );
# Line 636  MainWindow::MainWindow() : Line 1367  MainWindow::MainWindow() :
1367      // Add the TreeView's view columns:      // Add the TreeView's view columns:
1368      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1369      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      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);      m_TreeView.set_headers_visible(true);
1372            
1373      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 681  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 700  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 772  MainWindow::MainWindow() : Line 1516  MainWindow::MainWindow() :
1516          sigc::hide(          sigc::hide(
1517              sigc::bind(              sigc::bind(
1518                  file_structure_to_be_changed_signal.make_slot(),                  file_structure_to_be_changed_signal.make_slot(),
1519    #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1520                    std::ref(this->file)
1521    #else
1522                  sigc::ref(this->file)                  sigc::ref(this->file)
1523    #endif
1524              )              )
1525          )          )
1526      );      );
# Line 780  MainWindow::MainWindow() : Line 1528  MainWindow::MainWindow() :
1528          sigc::hide(          sigc::hide(
1529              sigc::bind(              sigc::bind(
1530                  file_structure_changed_signal.make_slot(),                  file_structure_changed_signal.make_slot(),
1531    #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1532                    std::ref(this->file)
1533    #else
1534                  sigc::ref(this->file)                  sigc::ref(this->file)
1535    #endif
1536              )              )
1537          )          )
1538      );      );
# Line 801  MainWindow::MainWindow() : Line 1553  MainWindow::MainWindow() :
1553      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
1554          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
1555    
1556        m_searchText.signal_changed().connect(
1557            sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1558        );
1559    
1560      file = 0;      file = 0;
1561      file_is_changed = false;      file_is_changed = false;
1562    
1563    #if HAS_GTKMM_SHOW_ALL_CHILDREN
1564      show_all_children();      show_all_children();
1565    #endif
1566    
1567      // start with a new gig file by default      // start with a new gig file by default
1568      on_action_file_new();      on_action_file_new();
1569    
1570        m_TreeViewNotebook.signal_switch_page().connect(
1571            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1572        );
1573    
1574      // select 'Instruments' tab by default      // select 'Instruments' tab by default
1575      // (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)
1576      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
# Line 818  MainWindow::MainWindow() : Line 1580  MainWindow::MainWindow() :
1580      );      );
1581      updateClipboardPasteAvailable();      updateClipboardPasteAvailable();
1582      updateClipboardCopyAvailable();      updateClipboardCopyAvailable();
1583    
1584        // setup macros and their keyboard accelerators
1585        {
1586    #if USE_GTKMM_BUILDER
1587            menuMacro = new Gtk::Menu(
1588                Glib::RefPtr<Gio::Menu>::cast_dynamic(
1589                    m_uiManager->get_object("MenuMacro")
1590                )
1591            );
1592    #else
1593            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1594                uiManager->get_widget("/MenuBar/MenuMacro")
1595            )->get_submenu();
1596    #endif
1597    
1598            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1599            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1600            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1601            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1602            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1603            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1604            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1605            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1606            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1607            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1608            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1609            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1610            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1611            Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1612            Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1613            Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1614            Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1615            Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1616            Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1617            Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1618            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1619    
1620            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1621            menuMacro->set_accel_group(accelGroup);
1622    
1623            updateMacroMenu();
1624        }
1625    
1626        // setup "Assign Scripts" keyboard accelerators
1627        {
1628            Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1629            Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1630            Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1631            Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1632            Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1633            Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1634            Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1635            Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1636            Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1637            Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1638            Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1639            Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1640            Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1641            Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1642            Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1643            Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1644            Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1645            Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1646            Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1647            Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1648    
1649            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1650            assign_scripts_menu->set_accel_group(accelGroup);
1651        }
1652    
1653        on_show_tooltips_changed();
1654    
1655        Glib::signal_idle().connect_once(
1656            sigc::mem_fun(*this, &MainWindow::bringToFront),
1657            200
1658        );
1659  }  }
1660    
1661  MainWindow::~MainWindow()  MainWindow::~MainWindow()
1662  {  {
1663  }  }
1664    
1665    void MainWindow::bringToFront() {
1666        #if defined(__APPLE__)
1667        macRaiseAppWindow();
1668        #endif
1669        raise();
1670        present();
1671    }
1672    
1673    void MainWindow::updateMacroMenu() {
1674    #if !USE_GTKMM_BUILDER
1675        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1676            uiManager->get_widget("/MenuBar/MenuMacro")
1677        )->get_submenu();
1678    #endif
1679    
1680        // remove all entries from "Macro" menu
1681        {
1682            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1683            for (int i = 0; i < children.size(); ++i) {
1684                Gtk::Widget* child = children[i];
1685                menuMacro->remove(*child);
1686                delete child;
1687            }
1688        }
1689    
1690        // (re)load all macros from config file
1691        try {
1692            Settings::singleton()->loadMacros(m_macros);
1693        } catch (Serialization::Exception e) {
1694            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1695        } catch (...) {
1696            std::cerr << "Unknown exception while loading macros!" << std::endl;
1697        }
1698    
1699        // add all configured macros as menu items to the "Macro" menu
1700        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1701            const Serialization::Archive& macro = m_macros[iMacro];
1702            std::string name =
1703                macro.name().empty() ?
1704                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1705            Gtk::MenuItem* item = new Gtk::MenuItem(name);
1706            item->signal_activate().connect(
1707                sigc::bind(
1708                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1709                )
1710            );
1711            menuMacro->append(*item);
1712            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1713            Glib::ustring comment = macro.comment();
1714            if (!comment.empty())
1715                item->set_tooltip_text(comment);
1716        }
1717        // if there are no macros configured at all, then show a dummy entry instead
1718        if (m_macros.empty()) {
1719            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1720            item->set_sensitive(false);
1721            menuMacro->append(*item);
1722        }
1723    
1724        // add separator line to menu
1725        menuMacro->append(*new Gtk::SeparatorMenuItem);
1726    
1727        {
1728            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1729            item->signal_activate().connect(
1730                sigc::mem_fun(*this, &MainWindow::setupMacros)
1731            );
1732            menuMacro->append(*item);
1733            item->set_accel_path("<Macros>/SetupMacros");
1734        }
1735    
1736    #if HAS_GTKMM_SHOW_ALL_CHILDREN
1737        menuMacro->show_all_children();
1738    #endif
1739    }
1740    
1741    void MainWindow::onMacroSelected(int iMacro) {
1742        printf("onMacroSelected(%d)\n", iMacro);
1743        if (iMacro < 0 || iMacro >= m_macros.size()) return;
1744        Glib::ustring errorText;
1745        try {
1746            applyMacro(m_macros[iMacro]);
1747        } catch (Serialization::Exception e) {
1748            errorText = e.Message;
1749        } catch (...) {
1750            errorText = _("Unknown exception while applying macro");
1751        }
1752        if (!errorText.empty()) {
1753            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1754            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1755            msg.run();
1756        }
1757    }
1758    
1759    void MainWindow::setupMacros() {
1760        MacrosSetup* setup = new MacrosSetup();
1761        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1762        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1763        setup->signal_macros_changed().connect(
1764            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1765        );
1766        setup->show();
1767    }
1768    
1769    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1770        m_macros = macros;
1771        Settings::singleton()->saveMacros(m_macros);
1772        updateMacroMenu();
1773    }
1774    
1775    //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.
1776    void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1777        bool isInstrumentsPage = (page_num == 1);
1778        // so far we only support filtering for the instruments list, so hide the
1779        // filter text entry field if another tab is selected
1780        m_searchField.set_visible(isInstrumentsPage);
1781    }
1782    
1783  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1784  {  {
1785      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 845  gig::Instrument* MainWindow::get_instrum Line 1801  gig::Instrument* MainWindow::get_instrum
1801      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
1802      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1803      if (rows.empty()) return NULL;      if (rows.empty()) return NULL;
1804      Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1805        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1806      if (it) {      if (it) {
1807          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1808          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 889  void MainWindow::update_dimregs() Line 1846  void MainWindow::update_dimregs()
1846          }          }
1847      }      }
1848    
1849        m_RegionChooser.setModifyAllRegions(all_regions);
1850      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1851      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1852      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
# Line 910  void MainWindow::dimreg_changed() Line 1868  void MainWindow::dimreg_changed()
1868    
1869  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1870  {  {
1871    #if !USE_GTKMM_BUILDER
1872      // select item in instrument menu      // select item in instrument menu
1873      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1874      if (!rows.empty()) {      if (!rows.empty()) {
# Line 922  void MainWindow::on_sel_change() Line 1881  void MainWindow::on_sel_change()
1881              static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1882          }          }
1883      }      }
1884    #endif
1885    
1886        updateScriptListOfMenu();
1887    
1888      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
1889    
# Line 930  void MainWindow::on_sel_change() Line 1892  void MainWindow::on_sel_change()
1892      }      }
1893  }  }
1894    
1895    
1896    LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :
1897        filename(filename), gig(gig), thread(0), progress(0.f)
1898    {
1899    }
1900    
1901  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
1902  {  {
1903      Loader* loader = static_cast<Loader*>(progress->custom);      LoaderSaverBase* loader = static_cast<LoaderSaverBase*>(progress->custom);
1904      loader->progress_callback(progress->factor);      loader->progress_callback(progress->factor);
1905  }  }
1906    
1907  void Loader::progress_callback(float fraction)  void LoaderSaverBase::progress_callback(float fraction)
1908  {  {
1909      {      {
1910          Glib::Threads::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
# Line 949  void Loader::progress_callback(float fra Line 1917  void Loader::progress_callback(float fra
1917  // make sure stack is 16-byte aligned for SSE instructions  // make sure stack is 16-byte aligned for SSE instructions
1918  __attribute__((force_align_arg_pointer))  __attribute__((force_align_arg_pointer))
1919  #endif  #endif
1920  void Loader::thread_function()  void LoaderSaverBase::thread_function()
1921  {  {
1922      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
1923             static_cast<void*>(Glib::Threads::Thread::self()));             static_cast<void*>(Glib::Threads::Thread::self()));
1924      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1925      try {      try {
         RIFF::File* riff = new RIFF::File(filename);  
         gig = new gig::File(riff);  
1926          gig::progress_t progress;          gig::progress_t progress;
1927          progress.callback = loader_progress_callback;          progress.callback = loader_progress_callback;
1928          progress.custom = this;          progress.custom = this;
1929    
1930          gig->GetInstrument(0, &progress);          thread_function_sub(progress);
1931          printf("End\n");          printf("End\n");
1932          finished_dispatcher();          finished_dispatcher();
1933      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 973  void Loader::thread_function() Line 1939  void Loader::thread_function()
1939      }      }
1940  }  }
1941    
1942  Loader::Loader(const char* filename)  void LoaderSaverBase::launch()
     : filename(filename), gig(0), thread(0), progress(0.f)  
 {  
 }  
   
 void Loader::launch()  
1943  {  {
1944  #ifdef OLD_THREADS  #ifdef OLD_THREADS
1945      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);
1946  #else  #else
1947      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));
1948  #endif  #endif
1949      printf("launch thread=%p\n", static_cast<void*>(thread));      printf("launch thread=%p\n", static_cast<void*>(thread));
1950  }  }
1951    
1952  float Loader::get_progress()  float LoaderSaverBase::get_progress()
1953  {  {
1954      float res;      Glib::Threads::Mutex::Lock lock(progressMutex);
1955      {      return progress;
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         res = progress;  
     }  
     return res;  
1956  }  }
1957    
1958  Glib::Dispatcher& Loader::signal_progress()  Glib::Dispatcher& LoaderSaverBase::signal_progress()
1959  {  {
1960      return progress_dispatcher;      return progress_dispatcher;
1961  }  }
1962    
1963  Glib::Dispatcher& Loader::signal_finished()  Glib::Dispatcher& LoaderSaverBase::signal_finished()
1964  {  {
1965      return finished_dispatcher;      return finished_dispatcher;
1966  }  }
1967    
1968  Glib::Dispatcher& Loader::signal_error()  Glib::Dispatcher& LoaderSaverBase::signal_error()
1969  {  {
1970      return error_dispatcher;      return error_dispatcher;
1971  }  }
1972    
 void saver_progress_callback(gig::progress_t* progress)  
 {  
     Saver* saver = static_cast<Saver*>(progress->custom);  
     saver->progress_callback(progress->factor);  
 }  
1973    
1974  void Saver::progress_callback(float fraction)  Loader::Loader(const char* filename) :
1975        LoaderSaverBase(filename, 0)
1976  {  {
     {  
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         progress = fraction;  
     }  
     progress_dispatcher.emit();  
1977  }  }
1978    
1979  #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))  void Loader::thread_function_sub(gig::progress_t& progress)
 // make sure stack is 16-byte aligned for SSE instructions  
 __attribute__((force_align_arg_pointer))  
 #endif  
 void Saver::thread_function()  
1980  {  {
1981      printf("thread_function self=%p\n",      RIFF::File* riff = new RIFF::File(filename);
1982             static_cast<void*>(Glib::Threads::Thread::self()));      gig = new gig::File(riff);
     printf("Start %s\n", filename.c_str());  
     try {  
         gig::progress_t progress;  
         progress.callback = saver_progress_callback;  
         progress.custom = this;  
1983    
1984          // if no filename was provided, that means "save", if filename was provided means "save as"      gig->GetInstrument(0, &progress);
         if (filename.empty()) {  
             if (!Settings::singleton()->saveWithTemporaryFile) {  
                 // save directly over the existing .gig file  
                 // (requires less disk space than solution below  
                 // but may be slower)  
                 gig->Save(&progress);  
             } else {  
                 // save the file as separate temporary file first,  
                 // then move the saved file over the old file  
                 // (may result in performance speedup during save)  
                 String tmpname = filename + ".TMP";  
                 gig->Save(tmpname, &progress);  
                 #if defined(WIN32)  
                 if (!DeleteFile(filename.c_str())) {  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");  
                 }  
                 #else // POSIX ...  
                 if (unlink(filename.c_str())) {  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));  
                 }  
                 #endif  
                 if (rename(tmpname.c_str(), filename.c_str())) {  
                     #if defined(WIN32)  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");  
                     #else  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));  
                     #endif  
                 }  
             }  
         } else {  
             gig->Save(filename, &progress);  
         }  
   
         printf("End\n");  
         finished_dispatcher.emit();  
     } catch (RIFF::Exception e) {  
         error_message = e.Message;  
         error_dispatcher.emit();  
     } catch (...) {  
         error_message = _("Unknown exception occurred");  
         error_dispatcher.emit();  
     }  
1985  }  }
1986    
1987  Saver::Saver(gig::File* file, Glib::ustring filename)  
1988      : gig(file), filename(filename), thread(0), progress(0.f)  Saver::Saver(gig::File* file, Glib::ustring filename) :
1989        LoaderSaverBase(filename, file)
1990  {  {
1991  }  }
1992    
1993  void Saver::launch()  void Saver::thread_function_sub(gig::progress_t& progress)
1994  {  {
1995  #ifdef OLD_THREADS      // if no filename was provided, that means "save", if filename was provided means "save as"
1996      thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);      if (filename.empty()) {
1997            if (!Settings::singleton()->saveWithTemporaryFile) {
1998                // save directly over the existing .gig file
1999                // (requires less disk space than solution below
2000                // but may be slower)
2001                gig->Save(&progress);
2002            } else {
2003                // save the file as separate temporary file first,
2004                // then move the saved file over the old file
2005                // (may result in performance speedup during save)
2006                gig::String tmpname = filename + ".TMP";
2007                gig->Save(tmpname, &progress);
2008    #if defined(WIN32)
2009                if (!DeleteFile(filename.c_str())) {
2010                    throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
2011                }
2012    #else // POSIX ...
2013                if (unlink(filename.c_str())) {
2014                    throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2015                }
2016    #endif
2017                if (rename(tmpname.c_str(), filename.c_str())) {
2018    #if defined(WIN32)
2019                    throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
2020  #else  #else
2021      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));                  throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2022  #endif  #endif
2023      printf("launch thread=%p\n", static_cast<void*>(thread));              }
2024  }          }
2025        } else {
2026  float Saver::get_progress()          gig->Save(filename, &progress);
 {  
     float res;  
     {  
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         res = progress;  
2027      }      }
     return res;  
 }  
   
 Glib::Dispatcher& Saver::signal_progress()  
 {  
     return progress_dispatcher;  
2028  }  }
2029    
 Glib::Dispatcher& Saver::signal_finished()  
 {  
     return finished_dispatcher;  
 }  
   
 Glib::Dispatcher& Saver::signal_error()  
 {  
     return error_dispatcher;  
 }  
2030    
2031  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2032      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
2033  {  {
2034    #if USE_GTKMM_BOX
2035        get_content_area()->pack_start(progressBar);
2036    #else
2037      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
2038    #endif
2039    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2040      show_all_children();      show_all_children();
2041    #endif
2042      resize(600,50);      resize(600,50);
2043  }  }
2044    
# Line 1144  void MainWindow::__clear() { Line 2051  void MainWindow::__clear() {
2051      m_refTreeModel->clear();      m_refTreeModel->clear();
2052      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2053      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2054    #if !USE_GTKMM_BUILDER
2055      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2056      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2057          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2058      }      }
2059    #endif
2060      // free libgig's gig::File instance      // free libgig's gig::File instance
2061      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
2062      file = NULL;      file = NULL;
# Line 1159  void MainWindow::__refreshEntireGUI() { Line 2068  void MainWindow::__refreshEntireGUI() {
2068      m_refTreeModel->clear();      m_refTreeModel->clear();
2069      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2070      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2071    #if !USE_GTKMM_BUILDER
2072      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2073      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2074          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2075      }      }
2076    #endif
2077    
2078      if (!this->file) return;      if (!this->file) return;
2079    
# Line 1196  bool MainWindow::close_confirmation_dial Line 2107  bool MainWindow::close_confirmation_dial
2107      g_free(msg);      g_free(msg);
2108      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."));
2109      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2110    #if HAS_GTKMM_STOCK
2111        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2112        dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2113    #else
2114        dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2115      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2116      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);  #endif
2117      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
2118      int response = dialog.run();      int response = dialog.run();
2119      dialog.hide();      dialog.hide();
# Line 1228  bool MainWindow::leaving_shared_mode_dia Line 2144  bool MainWindow::leaving_shared_mode_dia
2144            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
2145            "load it."));            "load it."));
2146      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2147    #if HAS_GTKMM_STOCK
2148        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2149    #else
2150      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2151    #endif
2152      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2153      int response = dialog.run();      int response = dialog.run();
2154      dialog.hide();      dialog.hide();
# Line 1242  void MainWindow::on_action_file_open() Line 2162  void MainWindow::on_action_file_open()
2162      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
2163    
2164      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
2165    #if HAS_GTKMM_STOCK
2166        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2167        dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2168    #else
2169      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2170      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2171    #endif
2172      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
2173  #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
2174      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1275  void MainWindow::load_file(const char* n Line 2200  void MainWindow::load_file(const char* n
2200          Glib::filename_display_basename(name) + "' ...",          Glib::filename_display_basename(name) + "' ...",
2201          *this          *this
2202      );      );
2203    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2204      progress_dialog->show_all();      progress_dialog->show_all();
2205    #endif
2206      loader = new Loader(name); //FIXME: memory leak!      loader = new Loader(name); //FIXME: memory leak!
2207      loader->signal_progress().connect(      loader->signal_progress().connect(
2208          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
# Line 1309  void MainWindow::load_instrument(gig::In Line 2236  void MainWindow::load_instrument(gig::In
2236              // make sure the selected item in the "instruments" tree view is              // make sure the selected item in the "instruments" tree view is
2237              // visible (scroll to it)              // visible (scroll to it)
2238              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2239    #if !USE_GTKMM_BUILDER
2240              // select item in instrument menu              // select item in instrument menu
2241              {              {
2242                  const std::vector<Gtk::Widget*> children =                  const std::vector<Gtk::Widget*> children =
2243                      instrument_menu->get_children();                      instrument_menu->get_children();
2244                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2245              }              }
2246    #endif
2247              // update region chooser and dimension region chooser              // update region chooser and dimension region chooser
2248              m_RegionChooser.set_instrument(instr);              m_RegionChooser.set_instrument(instr);
2249              break;              break;
# Line 1386  bool MainWindow::file_save() Line 2315  bool MainWindow::file_save()
2315          Glib::filename_display_basename(this->filename) + "' ...",          Glib::filename_display_basename(this->filename) + "' ...",
2316          *this          *this
2317      );      );
2318    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2319      progress_dialog->show_all();      progress_dialog->show_all();
2320    #endif
2321      saver = new Saver(this->file); //FIXME: memory leak!      saver = new Saver(this->file); //FIXME: memory leak!
2322      saver->signal_progress().connect(      saver->signal_progress().connect(
2323          sigc::mem_fun(*this, &MainWindow::on_saver_progress));          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 1438  void MainWindow::on_action_file_save_as( Line 2369  void MainWindow::on_action_file_save_as(
2369    
2370  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
2371  {  {
2372      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2373    #if HAS_GTKMM_STOCK
2374        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2375        dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2376    #else
2377      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2378      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2379    #endif
2380      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
2381      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
2382    
# Line 1469  bool MainWindow::file_save_as() Line 2405  bool MainWindow::file_save_as()
2405      }      }
2406    
2407      // show warning in the dialog      // show warning in the dialog
2408      Gtk::HBox descriptionArea;      HBox descriptionArea;
2409      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
2410      Gtk::Image warningIcon;      Gtk::Image warningIcon;
2411      warningIcon.set_from_icon_name("dialog-warning",      warningIcon.set_from_icon_name("dialog-warning",
# Line 1490  bool MainWindow::file_save_as() Line 2426  bool MainWindow::file_save_as()
2426            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
2427      );      );
2428      descriptionArea.pack_start(description);      descriptionArea.pack_start(description);
2429    #if USE_GTKMM_BOX
2430        dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2431    #else
2432      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2433    #endif
2434    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2435      descriptionArea.show_all();      descriptionArea.show_all();
2436    #endif
2437    
2438      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2439          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
# Line 1505  bool MainWindow::file_save_as() Line 2447  bool MainWindow::file_save_as()
2447              Glib::filename_display_basename(filename) + "' ...",              Glib::filename_display_basename(filename) + "' ...",
2448              *this              *this
2449          );          );
2450    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2451          progress_dialog->show_all();          progress_dialog->show_all();
2452    #endif
2453    
2454          saver = new Saver(file, filename); //FIXME: memory leak!          saver = new Saver(file, filename); //FIXME: memory leak!
2455          saver->signal_progress().connect(          saver->signal_progress().connect(
# Line 1629  void MainWindow::on_action_warn_user_on_ Line 2573  void MainWindow::on_action_warn_user_on_
2573          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
2574  }  }
2575    
2576    void MainWindow::on_action_show_tooltips() {
2577        Settings::singleton()->showTooltips =
2578            !Settings::singleton()->showTooltips;
2579    
2580        on_show_tooltips_changed();
2581    }
2582    
2583    void MainWindow::on_show_tooltips_changed() {
2584        const bool b = Settings::singleton()->showTooltips;
2585    
2586        dimreg_label.set_has_tooltip(b);
2587        dimreg_all_regions.set_has_tooltip(b);
2588        dimreg_all_dimregs.set_has_tooltip(b);
2589        dimreg_stereo.set_has_tooltip(b);
2590    
2591        // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2592        //m_TreeView.set_has_tooltip(b);
2593    
2594        m_TreeViewSamples.set_has_tooltip(b);
2595        m_TreeViewScripts.set_has_tooltip(b);
2596    
2597        set_has_tooltip(b);
2598    }
2599    
2600  void MainWindow::on_action_sync_sampler_instrument_selection() {  void MainWindow::on_action_sync_sampler_instrument_selection() {
2601      Settings::singleton()->syncSamplerInstrumentSelection =      Settings::singleton()->syncSamplerInstrumentSelection =
2602          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
# Line 1648  void MainWindow::on_action_help_about() Line 2616  void MainWindow::on_action_help_about()
2616      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
2617  #endif  #endif
2618      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2619      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2620      const std::string sComment =      const std::string sComment =
2621          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
2622          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1664  void MainWindow::on_action_help_about() Line 2632  void MainWindow::on_action_help_about()
2632      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
2633      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
2634      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
2635        dialog.set_position(Gtk::WIN_POS_CENTER);
2636      dialog.run();      dialog.run();
2637  }  }
2638    
# Line 1685  PropDialog::PropDialog() Line 2654  PropDialog::PropDialog()
2654        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
2655        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
2656        eSubject(_("Subject")),        eSubject(_("Subject")),
2657        quitButton(_("_Close"), true),  #if HAS_GTKMM_STOCK
2658          quitButton(Gtk::Stock::CLOSE),
2659    #else
2660          quitButton(_("_Close")),
2661    #endif
2662        table(2, 1),        table(2, 1),
2663        m_file(NULL)        m_file(NULL)
2664  {  {
2665        if (!Settings::singleton()->autoRestoreWindowDimension) {
2666            set_default_size(470, 390);
2667            set_position(Gtk::WIN_POS_MOUSE);
2668        }
2669    
2670      set_title(_("File Properties"));      set_title(_("File Properties"));
2671      eName.set_width_chars(50);      eName.set_width_chars(50);
2672    
2673        connect(eFileFormat, &PropDialog::set_FileFormat);
2674      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
2675      connect(eCreationDate, &DLS::Info::CreationDate);      connect(eCreationDate, &DLS::Info::CreationDate);
2676      connect(eComments, &DLS::Info::Comments);      connect(eComments, &DLS::Info::Comments);
# Line 1727  PropDialog::PropDialog() Line 2706  PropDialog::PropDialog()
2706      table.add(eCommissioned);      table.add(eCommissioned);
2707      table.add(eSubject);      table.add(eSubject);
2708    
2709    #if USE_GTKMM_GRID
2710        table.set_column_spacing(5);
2711    #else
2712      table.set_col_spacings(5);      table.set_col_spacings(5);
2713    #endif
2714    
2715      add(vbox);      add(vbox);
2716    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2717        table.set_margin(5);
2718    #else
2719      table.set_border_width(5);      table.set_border_width(5);
2720    #endif
2721      vbox.add(table);      vbox.add(table);
2722      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2723      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2724    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2725        buttonBox.set_margin(5);
2726    #else
2727      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
2728    #endif
2729      buttonBox.show();      buttonBox.show();
2730      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2731      quitButton.set_can_default();      quitButton.set_can_default();
2732      quitButton.grab_focus();      quitButton.grab_focus();
2733      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
2734          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
     eFileFormat.signal_value_changed().connect(  
         sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));  
2735    
2736      quitButton.show();      quitButton.show();
2737      vbox.show();      vbox.show();
2738    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2739      show_all_children();      show_all_children();
2740    #endif
2741  }  }
2742    
2743  void PropDialog::set_file(gig::File* file)  void PropDialog::set_file(gig::File* file)
2744  {  {
2745      m_file = file;      m_file = file;
2746        update(file->pInfo);
2747    
2748      // update file format version combo box      // update file format version combo box
2749      const std::string sGiga = "Gigasampler/GigaStudio v";      const std::string sGiga = "Gigasampler/GigaStudio v";
# Line 1758  void PropDialog::set_file(gig::File* fil Line 2751  void PropDialog::set_file(gig::File* fil
2751      std::vector<std::string> txts;      std::vector<std::string> txts;
2752      std::vector<int> values;      std::vector<int> values;
2753      txts.push_back(sGiga + "2"); values.push_back(2);      txts.push_back(sGiga + "2"); values.push_back(2);
2754      txts.push_back(sGiga + "3/v4"); values.push_back(3);      txts.push_back(sGiga + "3"); values.push_back(3);
2755      if (major != 2 && major != 3) {      txts.push_back(sGiga + "4"); values.push_back(4);
2756        if (major < 2 || major > 4) {
2757          txts.push_back(sGiga + ToString(major)); values.push_back(major);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
2758      }      }
2759      std::vector<const char*> texts;      std::vector<const char*> texts;
2760      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2761      texts.push_back(NULL); values.push_back(0);      texts.push_back(NULL); values.push_back(0);
2762    
2763        update_model++;
2764      eFileFormat.set_choices(&texts[0], &values[0]);      eFileFormat.set_choices(&texts[0], &values[0]);
2765      eFileFormat.set_value(major);      eFileFormat.set_value(major);
2766        update_model--;
2767  }  }
2768    
2769  void PropDialog::onFileFormatChanged() {  void PropDialog::set_FileFormat(int value)
     const int major = eFileFormat.get_value();  
     if (m_file) m_file->pVersion->major = major;  
 }  
   
 void PropDialog::set_info(DLS::Info* info)  
2770  {  {
2771      update(info);      m_file->pVersion->major = value;
2772  }  }
2773    
2774    
# Line 1808  void InstrumentProps::set_MIDIProgram(ui Line 2800  void InstrumentProps::set_MIDIProgram(ui
2800  }  }
2801    
2802  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
2803      quitButton(_("_Close"), true),  #if HAS_GTKMM_STOCK
2804        quitButton(Gtk::Stock::CLOSE),
2805    #else
2806        quitButton(_("_Close")),
2807    #endif
2808      table(2,1),      table(2,1),
2809      eName(_("Name")),      eName(_("Name")),
2810      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1818  InstrumentProps::InstrumentProps() : Line 2814  InstrumentProps::InstrumentProps() :
2814      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2815      eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
2816      eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
2817      ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 48),
2818      ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
2819      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2820      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2821  {  {
2822        if (!Settings::singleton()->autoRestoreWindowDimension) {
2823            //set_default_size(470, 390);
2824            set_position(Gtk::WIN_POS_MOUSE);
2825        }
2826    
2827      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2828    
2829      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1849  InstrumentProps::InstrumentProps() : Line 2850  InstrumentProps::InstrumentProps() :
2850    
2851      eName.signal_value_changed().connect(sig_name_changed.make_slot());      eName.signal_value_changed().connect(sig_name_changed.make_slot());
2852    
2853    #if USE_GTKMM_GRID
2854        table.set_column_spacing(5);
2855    #else
2856      table.set_col_spacings(5);      table.set_col_spacings(5);
2857    #endif
2858    
2859      table.add(eName);      table.add(eName);
2860      table.add(eIsDrum);      table.add(eIsDrum);
# Line 1865  InstrumentProps::InstrumentProps() : Line 2870  InstrumentProps::InstrumentProps() :
2870      table.add(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
2871    
2872      add(vbox);      add(vbox);
2873    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2874        table.set_margin(5);
2875    #else
2876      table.set_border_width(5);      table.set_border_width(5);
2877    #endif
2878      vbox.pack_start(table);      vbox.pack_start(table);
2879      table.show();      table.show();
2880      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2881      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2882    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2883        buttonBox.set_margin(5);
2884    #else
2885      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
2886    #endif
2887      buttonBox.show();      buttonBox.show();
2888      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2889      quitButton.set_can_default();      quitButton.set_can_default();
# Line 1881  InstrumentProps::InstrumentProps() : Line 2894  InstrumentProps::InstrumentProps() :
2894    
2895      quitButton.show();      quitButton.show();
2896      vbox.show();      vbox.show();
2897    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2898      show_all_children();      show_all_children();
2899    #endif
2900  }  }
2901    
2902  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
# Line 1926  void MainWindow::updateSampleRefCountMap Line 2941  void MainWindow::updateSampleRefCountMap
2941      }      }
2942  }  }
2943    
2944    bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
2945        Gtk::TreeModel::iterator iter;
2946        if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
2947            return false;
2948        }
2949        Gtk::TreeModel::Path path(iter);
2950        Gtk::TreeModel::Row row = *iter;
2951        Gtk::TreeViewColumn* pointedColumn = NULL;
2952        // resolve the precise table column the mouse points to
2953        {
2954            Gtk::TreeModel::Path path; // unused
2955            int cellX, cellY; // unused
2956            m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
2957        }
2958        Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
2959        if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
2960            // show the script(s) assigned to the hovered instrument as tooltip
2961            tooltip->set_markup( row[m_Columns.m_col_tooltip] );
2962            m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
2963        } else {
2964            // if beginners' tooltips is disabled then don't show the following one
2965            if (!Settings::singleton()->showTooltips)
2966                return false;
2967            // yeah, a beginners tooltip
2968            tooltip->set_text(_(
2969                "Right click here for actions on instruments & MIDI Rules. "
2970                "Drag & drop to change the order of instruments."
2971            ));
2972            m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
2973        }
2974        return true;
2975    }
2976    
2977    static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
2978        Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2979        const int iScriptSlots = instrument->ScriptSlotCount();
2980        Glib::ustring tooltip = "<u>(" + ToString(index) + ") “"  + name + "”</u>\n\n";
2981        if (!iScriptSlots)
2982            tooltip += "<span foreground='red'><i>No script assigned</i></span>";
2983        else {
2984            for (int i = 0; i < iScriptSlots; ++i) {
2985                tooltip += "• " + ToString(i+1) + ". Script: “<span foreground='#46DEFF'><b>" +
2986                           instrument->GetScriptOfSlot(i)->Name + "</b></span>”";
2987                if (i + 1 < iScriptSlots) tooltip += "\n\n";
2988            }
2989        }
2990        return tooltip;
2991    }
2992    
2993  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
2994  {  {
2995      file = 0;      file = 0;
# Line 1940  void MainWindow::load_gig(gig::File* gig Line 3004  void MainWindow::load_gig(gig::File* gig
3004      file_is_changed = false;      file_is_changed = false;
3005    
3006      propDialog.set_file(gig);      propDialog.set_file(gig);
     propDialog.set_info(gig->pInfo);  
3007    
3008      instrument_name_connection.block();      instrument_name_connection.block();
3009      int index = 0;      int index = 0;
3010      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
3011           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
3012          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3013            const int iScriptSlots = instrument->ScriptSlotCount();
3014    
3015          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
3016          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
3017          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
3018          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
3019          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
3020            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3021            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3022    
3023    #if !USE_GTKMM_BUILDER
3024          add_instrument_to_menu(name);          add_instrument_to_menu(name);
3025    #endif
3026      }      }
3027      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3028    #if !USE_GTKMM_BUILDER
3029      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
3030    #endif
3031    
3032      updateSampleRefCountMap(gig);      updateSampleRefCountMap(gig);
3033    
# Line 2028  bool MainWindow::instr_props_set_instrum Line 3098  bool MainWindow::instr_props_set_instrum
3098          instrumentProps.hide();          instrumentProps.hide();
3099          return false;          return false;
3100      }      }
3101      Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3102        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3103      if (it) {      if (it) {
3104          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3105          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 2045  bool MainWindow::instr_props_set_instrum Line 3116  bool MainWindow::instr_props_set_instrum
3116      } else {      } else {
3117          instrumentProps.hide();          instrumentProps.hide();
3118      }      }
3119      return it;      //NOTE: explicit boolean cast required for GTKMM4 development branch here
3120        return it ? true : false;
3121  }  }
3122    
3123  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
# Line 2064  void MainWindow::instr_name_changed_by_i Line 3136  void MainWindow::instr_name_changed_by_i
3136      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3137      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3138      if (gigname != name) {      if (gigname != name) {
3139            Gtk::TreeModel::Path path(*it);
3140            const int index = path[0];
3141          row[m_Columns.m_col_name] = gigname;          row[m_Columns.m_col_name] = gigname;
3142            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3143      }      }
3144  }  }
3145    
# Line 2091  void MainWindow::show_script_slots() { Line 3166  void MainWindow::show_script_slots() {
3166    
3167      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
3168      window->setInstrument(instrument);      window->setInstrument(instrument);
3169        window->signal_script_slots_changed().connect(
3170            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3171        );
3172      //window->reparent(*this);      //window->reparent(*this);
3173      window->show();      window->show();
3174  }  }
3175    
3176    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3177        if (!pInstrument) return;
3178        const int iScriptSlots = pInstrument->ScriptSlotCount();
3179    
3180        //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!
3181        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3182        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3183    
3184        for (int i = 0; i < model->children().size(); ++i) {
3185            Gtk::TreeModel::Row row = model->children()[i];
3186            if (row[m_Columns.m_col_instr] != pInstrument) continue;
3187            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3188            row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3189            break;
3190        }
3191    
3192        // causes the sampler to reload the instrument with the new script
3193        on_sel_change();
3194    }
3195    
3196    void MainWindow::assignScript(gig::Script* pScript) {
3197        if (!pScript) {
3198            printf("assignScript() : !script\n");
3199            return;
3200        }
3201        printf("assignScript('%s')\n", pScript->Name.c_str());
3202    
3203        gig::Instrument* pInstrument = get_instrument();
3204        if (!pInstrument) {
3205            printf("!instrument\n");
3206            return;
3207        }
3208    
3209        pInstrument->AddScriptSlot(pScript);
3210    
3211        onScriptSlotsModified(pInstrument);
3212    }
3213    
3214    void MainWindow::dropAllScriptSlots() {
3215        gig::Instrument* pInstrument = get_instrument();
3216        if (!pInstrument) {
3217            printf("!instrument\n");
3218            return;
3219        }
3220    
3221        const int iScriptSlots = pInstrument->ScriptSlotCount();
3222        for (int i = iScriptSlots - 1; i >= 0; --i)
3223            pInstrument->RemoveScriptSlot(i);
3224    
3225        onScriptSlotsModified(pInstrument);
3226    }
3227    
3228  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
3229      __refreshEntireGUI();      __refreshEntireGUI();
3230  }  }
3231    
3232  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
3233    #if USE_GLIB_ACTION
3234        bool active = false;
3235        m_actionToggleStatusBar->get_state(active);
3236        // for some reason toggle state does not change automatically
3237        active = !active;
3238        m_actionToggleStatusBar->change_state(active);
3239        if (active)
3240            m_StatusBar.show();
3241        else
3242            m_StatusBar.hide();
3243    #else
3244      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3245          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3246      if (!item) {      if (!item) {
# Line 2108  void MainWindow::on_action_view_status_b Line 3249  void MainWindow::on_action_view_status_b
3249      }      }
3250      if (item->get_active()) m_StatusBar.show();      if (item->get_active()) m_StatusBar.show();
3251      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
3252    #endif
3253  }  }
3254    
3255  void MainWindow::on_auto_restore_win_dim() {  void MainWindow::on_auto_restore_win_dim() {
3256    #if USE_GLIB_ACTION
3257        bool active = false;
3258        m_actionToggleRestoreWinDim->get_state(active);
3259        // for some reason toggle state does not change automatically
3260        active = !active;
3261        m_actionToggleRestoreWinDim->change_state(active);
3262        Settings::singleton()->autoRestoreWindowDimension = active;
3263    #else
3264      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3265          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3266      if (!item) {      if (!item) {
# Line 2118  void MainWindow::on_auto_restore_win_dim Line 3268  void MainWindow::on_auto_restore_win_dim
3268          return;          return;
3269      }      }
3270      Settings::singleton()->autoRestoreWindowDimension = item->get_active();      Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3271    #endif
3272  }  }
3273    
3274  void MainWindow::on_save_with_temporary_file() {  void MainWindow::on_save_with_temporary_file() {
3275    #if USE_GLIB_ACTION
3276        bool active = false;
3277        m_actionToggleSaveWithTempFile->get_state(active);
3278        // for some reason toggle state does not change automatically
3279        active = !active;
3280        m_actionToggleSaveWithTempFile->change_state(active);
3281        Settings::singleton()->saveWithTemporaryFile = active;
3282    #else
3283      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3284          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3285      if (!item) {      if (!item) {
# Line 2128  void MainWindow::on_save_with_temporary_ Line 3287  void MainWindow::on_save_with_temporary_
3287          return;          return;
3288      }      }
3289      Settings::singleton()->saveWithTemporaryFile = item->get_active();      Settings::singleton()->saveWithTemporaryFile = item->get_active();
3290    #endif
3291  }  }
3292    
3293  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
3294    #if USE_GLIB_ACTION
3295        bool active = false;
3296        m_actionToggleCopySampleUnity->get_state(active);
3297        return active;
3298    #else
3299      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3300          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3301      if (!item) {      if (!item) {
# Line 2138  bool MainWindow::is_copy_samples_unity_n Line 3303  bool MainWindow::is_copy_samples_unity_n
3303          return true;          return true;
3304      }      }
3305      return item->get_active();      return item->get_active();
3306    #endif
3307  }  }
3308    
3309  bool MainWindow::is_copy_samples_fine_tune_enabled() const {  bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3310    #if USE_GLIB_ACTION
3311        bool active = false;
3312        m_actionToggleCopySampleTune->get_state(active);
3313        return active;
3314    #else
3315      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3316          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3317      if (!item) {      if (!item) {
# Line 2148  bool MainWindow::is_copy_samples_fine_tu Line 3319  bool MainWindow::is_copy_samples_fine_tu
3319          return true;          return true;
3320      }      }
3321      return item->get_active();      return item->get_active();
3322    #endif
3323  }  }
3324    
3325  bool MainWindow::is_copy_samples_loop_enabled() const {  bool MainWindow::is_copy_samples_loop_enabled() const {
3326    #if USE_GLIB_ACTION
3327        bool active = false;
3328        m_actionToggleCopySampleLoop->get_state(active);
3329        return active;
3330    #else
3331      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3332          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3333      if (!item) {      if (!item) {
# Line 2158  bool MainWindow::is_copy_samples_loop_en Line 3335  bool MainWindow::is_copy_samples_loop_en
3335          return true;          return true;
3336      }      }
3337      return item->get_active();      return item->get_active();
3338    #endif
3339  }  }
3340    
3341  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
3342  {  bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3343        GdkEventButton* button = _button.gobj();
3344    #else
3345    void MainWindow::on_button_release(GdkEventButton* button) {
3346    #endif
3347      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3348          show_instr_props();          show_instr_props();
3349      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3350          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3351          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3352    #if USE_GTKMM_BUILDER
3353            m_actionMIDIRules->property_enabled() = bEnabled;
3354    #else
3355          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
3356              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3357                  bEnabled                  bEnabled
# Line 2175  void MainWindow::on_button_release(GdkEv Line 3360  void MainWindow::on_button_release(GdkEv
3360              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3361                  bEnabled                  bEnabled
3362              );              );
3363    #endif
3364          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
3365      }      }
3366    #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
3367        return false;
3368    #endif
3369  }  }
3370    
3371    #if !USE_GTKMM_BUILDER
3372  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3373      if (item->get_active()) {      if (item->get_active()) {
3374          const std::vector<Gtk::Widget*> children =          const std::vector<Gtk::Widget*> children =
# Line 2193  void MainWindow::on_instrument_selection Line 3383  void MainWindow::on_instrument_selection
3383          }          }
3384      }      }
3385  }  }
3386    #endif
3387    
3388  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
3389      if (!instrument) return;      if (!instrument) return;
3390    
3391        //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!
3392      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3393        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3394    
3395      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
3396          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3397          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
3398              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
3399              show_intruments_tab();              show_intruments_tab();
3400              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3401                
3402    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3403                auto iterSel = model->children()[i].get_iter();
3404                m_TreeView.get_selection()->select(iterSel);
3405    #else
3406              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
3407    #endif
3408              std::vector<Gtk::TreeModel::Path> rows =              std::vector<Gtk::TreeModel::Path> rows =
3409                  m_TreeView.get_selection()->get_selected_rows();                  m_TreeView.get_selection()->get_selected_rows();
3410              if (!rows.empty())              if (!rows.empty())
# Line 2219  bool MainWindow::select_dimension_region Line 3419  bool MainWindow::select_dimension_region
3419      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3420      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3421    
3422        //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!
3423      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3424        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3425    
3426      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
3427          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3428          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
3429              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
3430              show_intruments_tab();              show_intruments_tab();
3431              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3432    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3433                auto iterSel = model->children()[i].get_iter();
3434                m_TreeView.get_selection()->select(iterSel);
3435    #else
3436              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
3437    #endif
3438              std::vector<Gtk::TreeModel::Path> rows =              std::vector<Gtk::TreeModel::Path> rows =
3439                  m_TreeView.get_selection()->get_selected_rows();                  m_TreeView.get_selection()->get_selected_rows();
3440              if (!rows.empty())              if (!rows.empty())
# Line 2257  void MainWindow::select_sample(gig::Samp Line 3465  void MainWindow::select_sample(gig::Samp
3465              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3466                  show_samples_tab();                  show_samples_tab();
3467                  m_TreeViewSamples.get_selection()->unselect_all();                  m_TreeViewSamples.get_selection()->unselect_all();
3468    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3469                    auto iterSel = rowGroup.children()[s].get_iter();
3470                    m_TreeViewSamples.get_selection()->select(iterSel);
3471    #else
3472                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3473    #endif
3474                  std::vector<Gtk::TreeModel::Path> rows =                  std::vector<Gtk::TreeModel::Path> rows =
3475                      m_TreeViewSamples.get_selection()->get_selected_rows();                      m_TreeViewSamples.get_selection()->get_selected_rows();
3476                  if (rows.empty()) return;                  if (rows.empty()) return;
# Line 2268  void MainWindow::select_sample(gig::Samp Line 3481  void MainWindow::select_sample(gig::Samp
3481      }      }
3482  }  }
3483    
3484    #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
3485    bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3486        GdkEventButton* button = _button.gobj();
3487    #else
3488  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3489    #endif
3490      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3491          // by default if Ctrl keys is pressed down, then a mouse right-click          // by default if Ctrl keys is pressed down, then a mouse right-click
3492          // does not select the respective row, so we must assure this          // does not select the respective row, so we must assure this
# Line 2289  void MainWindow::on_sample_treeview_butt Line 3507  void MainWindow::on_sample_treeview_butt
3507              }              }
3508          }*/          }*/
3509    
3510    #if !USE_GTKMM_BUILDER
3511          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
3512              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
3513    #endif
3514    
3515          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3516          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3517          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
# Line 2305  void MainWindow::on_sample_treeview_butt Line 3526  void MainWindow::on_sample_treeview_butt
3526              if (row[m_SamplesModel.m_col_sample]) nSamples++;              if (row[m_SamplesModel.m_col_sample]) nSamples++;
3527          }          }
3528    
3529    #if USE_GTKMM_BUILDER
3530            m_actionSampleProperties->property_enabled() = (n == 1);
3531            m_actionAddSample->property_enabled() = (n);
3532            m_actionAddSampleGroup->property_enabled() = (file);
3533            m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
3534            m_actionRemoveSample->property_enabled() = (n);
3535            m_actionReplaceSample->property_enabled() = (nSamples == 1);
3536    #else
3537          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
3538              set_sensitive(n == 1);              set_sensitive(n == 1);
3539          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
# Line 2315  void MainWindow::on_sample_treeview_butt Line 3544  void MainWindow::on_sample_treeview_butt
3544              set_sensitive(nSamples == 1);              set_sensitive(nSamples == 1);
3545          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
3546              set_sensitive(n);              set_sensitive(n);
3547    #endif
3548          // show sample popup          // show sample popup
3549          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
3550    
3551    #if !USE_GTKMM_BUILDER
3552          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
3553              set_sensitive(n == 1);              set_sensitive(n == 1);
3554          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
# Line 2328  void MainWindow::on_sample_treeview_butt Line 3559  void MainWindow::on_sample_treeview_butt
3559              set_sensitive(nSamples == 1);              set_sensitive(nSamples == 1);
3560          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3561              set_sensitive(n);              set_sensitive(n);
3562    #endif
3563      }      }
3564        
3565    #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
3566        return false;
3567    #endif
3568  }  }
3569    
3570    #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
3571    bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3572        GdkEventButton* button = _button.gobj();
3573    #else
3574  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3575    #endif
3576      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3577    #if !USE_GTKMM_BUILDER
3578          Gtk::Menu* script_popup =          Gtk::Menu* script_popup =
3579              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3580    #endif
3581          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3582          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3583          Gtk::TreeModel::iterator it = sel->get_selected();          Gtk::TreeModel::iterator it = sel->get_selected();
# Line 2345  void MainWindow::on_script_treeview_butt Line 3588  void MainWindow::on_script_treeview_butt
3588              group_selected  = row[m_ScriptsModel.m_col_group];              group_selected  = row[m_ScriptsModel.m_col_group];
3589              script_selected = row[m_ScriptsModel.m_col_script];              script_selected = row[m_ScriptsModel.m_col_script];
3590          }          }
3591    #if USE_GTKMM_BUILDER
3592            m_actionAddScript->property_enabled() = (group_selected || script_selected);
3593            m_actionAddScriptGroup->property_enabled() = (file);
3594            m_actionEditScript->property_enabled() = (script_selected);
3595            m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
3596    #else
3597          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
3598              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3599          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
# Line 2353  void MainWindow::on_script_treeview_butt Line 3602  void MainWindow::on_script_treeview_butt
3602              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3603          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3604              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3605    #endif
3606          // show sample popup          // show sample popup
3607          script_popup->popup(button->button, button->time);          script_popup->popup(button->button, button->time);
3608    
3609    #if !USE_GTKMM_BUILDER
3610          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3611              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3612          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
# Line 2364  void MainWindow::on_script_treeview_butt Line 3615  void MainWindow::on_script_treeview_butt
3615              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3616          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3617              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3618    #endif
3619        }
3620    #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
3621        return false;
3622    #endif
3623    }
3624    
3625    void MainWindow::updateScriptListOfMenu() {
3626        // remove all entries from "Assign Script" menu
3627        {
3628            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
3629            for (int i = 0; i < children.size(); ++i) {
3630                Gtk::Widget* child = children[i];
3631                assign_scripts_menu->remove(*child);
3632                delete child;
3633            }
3634        }
3635    
3636        int iTotalScripts = 0;
3637    
3638        if (!file) goto noScripts;
3639    
3640        // add all configured macros as menu items to the "Macro" menu
3641        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
3642            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
3643            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
3644                gig::Script* pScript = pGroup->GetScript(iScript);
3645                std::string name = pScript->Name;
3646    
3647                Gtk::MenuItem* item = new Gtk::MenuItem(name);
3648                item->signal_activate().connect(
3649                    sigc::bind(
3650                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
3651                    )
3652                );
3653                assign_scripts_menu->append(*item);
3654                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
3655                //item->set_tooltip_text(comment);
3656            }
3657        }
3658    
3659        noScripts:
3660    
3661        // if there are no macros configured at all, then show a dummy entry instead
3662        if (!iTotalScripts) {
3663            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
3664            item->set_sensitive(false);
3665            assign_scripts_menu->append(*item);
3666      }      }
3667    
3668        // add separator line to menu
3669        assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
3670    
3671        {
3672            Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
3673            item->signal_activate().connect(
3674                sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
3675            );
3676            assign_scripts_menu->append(*item);
3677            item->set_accel_path("<Scripts>/DropAllScriptSlots");
3678        }
3679    
3680    #if HAS_GTKMM_SHOW_ALL_CHILDREN
3681        assign_scripts_menu->show_all_children();
3682    #endif
3683  }  }
3684    
3685    #if !USE_GTKMM_BUILDER
3686  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
3687      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
3688    
# Line 2390  Gtk::RadioMenuItem* MainWindow::add_inst Line 3706  Gtk::RadioMenuItem* MainWindow::add_inst
3706              item));              item));
3707      return item;      return item;
3708  }  }
3709    #endif
3710    
3711    #if !USE_GTKMM_BUILDER
3712  void MainWindow::remove_instrument_from_menu(int index) {  void MainWindow::remove_instrument_from_menu(int index) {
3713      const std::vector<Gtk::Widget*> children =      const std::vector<Gtk::Widget*> children =
3714          instrument_menu->get_children();          instrument_menu->get_children();
# Line 2398  void MainWindow::remove_instrument_from_ Line 3716  void MainWindow::remove_instrument_from_
3716      instrument_menu->remove(*child);      instrument_menu->remove(*child);
3717      delete child;      delete child;
3718  }  }
3719    #endif
3720    
3721  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
3722      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
# Line 2406  void MainWindow::add_instrument(gig::Ins Line 3725  void MainWindow::add_instrument(gig::Ins
3725      instrument_name_connection.block();      instrument_name_connection.block();
3726      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3727      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
3728      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      const int index = m_refTreeModel->children().size() - 1;
3729        rowInstr[m_Columns.m_col_nr] = index;
3730      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
3731      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
3732        rowInstr[m_Columns.m_col_scripts] = "";
3733        rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3734      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3735    
3736    #if !USE_GTKMM_BUILDER
3737      add_instrument_to_menu(name);      add_instrument_to_menu(name);
3738    #endif
3739      m_TreeView.get_selection()->select(iterInstr);      select_instrument(instrument);
   
3740      file_changed();      file_changed();
3741  }  }
3742    
# Line 2482  void MainWindow::on_action_remove_instru Line 3804  void MainWindow::on_action_remove_instru
3804              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
3805              file_changed();              file_changed();
3806    
3807    #if !USE_GTKMM_BUILDER
3808              remove_instrument_from_menu(index);              remove_instrument_from_menu(index);
3809    #endif
3810    
3811              // remove row from instruments tree view              // remove row from instruments tree view
3812              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
# Line 2493  void MainWindow::on_action_remove_instru Line 3817  void MainWindow::on_action_remove_instru
3817                       it != m_refTreeModel->children().end(); ++it, ++index)                       it != m_refTreeModel->children().end(); ++it, ++index)
3818                  {                  {
3819                      Gtk::TreeModel::Row row = *it;                      Gtk::TreeModel::Row row = *it;
3820                        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3821                      row[m_Columns.m_col_nr] = index;                      row[m_Columns.m_col_nr] = index;
3822                        row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3823                  }                  }
3824              }              }
3825    
# Line 2697  void MainWindow::add_or_replace_sample(b Line 4023  void MainWindow::add_or_replace_sample(b
4023    
4024      // show 'browse for file' dialog      // show 'browse for file' dialog
4025      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
4026    #if HAS_GTKMM_STOCK
4027        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4028        dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
4029    #else
4030      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4031      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
4032    #endif
4033      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
4034    
4035      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2747  void MainWindow::add_or_replace_sample(b Line 4078  void MainWindow::add_or_replace_sample(b
4078          for (std::vector<std::string>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
4079               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
4080              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
4081              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file information
4082              SF_INFO info;              SF_INFO info;
4083              info.format = 0;              info.format = 0;
4084              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
# Line 2888  void MainWindow::on_action_replace_all_s Line 4219  void MainWindow::on_action_replace_all_s
4219      Gtk::Label description(str);      Gtk::Label description(str);
4220      description.set_line_wrap();      description.set_line_wrap();
4221  #endif  #endif
4222      Gtk::HBox entryArea;      HBox entryArea;
4223      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4224      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
4225      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
4226      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
4227      entryArea.pack_start(postfixEntryBox);      entryArea.pack_start(postfixEntryBox);
4228    #if USE_GTKMM_BOX
4229        dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4230        dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4231    #else
4232      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4233      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4234    #endif
4235      description.show();      description.show();
4236    
4237    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4238      entryArea.show_all();      entryArea.show_all();
4239    #else
4240        entryArea.show();
4241    #endif
4242    
4243    #if HAS_GTKMM_STOCK
4244        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4245    #else
4246      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4247    #endif
4248      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4249      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
4250      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 3356  void MainWindow::instrument_name_changed Line 4702  void MainWindow::instrument_name_changed
4702      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
4703      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
4704    
4705    #if !USE_GTKMM_BUILDER
4706      // change name in instrument menu      // change name in instrument menu
4707      int index = path[0];      int index = path[0];
4708      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
# Line 3368  void MainWindow::instrument_name_changed Line 4715  void MainWindow::instrument_name_changed
4715          item->set_active();          item->set_active();
4716  #endif  #endif
4717      }      }
4718    #endif
4719    
4720      // change name in gig      // change name in gig
4721      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 3384  void MainWindow::instrument_name_changed Line 4732  void MainWindow::instrument_name_changed
4732      }      }
4733  }  }
4734    
4735    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
4736        if (!iter)
4737            return true;
4738    
4739        Glib::ustring pattern = m_searchText.get_text().lowercase();
4740        trim(pattern);
4741        if (pattern.empty()) return true;
4742    
4743    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4744        //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4745        Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4746    #else
4747        Gtk::TreeModel::Row row = *iter;
4748    #endif
4749        Glib::ustring name = row[m_Columns.m_col_name];
4750        name = name.lowercase();
4751    
4752        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
4753        for (int t = 0; t < tokens.size(); ++t)
4754            if (name.find(tokens[t]) == Glib::ustring::npos)
4755                return false;
4756    
4757        return true;
4758    }
4759    
4760  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
4761      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
4762    
4763        // take over selection from instruments list view for the combine dialog's
4764        // list view as pre-selection
4765        std::set<int> indeces;
4766        {
4767            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4768            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4769            for (int r = 0; r < rows.size(); ++r) {
4770                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4771                if (it) {
4772                    Gtk::TreeModel::Row row = *it;
4773                    int index = row[m_Columns.m_col_nr];
4774                    indeces.insert(index);
4775                }
4776            }
4777        }
4778        d->setSelectedInstruments(indeces);
4779    
4780    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4781      d->show_all();      d->show_all();
4782      d->resize(500, 400);  #else
4783        d->show();
4784    #endif
4785      d->run();      d->run();
4786      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
4787          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3411  void MainWindow::on_action_view_referenc Line 4805  void MainWindow::on_action_view_referenc
4805      d->dimension_region_selected.connect(      d->dimension_region_selected.connect(
4806          sigc::mem_fun(*this, &MainWindow::select_dimension_region)          sigc::mem_fun(*this, &MainWindow::select_dimension_region)
4807      );      );
4808    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4809      d->show_all();      d->show_all();
4810    #else
4811        d->show();
4812    #endif
4813      d->resize(500, 400);      d->resize(500, 400);
4814      d->run();      d->run();
4815      delete d;      delete d;
# Line 3495  void MainWindow::mergeFiles(const std::v Line 4893  void MainWindow::mergeFiles(const std::v
4893              Glib::filename_display_basename(this->filename) + "' ...",              Glib::filename_display_basename(this->filename) + "' ...",
4894              *this              *this
4895          );          );
4896    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4897          progress_dialog->show_all();          progress_dialog->show_all();
4898    #else
4899            progress_dialog->show();
4900    #endif
4901          saver = new Saver(this->file); //FIXME: memory leak!          saver = new Saver(this->file); //FIXME: memory leak!
4902          saver->signal_progress().connect(          saver->signal_progress().connect(
4903              sigc::mem_fun(*this, &MainWindow::on_saver_progress));              sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 3522  void MainWindow::on_action_merge_files() Line 4924  void MainWindow::on_action_merge_files()
4924      }      }
4925    
4926      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4927    #if HAS_GTKMM_STOCK
4928        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4929    #else
4930      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4931    #endif
4932      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
4933      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4934  #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 3539  void MainWindow::on_action_merge_files() Line 4945  void MainWindow::on_action_merge_files()
4945      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
4946    
4947      // show warning in the file picker dialog      // show warning in the file picker dialog
4948      Gtk::HBox descriptionArea;      HBox descriptionArea;
4949      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
4950      Gtk::Image warningIcon;      Gtk::Image warningIcon;
4951      warningIcon.set_from_icon_name("dialog-warning",      warningIcon.set_from_icon_name("dialog-warning",
# Line 3562  void MainWindow::on_action_merge_files() Line 4968  void MainWindow::on_action_merge_files()
4968          "will accordingly be stored separately in the target .gig file!"          "will accordingly be stored separately in the target .gig file!"
4969      ));      ));
4970      descriptionArea.pack_start(description);      descriptionArea.pack_start(description);
4971    #if USE_GTKMM_BOX
4972    # warning No description area implemented for dialog on GTKMM 3
4973    #else
4974      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
4975    #endif
4976    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4977      descriptionArea.show_all();      descriptionArea.show_all();
4978    #else
4979        descriptionArea.show();
4980    #endif
4981    
4982      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
4983          printf("on_action_merge_files self=%p\n",          printf("on_action_merge_files self=%p\n",
# Line 3599  void MainWindow::set_file_is_shared(bool Line 5013  void MainWindow::set_file_is_shared(bool
5013      }      }
5014    
5015      {      {
5016    #if USE_GTKMM_BUILDER
5017            m_actionToggleSyncSamplerSelection->property_enabled() = b;
5018    #else
5019          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
5020              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
5021          if (item) item->set_sensitive(b);          if (item) item->set_sensitive(b);
5022    #endif
5023      }      }
5024  }  }
5025    
# Line 3649  void MainWindow::show_scripts_tab() { Line 5067  void MainWindow::show_scripts_tab() {
5067      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
5068  }  }
5069    
5070    void MainWindow::select_instrument_by_dir(int dir) {
5071        if (!file) return;
5072        gig::Instrument* pInstrument = get_instrument();
5073        if (!pInstrument) {
5074            select_instrument( file->GetInstrument(0) );
5075            return;
5076        }
5077        for (int i = 0; file->GetInstrument(i); ++i) {
5078            if (file->GetInstrument(i) == pInstrument) {
5079                select_instrument( file->GetInstrument(i + dir) );
5080                return;
5081            }
5082        }
5083    }
5084    
5085    void MainWindow::select_prev_instrument() {
5086        select_instrument_by_dir(-1);
5087    }
5088    
5089    void MainWindow::select_next_instrument() {
5090        select_instrument_by_dir(1);
5091    }
5092    
5093  void MainWindow::select_prev_region() {  void MainWindow::select_prev_region() {
5094      m_RegionChooser.select_prev_region();      m_RegionChooser.select_prev_region();
5095  }  }
# Line 3720  void MainWindow::paste_copied_dimrgn() { Line 5161  void MainWindow::paste_copied_dimrgn() {
5161      updateClipboardPasteAvailable();      updateClipboardPasteAvailable();
5162  }  }
5163    
5164    void MainWindow::adjust_clipboard_content() {
5165        MacroEditor* editor = new MacroEditor();
5166        editor->setMacro(&m_serializationArchive, true);
5167        editor->show();
5168    }
5169    
5170  void MainWindow::updateClipboardPasteAvailable() {  void MainWindow::updateClipboardPasteAvailable() {
5171      Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();      Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5172      clipboard->request_targets(      clipboard->request_targets(
# Line 3729  void MainWindow::updateClipboardPasteAva Line 5176  void MainWindow::updateClipboardPasteAva
5176    
5177  void MainWindow::updateClipboardCopyAvailable() {  void MainWindow::updateClipboardCopyAvailable() {
5178      bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();      bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5179    #if USE_GTKMM_BUILDER
5180        m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5181    #else
5182      static_cast<Gtk::MenuItem*>(      static_cast<Gtk::MenuItem*>(
5183          uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")          uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5184      )->set_sensitive(bDimensionRegionCopyIsPossible);      )->set_sensitive(bDimensionRegionCopyIsPossible);
5185    #endif
5186  }  }
5187    
5188    #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
5189    void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5190    #else
5191  void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {  void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5192    #endif
5193      updateClipboardPasteAvailable();      updateClipboardPasteAvailable();
5194  }  }
5195    
# Line 3757  void MainWindow::on_clipboard_clear() { Line 5212  void MainWindow::on_clipboard_clear() {
5212      updateClipboardCopyAvailable();      updateClipboardCopyAvailable();
5213  }  }
5214    
5215    //NOTE: Might throw exception !!!
5216    void MainWindow::applyMacro(Serialization::Archive& macro) {
5217        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5218        if (!pDimRgn) return;
5219    
5220        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5221             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5222        {
5223            gig::DimensionRegion* pDimRgn = *itDimReg;
5224            DimRegionChangeGuard(this, pDimRgn);
5225            macro.deserialize(pDimRgn);
5226        }
5227        //region_changed()
5228        file_changed();
5229        dimreg_changed();
5230    }
5231    
5232  void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {  void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5233      const std::string target = selection_data.get_target();      const std::string target = selection_data.get_target();
5234      if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {      if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
         gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();  
         if (!pDimRgn) return;  
   
5235          Glib::ustring errorText;          Glib::ustring errorText;
5236          try {          try {
5237              m_serializationArchive.decode(              m_serializationArchive.decode(
5238                  selection_data.get_data(), selection_data.get_length()                  selection_data.get_data(), selection_data.get_length()
5239              );              );
5240                applyMacro(m_serializationArchive);
             for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();  
                  itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)  
             {  
                 gig::DimensionRegion* pDimRgn = *itDimReg;  
   
                 dimreg_to_be_changed_signal.emit(pDimRgn);  
   
                 m_serializationArchive.deserialize(pDimRgn);  
   
                 dimreg_changed_signal.emit(pDimRgn);  
             }  
   
             //region_changed()  
             file_changed();  
             dimreg_changed();  
   
5241          } catch (Serialization::Exception e) {          } catch (Serialization::Exception e) {
5242              errorText = e.Message;              errorText = e.Message;
5243          } catch (...) {          } catch (...) {
5244              errorText = _("Unknown exception during deserialization decoding");              errorText = _("Unknown exception while pasting DimensionRegion");
5245          }          }
5246          if (!errorText.empty()) {          if (!errorText.empty()) {
5247              Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;              Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
# Line 3803  void MainWindow::on_clipboard_received_t Line 5256  void MainWindow::on_clipboard_received_t
5256          std::find(targets.begin(), targets.end(),          std::find(targets.begin(), targets.end(),
5257                    CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();                    CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5258    
5259    #if USE_GTKMM_BUILDER
5260        m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5261        m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5262    #else
5263      static_cast<Gtk::MenuItem*>(      static_cast<Gtk::MenuItem*>(
5264          uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")          uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5265      )->set_sensitive(bDimensionRegionPasteIsPossible);      )->set_sensitive(bDimensionRegionPasteIsPossible);
5266    
5267        static_cast<Gtk::MenuItem*>(
5268            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5269        )->set_sensitive(bDimensionRegionPasteIsPossible);
5270    #endif
5271  }  }
5272    
5273  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {

Legend:
Removed from v.3144  
changed lines
  Added in v.3470

  ViewVC Help
Powered by ViewVC