/[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 2691 by schoenebeck, Sun Jan 4 19:46:54 2015 UTC revision 3408 by schoenebeck, Fri Jan 19 19:17:41 2018 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include "compat.h"
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
39  #include <gtkmm/stock.h>  #if HAS_GTKMM_STOCK
40    # include <gtkmm/stock.h>
41    #endif
42  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
43  #include <gtkmm/main.h>  #include <gtkmm/main.h>
44  #include <gtkmm/toggleaction.h>  #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89)
45    # include <gtkmm/toggleaction.h>
46    #endif
47    #include <gtkmm/accelmap.h>
48  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
49  #include "wrapLabel.hh"  #include "wrapLabel.hh"
50  #endif  #endif
# Line 39  Line 53 
53  #include "compat.h"  #include "compat.h"
54    
55  #include <stdio.h>  #include <stdio.h>
56  #include <sndfile.h>  #ifdef LIBSNDFILE_HEADER_FILE
57    # include LIBSNDFILE_HEADER_FILE(sndfile.h)
58    #else
59    # include <sndfile.h>
60    #endif
61  #include <assert.h>  #include <assert.h>
62    
63  #include "mainwindow.h"  #include "mainwindow.h"
# Line 50  Line 68 
68  #include "ReferencesView.h"  #include "ReferencesView.h"
69  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
70  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
71    #include "gfx/builtinpix.h"
72    #include "MacroEditor.h"
73    #include "MacrosSetup.h"
74    #if defined(__APPLE__)
75    # include "MacHelper.h"
76    #endif
77    
78    static const Gdk::ModifierType primaryModifierKey =
79        #if defined(__APPLE__)
80        Gdk::META_MASK; // Cmd key on Mac
81        #else
82        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
83        #endif
84    
85  MainWindow::MainWindow() :  MainWindow::MainWindow() :
86      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
87      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
88      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
89      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
90      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
91        labelLegend(_("Legend:")),
92        labelNoSample(_(" No Sample")),
93        labelMissingSample(_(" Missing some Sample(s)")),
94        labelLooped(_(" Looped")),
95        labelSomeLoops(_(" Some Loop(s)"))
96  {  {
97        loadBuiltInPix();
98    
99        this->file = NULL;
100    
101  //    set_border_width(5);  //    set_border_width(5);
 //    set_default_size(400, 200);  
102    
103        if (!Settings::singleton()->autoRestoreWindowDimension) {
104    #if GTKMM_MAJOR_VERSION >= 3
105            set_default_size(895, 600);
106    #else
107            set_default_size(800, 600);
108    #endif
109            set_position(Gtk::WIN_POS_CENTER);
110        }
111    
112      add(m_VBox);      add(m_VBox);
113    
# Line 71  MainWindow::MainWindow() : Line 117  MainWindow::MainWindow() :
117    
118      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
119    
120    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
121        m_TreeView.signal_button_press_event().connect(
122            sigc::mem_fun(*this, &MainWindow::on_button_release));
123    #else
124      m_TreeView.signal_button_press_event().connect_notify(      m_TreeView.signal_button_press_event().connect_notify(
125          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
126    #endif
127    
128      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
129      m_ScrolledWindow.add(m_TreeView);      m_ScrolledWindow.add(m_TreeView);
# Line 85  MainWindow::MainWindow() : Line 136  MainWindow::MainWindow() :
136      m_ScrolledWindowScripts.add(m_TreeViewScripts);      m_ScrolledWindowScripts.add(m_TreeViewScripts);
137      m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138    
139    #if GTKMM_MAJOR_VERSION < 3
140      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
141    #endif
142    
143        m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
144        m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
145        m_searchField.pack_start(m_searchText);
146        m_searchField.set_spacing(5);
147    
148        m_left_vbox.pack_start(m_TreeViewNotebook);
149        m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
150    
151        m_HPaned.add1(m_left_vbox);
152    
     m_HPaned.add1(m_TreeViewNotebook);  
153      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
154      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
155      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 96  MainWindow::MainWindow() : Line 157  MainWindow::MainWindow() :
157      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
158      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
159      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
160        {
161            legend_hbox.add(labelLegend);
162    
163            imageNoSample.set(redDot);
164    #if HAS_GTKMM_ALIGNMENT
165            imageNoSample.set_alignment(Gtk::ALIGN_END);
166            labelNoSample.set_alignment(Gtk::ALIGN_START);
167    #else
168            imageNoSample.set_halign(Gtk::ALIGN_END);
169            labelNoSample.set_halign(Gtk::ALIGN_START);
170    #endif
171            legend_hbox.add(imageNoSample);
172            legend_hbox.add(labelNoSample);
173    
174            imageMissingSample.set(yellowDot);
175    #if HAS_GTKMM_ALIGNMENT
176            imageMissingSample.set_alignment(Gtk::ALIGN_END);
177            labelMissingSample.set_alignment(Gtk::ALIGN_START);
178    #else
179            imageMissingSample.set_halign(Gtk::ALIGN_END);
180            labelMissingSample.set_halign(Gtk::ALIGN_START);
181    #endif
182            legend_hbox.add(imageMissingSample);
183            legend_hbox.add(labelMissingSample);
184    
185            imageLooped.set(blackLoop);
186    #if HAS_GTKMM_ALIGNMENT
187            imageLooped.set_alignment(Gtk::ALIGN_END);
188            labelLooped.set_alignment(Gtk::ALIGN_START);
189    #else
190            imageLooped.set_halign(Gtk::ALIGN_END);
191            labelLooped.set_halign(Gtk::ALIGN_START);
192    #endif
193            legend_hbox.add(imageLooped);
194            legend_hbox.add(labelLooped);
195    
196            imageSomeLoops.set(grayLoop);
197    #if HAS_GTKMM_ALIGNMENT
198            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
200    #else
201            imageSomeLoops.set_halign(Gtk::ALIGN_END);
202            labelSomeLoops.set_halign(Gtk::ALIGN_START);
203    #endif
204            legend_hbox.add(imageSomeLoops);
205            legend_hbox.add(labelSomeLoops);
206    
207    #if HAS_GTKMM_SHOW_ALL_CHILDREN
208            legend_hbox.show_all_children();
209    #endif
210        }
211        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
213    
214      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 107  MainWindow::MainWindow() : Line 220  MainWindow::MainWindow() :
220      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221      m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));      m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
222    
223    #if USE_GLIB_ACTION
224        m_actionGroup = Gio::SimpleActionGroup::create();
225        m_actionGroup->add_action(
226            "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
227        );
228        m_actionGroup->add_action(
229            "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
230        );
231        m_actionGroup->add_action(
232            "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
233        );
234        m_actionGroup->add_action(
235            "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
236        );
237        m_actionGroup->add_action(
238            "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
239        );
240        m_actionGroup->add_action(
241            "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
242        );
243        m_actionMIDIRules = m_actionGroup->add_action(
244            "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
245        );
246        m_actionGroup->add_action(
247            "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
248        );
249        m_actionGroup->add_action(
250            "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
251        );
252        m_actionGroup->add_action(
253            "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
254        );
255        m_actionGroup->add_action(
256            "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
257        );
258        m_actionGroup->add_action(
259            "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
260        );
261    #else
262      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
263    
264      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
# Line 156  MainWindow::MainWindow() : Line 308  MainWindow::MainWindow() :
308          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309      );      );
310      actionGroup->add(      actionGroup->add(
311          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
312          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313      );      );
314      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
315        actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
316    
317      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
318    #endif
319    
320        const Gdk::ModifierType primaryModifierKey =
321    #if defined(__APPLE__)
322        Gdk::META_MASK; // Cmd key on Mac
323    #else
324        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
325    #endif
326    
327    #if USE_GLIB_ACTION
328        m_actionCopyDimRgn = m_actionGroup->add_action(
329            "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)
330        );
331        m_actionPasteDimRgn = m_actionGroup->add_action(
332            "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)
333        );
334        m_actionAdjustClipboard = m_actionGroup->add_action(
335            "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)
336        );
337        m_actionGroup->add_action(
338            "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument)
339        );
340        m_actionGroup->add_action(
341            "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument)
342        );
343        m_actionGroup->add_action(
344            "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region)
345        );
346        m_actionGroup->add_action(
347            "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region)
348        );
349        m_actionGroup->add_action(
350            "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)
351        );
352        m_actionGroup->add_action(
353            "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)
354        );
355        m_actionGroup->add_action(
356            "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension)
357        );
358        m_actionGroup->add_action(
359            "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension)
360        );
361        m_actionGroup->add_action(
362            "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)
363        );
364        m_actionGroup->add_action(
365            "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)
366        );
367    #else
368        actionGroup->add(Gtk::Action::create("CopyDimRgn",
369                                             _("Copy selected dimension region")),
370                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
371                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
372    
373        actionGroup->add(Gtk::Action::create("PasteDimRgn",
374                                             _("Paste dimension region")),
375                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
376                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
377    
378        actionGroup->add(Gtk::Action::create("AdjustClipboard",
379                                             _("Adjust Clipboard Content")),
380                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
381                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
382    
383        actionGroup->add(Gtk::Action::create("SelectPrevInstr",
384                                             _("Select Previous Instrument")),
385                         Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
386                         sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
387    
388        actionGroup->add(Gtk::Action::create("SelectNextInstr",
389                                             _("Select Next Instrument")),
390                         Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
391                         sigc::mem_fun(*this, &MainWindow::select_next_instrument));
392    
393        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
394                                             _("Select Previous Region")),
395                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
396                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
397    
398        actionGroup->add(Gtk::Action::create("SelectNextRegion",
399                                             _("Select Next Region")),
400                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
401                         sigc::mem_fun(*this, &MainWindow::select_next_region));
402    
403        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
404                                             _("Select Previous Dimension Region Zone")),
405                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
406                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
407    
408        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
409                                             _("Select Next Dimension Region Zone")),
410                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
411                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
412    
413        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
414                                             _("Select Previous Dimension")),
415                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
416                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
417    
418        actionGroup->add(Gtk::Action::create("SelectNextDimension",
419                                             _("Select Next Dimension")),
420                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
421                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
422    
423        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
424                                             _("Add Previous Dimension Region Zone to Selection")),
425                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
426                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
427    
428        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
429                                             _("Add Next Dimension Region Zone to Selection")),
430                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
431                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
432    #endif
433    
434    #if USE_GLIB_ACTION
435        m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true);
436        m_actionToggleCopySampleTune  = m_actionGroup->add_action_bool("CopySampleTune", true);
437        m_actionToggleCopySampleLoop  = m_actionGroup->add_action_bool("CopySampleLoop", true);
438    #else
439      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
440          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
441      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 177  MainWindow::MainWindow() : Line 450  MainWindow::MainWindow() :
450          Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));          Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451      toggle_action->set_active(true);      toggle_action->set_active(true);
452      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
453    #endif
454    
455    #if USE_GLIB_ACTION
456        m_actionToggleStatusBar =
457            m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458        m_actionToggleRestoreWinDim =
459            m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460        m_actionToggleSaveWithTempFile =
461            m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
462        m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
463    #else
464        actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
465    
466    
467      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
468      toggle_action =      toggle_action =
469          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
470      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 187  MainWindow::MainWindow() : Line 472  MainWindow::MainWindow() :
472                       sigc::mem_fun(                       sigc::mem_fun(
473                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
474    
475        toggle_action =
476            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
477        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
478        actionGroup->add(toggle_action,
479                         sigc::mem_fun(
480                             *this, &MainWindow::on_auto_restore_win_dim));
481    
482        toggle_action =
483            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
484        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
485        actionGroup->add(toggle_action,
486                         sigc::mem_fun(
487                             *this, &MainWindow::on_save_with_temporary_file));
488    
489        actionGroup->add(
490            Gtk::Action::create("RefreshAll", _("_Refresh All")),
491            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
492        );                
493    #endif
494    
495    #if USE_GLIB_ACTION
496        m_actionGroup->add_action(
497            "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
498        );
499        m_actionGroup->add_action(
500            "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
501        );
502        m_actionGroup->add_action(
503            "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
504        );
505        m_actionGroup->add_action(
506            "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
507        );
508        m_actionGroup->add_action(
509            "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
510        );
511    #else
512      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
513      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
514                                           action->property_label()));                                           action->property_label()));
# Line 202  MainWindow::MainWindow() : Line 524  MainWindow::MainWindow() :
524          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
525      );      );
526      actionGroup->add(      actionGroup->add(
527            Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
528            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
529            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
530        );
531        actionGroup->add(
532          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
533          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
534      );      );
535    #endif
536    
537    #if USE_GLIB_ACTION
538        m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool(
539            "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions),
540            Settings::singleton()->warnUserOnExtensions
541        );
542        m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool(
543            "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection),
544            Settings::singleton()->syncSamplerInstrumentSelection
545        );
546        m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool(
547            "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved),
548            Settings::singleton()->moveRootNoteWithRegionMoved
549        );
550    #else
551      actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));      actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
552            
553      toggle_action =      toggle_action =
# Line 225  MainWindow::MainWindow() : Line 566  MainWindow::MainWindow() :
566          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
567      );      );
568    
569        toggle_action =
570            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
571        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
572        actionGroup->add(
573            toggle_action,
574            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
575        );
576    #endif
577    
578    #if USE_GLIB_ACTION
579        m_actionGroup->add_action(
580            "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
581        );
582        m_actionGroup->add_action(
583            "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
584        );
585    #else
586      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
587    
588      actionGroup->add(      actionGroup->add(
# Line 237  MainWindow::MainWindow() : Line 594  MainWindow::MainWindow() :
594          Gtk::Action::create("MergeFiles", _("_Merge Files...")),          Gtk::Action::create("MergeFiles", _("_Merge Files...")),
595          sigc::mem_fun(*this, &MainWindow::on_action_merge_files)          sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
596      );      );
597    #endif
598    
599      // sample right-click popup actions      // sample right-click popup actions
600    #if USE_GLIB_ACTION
601        m_actionSampleProperties = m_actionGroup->add_action(
602            "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
603        );
604        m_actionAddSampleGroup = m_actionGroup->add_action(
605            "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group)
606        );
607        m_actionAddSample = m_actionGroup->add_action(
608            "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
609        );
610        m_actionRemoveSample = m_actionGroup->add_action(
611            "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
612        );
613        m_actionGroup->add_action(
614            "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
615        );
616        m_actionViewSampleRefs = m_actionGroup->add_action(
617            "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references)
618        );
619        m_actionReplaceSample = m_actionGroup->add_action(
620            "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
621        );
622        m_actionGroup->add_action(
623            "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
624        );
625    #else
626      actionGroup->add(      actionGroup->add(
627          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
628          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
# Line 257  MainWindow::MainWindow() : Line 640  MainWindow::MainWindow() :
640          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
641      );      );
642      actionGroup->add(      actionGroup->add(
643            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
644            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
645        );
646        actionGroup->add(
647          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
648          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
649      );      );
650      actionGroup->add(      actionGroup->add(
651            Gtk::Action::create("ReplaceSample",
652                                _("Replace Sample...")),
653            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
654        );
655        actionGroup->add(
656          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
657                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
658          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)
659      );      );
660    #endif
661            
662      // script right-click popup actions      // script right-click popup actions
663    #if USE_GLIB_ACTION
664        m_actionAddScriptGroup = m_actionGroup->add_action(
665            "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
666        );
667        m_actionAddScript = m_actionGroup->add_action(
668            "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script)
669        );
670        m_actionEditScript = m_actionGroup->add_action(
671            "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
672        );
673        m_actionRemoveScript = m_actionGroup->add_action(
674            "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
675        );
676    #else
677      actionGroup->add(      actionGroup->add(
678          Gtk::Action::create("AddScriptGroup", _("Add _Group")),          Gtk::Action::create("AddScriptGroup", _("Add _Group")),
679          sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
# Line 283  MainWindow::MainWindow() : Line 690  MainWindow::MainWindow() :
690          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
691          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
692      );      );
693    #endif
694    
695    #if USE_GTKMM_BUILDER
696        insert_action_group("AppMenu", m_actionGroup);
697        
698        m_uiManager = Gtk::Builder::create();
699        Glib::ustring ui_info =
700            "<interface>"
701            "  <menubar id='MenuBar'>"
702            "    <menu id='MenuFile'>"
703            "      <attribute name='label' translatable='yes'>_File</attribute>"
704            "      <section>"
705            "        <item id='New'>"
706            "          <attribute name='label' translatable='yes'>New</attribute>"
707            "          <attribute name='action'>AppMenu.New</attribute>"
708            "        </item>"
709            "        <item id='Open'>"
710            "          <attribute name='label' translatable='yes'>Open</attribute>"
711            "          <attribute name='action'>AppMenu.Open</attribute>"
712            "        </item>"
713            "      </section>"
714            "      <section>"
715            "        <item id='Save'>"
716            "          <attribute name='label' translatable='yes'>Save</attribute>"
717            "          <attribute name='action'>AppMenu.Save</attribute>"
718            "        </item>"
719            "        <item id='SaveAs'>"
720            "          <attribute name='label' translatable='yes'>Save As</attribute>"
721            "          <attribute name='action'>AppMenu.SaveAs</attribute>"
722            "        </item>"
723            "      </section>"
724            "      <section>"
725            "        <item id='Properties'>"
726            "          <attribute name='label' translatable='yes'>Properties</attribute>"
727            "          <attribute name='action'>AppMenu.Properties</attribute>"
728            "        </item>"
729            "      </section>"
730            "      <section>"
731            "        <item id='Quit'>"
732            "          <attribute name='label' translatable='yes'>Quit</attribute>"
733            "          <attribute name='action'>AppMenu.Quit</attribute>"
734            "        </item>"
735            "      </section>"
736            "    </menu>"
737            "    <menu id='MenuEdit'>"
738            "      <attribute name='label' translatable='yes'>Edit</attribute>"
739            "      <section>"
740            "        <item id='CopyDimRgn'>"
741            "          <attribute name='label' translatable='yes'>Copy Dimension Region</attribute>"
742            "          <attribute name='action'>AppMenu.CopyDimRgn</attribute>"
743            "        </item>"
744            "        <item id='AdjustClipboard'>"
745            "          <attribute name='label' translatable='yes'>Adjust Clipboard</attribute>"
746            "          <attribute name='action'>AppMenu.AdjustClipboard</attribute>"
747            "        </item>"
748            "        <item id='PasteDimRgn'>"
749            "          <attribute name='label' translatable='yes'>Paste Dimension Region</attribute>"
750            "          <attribute name='action'>AppMenu.PasteDimRgn</attribute>"
751            "        </item>"
752            "      </section>"
753            "        <item id='SelectPrevInstr'>"
754            "          <attribute name='label' translatable='yes'>Previous Instrument</attribute>"
755            "          <attribute name='action'>AppMenu.SelectPrevInstr</attribute>"
756            "        </item>"
757            "        <item id='SelectNextInstr'>"
758            "          <attribute name='label' translatable='yes'>Next Instrument</attribute>"
759            "          <attribute name='action'>AppMenu.SelectNextInstr</attribute>"
760            "        </item>"
761            "      <section>"
762            "        <item id='SelectPrevRegion'>"
763            "          <attribute name='label' translatable='yes'>Previous Region</attribute>"
764            "          <attribute name='action'>AppMenu.SelectPrevRegion</attribute>"
765            "        </item>"
766            "        <item id='SelectNextRegion'>"
767            "          <attribute name='label' translatable='yes'>Next Region</attribute>"
768            "          <attribute name='action'>AppMenu.SelectNextRegion</attribute>"
769            "        </item>"
770            "      </section>"
771            "        <item id='SelectPrevDimension'>"
772            "          <attribute name='label' translatable='yes'>Previous Dimension</attribute>"
773            "          <attribute name='action'>AppMenu.SelectPrevDimension</attribute>"
774            "        </item>"
775            "        <item id='SelectNextDimension'>"
776            "          <attribute name='label' translatable='yes'>Next Dimension</attribute>"
777            "          <attribute name='action'>AppMenu.SelectNextDimension</attribute>"
778            "        </item>"
779            "        <item id='SelectPrevDimRgnZone'>"
780            "          <attribute name='label' translatable='yes'>Previous Dimension Region Zone</attribute>"
781            "          <attribute name='action'>AppMenu.SelectPrevDimRgnZone</attribute>"
782            "        </item>"
783            "        <item id='SelectNextDimRgnZone'>"
784            "          <attribute name='label' translatable='yes'>Next Dimension Region Zone</attribute>"
785            "          <attribute name='action'>AppMenu.SelectNextDimRgnZone</attribute>"
786            "        </item>"
787            "        <item id='SelectAddPrevDimRgnZone'>"
788            "          <attribute name='label' translatable='yes'>Add Previous Dimension Region Zone</attribute>"
789            "          <attribute name='action'>AppMenu.SelectAddPrevDimRgnZone</attribute>"
790            "        </item>"
791            "        <item id='SelectAddNextDimRgnZone'>"
792            "          <attribute name='label' translatable='yes'>Add Next Dimension Region Zone</attribute>"
793            "          <attribute name='action'>AppMenu.SelectAddNextDimRgnZone</attribute>"
794            "        </item>"
795            "      <section>"
796            "        <item id='CopySampleUnity'>"
797            "          <attribute name='label' translatable='yes'>Copy Sample Unity</attribute>"
798            "          <attribute name='action'>AppMenu.CopySampleUnity</attribute>"
799            "        </item>"
800            "        <item id='CopySampleTune'>"
801            "          <attribute name='label' translatable='yes'>Copy Sample Tune</attribute>"
802            "          <attribute name='action'>AppMenu.CopySampleTune</attribute>"
803            "        </item>"
804            "        <item id='CopySampleLoop'>"
805            "          <attribute name='label' translatable='yes'>Copy Sample Loop</attribute>"
806            "          <attribute name='action'>AppMenu.CopySampleLoop</attribute>"
807            "        </item>"
808            "      </section>"
809            "    </menu>"
810            "    <menu id='MenuMacro'>"
811            "      <attribute name='label' translatable='yes'>Macro</attribute>"
812            "      <section>"
813            "      </section>"
814            "    </menu>"
815            "    <menu id='MenuSample'>"
816            "      <attribute name='label' translatable='yes'>Sample</attribute>"
817            "      <section>"
818            "        <item id='SampleProperties'>"
819            "          <attribute name='label' translatable='yes'>Properties</attribute>"
820            "          <attribute name='action'>AppMenu.SampleProperties</attribute>"
821            "        </item>"
822            "        <item id='AddGroup'>"
823            "          <attribute name='label' translatable='yes'>Add Group</attribute>"
824            "          <attribute name='action'>AppMenu.AddGroup</attribute>"
825            "        </item>"
826            "        <item id='AddSample'>"
827            "          <attribute name='label' translatable='yes'>Add Sample</attribute>"
828            "          <attribute name='action'>AppMenu.AddSample</attribute>"
829            "        </item>"
830            "        <item id='ShowSampleRefs'>"
831            "          <attribute name='label' translatable='yes'>Show Sample References</attribute>"
832            "          <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
833            "        </item>"
834            "        <item id='ReplaceSample'>"
835            "          <attribute name='label' translatable='yes'>Replace Sample</attribute>"
836            "          <attribute name='action'>AppMenu.ReplaceSample</attribute>"
837            "        </item>"
838            "        <item id='ReplaceAllSamplesInAllGroups'>"
839            "          <attribute name='label' translatable='yes'>Replace all Samples in all Groups</attribute>"
840            "          <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
841            "        </item>"
842            "      </section>"
843            "      <section>"
844            "        <item id='RemoveSample'>"
845            "          <attribute name='label' translatable='yes'>Remove Sample</attribute>"
846            "          <attribute name='action'>AppMenu.RemoveSample</attribute>"
847            "        </item>"
848            "        <item id='RemoveUnusedSamples'>"
849            "          <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
850            "          <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
851            "        </item>"
852            "      </section>"
853            "    </menu>"
854            "    <menu id='MenuInstrument'>"
855            "      <attribute name='label' translatable='yes'>Instrument</attribute>"
856            "      <section>"
857            "        <item id='InstrProperties'>"
858            "          <attribute name='label' translatable='yes'>Properties</attribute>"
859            "          <attribute name='action'>AppMenu.InstrProperties</attribute>"
860            "        </item>"
861            "        <item id='MidiRules'>"
862            "          <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
863            "          <attribute name='action'>AppMenu.MidiRules</attribute>"
864            "        </item>"
865            "        <item id='ScriptSlots'>"
866            "          <attribute name='label' translatable='yes'>Script Slots</attribute>"
867            "          <attribute name='action'>AppMenu.ScriptSlots</attribute>"
868            "        </item>"
869            "      </section>"
870            "      <submenu id='AssignScripts'>"
871            "        <attribute name='label' translatable='yes'>Assign Scripts</attribute>"
872            "      </submenu>"
873            "      <section>"
874            "        <item id='AddInstrument'>"
875            "          <attribute name='label' translatable='yes'>Add Instrument</attribute>"
876            "          <attribute name='action'>AppMenu.AddInstrument</attribute>"
877            "        </item>"
878            "        <item id='DupInstrument'>"
879            "          <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
880            "          <attribute name='action'>AppMenu.DupInstrument</attribute>"
881            "        </item>"
882            "        <item id='CombInstruments'>"
883            "          <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
884            "          <attribute name='action'>AppMenu.CombInstruments</attribute>"
885            "        </item>"
886            "      </section>"
887            "      <section>"
888            "        <item id='RemoveInstrument'>"
889            "          <attribute name='label' translatable='yes'>Remove Instrument</attribute>"
890            "          <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
891            "        </item>"
892            "      </section>"
893            "    </menu>"
894            "    <menu id='MenuScript'>"
895            "      <attribute name='label' translatable='yes'>Script</attribute>"
896            "      <section>"
897            "        <item id='AddScriptGroup'>"
898            "          <attribute name='label' translatable='yes'>Add Script Group</attribute>"
899            "          <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
900            "        </item>"
901            "        <item id='AddScript'>"
902            "          <attribute name='label' translatable='yes'>Add Script</attribute>"
903            "          <attribute name='action'>AppMenu.AddScript</attribute>"
904            "        </item>"
905            "        <item id='EditScript'>"
906            "          <attribute name='label' translatable='yes'>Edit Script</attribute>"
907            "          <attribute name='action'>AppMenu.EditScript</attribute>"
908            "        </item>"
909            "      </section>"
910            "      <section>"
911            "        <item id='RemoveScript'>"
912            "          <attribute name='label' translatable='yes'>Remove Script</attribute>"
913            "          <attribute name='action'>AppMenu.RemoveScript</attribute>"
914            "        </item>"
915            "      </section>"
916            "    </menu>"
917            "    <menu id='MenuView'>"
918            "      <attribute name='label' translatable='yes'>View</attribute>"
919            "      <section>"
920            "        <item id='Statusbar'>"
921            "          <attribute name='label' translatable='yes'>Statusbar</attribute>"
922            "          <attribute name='action'>AppMenu.Statusbar</attribute>"
923            "        </item>"
924            "        <item id='AutoRestoreWinDim'>"
925            "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
926            "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
927            "        </item>"
928            "      </section>"
929            "      <section>"
930            "        <item id='RefreshAll'>"
931            "          <attribute name='label' translatable='yes'>Refresh All</attribute>"
932            "          <attribute name='action'>AppMenu.RefreshAll</attribute>"
933            "        </item>"
934            "      </section>"
935            "    </menu>"
936            "    <menu id='MenuTools'>"
937            "      <attribute name='label' translatable='yes'>Tools</attribute>"
938            "      <section>"
939            "        <item id='CombineInstruments'>"
940            "          <attribute name='label' translatable='yes'>Combine Instruments ...</attribute>"
941            "          <attribute name='action'>AppMenu.CombineInstruments</attribute>"
942            "        </item>"
943            "        <item id='MergeFiles'>"
944            "          <attribute name='label' translatable='yes'>Merge Files ...</attribute>"
945            "          <attribute name='action'>AppMenu.MergeFiles</attribute>"
946            "        </item>"
947            "      </section>"
948            "    </menu>"
949            "    <menu id='MenuSettings'>"
950            "      <attribute name='label' translatable='yes'>Settings</attribute>"
951            "      <section>"
952            "        <item id='WarnUserOnExtensions'>"
953            "          <attribute name='label' translatable='yes'>Warning on Format Extensions</attribute>"
954            "          <attribute name='action'>AppMenu.WarnUserOnExtensions</attribute>"
955            "        </item>"
956            "        <item id='SyncSamplerInstrumentSelection'>"
957            "          <attribute name='label' translatable='yes'>Synchronize Sampler Selection</attribute>"
958            "          <attribute name='action'>AppMenu.SyncSamplerInstrumentSelection</attribute>"
959            "        </item>"
960            "        <item id='MoveRootNoteWithRegionMoved'>"
961            "          <attribute name='label' translatable='yes'>Move Root Note with Region moved</attribute>"
962            "          <attribute name='action'>AppMenu.MoveRootNoteWithRegionMoved</attribute>"
963            "        </item>"
964            "        <item id='SaveWithTemporaryFile'>"
965            "          <attribute name='label' translatable='yes'>Save with temporary file</attribute>"
966            "          <attribute name='action'>AppMenu.SaveWithTemporaryFile</attribute>"
967            "        </item>"
968            "      </section>"
969            "    </menu>"
970            "    <menu id='MenuHelp'>"
971            "      <attribute name='label' translatable='yes'>Help</attribute>"
972            "      <section>"
973            "        <item id='About'>"
974            "          <attribute name='label' translatable='yes'>About ...</attribute>"
975            "          <attribute name='action'>AppMenu.About</attribute>"
976            "        </item>"
977            "      </section>"
978            "    </menu>"
979            "  </menubar>"
980            // popups
981            "  <menu id='PopupMenu'>"
982            "    <section>"
983            "      <item id='InstrProperties'>"
984            "        <attribute name='label' translatable='yes'>Instrument Properties</attribute>"
985            "        <attribute name='action'>AppMenu.InstrProperties</attribute>"
986            "      </item>"
987            "      <item id='MidiRules'>"
988            "        <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
989            "        <attribute name='action'>AppMenu.MidiRules</attribute>"
990            "      </item>"
991            "      <item id='ScriptSlots'>"
992            "        <attribute name='label' translatable='yes'>Script Slots</attribute>"
993            "        <attribute name='action'>AppMenu.ScriptSlots</attribute>"
994            "      </item>"
995            "      <item id='AddInstrument'>"
996            "        <attribute name='label' translatable='yes'>Add Instrument</attribute>"
997            "        <attribute name='action'>AppMenu.AddInstrument</attribute>"
998            "      </item>"
999            "      <item id='DupInstrument'>"
1000            "        <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1001            "        <attribute name='action'>AppMenu.DupInstrument</attribute>"
1002            "      </item>"
1003            "      <item id='CombInstruments'>"
1004            "        <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1005            "        <attribute name='action'>AppMenu.CombInstruments</attribute>"
1006            "      </item>"
1007            "    </section>"
1008            "    <section>"
1009            "      <item id='RemoveInstrument'>"
1010            "        <attribute name='label' translatable='yes'>Remove Instruments</attribute>"
1011            "        <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
1012            "      </item>"
1013            "    </section>"
1014            "  </menu>"
1015            "  <menu id='SamplePopupMenu'>"
1016            "    <section>"
1017            "      <item id='SampleProperties'>"
1018            "        <attribute name='label' translatable='yes'>Sample Properties</attribute>"
1019            "        <attribute name='action'>AppMenu.SampleProperties</attribute>"
1020            "      </item>"
1021            "      <item id='AddGroup'>"
1022            "        <attribute name='label' translatable='yes'>Add Sample Group</attribute>"
1023            "        <attribute name='action'>AppMenu.AddGroup</attribute>"
1024            "      </item>"
1025            "      <item id='AddSample'>"
1026            "        <attribute name='label' translatable='yes'>Add Sample</attribute>"
1027            "        <attribute name='action'>AppMenu.AddSample</attribute>"
1028            "      </item>"
1029            "      <item id='ShowSampleRefs'>"
1030            "        <attribute name='label' translatable='yes'>Show Sample References ...</attribute>"
1031            "        <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
1032            "      </item>"
1033            "      <item id='ReplaceSample'>"
1034            "        <attribute name='label' translatable='yes'>Replace Sample</attribute>"
1035            "        <attribute name='action'>AppMenu.ReplaceSample</attribute>"
1036            "      </item>"
1037            "      <item id='ReplaceAllSamplesInAllGroups'>"
1038            "        <attribute name='label' translatable='yes'>Replace all Samples ...</attribute>"
1039            "        <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
1040            "      </item>"
1041            "    </section>"
1042            "    <section>"
1043            "      <item id='RemoveSample'>"
1044            "        <attribute name='label' translatable='yes'>Remove Sample</attribute>"
1045            "        <attribute name='action'>AppMenu.RemoveSample</attribute>"
1046            "      </item>"
1047            "      <item id='RemoveUnusedSamples'>"
1048            "        <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
1049            "        <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
1050            "      </item>"
1051            "    </section>"
1052            "  </menu>"
1053            "  <menu id='ScriptPopupMenu'>"
1054            "    <section>"
1055            "      <item id='AddScriptGroup'>"
1056            "        <attribute name='label' translatable='yes'>Add Script Group</attribute>"
1057            "        <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
1058            "      </item>"
1059            "      <item id='AddScript'>"
1060            "        <attribute name='label' translatable='yes'>Add Script</attribute>"
1061            "        <attribute name='action'>AppMenu.AddScript</attribute>"
1062            "      </item>"
1063            "      <item id='EditScript'>"
1064            "        <attribute name='label' translatable='yes'>Edit Script</attribute>"
1065            "        <attribute name='action'>AppMenu.EditScript</attribute>"
1066            "      </item>"
1067            "    </section>"
1068            "    <section>"
1069            "      <item id='RemoveScript'>"
1070            "        <attribute name='label' translatable='yes'>Remove Script</attribute>"
1071            "        <attribute name='action'>AppMenu.RemoveScript</attribute>"
1072            "      </item>"
1073            "    </section>"
1074            "  </menu>"
1075            "</interface>";
1076        m_uiManager->add_from_string(ui_info);
1077    #else
1078      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
1079      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
1080      add_accel_group(uiManager->get_accel_group());      add_accel_group(uiManager->get_accel_group());
# Line 303  MainWindow::MainWindow() : Line 1094  MainWindow::MainWindow() :
1094          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
1095          "    </menu>"          "    </menu>"
1096          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
1097            "      <menuitem action='CopyDimRgn'/>"
1098            "      <menuitem action='AdjustClipboard'/>"
1099            "      <menuitem action='PasteDimRgn'/>"
1100            "      <separator/>"
1101            "      <menuitem action='SelectPrevInstr'/>"
1102            "      <menuitem action='SelectNextInstr'/>"
1103            "      <separator/>"
1104            "      <menuitem action='SelectPrevRegion'/>"
1105            "      <menuitem action='SelectNextRegion'/>"
1106            "      <separator/>"
1107            "      <menuitem action='SelectPrevDimension'/>"
1108            "      <menuitem action='SelectNextDimension'/>"
1109            "      <menuitem action='SelectPrevDimRgnZone'/>"
1110            "      <menuitem action='SelectNextDimRgnZone'/>"
1111            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
1112            "      <menuitem action='SelectAddNextDimRgnZone'/>"
1113            "      <separator/>"
1114          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
1115          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
1116          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
1117          "    </menu>"          "    </menu>"
1118            "    <menu action='MenuMacro'>"
1119            "    </menu>"
1120          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
1121          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
1122          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
1123          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
1124          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
1125            "      <menuitem action='ReplaceSample' />"
1126          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
1127          "      <separator/>"          "      <separator/>"
1128          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
1129            "      <menuitem action='RemoveUnusedSamples'/>"
1130          "    </menu>"          "    </menu>"
1131          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
1132          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 323  MainWindow::MainWindow() : Line 1135  MainWindow::MainWindow() :
1135          "      <menuitem action='InstrProperties'/>"          "      <menuitem action='InstrProperties'/>"
1136          "      <menuitem action='MidiRules'/>"          "      <menuitem action='MidiRules'/>"
1137          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
1138            "      <menu action='AssignScripts'/>"
1139          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
1140          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
1141            "      <menuitem action='CombInstruments'/>"
1142          "      <separator/>"          "      <separator/>"
1143          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
1144          "    </menu>"          "    </menu>"
# Line 337  MainWindow::MainWindow() : Line 1151  MainWindow::MainWindow() :
1151          "    </menu>"          "    </menu>"
1152          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
1153          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
1154            "      <menuitem action='AutoRestoreWinDim'/>"
1155            "      <separator/>"
1156            "      <menuitem action='RefreshAll'/>"
1157          "    </menu>"          "    </menu>"
1158          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
1159          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 1162  MainWindow::MainWindow() :
1162          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
1163          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
1164          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
1165            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
1166            "      <menuitem action='SaveWithTemporaryFile'/>"
1167          "    </menu>"          "    </menu>"
1168          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
1169          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 356  MainWindow::MainWindow() : Line 1175  MainWindow::MainWindow() :
1175          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
1176          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
1177          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
1178            "    <menuitem action='CombInstruments'/>"
1179          "    <separator/>"          "    <separator/>"
1180          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
1181          "  </popup>"          "  </popup>"
# Line 364  MainWindow::MainWindow() : Line 1184  MainWindow::MainWindow() :
1184          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
1185          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
1186          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
1187            "    <menuitem action='ReplaceSample' />"
1188          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
1189          "    <separator/>"          "    <separator/>"
1190          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
1191            "    <menuitem action='RemoveUnusedSamples'/>"
1192          "  </popup>"          "  </popup>"
1193          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
1194          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 377  MainWindow::MainWindow() : Line 1199  MainWindow::MainWindow() :
1199          "  </popup>"          "  </popup>"
1200          "</ui>";          "</ui>";
1201      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
1202    #endif
1203    
1204    #if USE_GTKMM_BUILDER
1205        popup_menu = new Gtk::Menu(
1206            Glib::RefPtr<Gio::Menu>::cast_dynamic(
1207                m_uiManager->get_object("PopupMenu")
1208            )
1209        );
1210        sample_popup = new Gtk::Menu(
1211            Glib::RefPtr<Gio::Menu>::cast_dynamic(
1212                m_uiManager->get_object("SamplePopupMenu")
1213            )
1214        );
1215        script_popup = new Gtk::Menu(
1216            Glib::RefPtr<Gio::Menu>::cast_dynamic(
1217                m_uiManager->get_object("ScriptPopupMenu")
1218            )
1219        );
1220    #else
1221      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
1222            
1223      // Set tooltips for menu items (for some reason, setting a tooltip on the      // Set tooltips for menu items (for some reason, setting a tooltip on the
# Line 397  MainWindow::MainWindow() : Line 1237  MainWindow::MainWindow() :
1237      {      {
1238          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1239              uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));              uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1240          item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action."));          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."));
1241      }      }
1242      {      {
1243          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
# Line 411  MainWindow::MainWindow() : Line 1251  MainWindow::MainWindow() :
1251      }      }
1252      {      {
1253          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1254                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
1255            item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keyboard position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
1256        }
1257        {
1258            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1259                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
1260            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
1261            // copy tooltip to popup menu
1262            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
1263                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
1264            item2->set_tooltip_text(item->get_tooltip_text());
1265        }
1266        {
1267            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1268                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
1269            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
1270        }
1271        {
1272            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1273                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1274            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
1275        }
1276        {
1277            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1278              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1279          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1280      }      }
# Line 419  MainWindow::MainWindow() : Line 1283  MainWindow::MainWindow() :
1283              uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));              uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1284          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."));
1285      }      }
1286    #endif
1287    
1288    #if USE_GTKMM_BUILDER
1289        assign_scripts_menu = new Gtk::Menu(
1290            Glib::RefPtr<Gio::Menu>::cast_dynamic(
1291                m_uiManager->get_object("AssignScripts")
1292            )
1293        );
1294    #else
1295      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
1296          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
1297    
1298        assign_scripts_menu = static_cast<Gtk::MenuItem*>(
1299            uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
1300    #endif
1301    
1302    #if USE_GTKMM_BUILDER
1303        Gtk::Widget* menuBar = NULL;
1304        m_uiManager->get_widget("MenuBar", menuBar);
1305    #else
1306      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1307    #endif
1308    
1309      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1310      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
1311      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
# Line 435  MainWindow::MainWindow() : Line 1316  MainWindow::MainWindow() :
1316      set_file_is_shared(false);      set_file_is_shared(false);
1317    
1318      // Status Bar:      // Status Bar:
1319    #if USE_GTKMM_BOX
1320    # warning No status bar layout for GTKMM 4 yet
1321    #else
1322      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1323      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1324    #endif
1325      m_StatusBar.show();      m_StatusBar.show();
1326    
1327      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
# Line 447  MainWindow::MainWindow() : Line 1332  MainWindow::MainWindow() :
1332    
1333      // Create the Tree model:      // Create the Tree model:
1334      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
1335      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1336      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_refTreeModelFilter->set_visible_func(
1337            sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1338        );
1339        m_TreeView.set_model(m_refTreeModelFilter);
1340    
1341        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1342        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
1343      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1344          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1345      );      );
1346    
1347      // Add the TreeView's view columns:      // Add the TreeView's view columns:
1348      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1349      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1350        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1351        m_TreeView.set_headers_visible(true);
1352        
1353        // establish drag&drop within the instrument tree view, allowing to reorder
1354        // the sequence of instruments within the gig file
1355        {
1356            std::vector<Gtk::TargetEntry> drag_target_instrument;
1357            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1358            m_TreeView.drag_source_set(drag_target_instrument);
1359            m_TreeView.drag_dest_set(drag_target_instrument);
1360            m_TreeView.signal_drag_begin().connect(
1361                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1362            );
1363            m_TreeView.signal_drag_data_get().connect(
1364                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1365            );
1366            m_TreeView.signal_drag_data_received().connect(
1367                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1368            );
1369        }
1370    
1371      // create samples treeview (including its data model)      // create samples treeview (including its data model)
1372      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1373      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1374        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1375      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
1376      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
1377      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 481  MainWindow::MainWindow() : Line 1393  MainWindow::MainWindow() :
1393          );          );
1394      }      }
1395      m_TreeViewSamples.set_headers_visible(true);      m_TreeViewSamples.set_headers_visible(true);
1396    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1397        m_TreeViewSamples.signal_button_press_event().connect(
1398            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1399        );
1400    #else
1401      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
1402          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1403      );      );
1404    #endif
1405      m_refSamplesTreeModel->signal_row_changed().connect(      m_refSamplesTreeModel->signal_row_changed().connect(
1406          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1407      );      );
# Line 500  MainWindow::MainWindow() : Line 1418  MainWindow::MainWindow() :
1418      // m_TreeViewScripts.set_reorderable();      // m_TreeViewScripts.set_reorderable();
1419      m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);      m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1420      m_TreeViewScripts.set_headers_visible(false);      m_TreeViewScripts.set_headers_visible(false);
1421    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1422        m_TreeViewScripts.signal_button_press_event().connect(
1423            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1424        );
1425    #else
1426      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
1427          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1428      );      );
1429      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?  #endif
1430        //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1431      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
1432          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1433      );      );
# Line 540  MainWindow::MainWindow() : Line 1464  MainWindow::MainWindow() :
1464          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1465      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
1466          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1467        m_RegionChooser.signal_instrument_changed().connect(
1468            sigc::mem_fun(*this, &MainWindow::region_changed));
1469      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
1470          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1471      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 599  MainWindow::MainWindow() : Line 1525  MainWindow::MainWindow() :
1525      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
1526          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
1527    
1528        m_searchText.signal_changed().connect(
1529            sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1530        );
1531    
1532      file = 0;      file = 0;
1533      file_is_changed = false;      file_is_changed = false;
1534    
1535    #if HAS_GTKMM_SHOW_ALL_CHILDREN
1536      show_all_children();      show_all_children();
1537    #endif
1538    
1539      // start with a new gig file by default      // start with a new gig file by default
1540      on_action_file_new();      on_action_file_new();
1541    
1542        m_TreeViewNotebook.signal_switch_page().connect(
1543            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1544        );
1545    
1546      // select 'Instruments' tab by default      // select 'Instruments' tab by default
1547      // (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)
1548      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
1549    
1550        Gtk::Clipboard::get()->signal_owner_change().connect(
1551            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1552        );
1553        updateClipboardPasteAvailable();
1554        updateClipboardCopyAvailable();
1555    
1556        // setup macros and their keyboard accelerators
1557        {
1558    #if USE_GTKMM_BUILDER
1559            menuMacro = new Gtk::Menu(
1560                Glib::RefPtr<Gio::Menu>::cast_dynamic(
1561                    m_uiManager->get_object("MenuMacro")
1562                )
1563            );
1564    #else
1565            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1566                uiManager->get_widget("/MenuBar/MenuMacro")
1567            )->get_submenu();
1568    #endif
1569    
1570            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1571            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1572            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1573            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1574            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1575            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1576            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1577            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1578            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1579            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1580            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1581            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1582            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1583            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1584    
1585            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1586            menuMacro->set_accel_group(accelGroup);
1587    
1588            updateMacroMenu();
1589        }
1590    
1591        // setup "Assign Scripts" keyboard accelerators
1592        {
1593            Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1594            Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1595            Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1596            Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1597            Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1598            Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1599            Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1600            Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1601            Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1602            Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1603            Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1604            Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1605    
1606            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1607            assign_scripts_menu->set_accel_group(accelGroup);
1608        }
1609    
1610        Glib::signal_idle().connect_once(
1611            sigc::mem_fun(*this, &MainWindow::bringToFront),
1612            200
1613        );
1614  }  }
1615    
1616  MainWindow::~MainWindow()  MainWindow::~MainWindow()
1617  {  {
1618  }  }
1619    
1620    void MainWindow::bringToFront() {
1621        #if defined(__APPLE__)
1622        macRaiseAppWindow();
1623        #endif
1624        raise();
1625        present();
1626    }
1627    
1628    void MainWindow::updateMacroMenu() {
1629    #if !USE_GTKMM_BUILDER
1630        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1631            uiManager->get_widget("/MenuBar/MenuMacro")
1632        )->get_submenu();
1633    #endif
1634    
1635        // remove all entries from "Macro" menu
1636        {
1637            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1638            for (int i = 0; i < children.size(); ++i) {
1639                Gtk::Widget* child = children[i];
1640                menuMacro->remove(*child);
1641                delete child;
1642            }
1643        }
1644    
1645        // (re)load all macros from config file
1646        try {
1647            Settings::singleton()->loadMacros(m_macros);
1648        } catch (Serialization::Exception e) {
1649            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1650        } catch (...) {
1651            std::cerr << "Unknown exception while loading macros!" << std::endl;
1652        }
1653    
1654        // add all configured macros as menu items to the "Macro" menu
1655        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1656            const Serialization::Archive& macro = m_macros[iMacro];
1657            std::string name =
1658                macro.name().empty() ?
1659                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1660            Gtk::MenuItem* item = new Gtk::MenuItem(name);
1661            item->signal_activate().connect(
1662                sigc::bind(
1663                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1664                )
1665            );
1666            menuMacro->append(*item);
1667            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1668            Glib::ustring comment = macro.comment();
1669            if (!comment.empty())
1670                item->set_tooltip_text(comment);
1671        }
1672        // if there are no macros configured at all, then show a dummy entry instead
1673        if (m_macros.empty()) {
1674            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1675            item->set_sensitive(false);
1676            menuMacro->append(*item);
1677        }
1678    
1679        // add separator line to menu
1680        menuMacro->append(*new Gtk::SeparatorMenuItem);
1681    
1682        {
1683            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1684            item->signal_activate().connect(
1685                sigc::mem_fun(*this, &MainWindow::setupMacros)
1686            );
1687            menuMacro->append(*item);
1688            item->set_accel_path("<Macros>/SetupMacros");
1689        }
1690    
1691    #if HAS_GTKMM_SHOW_ALL_CHILDREN
1692        menuMacro->show_all_children();
1693    #endif
1694    }
1695    
1696    void MainWindow::onMacroSelected(int iMacro) {
1697        printf("onMacroSelected(%d)\n", iMacro);
1698        if (iMacro < 0 || iMacro >= m_macros.size()) return;
1699        Glib::ustring errorText;
1700        try {
1701            applyMacro(m_macros[iMacro]);
1702        } catch (Serialization::Exception e) {
1703            errorText = e.Message;
1704        } catch (...) {
1705            errorText = _("Unknown exception while applying macro");
1706        }
1707        if (!errorText.empty()) {
1708            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1709            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1710            msg.run();
1711        }
1712    }
1713    
1714    void MainWindow::setupMacros() {
1715        MacrosSetup* setup = new MacrosSetup();
1716        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1717        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1718        setup->signal_macros_changed().connect(
1719            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1720        );
1721        setup->show();
1722    }
1723    
1724    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1725        m_macros = macros;
1726        Settings::singleton()->saveMacros(m_macros);
1727        updateMacroMenu();
1728    }
1729    
1730    //NOTE: the actual signal's first argument for argument 'page' is on some gtkmm version GtkNotebookPage* and on some Gtk::Widget*. Since we don't need that argument, it is simply void* here for now.
1731    void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1732        bool isInstrumentsPage = (page_num == 1);
1733        // so far we only support filtering for the instruments list, so hide the
1734        // filter text entry field if another tab is selected
1735        m_searchField.set_visible(isInstrumentsPage);
1736    }
1737    
1738  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1739  {  {
1740      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 635  void MainWindow::region_changed() Line 1754  void MainWindow::region_changed()
1754  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
1755  {  {
1756      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
1757      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1758          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
1759        //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1760        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1761      if (it) {      if (it) {
1762          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1763          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 679  void MainWindow::update_dimregs() Line 1800  void MainWindow::update_dimregs()
1800              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1801          }          }
1802      }      }
1803    
1804        m_RegionChooser.setModifyAllRegions(all_regions);
1805        m_DimRegionChooser.setModifyAllRegions(all_regions);
1806        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1807        m_DimRegionChooser.setModifyBothChannels(stereo);
1808    
1809        updateClipboardCopyAvailable();
1810  }  }
1811    
1812  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 695  void MainWindow::dimreg_changed() Line 1823  void MainWindow::dimreg_changed()
1823    
1824  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1825  {  {
1826    #if !USE_GTKMM_BUILDER
1827      // select item in instrument menu      // select item in instrument menu
1828      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1829      if (it) {      if (!rows.empty()) {
1830          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1831          int index = path[0];          if (it) {
1832          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1833              instrument_menu->get_children();              int index = path[0];
1834          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1835                    instrument_menu->get_children();
1836                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1837            }
1838      }      }
1839    #endif
1840    
1841        updateScriptListOfMenu();
1842    
1843      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
1844    
# Line 727  void Loader::progress_callback(float fra Line 1862  void Loader::progress_callback(float fra
1862      progress_dispatcher();      progress_dispatcher();
1863  }  }
1864    
1865    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1866    // make sure stack is 16-byte aligned for SSE instructions
1867    __attribute__((force_align_arg_pointer))
1868    #endif
1869  void Loader::thread_function()  void Loader::thread_function()
1870  {  {
1871      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1872               static_cast<void*>(Glib::Threads::Thread::self()));
1873      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1874      try {      try {
1875          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 751  void Loader::thread_function() Line 1891  void Loader::thread_function()
1891  }  }
1892    
1893  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1894      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
1895  {  {
1896  }  }
1897    
# Line 762  void Loader::launch() Line 1902  void Loader::launch()
1902  #else  #else
1903      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1904  #endif  #endif
1905      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1906  }  }
1907    
1908  float Loader::get_progress()  float Loader::get_progress()
# Line 805  void Saver::progress_callback(float frac Line 1945  void Saver::progress_callback(float frac
1945      progress_dispatcher.emit();      progress_dispatcher.emit();
1946  }  }
1947    
1948    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1949    // make sure stack is 16-byte aligned for SSE instructions
1950    __attribute__((force_align_arg_pointer))
1951    #endif
1952  void Saver::thread_function()  void Saver::thread_function()
1953  {  {
1954      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1955               static_cast<void*>(Glib::Threads::Thread::self()));
1956      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1957      try {      try {
1958          gig::progress_t progress;          gig::progress_t progress;
# Line 816  void Saver::thread_function() Line 1961  void Saver::thread_function()
1961    
1962          // if no filename was provided, that means "save", if filename was provided means "save as"          // if no filename was provided, that means "save", if filename was provided means "save as"
1963          if (filename.empty()) {          if (filename.empty()) {
1964              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1965                    // save directly over the existing .gig file
1966                    // (requires less disk space than solution below
1967                    // but may be slower)
1968                    gig->Save(&progress);
1969                } else {
1970                    // save the file as separate temporary file first,
1971                    // then move the saved file over the old file
1972                    // (may result in performance speedup during save)
1973                    gig::String tmpname = filename + ".TMP";
1974                    gig->Save(tmpname, &progress);
1975                    #if defined(WIN32)
1976                    if (!DeleteFile(filename.c_str())) {
1977                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1978                    }
1979                    #else // POSIX ...
1980                    if (unlink(filename.c_str())) {
1981                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1982                    }
1983                    #endif
1984                    if (rename(tmpname.c_str(), filename.c_str())) {
1985                        #if defined(WIN32)
1986                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1987                        #else
1988                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1989                        #endif
1990                    }
1991                }
1992          } else {          } else {
1993              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1994          }          }
# Line 844  void Saver::launch() Line 2016  void Saver::launch()
2016  #else  #else
2017      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2018  #endif  #endif
2019      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
2020  }  }
2021    
2022  float Saver::get_progress()  float Saver::get_progress()
# Line 875  Glib::Dispatcher& Saver::signal_error() Line 2047  Glib::Dispatcher& Saver::signal_error()
2047  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2048      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
2049  {  {
2050    #if USE_GTKMM_BOX
2051        get_content_area()->pack_start(progressBar);
2052    #else
2053      get_vbox()->pack_start(progressBar);      get_vbox()->pack_start(progressBar);
2054    #endif
2055    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2056      show_all_children();      show_all_children();
2057    #endif
2058      resize(600,50);      resize(600,50);
2059  }  }
2060    
# Line 889  void MainWindow::__clear() { Line 2067  void MainWindow::__clear() {
2067      m_refTreeModel->clear();      m_refTreeModel->clear();
2068      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2069      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2070    #if !USE_GTKMM_BUILDER
2071      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2072      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2073          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2074      }      }
2075    #endif
2076      // free libgig's gig::File instance      // free libgig's gig::File instance
2077      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
2078      file = NULL;      file = NULL;
# Line 904  void MainWindow::__refreshEntireGUI() { Line 2084  void MainWindow::__refreshEntireGUI() {
2084      m_refTreeModel->clear();      m_refTreeModel->clear();
2085      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2086      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2087    #if !USE_GTKMM_BUILDER
2088      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
2089      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
2090          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
2091      }      }
2092    #endif
2093    
2094      if (!this->file) return;      if (!this->file) return;
2095    
# Line 941  bool MainWindow::close_confirmation_dial Line 2123  bool MainWindow::close_confirmation_dial
2123      g_free(msg);      g_free(msg);
2124      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."));
2125      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2126    #if HAS_GTKMM_STOCK
2127      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2128      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2129    #else
2130        dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2131        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2132    #endif
2133      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
2134      int response = dialog.run();      int response = dialog.run();
2135      dialog.hide();      dialog.hide();
2136    
2137        // user decided to exit app without saving
2138        if (response == Gtk::RESPONSE_NO) return true;
2139    
2140        // user cancelled dialog, thus don't close app
2141        if (response == Gtk::RESPONSE_CANCEL) return false;
2142    
2143      // TODO: the following return valid is disabled and hard coded instead for      // TODO: the following return valid is disabled and hard coded instead for
2144      // now, due to the fact that saving with progress bar is now implemented      // now, due to the fact that saving with progress bar is now implemented
2145      // asynchronously, as a result the app does not close automatically anymore      // asynchronously, as a result the app does not close automatically anymore
# Line 967  bool MainWindow::leaving_shared_mode_dia Line 2160  bool MainWindow::leaving_shared_mode_dia
2160            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
2161            "load it."));            "load it."));
2162      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2163    #if HAS_GTKMM_STOCK
2164      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2165    #else
2166        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2167    #endif
2168      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2169      int response = dialog.run();      int response = dialog.run();
2170      dialog.hide();      dialog.hide();
# Line 981  void MainWindow::on_action_file_open() Line 2178  void MainWindow::on_action_file_open()
2178      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
2179    
2180      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
2181    #if HAS_GTKMM_STOCK
2182      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2183      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2184    #else
2185        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2186        dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2187    #endif
2188      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
2189  #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
2190      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 998  void MainWindow::on_action_file_open() Line 2200  void MainWindow::on_action_file_open()
2200      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2201          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
2202          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
2203          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
2204                   static_cast<void*>(Glib::Threads::Thread::self()));
2205          load_file(filename.c_str());          load_file(filename.c_str());
2206          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
2207      }      }
# Line 1013  void MainWindow::load_file(const char* n Line 2216  void MainWindow::load_file(const char* n
2216          Glib::filename_display_basename(name) + "' ...",          Glib::filename_display_basename(name) + "' ...",
2217          *this          *this
2218      );      );
2219    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2220      progress_dialog->show_all();      progress_dialog->show_all();
2221    #endif
2222      loader = new Loader(name); //FIXME: memory leak!      loader = new Loader(name); //FIXME: memory leak!
2223      loader->signal_progress().connect(      loader->signal_progress().connect(
2224          sigc::mem_fun(*this, &MainWindow::on_loader_progress));          sigc::mem_fun(*this, &MainWindow::on_loader_progress));
# Line 1047  void MainWindow::load_instrument(gig::In Line 2252  void MainWindow::load_instrument(gig::In
2252              // make sure the selected item in the "instruments" tree view is              // make sure the selected item in the "instruments" tree view is
2253              // visible (scroll to it)              // visible (scroll to it)
2254              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2255    #if !USE_GTKMM_BUILDER
2256              // select item in instrument menu              // select item in instrument menu
2257              {              {
2258                  const std::vector<Gtk::Widget*> children =                  const std::vector<Gtk::Widget*> children =
2259                      instrument_menu->get_children();                      instrument_menu->get_children();
2260                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();                  static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2261              }              }
2262    #endif
2263              // update region chooser and dimension region chooser              // update region chooser and dimension region chooser
2264              m_RegionChooser.set_instrument(instr);              m_RegionChooser.set_instrument(instr);
2265              break;              break;
# Line 1068  void MainWindow::on_loader_progress() Line 2275  void MainWindow::on_loader_progress()
2275  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
2276  {  {
2277      printf("Loader finished!\n");      printf("Loader finished!\n");
2278      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
2279               static_cast<void*>(Glib::Threads::Thread::self()));
2280      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
2281      progress_dialog->hide();      progress_dialog->hide();
2282  }  }
# Line 1123  bool MainWindow::file_save() Line 2331  bool MainWindow::file_save()
2331          Glib::filename_display_basename(this->filename) + "' ...",          Glib::filename_display_basename(this->filename) + "' ...",
2332          *this          *this
2333      );      );
2334    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2335      progress_dialog->show_all();      progress_dialog->show_all();
2336    #endif
2337      saver = new Saver(this->file); //FIXME: memory leak!      saver = new Saver(this->file); //FIXME: memory leak!
2338      saver->signal_progress().connect(      saver->signal_progress().connect(
2339          sigc::mem_fun(*this, &MainWindow::on_saver_progress));          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 1163  void MainWindow::on_saver_finished() Line 2373  void MainWindow::on_saver_finished()
2373    
2374      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
2375    
2376      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
2377      progress_dialog->hide();      progress_dialog->hide();
2378  }  }
2379    
# Line 1176  void MainWindow::on_action_file_save_as( Line 2386  void MainWindow::on_action_file_save_as(
2386  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
2387  {  {
2388      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2389    #if HAS_GTKMM_STOCK
2390      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2391      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2392    #else
2393        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2394        dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2395    #endif
2396      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
2397      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
2398    
# Line 1206  bool MainWindow::file_save_as() Line 2421  bool MainWindow::file_save_as()
2421      }      }
2422    
2423      // show warning in the dialog      // show warning in the dialog
2424      Gtk::HBox descriptionArea;      HBox descriptionArea;
2425      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
2426      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
2427        warningIcon.set_from_icon_name("dialog-warning",
2428                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2429      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2430  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2431      view::WrapLabel description;      view::WrapLabel description;
# Line 1225  bool MainWindow::file_save_as() Line 2442  bool MainWindow::file_save_as()
2442            "same .gig file will end up in corrupted sample wave data!\n")            "same .gig file will end up in corrupted sample wave data!\n")
2443      );      );
2444      descriptionArea.pack_start(description);      descriptionArea.pack_start(description);
2445    #if USE_GTKMM_BOX
2446        dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2447    #else
2448      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2449    #endif
2450    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2451      descriptionArea.show_all();      descriptionArea.show_all();
2452    #endif
2453    
2454      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2455          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
# Line 1240  bool MainWindow::file_save_as() Line 2463  bool MainWindow::file_save_as()
2463              Glib::filename_display_basename(filename) + "' ...",              Glib::filename_display_basename(filename) + "' ...",
2464              *this              *this
2465          );          );
2466    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2467          progress_dialog->show_all();          progress_dialog->show_all();
2468    #endif
2469    
2470          saver = new Saver(file, filename); //FIXME: memory leak!          saver = new Saver(file, filename); //FIXME: memory leak!
2471          saver->signal_progress().connect(          saver->signal_progress().connect(
# Line 1260  bool MainWindow::file_save_as() Line 2485  bool MainWindow::file_save_as()
2485  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
2486      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
2487      Glib::ustring error_files;      Glib::ustring error_files;
2488      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2489      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2490           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
2491          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
2492          SF_INFO info;          SF_INFO info;
2493          info.format = 0;          info.format = 0;
2494          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2495          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2496          try {          try {
2497              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1289  void MainWindow::__import_queued_samples Line 2514  void MainWindow::__import_queued_samples
2514                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
2515              }              }
2516    
2517                // reset write position for sample
2518                iter->first->SetPos(0);
2519    
2520              const int bufsize = 10000;              const int bufsize = 10000;
2521              switch (bitdepth) {              switch (bitdepth) {
2522                  case 16: {                  case 16: {
# Line 1298  void MainWindow::__import_queued_samples Line 2526  void MainWindow::__import_queued_samples
2526                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
2527                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
2528                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
2529                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
2530                          cnt -= n;                          cnt -= n;
2531                      }                      }
2532                      delete[] buffer;                      delete[] buffer;
# Line 1318  void MainWindow::__import_queued_samples Line 2546  void MainWindow::__import_queued_samples
2546                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
2547                          }                          }
2548                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
2549                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
2550                          cnt -= n;                          cnt -= n;
2551                      }                      }
2552                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1329  void MainWindow::__import_queued_samples Line 2557  void MainWindow::__import_queued_samples
2557              // cleanup              // cleanup
2558              sf_close(hFile);              sf_close(hFile);
2559              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
2560              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
2561              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
2562              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
2563              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2564              ++iter;              ++iter;
2565              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
2566          } catch (std::string what) {          } catch (std::string what) {
2567              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
2568              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
2569              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
2570              ++iter;              ++iter;
2571          }          }
2572      }      }
# Line 1366  void MainWindow::on_action_sync_sampler_ Line 2594  void MainWindow::on_action_sync_sampler_
2594          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
2595  }  }
2596    
2597    void MainWindow::on_action_move_root_note_with_region_moved() {
2598        Settings::singleton()->moveRootNoteWithRegionMoved =
2599            !Settings::singleton()->moveRootNoteWithRegionMoved;
2600    }
2601    
2602  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
2603  {  {
2604      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1375  void MainWindow::on_action_help_about() Line 2608  void MainWindow::on_action_help_about()
2608      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
2609  #endif  #endif
2610      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2611      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
2612      const std::string sComment =      const std::string sComment =
2613          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
2614          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1391  void MainWindow::on_action_help_about() Line 2624  void MainWindow::on_action_help_about()
2624      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
2625      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
2626      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
2627        dialog.set_position(Gtk::WIN_POS_CENTER);
2628      dialog.run();      dialog.run();
2629  }  }
2630    
# Line 1412  PropDialog::PropDialog() Line 2646  PropDialog::PropDialog()
2646        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
2647        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
2648        eSubject(_("Subject")),        eSubject(_("Subject")),
2649    #if HAS_GTKMM_STOCK
2650        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
2651    #else
2652          quitButton(_("_Close")),
2653    #endif
2654        table(2, 1),        table(2, 1),
2655        m_file(NULL)        m_file(NULL)
2656  {  {
2657        if (!Settings::singleton()->autoRestoreWindowDimension) {
2658            set_default_size(470, 390);
2659            set_position(Gtk::WIN_POS_MOUSE);
2660        }
2661    
2662      set_title(_("File Properties"));      set_title(_("File Properties"));
2663      eName.set_width_chars(50);      eName.set_width_chars(50);
2664    
# Line 1454  PropDialog::PropDialog() Line 2697  PropDialog::PropDialog()
2697      table.add(eCommissioned);      table.add(eCommissioned);
2698      table.add(eSubject);      table.add(eSubject);
2699    
2700    #if USE_GTKMM_GRID
2701        table.set_column_spacing(5);
2702    #else
2703      table.set_col_spacings(5);      table.set_col_spacings(5);
2704    #endif
2705    
2706      add(vbox);      add(vbox);
2707    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2708        table.set_margin(5);
2709    #else
2710      table.set_border_width(5);      table.set_border_width(5);
2711    #endif
2712      vbox.add(table);      vbox.add(table);
2713      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2714      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2715    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2716        buttonBox.set_margin(5);
2717    #else
2718      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
2719    #endif
2720      buttonBox.show();      buttonBox.show();
2721      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2722      quitButton.set_can_default();      quitButton.set_can_default();
# Line 1472  PropDialog::PropDialog() Line 2728  PropDialog::PropDialog()
2728    
2729      quitButton.show();      quitButton.show();
2730      vbox.show();      vbox.show();
2731    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2732      show_all_children();      show_all_children();
2733    #endif
2734  }  }
2735    
2736  void PropDialog::set_file(gig::File* file)  void PropDialog::set_file(gig::File* file)
# Line 1535  void InstrumentProps::set_MIDIProgram(ui Line 2793  void InstrumentProps::set_MIDIProgram(ui
2793  }  }
2794    
2795  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
2796    #if HAS_GTKMM_STOCK
2797      quitButton(Gtk::Stock::CLOSE),      quitButton(Gtk::Stock::CLOSE),
2798    #else
2799        quitButton(_("_Close")),
2800    #endif
2801      table(2,1),      table(2,1),
2802      eName(_("Name")),      eName(_("Name")),
2803      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1545  InstrumentProps::InstrumentProps() : Line 2807  InstrumentProps::InstrumentProps() :
2807      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2808      eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
2809      eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
2810      ePitchbendRange(_("Pitchbend range"), 0, 12),      ePitchbendRange(_("Pitchbend range"), 0, 48),
2811      ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
2812      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2813      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2814  {  {
2815        if (!Settings::singleton()->autoRestoreWindowDimension) {
2816            //set_default_size(470, 390);
2817            set_position(Gtk::WIN_POS_MOUSE);
2818        }
2819    
2820      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2821    
2822      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1576  InstrumentProps::InstrumentProps() : Line 2843  InstrumentProps::InstrumentProps() :
2843    
2844      eName.signal_value_changed().connect(sig_name_changed.make_slot());      eName.signal_value_changed().connect(sig_name_changed.make_slot());
2845    
2846    #if USE_GTKMM_GRID
2847        table.set_column_spacing(5);
2848    #else
2849      table.set_col_spacings(5);      table.set_col_spacings(5);
2850    #endif
2851    
2852      table.add(eName);      table.add(eName);
2853      table.add(eIsDrum);      table.add(eIsDrum);
# Line 1592  InstrumentProps::InstrumentProps() : Line 2863  InstrumentProps::InstrumentProps() :
2863      table.add(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
2864    
2865      add(vbox);      add(vbox);
2866    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2867        table.set_margin(5);
2868    #else
2869      table.set_border_width(5);      table.set_border_width(5);
2870    #endif
2871      vbox.pack_start(table);      vbox.pack_start(table);
2872      table.show();      table.show();
2873      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2874      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2875    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2876        buttonBox.set_margin(5);
2877    #else
2878      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
2879    #endif
2880      buttonBox.show();      buttonBox.show();
2881      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
2882      quitButton.set_can_default();      quitButton.set_can_default();
# Line 1608  InstrumentProps::InstrumentProps() : Line 2887  InstrumentProps::InstrumentProps() :
2887    
2888      quitButton.show();      quitButton.show();
2889      vbox.show();      vbox.show();
2890    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2891      show_all_children();      show_all_children();
2892    #endif
2893  }  }
2894    
2895  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
# Line 1658  void MainWindow::load_gig(gig::File* gig Line 2939  void MainWindow::load_gig(gig::File* gig
2939      file = 0;      file = 0;
2940      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
2941    
2942      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
2943            (filename && strlen(filename) > 0) ?
2944                filename : (!gig->GetFileName().empty()) ?
2945                    gig->GetFileName() : _("Unsaved Gig File");
2946      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
2947      file_has_name = filename;      file_has_name = filename;
2948      file_is_changed = false;      file_is_changed = false;
# Line 1667  void MainWindow::load_gig(gig::File* gig Line 2951  void MainWindow::load_gig(gig::File* gig
2951      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2952    
2953      instrument_name_connection.block();      instrument_name_connection.block();
2954        int index = 0;
2955      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2956           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2957          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2958            const int iScriptSlots = instrument->ScriptSlotCount();
2959    
2960          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2961          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2962            row[m_Columns.m_col_nr] = index;
2963          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2964          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2965            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2966    
2967    #if !USE_GTKMM_BUILDER
2968          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2969    #endif
2970      }      }
2971      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2972    #if !USE_GTKMM_BUILDER
2973      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
2974    #endif
2975    
2976      updateSampleRefCountMap(gig);      updateSampleRefCountMap(gig);
2977    
# Line 1745  bool MainWindow::instr_props_set_instrum Line 3037  bool MainWindow::instr_props_set_instrum
3037  {  {
3038      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
3039    
3040      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3041          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
3042            instrumentProps.hide();
3043            return false;
3044        }
3045        //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3046        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3047      if (it) {      if (it) {
3048          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3049          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1763  bool MainWindow::instr_props_set_instrum Line 3060  bool MainWindow::instr_props_set_instrum
3060      } else {      } else {
3061          instrumentProps.hide();          instrumentProps.hide();
3062      }      }
3063      return it;      //NOTE: explicit boolean cast required for GTKMM4 development branch here
3064        return it ? true : false;
3065  }  }
3066    
3067  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
# Line 1799  void MainWindow::show_midi_rules() Line 3097  void MainWindow::show_midi_rules()
3097  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
3098      if (!file) return;      if (!file) return;
3099      // get selected instrument      // get selected instrument
3100      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3101      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
3102        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3103      if (!it) return;      if (!it) return;
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 1808  void MainWindow::show_script_slots() { Line 3107  void MainWindow::show_script_slots() {
3107    
3108      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
3109      window->setInstrument(instrument);      window->setInstrument(instrument);
3110        window->signal_script_slots_changed().connect(
3111            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3112        );
3113      //window->reparent(*this);      //window->reparent(*this);
3114      window->show();      window->show();
3115  }  }
3116    
3117    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3118        if (!pInstrument) return;
3119        const int iScriptSlots = pInstrument->ScriptSlotCount();
3120    
3121        //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!
3122        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3123        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3124    
3125        for (int i = 0; i < model->children().size(); ++i) {
3126            Gtk::TreeModel::Row row = model->children()[i];
3127            if (row[m_Columns.m_col_instr] != pInstrument) continue;
3128            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3129            break;
3130        }
3131    
3132        // causes the sampler to reload the instrument with the new script
3133        on_sel_change();
3134    }
3135    
3136    void MainWindow::assignScript(gig::Script* pScript) {
3137        if (!pScript) {
3138            printf("assignScript() : !script\n");
3139            return;
3140        }
3141        printf("assignScript('%s')\n", pScript->Name.c_str());
3142    
3143        gig::Instrument* pInstrument = get_instrument();
3144        if (!pInstrument) {
3145            printf("!instrument\n");
3146            return;
3147        }
3148    
3149        pInstrument->AddScriptSlot(pScript);
3150    
3151        onScriptSlotsModified(pInstrument);
3152    }
3153    
3154    void MainWindow::on_action_refresh_all() {
3155        __refreshEntireGUI();
3156    }
3157    
3158  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
3159    #if USE_GLIB_ACTION
3160        bool active = false;
3161        m_actionToggleStatusBar->get_state(active);
3162        // for some reason toggle state does not change automatically
3163        active = !active;
3164        m_actionToggleStatusBar->change_state(active);
3165        if (active)
3166            m_StatusBar.show();
3167        else
3168            m_StatusBar.hide();
3169    #else
3170      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3171          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3172      if (!item) {      if (!item) {
# Line 1821  void MainWindow::on_action_view_status_b Line 3175  void MainWindow::on_action_view_status_b
3175      }      }
3176      if (item->get_active()) m_StatusBar.show();      if (item->get_active()) m_StatusBar.show();
3177      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
3178    #endif
3179    }
3180    
3181    void MainWindow::on_auto_restore_win_dim() {
3182    #if USE_GLIB_ACTION
3183        bool active = false;
3184        m_actionToggleRestoreWinDim->get_state(active);
3185        // for some reason toggle state does not change automatically
3186        active = !active;
3187        m_actionToggleRestoreWinDim->change_state(active);
3188        Settings::singleton()->autoRestoreWindowDimension = active;
3189    #else
3190        Gtk::CheckMenuItem* item =
3191            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3192        if (!item) {
3193            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
3194            return;
3195        }
3196        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3197    #endif
3198    }
3199    
3200    void MainWindow::on_save_with_temporary_file() {
3201    #if USE_GLIB_ACTION
3202        bool active = false;
3203        m_actionToggleSaveWithTempFile->get_state(active);
3204        // for some reason toggle state does not change automatically
3205        active = !active;
3206        m_actionToggleSaveWithTempFile->change_state(active);
3207        Settings::singleton()->saveWithTemporaryFile = active;
3208    #else
3209        Gtk::CheckMenuItem* item =
3210            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3211        if (!item) {
3212            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
3213            return;
3214        }
3215        Settings::singleton()->saveWithTemporaryFile = item->get_active();
3216    #endif
3217  }  }
3218    
3219  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
3220    #if USE_GLIB_ACTION
3221        bool active = false;
3222        m_actionToggleCopySampleUnity->get_state(active);
3223        return active;
3224    #else
3225      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3226          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3227      if (!item) {      if (!item) {
# Line 1831  bool MainWindow::is_copy_samples_unity_n Line 3229  bool MainWindow::is_copy_samples_unity_n
3229          return true;          return true;
3230      }      }
3231      return item->get_active();      return item->get_active();
3232    #endif
3233  }  }
3234    
3235  bool MainWindow::is_copy_samples_fine_tune_enabled() const {  bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3236    #if USE_GLIB_ACTION
3237        bool active = false;
3238        m_actionToggleCopySampleTune->get_state(active);
3239        return active;
3240    #else
3241      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3242          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3243      if (!item) {      if (!item) {
# Line 1841  bool MainWindow::is_copy_samples_fine_tu Line 3245  bool MainWindow::is_copy_samples_fine_tu
3245          return true;          return true;
3246      }      }
3247      return item->get_active();      return item->get_active();
3248    #endif
3249  }  }
3250    
3251  bool MainWindow::is_copy_samples_loop_enabled() const {  bool MainWindow::is_copy_samples_loop_enabled() const {
3252    #if USE_GLIB_ACTION
3253        bool active = false;
3254        m_actionToggleCopySampleLoop->get_state(active);
3255        return active;
3256    #else
3257      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
3258          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3259      if (!item) {      if (!item) {
# Line 1851  bool MainWindow::is_copy_samples_loop_en Line 3261  bool MainWindow::is_copy_samples_loop_en
3261          return true;          return true;
3262      }      }
3263      return item->get_active();      return item->get_active();
3264    #endif
3265  }  }
3266    
3267  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
3268  {  bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3269        GdkEventButton* button = _button.gobj();
3270    #else
3271    void MainWindow::on_button_release(GdkEventButton* button) {
3272    #endif
3273      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3274          show_instr_props();          show_instr_props();
3275      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3276          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3277          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3278    #if USE_GTKMM_BUILDER
3279            m_actionMIDIRules->property_enabled() = bEnabled;
3280    #else
3281          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
3282              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(              uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3283                  bEnabled                  bEnabled
# Line 1868  void MainWindow::on_button_release(GdkEv Line 3286  void MainWindow::on_button_release(GdkEv
3286              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3287                  bEnabled                  bEnabled
3288              );              );
3289    #endif
3290          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
3291      }      }
3292    #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
3293        return false;
3294    #endif
3295  }  }
3296    
3297    #if !USE_GTKMM_BUILDER
3298  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3299      if (item->get_active()) {      if (item->get_active()) {
3300          const std::vector<Gtk::Widget*> children =          const std::vector<Gtk::Widget*> children =
# Line 1886  void MainWindow::on_instrument_selection Line 3309  void MainWindow::on_instrument_selection
3309          }          }
3310      }      }
3311  }  }
3312    #endif
3313    
3314    void MainWindow::select_instrument(gig::Instrument* instrument) {
3315        if (!instrument) return;
3316    
3317        //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!
3318        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3319        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3320    
3321        for (int i = 0; i < model->children().size(); ++i) {
3322            Gtk::TreeModel::Row row = model->children()[i];
3323            if (row[m_Columns.m_col_instr] == instrument) {
3324                // select and show the respective instrument in the list view
3325                show_intruments_tab();
3326                m_TreeView.get_selection()->unselect_all();
3327                
3328    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3329                auto iterSel = model->children()[i].get_iter();
3330                m_TreeView.get_selection()->select(iterSel);
3331    #else
3332                m_TreeView.get_selection()->select(model->children()[i]);
3333    #endif
3334                std::vector<Gtk::TreeModel::Path> rows =
3335                    m_TreeView.get_selection()->get_selected_rows();
3336                if (!rows.empty())
3337                    m_TreeView.scroll_to_row(rows[0]);
3338                on_sel_change(); // the regular instrument selection change callback
3339            }
3340        }
3341    }
3342    
3343    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
3344    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
3345        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3346        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3347    
3348        //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!
3349        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3350        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3351    
3352        for (int i = 0; i < model->children().size(); ++i) {
3353            Gtk::TreeModel::Row row = model->children()[i];
3354            if (row[m_Columns.m_col_instr] == pInstrument) {
3355                // select and show the respective instrument in the list view
3356                show_intruments_tab();
3357                m_TreeView.get_selection()->unselect_all();
3358    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3359                auto iterSel = model->children()[i].get_iter();
3360                m_TreeView.get_selection()->select(iterSel);
3361    #else
3362                m_TreeView.get_selection()->select(model->children()[i]);
3363    #endif
3364                std::vector<Gtk::TreeModel::Path> rows =
3365                    m_TreeView.get_selection()->get_selected_rows();
3366                if (!rows.empty())
3367                    m_TreeView.scroll_to_row(rows[0]);
3368                on_sel_change(); // the regular instrument selection change callback
3369    
3370                // select respective region in the region selector
3371                m_RegionChooser.set_region(pRegion);
3372    
3373                // select and show the respective dimension region in the editor
3374                //update_dimregs();
3375                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
3376                //dimreg_edit.set_dim_region(dimRgn);
3377    
3378                return true;
3379            }
3380        }
3381    
3382        return false;
3383    }
3384    
3385  void MainWindow::select_sample(gig::Sample* sample) {  void MainWindow::select_sample(gig::Sample* sample) {
3386      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
# Line 1895  void MainWindow::select_sample(gig::Samp Line 3390  void MainWindow::select_sample(gig::Samp
3390              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3391              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3392                  show_samples_tab();                  show_samples_tab();
3393                    m_TreeViewSamples.get_selection()->unselect_all();
3394    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3395                    auto iterSel = rowGroup.children()[s].get_iter();
3396                    m_TreeViewSamples.get_selection()->select(iterSel);
3397    #else
3398                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3399                  Gtk::TreePath path(  #endif
3400                      m_TreeViewSamples.get_selection()->get_selected()                  std::vector<Gtk::TreeModel::Path> rows =
3401                  );                      m_TreeViewSamples.get_selection()->get_selected_rows();
3402                  m_TreeViewSamples.scroll_to_row(path);                  if (rows.empty()) return;
3403                    m_TreeViewSamples.scroll_to_row(rows[0]);
3404                  return;                  return;
3405              }              }
3406          }          }
3407      }      }
3408  }  }
3409    
3410    #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
3411    bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3412        GdkEventButton* button = _button.gobj();
3413    #else
3414  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3415    #endif
3416      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3417            // by default if Ctrl keys is pressed down, then a mouse right-click
3418            // does not select the respective row, so we must assure this
3419            // programmatically ...
3420            /*{
3421                Gtk::TreeModel::Path path;
3422                Gtk::TreeViewColumn* pColumn = NULL;
3423                int cellX, cellY;
3424                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
3425                    (int)button->x, (int)button->y,
3426                    path, pColumn, cellX, cellY
3427                );
3428                if (bSuccess) {
3429                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
3430                        printf("not selected !!!\n");
3431                        m_TreeViewSamples.get_selection()->select(path);
3432                    }
3433                }
3434            }*/
3435    
3436    #if !USE_GTKMM_BUILDER
3437          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
3438              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
3439    #endif
3440    
3441          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3442          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3443          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3444          bool group_selected  = false;          const int n = rows.size();
3445          bool sample_selected = false;          int nGroups  = 0;
3446          if (it) {          int nSamples = 0;
3447            for (int r = 0; r < n; ++r) {
3448                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3449                if (!it) continue;
3450              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
3451              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
3452              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
3453          }          }
3454            
3455                #if USE_GTKMM_BUILDER
3456            m_actionSampleProperties->property_enabled() = (n == 1);
3457            m_actionAddSample->property_enabled() = (n);
3458            m_actionAddSampleGroup->property_enabled() = (file);
3459            m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
3460            m_actionRemoveSample->property_enabled() = (n);
3461            m_actionReplaceSample->property_enabled() = (nSamples == 1);
3462    #else
3463          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
3464              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
3465          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
3466              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3467          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
3468              set_sensitive(file);              set_sensitive(file);
3469          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
3470              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
3471          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
3472              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3473    #endif
3474          // show sample popup          // show sample popup
3475          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
3476    
3477    #if !USE_GTKMM_BUILDER
3478          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
3479              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
3480          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
3481              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3482          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
3483              set_sensitive(file);              set_sensitive(file);
3484          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
3485              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
3486          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3487              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
3488    #endif
3489      }      }
3490        
3491    #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
3492        return false;
3493    #endif
3494  }  }
3495    
3496    #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
3497    bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3498        GdkEventButton* button = _button.gobj();
3499    #else
3500  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3501    #endif
3502      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3503    #if !USE_GTKMM_BUILDER
3504          Gtk::Menu* script_popup =          Gtk::Menu* script_popup =
3505              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3506    #endif
3507          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
3508          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3509          Gtk::TreeModel::iterator it = sel->get_selected();          Gtk::TreeModel::iterator it = sel->get_selected();
# Line 1962  void MainWindow::on_script_treeview_butt Line 3514  void MainWindow::on_script_treeview_butt
3514              group_selected  = row[m_ScriptsModel.m_col_group];              group_selected  = row[m_ScriptsModel.m_col_group];
3515              script_selected = row[m_ScriptsModel.m_col_script];              script_selected = row[m_ScriptsModel.m_col_script];
3516          }          }
3517    #if USE_GTKMM_BUILDER
3518            m_actionAddScript->property_enabled() = (group_selected || script_selected);
3519            m_actionAddScriptGroup->property_enabled() = (file);
3520            m_actionEditScript->property_enabled() = (script_selected);
3521            m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
3522    #else
3523          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
3524              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3525          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
# Line 1970  void MainWindow::on_script_treeview_butt Line 3528  void MainWindow::on_script_treeview_butt
3528              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3529          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3530              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3531    #endif
3532          // show sample popup          // show sample popup
3533          script_popup->popup(button->button, button->time);          script_popup->popup(button->button, button->time);
3534    
3535    #if !USE_GTKMM_BUILDER
3536          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3537              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3538          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
# Line 1981  void MainWindow::on_script_treeview_butt Line 3541  void MainWindow::on_script_treeview_butt
3541              set_sensitive(script_selected);                  set_sensitive(script_selected);    
3542          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3543              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
3544    #endif
3545      }      }
3546    #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
3547        return false;
3548    #endif
3549  }  }
3550    
3551    void MainWindow::updateScriptListOfMenu() {
3552        // remove all entries from "Assign Script" menu
3553        {
3554            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
3555            for (int i = 0; i < children.size(); ++i) {
3556                Gtk::Widget* child = children[i];
3557                assign_scripts_menu->remove(*child);
3558                delete child;
3559            }
3560        }
3561    
3562        int iTotalScripts = 0;
3563    
3564        if (!file) goto noScripts;
3565    
3566        // add all configured macros as menu items to the "Macro" menu
3567        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
3568            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
3569            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
3570                gig::Script* pScript = pGroup->GetScript(iScript);
3571                std::string name = pScript->Name;
3572    
3573                Gtk::MenuItem* item = new Gtk::MenuItem(name);
3574                item->signal_activate().connect(
3575                    sigc::bind(
3576                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
3577                    )
3578                );
3579                assign_scripts_menu->append(*item);
3580                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
3581                //item->set_tooltip_text(comment);
3582            }
3583        }
3584    
3585        noScripts:
3586    
3587        // if there are no macros configured at all, then show a dummy entry instead
3588        if (!iTotalScripts) {
3589            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
3590            item->set_sensitive(false);
3591            assign_scripts_menu->append(*item);
3592        }
3593    
3594    #if HAS_GTKMM_SHOW_ALL_CHILDREN
3595        assign_scripts_menu->show_all_children();
3596    #endif
3597    }
3598    
3599    #if !USE_GTKMM_BUILDER
3600  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
3601      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
3602    
# Line 2007  Gtk::RadioMenuItem* MainWindow::add_inst Line 3620  Gtk::RadioMenuItem* MainWindow::add_inst
3620              item));              item));
3621      return item;      return item;
3622  }  }
3623    #endif
3624    
3625    #if !USE_GTKMM_BUILDER
3626  void MainWindow::remove_instrument_from_menu(int index) {  void MainWindow::remove_instrument_from_menu(int index) {
3627      const std::vector<Gtk::Widget*> children =      const std::vector<Gtk::Widget*> children =
3628          instrument_menu->get_children();          instrument_menu->get_children();
# Line 2015  void MainWindow::remove_instrument_from_ Line 3630  void MainWindow::remove_instrument_from_
3630      instrument_menu->remove(*child);      instrument_menu->remove(*child);
3631      delete child;      delete child;
3632  }  }
3633    #endif
3634    
3635  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
3636      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
# Line 2023  void MainWindow::add_instrument(gig::Ins Line 3639  void MainWindow::add_instrument(gig::Ins
3639      instrument_name_connection.block();      instrument_name_connection.block();
3640      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3641      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
3642        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
3643      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
3644      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
3645        rowInstr[m_Columns.m_col_scripts] = "";
3646      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3647    
3648    #if !USE_GTKMM_BUILDER
3649      add_instrument_to_menu(name);      add_instrument_to_menu(name);
3650    #endif
3651      m_TreeView.get_selection()->select(iterInstr);      select_instrument(instrument);
   
3652      file_changed();      file_changed();
3653  }  }
3654    
# Line 2051  void MainWindow::on_action_duplicate_ins Line 3669  void MainWindow::on_action_duplicate_ins
3669      // retrieve the currently selected instrument      // retrieve the currently selected instrument
3670      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
3671      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3672      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3673      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
3674      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3675      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
3676      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
3677                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
3678      // duplicate the orginal instrument              if (instrOrig) {
3679      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
3680      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
3681          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
3682          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
3683                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
3684    
3685      add_instrument(instrNew);                  add_instrument(instrNew);
3686                }
3687            }
3688        }
3689  }  }
3690    
3691  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2080  void MainWindow::on_action_remove_instru Line 3702  void MainWindow::on_action_remove_instru
3702      }      }
3703    
3704      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3705      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3706      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3707            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3708            if (!it) continue;
3709          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3710          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
3711          try {          try {
# Line 2092  void MainWindow::on_action_remove_instru Line 3716  void MainWindow::on_action_remove_instru
3716              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
3717              file_changed();              file_changed();
3718    
3719    #if !USE_GTKMM_BUILDER
3720              remove_instrument_from_menu(index);              remove_instrument_from_menu(index);
3721    #endif
3722    
3723              // remove row from instruments tree view              // remove row from instruments tree view
3724              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
3725                // update "Nr" column of all instrument rows
3726                {
3727                    int index = 0;
3728                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
3729                         it != m_refTreeModel->children().end(); ++it, ++index)
3730                    {
3731                        Gtk::TreeModel::Row row = *it;
3732                        row[m_Columns.m_col_nr] = index;
3733                    }
3734                }
3735    
3736  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3737              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2193  void MainWindow::on_action_edit_script() Line 3829  void MainWindow::on_action_edit_script()
3829      if (!script) return;      if (!script) return;
3830    
3831      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3832        editor->signal_script_to_be_changed.connect(
3833            signal_script_to_be_changed.make_slot()
3834        );
3835        editor->signal_script_changed.connect(
3836            signal_script_changed.make_slot()
3837        );
3838      editor->setScript(script);      editor->setScript(script);
3839      //editor->reparent(*this);      //editor->reparent(*this);
3840      editor->show();      editor->show();
# Line 2258  void MainWindow::on_action_add_group() { Line 3900  void MainWindow::on_action_add_group() {
3900      file_changed();      file_changed();
3901  }  }
3902    
3903    void MainWindow::on_action_replace_sample() {
3904        add_or_replace_sample(true);
3905    }
3906    
3907  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
3908        add_or_replace_sample(false);
3909    }
3910    
3911    void MainWindow::add_or_replace_sample(bool replace) {
3912      if (!file) return;      if (!file) return;
3913      // get selected group  
3914        // get selected group (and probably selected sample)
3915      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3916      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3917        if (rows.empty()) return;
3918        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3919      if (!it) return;      if (!it) return;
3920      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3921        gig::Sample* sample = NULL;
3922      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
3923      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
3924          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
3925          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
3926          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
3927          if (!it) return;          if (!it) return;
3928          row = *it;          if (!replace) row = *it;
3929          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
3930          if (!group) return;          if (!group) return;
3931      }      }
3932        if (replace && !sample) return;
3933    
3934      // show 'browse for file' dialog      // show 'browse for file' dialog
3935      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
3936    #if HAS_GTKMM_STOCK
3937      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3938      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
3939      dialog.set_select_multiple(true);  #else
3940        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3941        dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
3942    #endif
3943        dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
3944    
3945      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
3946  #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 2327  void MainWindow::on_action_add_sample() Line 3988  void MainWindow::on_action_add_sample()
3988          for (std::vector<std::string>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
3989               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
3990              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
3991              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file information
3992              SF_INFO info;              SF_INFO info;
3993              info.format = 0;              info.format = 0;
3994              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
# Line 2350  void MainWindow::on_action_add_sample() Line 4011  void MainWindow::on_action_add_sample()
4011                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
4012                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
4013                  }                  }
4014                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
4015                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
4016                  // file name without path                  // file name without path
4017                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
4018                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2402  void MainWindow::on_action_add_sample() Line 4063  void MainWindow::on_action_add_sample()
4063                  // physically when File::Save() is called)                  // physically when File::Save() is called)
4064                  sample->Resize(info.frames);                  sample->Resize(info.frames);
4065                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
4066                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
4067                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
4068                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
4069                  SampleImportItem sched_item;                  SampleImportItem sched_item;
4070                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
4071                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
4072                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
4073                  // add sample to the tree view                  // add sample to the tree view
4074                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
4075                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
4076                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
4077                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
4078                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
4079                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
4080                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
4081                            gig_to_utf8(sample->pInfo->Name);
4082                        rowSample[m_SamplesModel.m_col_sample] = sample;
4083                        rowSample[m_SamplesModel.m_col_group]  = NULL;
4084                    }
4085                  // close sound file                  // close sound file
4086                  sf_close(hFile);                  sf_close(hFile);
4087                  file_changed();                  file_changed();
# Line 2427  void MainWindow::on_action_add_sample() Line 4092  void MainWindow::on_action_add_sample()
4092          }          }
4093          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
4094          if (!error_files.empty()) {          if (!error_files.empty()) {
4095              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
4096                    (replace
4097                        ? _("Failed to replace sample with:\n")
4098                        : _("Could not add the following sample(s):\n"))
4099                    + error_files;
4100              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4101              msg.run();              msg.run();
4102          }          }
# Line 2460  void MainWindow::on_action_replace_all_s Line 4129  void MainWindow::on_action_replace_all_s
4129      Gtk::Label description(str);      Gtk::Label description(str);
4130      description.set_line_wrap();      description.set_line_wrap();
4131  #endif  #endif
4132      Gtk::HBox entryArea;      HBox entryArea;
4133      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4134      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;
4135      postfixEntryBox.set_text(".wav");      postfixEntryBox.set_text(".wav");
4136      entryArea.pack_start(entryLabel);      entryArea.pack_start(entryLabel);
4137      entryArea.pack_start(postfixEntryBox);      entryArea.pack_start(postfixEntryBox);
4138    #if USE_GTKMM_BOX
4139        dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4140        dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4141    #else
4142      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4143      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4144    #endif
4145      description.show();      description.show();
4146    
4147    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4148      entryArea.show_all();      entryArea.show_all();
4149    #else
4150        entryArea.show();
4151    #endif
4152    
4153    #if HAS_GTKMM_STOCK
4154      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4155    #else
4156        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4157    #endif
4158      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4159      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
4160      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2494  void MainWindow::on_action_replace_all_s Line 4178  void MainWindow::on_action_replace_all_s
4178              try              try
4179              {              {
4180                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
4181                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
4182                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
4183                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
4184                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
4185                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
4186                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
4187                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
4188                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
4189                          break;                          break;
4190                      default:                      default:
4191                          sf_close(hFile);                          sf_close(hFile);
# Line 2514  void MainWindow::on_action_replace_all_s Line 4194  void MainWindow::on_action_replace_all_s
4194                  SampleImportItem sched_item;                  SampleImportItem sched_item;
4195                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
4196                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
4197                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
4198                  sf_close(hFile);                  sf_close(hFile);
4199                  file_changed();                  file_changed();
4200              }              }
# Line 2538  void MainWindow::on_action_replace_all_s Line 4218  void MainWindow::on_action_replace_all_s
4218  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
4219      if (!file) return;      if (!file) return;
4220      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4221      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4222      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
4223            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4224            if (!it) continue;
4225          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
4226          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
4227          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2564  void MainWindow::on_action_remove_sample Line 4246  void MainWindow::on_action_remove_sample
4246                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
4247                  // them from the import queue                  // them from the import queue
4248                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
4249                       member != members.end(); ++member) {                       member != members.end(); ++member)
4250                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
4251                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
4252                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
4253                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
4254                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
4255                      }                      }
4256                  }                  }
4257                  file_changed();                  file_changed();
# Line 2587  void MainWindow::on_action_remove_sample Line 4266  void MainWindow::on_action_remove_sample
4266                  samples_removed_signal.emit();                  samples_removed_signal.emit();
4267                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
4268                  // the import queue                  // the import queue
4269                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
4270                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
4271                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
4272                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
4273                  }                  }
4274                  dimreg_changed();                  dimreg_changed();
4275                  file_changed();                  file_changed();
# Line 2611  void MainWindow::on_action_remove_sample Line 4286  void MainWindow::on_action_remove_sample
4286      }      }
4287  }  }
4288    
4289    void MainWindow::on_action_remove_unused_samples() {
4290        if (!file) return;
4291    
4292        // collect all samples that are not referenced by any instrument
4293        std::list<gig::Sample*> lsamples;
4294        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
4295            gig::Sample* sample = file->GetSample(iSample);
4296            bool isUsed = false;
4297            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
4298                                  instrument = file->GetNextInstrument())
4299            {
4300                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
4301                                  rgn = instrument->GetNextRegion())
4302                {
4303                    for (int i = 0; i < 256; ++i) {
4304                        if (!rgn->pDimensionRegions[i]) continue;
4305                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
4306                        isUsed = true;
4307                        goto endOfRefSearch;
4308                    }
4309                }
4310            }
4311            endOfRefSearch:
4312            if (!isUsed) lsamples.push_back(sample);
4313        }
4314    
4315        if (lsamples.empty()) return;
4316    
4317        // notify everybody that we're going to remove these samples
4318        samples_to_be_removed_signal.emit(lsamples);
4319    
4320        // remove collected samples
4321        try {
4322            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
4323                 itSample != lsamples.end(); ++itSample)
4324            {
4325                gig::Sample* sample = *itSample;
4326                // remove sample from the .gig file
4327                file->DeleteSample(sample);
4328                // if sample was just previously added, remove it from the import queue
4329                if (m_SampleImportQueue.count(sample)) {
4330                    printf("Removing previously added sample '%s'\n",
4331                           m_SampleImportQueue[sample].sample_path.c_str());
4332                    m_SampleImportQueue.erase(sample);
4333                }
4334            }
4335        } catch (RIFF::Exception e) {
4336            // show error message
4337            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4338            msg.run();
4339        }
4340    
4341        // notify everybody that we're done with removal
4342        samples_removed_signal.emit();
4343    
4344        dimreg_changed();
4345        file_changed();
4346        __refreshEntireGUI();
4347    }
4348    
4349  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
4350  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4351  {  {
# Line 2637  void MainWindow::on_scripts_treeview_dra Line 4372  void MainWindow::on_scripts_treeview_dra
4372                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
4373  }  }
4374    
4375    // see comment on on_sample_treeview_drag_begin()
4376    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4377    {
4378        first_call_to_drag_data_get = true;
4379    }
4380    
4381    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4382                                                           Gtk::SelectionData& selection_data, guint, guint)
4383    {
4384        if (!first_call_to_drag_data_get) return;
4385        first_call_to_drag_data_get = false;
4386    
4387        // get selected source instrument
4388        gig::Instrument* src = NULL;
4389        {
4390            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4391            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4392            if (!rows.empty()) {
4393                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
4394                if (it) {
4395                    Gtk::TreeModel::Row row = *it;
4396                    src = row[m_Columns.m_col_instr];
4397                }
4398            }
4399        }
4400        if (!src) return;
4401    
4402        // pass the source gig::Instrument as pointer
4403        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
4404                           sizeof(src)/*length of data in bytes*/);
4405    }
4406    
4407    void MainWindow::on_instruments_treeview_drop_drag_data_received(
4408        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
4409        const Gtk::SelectionData& selection_data, guint, guint time)
4410    {
4411        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
4412        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
4413            return;
4414    
4415        gig::Instrument* dst = NULL;
4416        {
4417            Gtk::TreeModel::Path path;
4418            const bool found = m_TreeView.get_path_at_pos(x, y, path);
4419            if (!found) return;
4420    
4421            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
4422            if (!iter) return;
4423            Gtk::TreeModel::Row row = *iter;
4424            dst = row[m_Columns.m_col_instr];
4425        }
4426        if (!dst) return;
4427    
4428        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
4429        src->MoveTo(dst);
4430        __refreshEntireGUI();
4431        select_instrument(src);
4432    }
4433    
4434  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
4435  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
4436  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2655  void MainWindow::on_sample_treeview_drag Line 4449  void MainWindow::on_sample_treeview_drag
4449      // get selected sample      // get selected sample
4450      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
4451      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4452      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4453      if (it) {      if (!rows.empty()) {
4454          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4455          sample = row[m_SamplesModel.m_col_sample];          if (it) {
4456                Gtk::TreeModel::Row row = *it;
4457                sample = row[m_SamplesModel.m_col_sample];
4458            }
4459      }      }
4460      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
4461      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 2798  void MainWindow::script_double_clicked(c Line 4595  void MainWindow::script_double_clicked(c
4595      if (!script) return;      if (!script) return;
4596    
4597      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
4598        editor->signal_script_to_be_changed.connect(
4599            signal_script_to_be_changed.make_slot()
4600        );
4601        editor->signal_script_changed.connect(
4602            signal_script_changed.make_slot()
4603        );
4604      editor->setScript(script);      editor->setScript(script);
4605      //editor->reparent(*this);      //editor->reparent(*this);
4606      editor->show();      editor->show();
# Line 2809  void MainWindow::instrument_name_changed Line 4612  void MainWindow::instrument_name_changed
4612      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
4613      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
4614    
4615    #if !USE_GTKMM_BUILDER
4616      // change name in instrument menu      // change name in instrument menu
4617      int index = path[0];      int index = path[0];
4618      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
# Line 2821  void MainWindow::instrument_name_changed Line 4625  void MainWindow::instrument_name_changed
4625          item->set_active();          item->set_active();
4626  #endif  #endif
4627      }      }
4628    #endif
4629    
4630      // change name in gig      // change name in gig
4631      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 2837  void MainWindow::instrument_name_changed Line 4642  void MainWindow::instrument_name_changed
4642      }      }
4643  }  }
4644    
4645    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
4646        if (!iter)
4647            return true;
4648    
4649        Glib::ustring pattern = m_searchText.get_text().lowercase();
4650        trim(pattern);
4651        if (pattern.empty()) return true;
4652    
4653    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
4654        //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4655        Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4656    #else
4657        Gtk::TreeModel::Row row = *iter;
4658    #endif
4659        Glib::ustring name = row[m_Columns.m_col_name];
4660        name = name.lowercase();
4661    
4662        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
4663        for (int t = 0; t < tokens.size(); ++t)
4664            if (name.find(tokens[t]) == Glib::ustring::npos)
4665                return false;
4666    
4667        return true;
4668    }
4669    
4670  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
4671      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
4672    
4673        // take over selection from instruments list view for the combine dialog's
4674        // list view as pre-selection
4675        std::set<int> indeces;
4676        {
4677            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4678            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4679            for (int r = 0; r < rows.size(); ++r) {
4680                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4681                if (it) {
4682                    Gtk::TreeModel::Row row = *it;
4683                    int index = row[m_Columns.m_col_nr];
4684                    indeces.insert(index);
4685                }
4686            }
4687        }
4688        d->setSelectedInstruments(indeces);
4689    
4690    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4691      d->show_all();      d->show_all();
4692      d->resize(500, 400);  #else
4693        d->show();
4694    #endif
4695      d->run();      d->run();
4696      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
4697          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 2851  void MainWindow::on_action_combine_instr Line 4702  void MainWindow::on_action_combine_instr
4702    
4703  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
4704      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4705      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4706        if (rows.empty()) return;
4707        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4708      if (!it) return;      if (!it) return;
4709      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4710      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2859  void MainWindow::on_action_view_referenc Line 4712  void MainWindow::on_action_view_referenc
4712    
4713      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
4714      d->setSample(sample);      d->setSample(sample);
4715        d->dimension_region_selected.connect(
4716            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
4717        );
4718    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4719      d->show_all();      d->show_all();
4720    #else
4721        d->show();
4722    #endif
4723      d->resize(500, 400);      d->resize(500, 400);
4724      d->run();      d->run();
4725      delete d;      delete d;
# Line 2943  void MainWindow::mergeFiles(const std::v Line 4803  void MainWindow::mergeFiles(const std::v
4803              Glib::filename_display_basename(this->filename) + "' ...",              Glib::filename_display_basename(this->filename) + "' ...",
4804              *this              *this
4805          );          );
4806    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4807          progress_dialog->show_all();          progress_dialog->show_all();
4808    #else
4809            progress_dialog->show();
4810    #endif
4811          saver = new Saver(this->file); //FIXME: memory leak!          saver = new Saver(this->file); //FIXME: memory leak!
4812          saver->signal_progress().connect(          saver->signal_progress().connect(
4813              sigc::mem_fun(*this, &MainWindow::on_saver_progress));              sigc::mem_fun(*this, &MainWindow::on_saver_progress));
# Line 2970  void MainWindow::on_action_merge_files() Line 4834  void MainWindow::on_action_merge_files()
4834      }      }
4835    
4836      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4837    #if HAS_GTKMM_STOCK
4838      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4839    #else
4840        dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4841    #endif
4842      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
4843      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4844  #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 2987  void MainWindow::on_action_merge_files() Line 4855  void MainWindow::on_action_merge_files()
4855      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
4856    
4857      // show warning in the file picker dialog      // show warning in the file picker dialog
4858      Gtk::HBox descriptionArea;      HBox descriptionArea;
4859      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
4860      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
4861        warningIcon.set_from_icon_name("dialog-warning",
4862                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
4863      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
4864  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
4865      view::WrapLabel description;      view::WrapLabel description;
# Line 3008  void MainWindow::on_action_merge_files() Line 4878  void MainWindow::on_action_merge_files()
4878          "will accordingly be stored separately in the target .gig file!"          "will accordingly be stored separately in the target .gig file!"
4879      ));      ));
4880      descriptionArea.pack_start(description);      descriptionArea.pack_start(description);
4881    #if USE_GTKMM_BOX
4882    # warning No description area implemented for dialog on GTKMM 3
4883    #else
4884      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
4885    #endif
4886    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4887      descriptionArea.show_all();      descriptionArea.show_all();
4888    #else
4889        descriptionArea.show();
4890    #endif
4891    
4892      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
4893          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
4894                   static_cast<void*>(Glib::Threads::Thread::self()));
4895          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
4896    
4897          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3024  void MainWindow::on_action_merge_files() Line 4903  void MainWindow::on_action_merge_files()
4903          }          }
4904    
4905          // update GUI          // update GUI
4906          __refreshEntireGUI();                  __refreshEntireGUI();
4907      }      }
4908  }  }
4909    
# Line 3044  void MainWindow::set_file_is_shared(bool Line 4923  void MainWindow::set_file_is_shared(bool
4923      }      }
4924    
4925      {      {
4926    #if USE_GTKMM_BUILDER
4927            m_actionToggleSyncSamplerSelection->property_enabled() = b;
4928    #else
4929          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
4930              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));              uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
4931          if (item) item->set_sensitive(b);          if (item) item->set_sensitive(b);
4932    #endif
4933      }      }
4934  }  }
4935    
# Line 3094  void MainWindow::show_scripts_tab() { Line 4977  void MainWindow::show_scripts_tab() {
4977      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
4978  }  }
4979    
4980    void MainWindow::select_instrument_by_dir(int dir) {
4981        if (!file) return;
4982        gig::Instrument* pInstrument = get_instrument();
4983        if (!pInstrument) {
4984            select_instrument( file->GetInstrument(0) );
4985            return;
4986        }
4987        for (int i = 0; file->GetInstrument(i); ++i) {
4988            if (file->GetInstrument(i) == pInstrument) {
4989                select_instrument( file->GetInstrument(i + dir) );
4990                return;
4991            }
4992        }
4993    }
4994    
4995    void MainWindow::select_prev_instrument() {
4996        select_instrument_by_dir(-1);
4997    }
4998    
4999    void MainWindow::select_next_instrument() {
5000        select_instrument_by_dir(1);
5001    }
5002    
5003    void MainWindow::select_prev_region() {
5004        m_RegionChooser.select_prev_region();
5005    }
5006    
5007    void MainWindow::select_next_region() {
5008        m_RegionChooser.select_next_region();
5009    }
5010    
5011    void MainWindow::select_next_dim_rgn_zone() {
5012        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5013        m_DimRegionChooser.select_next_dimzone();
5014    }
5015    
5016    void MainWindow::select_prev_dim_rgn_zone() {
5017        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5018        m_DimRegionChooser.select_prev_dimzone();
5019    }
5020    
5021    void MainWindow::select_add_next_dim_rgn_zone() {
5022        m_DimRegionChooser.select_next_dimzone(true);
5023    }
5024    
5025    void MainWindow::select_add_prev_dim_rgn_zone() {
5026        m_DimRegionChooser.select_prev_dimzone(true);
5027    }
5028    
5029    void MainWindow::select_prev_dimension() {
5030        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5031        m_DimRegionChooser.select_prev_dimension();
5032    }
5033    
5034    void MainWindow::select_next_dimension() {
5035        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5036        m_DimRegionChooser.select_next_dimension();
5037    }
5038    
5039    #define CLIPBOARD_DIMENSIONREGION_TARGET \
5040        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
5041    
5042    void MainWindow::copy_selected_dimrgn() {
5043        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5044        if (!pDimRgn) {
5045            updateClipboardPasteAvailable();
5046            updateClipboardCopyAvailable();
5047            return;
5048        }
5049    
5050        std::vector<Gtk::TargetEntry> targets;
5051        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
5052    
5053        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5054        clipboard->set(
5055            targets,
5056            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
5057            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
5058        );
5059    
5060        m_serializationArchive.serialize(pDimRgn);
5061    
5062        updateClipboardPasteAvailable();
5063    }
5064    
5065    void MainWindow::paste_copied_dimrgn() {
5066        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5067        clipboard->request_contents(
5068            CLIPBOARD_DIMENSIONREGION_TARGET,
5069            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
5070        );
5071        updateClipboardPasteAvailable();
5072    }
5073    
5074    void MainWindow::adjust_clipboard_content() {
5075        MacroEditor* editor = new MacroEditor();
5076        editor->setMacro(&m_serializationArchive, true);
5077        editor->show();
5078    }
5079    
5080    void MainWindow::updateClipboardPasteAvailable() {
5081        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5082        clipboard->request_targets(
5083            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
5084        );
5085    }
5086    
5087    void MainWindow::updateClipboardCopyAvailable() {
5088        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5089    #if USE_GTKMM_BUILDER
5090        m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5091    #else
5092        static_cast<Gtk::MenuItem*>(
5093            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5094        )->set_sensitive(bDimensionRegionCopyIsPossible);
5095    #endif
5096    }
5097    
5098    #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
5099    void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5100    #else
5101    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5102    #endif
5103        updateClipboardPasteAvailable();
5104    }
5105    
5106    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
5107        const std::string target = selection_data.get_target();
5108        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5109            selection_data.set(
5110                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
5111                &m_serializationArchive.rawData()[0],
5112                m_serializationArchive.rawData().size()
5113            );
5114        } else {
5115            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
5116        }
5117    }
5118    
5119    void MainWindow::on_clipboard_clear() {
5120        m_serializationArchive.clear();
5121        updateClipboardPasteAvailable();
5122        updateClipboardCopyAvailable();
5123    }
5124    
5125    //NOTE: Might throw exception !!!
5126    void MainWindow::applyMacro(Serialization::Archive& macro) {
5127        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5128        if (!pDimRgn) return;
5129    
5130        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5131             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5132        {
5133            gig::DimensionRegion* pDimRgn = *itDimReg;
5134            DimRegionChangeGuard(this, pDimRgn);
5135            macro.deserialize(pDimRgn);
5136        }
5137        //region_changed()
5138        file_changed();
5139        dimreg_changed();
5140    }
5141    
5142    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5143        const std::string target = selection_data.get_target();
5144        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5145            Glib::ustring errorText;
5146            try {
5147                m_serializationArchive.decode(
5148                    selection_data.get_data(), selection_data.get_length()
5149                );
5150                applyMacro(m_serializationArchive);
5151            } catch (Serialization::Exception e) {
5152                errorText = e.Message;
5153            } catch (...) {
5154                errorText = _("Unknown exception while pasting DimensionRegion");
5155            }
5156            if (!errorText.empty()) {
5157                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
5158                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5159                msg.run();
5160            }
5161        }
5162    }
5163    
5164    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
5165        const bool bDimensionRegionPasteIsPossible =
5166            std::find(targets.begin(), targets.end(),
5167                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5168    
5169    #if USE_GTKMM_BUILDER
5170        m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5171        m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5172    #else
5173        static_cast<Gtk::MenuItem*>(
5174            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5175        )->set_sensitive(bDimensionRegionPasteIsPossible);
5176    
5177        static_cast<Gtk::MenuItem*>(
5178            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5179        )->set_sensitive(bDimensionRegionPasteIsPossible);
5180    #endif
5181    }
5182    
5183  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
5184      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
5185  }  }

Legend:
Removed from v.2691  
changed lines
  Added in v.3408

  ViewVC Help
Powered by ViewVC