/[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 1673 by schoenebeck, Wed Feb 6 22:08:29 2008 UTC revision 3368 by schoenebeck, Thu Nov 16 19:18:42 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006 - 2008 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 18  Line 18 
18   */   */
19    
20  #include <iostream>  #include <iostream>
21    #include <cstring>
22    
23    #include "compat.h"
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31    #include <glibmm/convert.h>
32    #include <glibmm/dispatcher.h>
33    #include <glibmm/miscutils.h>
34    #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36    #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #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>
 #include "global.h"  
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
46  #endif  #endif
47    #include <gtkmm/accelmap.h>
48  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #if GTKMM_MAJOR_VERSION < 3
49  namespace Glib {  #include "wrapLabel.hh"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
50  #endif  #endif
51    
52    #include "global.h"
53    #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>
62    
63  #include "mainwindow.h"  #include "mainwindow.h"
64    #include "Settings.h"
65    #include "CombineInstrumentsDialog.h"
66    #include "scripteditor.h"
67    #include "scriptslots.h"
68    #include "ReferencesView.h"
69  #include "../../gfx/status_attached.xpm"  #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  template<class T> inline std::string ToString(T o) {  static const Gdk::ModifierType primaryModifierKey =
79      std::stringstream ss;      #if defined(__APPLE__)
80      ss << o;      Gdk::META_MASK; // Cmd key on Mac
81      return ss.str();      #else
82  }      Gdk::CONTROL_MASK; // Ctrl key on all other OSs
83        #endif
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
84    
85  MainWindow::MainWindow() :  MainWindow::MainWindow() :
86        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    
114      // Handle selection      // Handle selection
115      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
116          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
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 114  MainWindow::MainWindow() : Line 133  MainWindow::MainWindow() :
133      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
134      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
135    
136        m_ScrolledWindowScripts.add(m_TreeViewScripts);
137        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138    
139    #if GTKMM_MAJOR_VERSION < 3
140      m_TreeViewNotebook.set_size_request(300);      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 125  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      m_HPaned.add2(dimreg_vbox);      {
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      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");          imageLooped.set(blackLoop);
186      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");  #if HAS_GTKMM_ALIGNMENT
187            imageLooped.set_alignment(Gtk::ALIGN_END);
188            labelLooped.set_alignment(Gtk::ALIGN_START);
189    #else
190            imageLooped.set_halign(Gtk::ALIGN_END);
191            labelLooped.set_halign(Gtk::ALIGN_START);
192    #endif
193            legend_hbox.add(imageLooped);
194            legend_hbox.add(labelLooped);
195    
196            imageSomeLoops.set(grayLoop);
197    #if HAS_GTKMM_ALIGNMENT
198            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
200    #else
201            imageSomeLoops.set_halign(Gtk::ALIGN_END);
202            labelSomeLoops.set_halign(Gtk::ALIGN_START);
203    #endif
204            legend_hbox.add(imageSomeLoops);
205            legend_hbox.add(labelSomeLoops);
206    
207    #if HAS_GTKMM_SHOW_ALL_CHILDREN
208            legend_hbox.show_all_children();
209    #endif
210        }
211        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212        m_HPaned.add2(dimreg_vbox);
213    
214        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
215        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
216        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
217        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
218    
219        m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
220        m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
222    
223    #if USE_GLIB_ACTION
224        m_actionGroup = Gio::SimpleActionGroup::create();
225        m_actionGroup->add_action(
226            "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
227        );
228        m_actionGroup->add_action(
229            "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
230        );
231        m_actionGroup->add_action(
232            "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
233        );
234        m_actionGroup->add_action(
235            "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
236        );
237        m_actionGroup->add_action(
238            "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
239        );
240        m_actionGroup->add_action(
241            "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
242        );
243        m_actionMIDIRules = m_actionGroup->add_action(
244            "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
245        );
246        m_actionGroup->add_action(
247            "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
248        );
249        m_actionGroup->add_action(
250            "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
251        );
252        m_actionGroup->add_action(
253            "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
254        );
255        m_actionGroup->add_action(
256            "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
257        );
258        m_actionGroup->add_action(
259            "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
260        );
261    #else
262      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
263    
264      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
# Line 161  MainWindow::MainWindow() : Line 288  MainWindow::MainWindow() :
288                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
289                       sigc::mem_fun(                       sigc::mem_fun(
290                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
291        actionGroup->add(Gtk::Action::create("MidiRules",
292                                             _("_Midi Rules...")),
293                         sigc::mem_fun(
294                             *this, &MainWindow::show_midi_rules));
295        actionGroup->add(Gtk::Action::create("ScriptSlots",
296                                             _("_Script Slots...")),
297                         sigc::mem_fun(
298                             *this, &MainWindow::show_script_slots));
299      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
300                       sigc::mem_fun(                       sigc::mem_fun(
301                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
302      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
303            Gtk::Action::create("MenuSample", _("_Sample")),
304            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
305        );
306        actionGroup->add(
307            Gtk::Action::create("MenuInstrument", _("_Instrument")),
308            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309        );
310        actionGroup->add(
311            Gtk::Action::create("MenuScript", _("Scr_ipt")),
312            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313        );
314        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
315        actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
316    
317        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
318    #endif
319    
320      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      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"));
441        toggle_action->set_active(true);
442        actionGroup->add(toggle_action);
443    
444        toggle_action =
445            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
446        toggle_action->set_active(true);
447        actionGroup->add(toggle_action);
448    
449        toggle_action =
450            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451        toggle_action->set_active(true);
452        actionGroup->add(toggle_action);
453    #endif
454    
455    #if USE_GLIB_ACTION
456        m_actionToggleStatusBar =
457            m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458        m_actionToggleRestoreWinDim =
459            m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460        m_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", _("Vie_w")));
468        toggle_action =
469          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
470      toggle_action->set_active(true);      toggle_action->set_active(true);
471      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
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()));
 #ifdef ABOUT_DIALOG  
515      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
516                       sigc::mem_fun(                       sigc::mem_fun(
517                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
518      actionGroup->add(      actionGroup->add(
519          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
520          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
521      );      );
522      actionGroup->add(      actionGroup->add(
523            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
524            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
525        );
526        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")));
552        
553        toggle_action =
554            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
555        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
556        actionGroup->add(
557            toggle_action,
558            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
559        );
560    
561        toggle_action =
562            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
563        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
564        actionGroup->add(
565            toggle_action,
566            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")));
587    
588        actionGroup->add(
589            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
590            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
591        );
592    
593        actionGroup->add(
594            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
595            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 201  MainWindow::MainWindow() : Line 632  MainWindow::MainWindow() :
632          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
633      );      );
634      actionGroup->add(      actionGroup->add(
635          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
636          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
637      );      );
638      actionGroup->add(      actionGroup->add(
# Line 209  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("ReplaceAllSamplesInAllGroups", _("Replace All Samples In All Groups")),          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...")),
648            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
649        );
650        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",
657                                _("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
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(
678            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
679            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
680        );
681        actionGroup->add(
682            Gtk::Action::create("AddScript", _("Add _Script")),
683            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
684        );
685        actionGroup->add(
686            Gtk::Action::create("EditScript", _("_Edit Script...")),
687            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
688        );
689        actionGroup->add(
690            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
691            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 231  MainWindow::MainWindow() : Line 1093  MainWindow::MainWindow() :
1093          "      <separator/>"          "      <separator/>"
1094          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
1095          "    </menu>"          "    </menu>"
1096            "    <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'/>"
1115            "      <menuitem action='CopySampleTune'/>"
1116            "      <menuitem action='CopySampleLoop'/>"
1117            "    </menu>"
1118            "    <menu action='MenuMacro'>"
1119            "    </menu>"
1120            "    <menu action='MenuSample'>"
1121            "      <menuitem action='SampleProperties'/>"
1122            "      <menuitem action='AddGroup'/>"
1123            "      <menuitem action='AddSample'/>"
1124            "      <menuitem action='ShowSampleRefs'/>"
1125            "      <menuitem action='ReplaceSample' />"
1126            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
1127            "      <separator/>"
1128            "      <menuitem action='RemoveSample'/>"
1129            "      <menuitem action='RemoveUnusedSamples'/>"
1130            "    </menu>"
1131          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
1132            "      <menu action='AllInstruments'>"
1133            "      </menu>"
1134            "      <separator/>"
1135            "      <menuitem action='InstrProperties'/>"
1136            "      <menuitem action='MidiRules'/>"
1137            "      <menuitem action='ScriptSlots'/>"
1138            "      <menu action='AssignScripts'/>"
1139            "      <menuitem action='AddInstrument'/>"
1140            "      <menuitem action='DupInstrument'/>"
1141            "      <menuitem action='CombInstruments'/>"
1142            "      <separator/>"
1143            "      <menuitem action='RemoveInstrument'/>"
1144            "    </menu>"
1145            "    <menu action='MenuScript'>"
1146            "      <menuitem action='AddScriptGroup'/>"
1147            "      <menuitem action='AddScript'/>"
1148            "      <menuitem action='EditScript'/>"
1149            "      <separator/>"
1150            "      <menuitem action='RemoveScript'/>"
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>"
1158            "    <menu action='MenuTools'>"
1159            "      <menuitem action='CombineInstruments'/>"
1160            "      <menuitem action='MergeFiles'/>"
1161            "    </menu>"
1162            "    <menu action='MenuSettings'>"
1163            "      <menuitem action='WarnUserOnExtensions'/>"
1164            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
1165            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
1166            "      <menuitem action='SaveWithTemporaryFile'/>"
1167          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
1168          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
1169          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
1170          "    </menu>"          "    </menu>"
 #endif  
1171          "  </menubar>"          "  </menubar>"
1172          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
1173          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
1174            "    <menuitem action='MidiRules'/>"
1175            "    <menuitem action='ScriptSlots'/>"
1176          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
1177            "    <menuitem action='DupInstrument'/>"
1178            "    <menuitem action='CombInstruments'/>"
1179          "    <separator/>"          "    <separator/>"
1180          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
1181          "  </popup>"          "  </popup>"
# Line 252  MainWindow::MainWindow() : Line 1183  MainWindow::MainWindow() :
1183          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
1184          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
1185          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
1186          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ShowSampleRefs'/>"
1187            "    <menuitem action='ReplaceSample' />"
1188            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
1189          "    <separator/>"          "    <separator/>"
1190          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
1191            "    <menuitem action='RemoveUnusedSamples'/>"
1192            "  </popup>"
1193            "  <popup name='ScriptPopupMenu'>"
1194            "    <menuitem action='AddScriptGroup'/>"
1195            "    <menuitem action='AddScript'/>"
1196            "    <menuitem action='EditScript'/>"
1197            "    <separator/>"
1198            "    <menuitem action='RemoveScript'/>"
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
1224        // respective Gtk::Action objects above will simply be ignored, no matter
1225        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
1226        // Gtk::Action::create()).
1227        {
1228            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1229                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1230            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
1231        }
1232        {
1233            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1234                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1235            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
1236        }
1237        {
1238            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1239                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."));
1241        }
1242        {
1243            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1244                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
1245            item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
1246        }
1247        {
1248            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1249                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
1250            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
1251        }
1252        {
1253            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 keybord 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"));
1279            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1280        }
1281        {
1282            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1283                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1284            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*>(
1296            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 269  MainWindow::MainWindow() : Line 1313  MainWindow::MainWindow() :
1313      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
1314      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
1315    
1316        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 282  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_refTreeModel->signal_row_changed().connect(      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(
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."));
1376      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
1377      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1378      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1379        {
1380            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1381            Gtk::CellRendererText* cellrenderer =
1382                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1383            column->add_attribute(
1384                cellrenderer->property_foreground(), m_SamplesModel.m_color
1385            );
1386        }
1387        {
1388            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1389            Gtk::CellRendererText* cellrenderer =
1390                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1391            column->add_attribute(
1392                cellrenderer->property_foreground(), m_SamplesModel.m_color
1393            );
1394        }
1395        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      );      );
1408    
1409        // create scripts treeview (including its data model)
1410        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1411        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1412        m_TreeViewScripts.set_tooltip_text(_(
1413            "Use CTRL + double click for editing a script."
1414            "\n\n"
1415            "Note: instrument scripts are a LinuxSampler extension of the gig "
1416            "format. This feature will not work with the GigaStudio software!"
1417        ));
1418        // m_TreeViewScripts.set_reorderable();
1419        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1420        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(
1427            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1428        );
1429    #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(
1432            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1433        );
1434        m_refScriptsTreeModel->signal_row_changed().connect(
1435            sigc::mem_fun(*this, &MainWindow::script_name_changed)
1436        );
1437    
1438        // establish drag&drop between scripts tree view and ScriptSlots window
1439        std::vector<Gtk::TargetEntry> drag_target_gig_script;
1440        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1441        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1442        m_TreeViewScripts.signal_drag_begin().connect(
1443            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1444        );
1445        m_TreeViewScripts.signal_drag_data_get().connect(
1446            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1447        );
1448    
1449      // establish drag&drop between samples tree view and dimension region 'Sample' text entry      // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1450      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1451      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1452      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1453      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
1454          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 322  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_instrument_changed().connect(      instrumentProps.signal_changed().connect(
1472          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1473      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
1474            sigc::mem_fun(*this, &MainWindow::file_changed));
1475        midiRules.signal_changed().connect(
1476          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1477    
1478      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 335  MainWindow::MainWindow() : Line 1481  MainWindow::MainWindow() :
1481          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
1482      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
1483          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
1484        sample_ref_changed_signal.connect(
1485            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1486        );
1487        samples_to_be_removed_signal.connect(
1488            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1489        );
1490    
1491        dimreg_edit.signal_select_sample().connect(
1492            sigc::mem_fun(*this, &MainWindow::select_sample)
1493        );
1494    
1495      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1496          sigc::hide(          sigc::hide(
# Line 369  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;
     set_file_is_shared(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
1547        // (gtk allows this only if the tab childs are visible, thats why it's here)
1548        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 402  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      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1758        if (rows.empty()) return NULL;
1759      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();      //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 447  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 458  void MainWindow::dimreg_all_dimregs_togg Line 1818  void MainWindow::dimreg_all_dimregs_togg
1818  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
1819  {  {
1820      update_dimregs();      update_dimregs();
1821      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1822  }  }
1823    
1824  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1825  {  {
1826    #if !USE_GTKMM_BUILDER
1827        // select item in instrument menu
1828        std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1829        if (!rows.empty()) {
1830            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1831            if (it) {
1832                Gtk::TreePath path(it);
1833                int index = path[0];
1834                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    
1845        if (Settings::singleton()->syncSamplerInstrumentSelection) {
1846            switch_sampler_instrument_signal.emit(get_instrument());
1847        }
1848  }  }
1849    
1850  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 475  void loader_progress_callback(gig::progr Line 1856  void loader_progress_callback(gig::progr
1856  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
1857  {  {
1858      {      {
1859          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
1860          progress = fraction;          progress = fraction;
1861      }      }
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::Thread::self());      printf("thread_function self=%p\n",
1872      printf("Start %s\n", filename);             static_cast<void*>(Glib::Threads::Thread::self()));
1873      RIFF::File* riff = new RIFF::File(filename);      printf("Start %s\n", filename.c_str());
1874      gig = new gig::File(riff);      try {
1875      gig::progress_t progress;          RIFF::File* riff = new RIFF::File(filename);
1876      progress.callback = loader_progress_callback;          gig = new gig::File(riff);
1877      progress.custom = this;          gig::progress_t progress;
1878            progress.callback = loader_progress_callback;
1879      gig->GetInstrument(0, &progress);          progress.custom = this;
1880      printf("End\n");  
1881      finished_dispatcher();          gig->GetInstrument(0, &progress);
1882            printf("End\n");
1883            finished_dispatcher();
1884        } catch (RIFF::Exception e) {
1885            error_message = e.Message;
1886            error_dispatcher.emit();
1887        } catch (...) {
1888            error_message = _("Unknown exception occurred");
1889            error_dispatcher.emit();
1890        }
1891  }  }
1892    
1893  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1894      : thread(0), filename(filename)      : filename(filename), gig(0), thread(0), progress(0.f)
1895  {  {
1896  }  }
1897    
1898  void Loader::launch()  void Loader::launch()
1899  {  {
1900    #ifdef OLD_THREADS
1901      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
1902      printf("launch thread=%x\n", thread);  #else
1903        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1904    #endif
1905        printf("launch thread=%p\n", static_cast<void*>(thread));
1906  }  }
1907    
1908  float Loader::get_progress()  float Loader::get_progress()
1909  {  {
1910      float res;      float res;
1911      {      {
1912          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
1913          res = progress;          res = progress;
1914      }      }
1915      return res;      return res;
# Line 527  Glib::Dispatcher& Loader::signal_finishe Line 1925  Glib::Dispatcher& Loader::signal_finishe
1925      return finished_dispatcher;      return finished_dispatcher;
1926  }  }
1927    
1928  LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)  Glib::Dispatcher& Loader::signal_error()
1929    {
1930        return error_dispatcher;
1931    }
1932    
1933    void saver_progress_callback(gig::progress_t* progress)
1934    {
1935        Saver* saver = static_cast<Saver*>(progress->custom);
1936        saver->progress_callback(progress->factor);
1937    }
1938    
1939    void Saver::progress_callback(float fraction)
1940    {
1941        {
1942            Glib::Threads::Mutex::Lock lock(progressMutex);
1943            progress = fraction;
1944        }
1945        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()
1953    {
1954        printf("thread_function self=%p\n",
1955               static_cast<void*>(Glib::Threads::Thread::self()));
1956        printf("Start %s\n", filename.c_str());
1957        try {
1958            gig::progress_t progress;
1959            progress.callback = saver_progress_callback;
1960            progress.custom = this;
1961    
1962            // if no filename was provided, that means "save", if filename was provided means "save as"
1963            if (filename.empty()) {
1964                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 {
1993                gig->Save(filename, &progress);
1994            }
1995    
1996            printf("End\n");
1997            finished_dispatcher.emit();
1998        } catch (RIFF::Exception e) {
1999            error_message = e.Message;
2000            error_dispatcher.emit();
2001        } catch (...) {
2002            error_message = _("Unknown exception occurred");
2003            error_dispatcher.emit();
2004        }
2005    }
2006    
2007    Saver::Saver(gig::File* file, Glib::ustring filename)
2008        : gig(file), filename(filename), thread(0), progress(0.f)
2009    {
2010    }
2011    
2012    void Saver::launch()
2013    {
2014    #ifdef OLD_THREADS
2015        thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
2016    #else
2017        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2018    #endif
2019        printf("launch thread=%p\n", static_cast<void*>(thread));
2020    }
2021    
2022    float Saver::get_progress()
2023    {
2024        float res;
2025        {
2026            Glib::Threads::Mutex::Lock lock(progressMutex);
2027            res = progress;
2028        }
2029        return res;
2030    }
2031    
2032    Glib::Dispatcher& Saver::signal_progress()
2033    {
2034        return progress_dispatcher;
2035    }
2036    
2037    Glib::Dispatcher& Saver::signal_finished()
2038    {
2039        return finished_dispatcher;
2040    }
2041    
2042    Glib::Dispatcher& Saver::signal_error()
2043    {
2044        return error_dispatcher;
2045    }
2046    
2047    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);
2059  }  }
2060    
2061  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
2062  // before a new .gig file is to be created or to be loaded.  // before a new .gig file is to be created or to be loaded.
2063  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) {  
         delete &instrument_menu->get_submenu()->items()[i];  
     }  
     instrument_menu->get_submenu()->items().clear();  
2064      // forget all samples that ought to be imported      // forget all samples that ought to be imported
2065      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
2066      // clear the samples and instruments tree views      // clear the samples and instruments tree views
2067      m_refTreeModel->clear();      m_refTreeModel->clear();
2068      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2069        m_refScriptsTreeModel->clear();
2070    #if !USE_GTKMM_BUILDER
2071        // remove all entries from "Instrument" menu
2072        while (!instrument_menu->get_children().empty()) {
2073            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;
2079      set_file_is_shared(false);      set_file_is_shared(false);
2080  }  }
2081    
2082    void MainWindow::__refreshEntireGUI() {
2083        // clear the samples and instruments tree views
2084        m_refTreeModel->clear();
2085        m_refSamplesTreeModel->clear();
2086        m_refScriptsTreeModel->clear();
2087    #if !USE_GTKMM_BUILDER
2088        // remove all entries from "Instrument" menu
2089        while (!instrument_menu->get_children().empty()) {
2090            remove_instrument_from_menu(0);
2091        }
2092    #endif
2093    
2094        if (!this->file) return;
2095    
2096        load_gig(
2097            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2098        );
2099    }
2100    
2101  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
2102  {  {
2103      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 568  void MainWindow::on_action_file_new() Line 2110  void MainWindow::on_action_file_new()
2110      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
2111      // already add one new instrument by default      // already add one new instrument by default
2112      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
2113      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2114      // update GUI with that new gig::File      // update GUI with that new gig::File
2115      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
2116  }  }
# Line 579  bool MainWindow::close_confirmation_dial Line 2121  bool MainWindow::close_confirmation_dial
2121                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
2122      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2123      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
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."));
 #endif  
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      if (response == Gtk::RESPONSE_YES) return file_save();  
2137      return response != Gtk::RESPONSE_CANCEL;      // 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
2144        // 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
2146        // after saving the file has completed
2147        //
2148        //   if (response == Gtk::RESPONSE_YES) return file_save();
2149        //   return response != Gtk::RESPONSE_CANCEL;
2150        //
2151        if (response == Gtk::RESPONSE_YES) file_save();
2152        return false; // always prevent closing the app for now (see comment above)
2153  }  }
2154    
2155  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
2156      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2157      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
2158      dialog.set_secondary_text(      dialog.set_secondary_text(
2159          _("If you proceed to work on another instrument file, it won't be "          _("If you proceed to work on another instrument file, it won't be "
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."));
    );  
 #endif  
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 617  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
2190      Gtk::FileFilter filter;      Gtk::FileFilter filter;
2191      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
2192    #else
2193        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2194        filter->add_pattern("*.gig");
2195    #endif
2196      dialog.set_filter(filter);      dialog.set_filter(filter);
2197      if (current_dir != "") {      if (current_gig_dir != "") {
2198          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
2199      }      }
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::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_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
2207      }      }
2208  }  }
2209    
2210  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
2211  {  {
2212      __clear();      __clear();
2213      load_dialog = new LoadDialog("Loading...", *this);  
2214      load_dialog->show_all();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
2215      loader = new Loader(strdup(name));          _("Loading") +  Glib::ustring(" '") +
2216            Glib::filename_display_basename(name) + "' ...",
2217            *this
2218        );
2219    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2220        progress_dialog->show_all();
2221    #endif
2222        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));
2225      loader->signal_finished().connect(      loader->signal_finished().connect(
2226          sigc::mem_fun(*this, &MainWindow::on_loader_finished));          sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2227        loader->signal_error().connect(
2228            sigc::mem_fun(*this, &MainWindow::on_loader_error));
2229      loader->launch();      loader->launch();
2230  }  }
2231    
# Line 660  void MainWindow::load_instrument(gig::In Line 2241  void MainWindow::load_instrument(gig::In
2241      // load the instrument      // load the instrument
2242      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
2243      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2244      //TODO: automatically select the given instrument      // automatically select the given instrument
2245        int i = 0;
2246        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2247             instrument = pFile->GetNextInstrument(), ++i)
2248        {
2249            if (instrument == instr) {
2250                // select item in "instruments" tree view
2251                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2252                // make sure the selected item in the "instruments" tree view is
2253                // visible (scroll to it)
2254                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2255    #if !USE_GTKMM_BUILDER
2256                // select item in instrument menu
2257                {
2258                    const std::vector<Gtk::Widget*> children =
2259                        instrument_menu->get_children();
2260                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2261                }
2262    #endif
2263                // update region chooser and dimension region chooser
2264                m_RegionChooser.set_instrument(instr);
2265                break;
2266            }
2267        }
2268  }  }
2269    
2270  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
2271  {  {
2272      load_dialog->set_fraction(loader->get_progress());      progress_dialog->set_fraction(loader->get_progress());
2273  }  }
2274    
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::Thread::self());      printf("on_loader_finished self=%p\n",
2279      load_gig(loader->gig, loader->filename);             static_cast<void*>(Glib::Threads::Thread::self()));
2280      load_dialog->hide();      load_gig(loader->gig, loader->filename.c_str());
2281        progress_dialog->hide();
2282    }
2283    
2284    void MainWindow::on_loader_error()
2285    {
2286        Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2287        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2288        msg.run();
2289        progress_dialog->hide();
2290  }  }
2291    
2292  void MainWindow::on_action_file_save()  void MainWindow::on_action_file_save()
# Line 712  bool MainWindow::file_save() Line 2325  bool MainWindow::file_save()
2325    
2326      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
2327      file_structure_to_be_changed_signal.emit(this->file);      file_structure_to_be_changed_signal.emit(this->file);
2328      try {  
2329          file->Save();      progress_dialog = new ProgressDialog( //FIXME: memory leak!
2330          if (file_is_changed) {          _("Saving") +  Glib::ustring(" '") +
2331              set_title(get_title().substr(1));          Glib::filename_display_basename(this->filename) + "' ...",
2332              file_is_changed = false;          *this
2333          }      );
2334      } catch (RIFF::Exception e) {  #if HAS_GTKMM_SHOW_ALL_CHILDREN
2335          file_structure_changed_signal.emit(this->file);      progress_dialog->show_all();
2336          Glib::ustring txt = _("Could not save file: ") + e.Message;  #endif
2337          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);      saver = new Saver(this->file); //FIXME: memory leak!
2338          msg.run();      saver->signal_progress().connect(
2339          return false;          sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2340      }      saver->signal_finished().connect(
2341      std::cout << "Saving file done\n" << std::flush;          sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2342        saver->signal_error().connect(
2343            sigc::mem_fun(*this, &MainWindow::on_saver_error));
2344        saver->launch();
2345    
2346        return true;
2347    }
2348    
2349    void MainWindow::on_saver_progress()
2350    {
2351        progress_dialog->set_fraction(saver->get_progress());
2352    }
2353    
2354    void MainWindow::on_saver_error()
2355    {
2356        file_structure_changed_signal.emit(this->file);
2357        Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2358        Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2359        msg.run();
2360    }
2361    
2362    void MainWindow::on_saver_finished()
2363    {
2364        this->file = saver->gig;
2365        this->filename = saver->filename;
2366        current_gig_dir = Glib::path_get_dirname(filename);
2367        set_title(Glib::filename_display_basename(filename));
2368        file_has_name = true;
2369        file_is_changed = false;
2370        std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
2371      __import_queued_samples();      __import_queued_samples();
2372        std::cout << "Importing queued samples done.\n" << std::flush;
2373    
2374      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
2375      return true;  
2376        __refreshEntireGUI();
2377        progress_dialog->hide();
2378  }  }
2379    
2380  void MainWindow::on_action_file_save_as()  void MainWindow::on_action_file_save_as()
# Line 740  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);
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2  
2397      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
2398      // TODO: an overwrite dialog for gtkmm < 2.8  
2399  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2400      Gtk::FileFilter filter;      Gtk::FileFilter filter;
2401      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
2402    #else
2403        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2404        filter->add_pattern("*.gig");
2405    #endif
2406      dialog.set_filter(filter);      dialog.set_filter(filter);
2407    
2408      if (Glib::path_is_absolute(filename)) {      // set initial dir and filename of the Save As dialog
2409          dialog.set_filename(filename);      // and prepare that initial filename as a copy of the gig
2410      } else if (current_dir != "") {      {
2411          dialog.set_current_folder(current_dir);          std::string basename = Glib::path_get_basename(filename);
2412            std::string dir = Glib::path_get_dirname(filename);
2413            basename = std::string(_("copy_of_")) + basename;
2414            Glib::ustring copyFileName = Glib::build_filename(dir, basename);
2415            if (Glib::path_is_absolute(filename)) {
2416                dialog.set_filename(copyFileName);
2417            } else {
2418                if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
2419            }
2420            dialog.set_current_name(Glib::filename_display_basename(copyFileName));
2421      }      }
2422      dialog.set_current_name(Glib::filename_display_basename(filename));  
2423        // show warning in the dialog
2424        HBox descriptionArea;
2425        descriptionArea.set_spacing(15);
2426        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);
2430    #if GTKMM_MAJOR_VERSION < 3
2431        view::WrapLabel description;
2432    #else
2433        Gtk::Label description;
2434        description.set_line_wrap();
2435    #endif
2436        description.set_markup(
2437            _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
2438              "<span style=\"italic\">\"Save\"</span> dialog instead of "
2439              "<span style=\"italic\">\"Save As...\"</span> if you want to save "
2440              "to the same .gig file. Using "
2441              "<span style=\"italic\">\"Save As...\"</span> for writing to the "
2442              "same .gig file will end up in corrupted sample wave data!\n")
2443        );
2444        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);
2449    #endif
2450    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2451        descriptionArea.show_all();
2452    #endif
2453    
2454      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
2455          file_structure_to_be_changed_signal.emit(this->file);          std::string filename = dialog.get_filename();
2456          try {          if (!Glib::str_has_suffix(filename, ".gig")) {
2457              std::string filename = dialog.get_filename();              filename += ".gig";
             if (!Glib::str_has_suffix(filename, ".gig")) {  
                 filename += ".gig";  
             }  
             printf("filename=%s\n", filename.c_str());  
             file->Save(filename);  
             this->filename = filename;  
             current_dir = Glib::path_get_dirname(filename);  
             set_title(Glib::filename_display_basename(filename));  
             file_has_name = true;  
             file_is_changed = false;  
         } catch (RIFF::Exception e) {  
             file_structure_changed_signal.emit(this->file);  
             Glib::ustring txt = _("Could not save file: ") + e.Message;  
             Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);  
             msg.run();  
             return false;  
2458          }          }
2459          __import_queued_samples();          printf("filename=%s\n", filename.c_str());
2460          file_structure_changed_signal.emit(this->file);  
2461            progress_dialog = new ProgressDialog( //FIXME: memory leak!
2462                _("Saving") +  Glib::ustring(" '") +
2463                Glib::filename_display_basename(filename) + "' ...",
2464                *this
2465            );
2466    #if HAS_GTKMM_SHOW_ALL_CHILDREN
2467            progress_dialog->show_all();
2468    #endif
2469    
2470            saver = new Saver(file, filename); //FIXME: memory leak!
2471            saver->signal_progress().connect(
2472                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2473            saver->signal_finished().connect(
2474                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2475            saver->signal_error().connect(
2476                sigc::mem_fun(*this, &MainWindow::on_saver_error));
2477            saver->launch();
2478    
2479          return true;          return true;
2480      }      }
2481      return false;      return false;
# Line 791  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);
2496          try {          try {
2497              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
2498              // determine sample's bit depth              // determine sample's bit depth
2499              int bitdepth;              int bitdepth;
2500              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 816  void MainWindow::__import_queued_samples Line 2511  void MainWindow::__import_queued_samples
2511                      break;                      break;
2512                  default:                  default:
2513                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
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 828  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 848  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 858  void MainWindow::__import_queued_samples Line 2556  void MainWindow::__import_queued_samples
2556              }              }
2557              // cleanup              // cleanup
2558              sf_close(hFile);              sf_close(hFile);
2559                // let the sampler re-cache the sample if needed
2560                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.size()) 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      }      }
2573      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
2574      if (error_files.size()) {      if (!error_files.empty()) {
2575          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
2576          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2577          msg.run();          msg.run();
# Line 884  void MainWindow::on_action_file_properti Line 2584  void MainWindow::on_action_file_properti
2584      propDialog.deiconify();      propDialog.deiconify();
2585  }  }
2586    
2587    void MainWindow::on_action_warn_user_on_extensions() {
2588        Settings::singleton()->warnUserOnExtensions =
2589            !Settings::singleton()->warnUserOnExtensions;
2590    }
2591    
2592    void MainWindow::on_action_sync_sampler_instrument_selection() {
2593        Settings::singleton()->syncSamplerInstrumentSelection =
2594            !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  {  {
 #ifdef ABOUT_DIALOG  
2604      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
2605    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
2606        dialog.set_program_name("Gigedit");
2607    #else
2608        dialog.set_name("Gigedit");
2609    #endif
2610      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2611      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
2612      dialog.set_comments(      const std::string sComment =
2613          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
2614          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
2615          "Please notice that this is still a very young instrument editor. "          _(
2616          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
2617          "this application.\n"              "\n"
2618          "\n"              "This program is distributed WITHOUT ANY WARRANTY; So better "
2619          "Please report bugs to: http://bugs.linuxsampler.org"              "backup your Gigasampler/GigaStudio files before editing them with "
2620      );              "this application.\n"
2621                "\n"
2622                "Please report bugs to: http://bugs.linuxsampler.org"
2623            );
2624        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();
 #endif  
2629  }  }
2630    
2631  PropDialog::PropDialog()  PropDialog::PropDialog()
2632      : table(2,1),      : eFileFormat(_("File Format")),
2633        eName("Name"),        eName(_("Name")),
2634        eCreationDate("Creation date"),        eCreationDate(_("Creation date")),
2635        eComments("Comments"),        eComments(_("Comments")),
2636        eProduct("Product"),        eProduct(_("Product")),
2637        eCopyright("Copyright"),        eCopyright(_("Copyright")),
2638        eArtists("Artists"),        eArtists(_("Artists")),
2639        eGenre("Genre"),        eGenre(_("Genre")),
2640        eKeywords("Keywords"),        eKeywords(_("Keywords")),
2641        eEngineer("Engineer"),        eEngineer(_("Engineer")),
2642        eTechnician("Technician"),        eTechnician(_("Technician")),
2643        eSoftware("Software"),        eSoftware(_("Software")),
2644        eMedium("Medium"),        eMedium(_("Medium")),
2645        eSource("Source"),        eSource(_("Source")),
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        update_model(0)  #else
2652          quitButton(_("_Close")),
2653    #endif
2654          table(2, 1),
2655          m_file(NULL)
2656  {  {
2657      set_title("File Properties");      if (!Settings::singleton()->autoRestoreWindowDimension) {
2658            set_default_size(470, 390);
2659            set_position(Gtk::WIN_POS_MOUSE);
2660        }
2661    
2662        set_title(_("File Properties"));
2663      eName.set_width_chars(50);      eName.set_width_chars(50);
2664    
2665      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
# Line 946  PropDialog::PropDialog() Line 2679  PropDialog::PropDialog()
2679      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
2680      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
2681    
2682        table.add(eFileFormat);
2683      table.add(eName);      table.add(eName);
2684      table.add(eCreationDate);      table.add(eCreationDate);
2685      table.add(eComments);      table.add(eComments);
# Line 963  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_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
2723      quitButton.grab_focus();      quitButton.grab_focus();
2724      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
2725          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
2726        eFileFormat.signal_value_changed().connect(
2727            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
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_info(DLS::Info* info)  void PropDialog::set_file(gig::File* file)
2737  {  {
2738      this->info = info;      m_file = file;
2739      update_model++;  
2740      eName.set_value(info->Name);      // update file format version combo box
2741      eCreationDate.set_value(info->CreationDate);      const std::string sGiga = "Gigasampler/GigaStudio v";
2742      eComments.set_value(info->Comments);      const int major = file->pVersion->major;
2743      eProduct.set_value(info->Product);      std::vector<std::string> txts;
2744      eCopyright.set_value(info->Copyright);      std::vector<int> values;
2745      eArtists.set_value(info->Artists);      txts.push_back(sGiga + "2"); values.push_back(2);
2746      eGenre.set_value(info->Genre);      txts.push_back(sGiga + "3/v4"); values.push_back(3);
2747      eKeywords.set_value(info->Keywords);      if (major != 2 && major != 3) {
2748      eEngineer.set_value(info->Engineer);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
2749      eTechnician.set_value(info->Technician);      }
2750      eSoftware.set_value(info->Software);      std::vector<const char*> texts;
2751      eMedium.set_value(info->Medium);      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2752      eSource.set_value(info->Source);      texts.push_back(NULL); values.push_back(0);
2753      eSourceForm.set_value(info->SourceForm);      eFileFormat.set_choices(&texts[0], &values[0]);
2754      eCommissioned.set_value(info->Commissioned);      eFileFormat.set_value(major);
     eSubject.set_value(info->Subject);  
     update_model--;  
2755  }  }
2756    
2757  sigc::signal<void>& PropDialog::signal_info_changed()  void PropDialog::onFileFormatChanged() {
2758  {      const int major = eFileFormat.get_value();
2759      return info_changed;      if (m_file) m_file->pVersion->major = major;
2760  }  }
2761    
2762  void InstrumentProps::set_IsDrum(bool value)  void PropDialog::set_info(DLS::Info* info)
2763  {  {
2764      instrument->IsDrum = value;      update(info);
2765  }  }
2766    
2767  void InstrumentProps::set_MIDIBank(uint16_t value)  
2768    void InstrumentProps::set_Name(const gig::String& name)
2769  {  {
2770      instrument->MIDIBank = value;      m->pInfo->Name = name;
2771  }  }
2772    
2773  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::update_name()
2774  {  {
2775      instrument->MIDIProgram = value;      update_model++;
2776        eName.set_value(m->pInfo->Name);
2777        update_model--;
2778  }  }
2779    
2780  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_IsDrum(bool value)
2781  {  {
2782      instrument->DimensionKeyRange.low = value;      m->IsDrum = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
2783  }  }
2784    
2785  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
2786  {  {
2787      instrument->DimensionKeyRange.high = value;      m->MIDIBank = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
2788  }  }
2789    
2790  InstrumentProps::InstrumentProps()  void InstrumentProps::set_MIDIProgram(uint32_t value)
     : table(2,1),  
       quitButton(Gtk::Stock::CLOSE),  
       eName("Name"),  
       eIsDrum("Is drum"),  
       eMIDIBank("MIDI bank", 0, 16383),  
       eMIDIProgram("MIDI program"),  
       eAttenuation("Attenuation", 0, 96, 0, 1),  
       eGainPlus6("Gain +6dB", eAttenuation, -6),  
       eEffectSend("Effect send", 0, 65535),  
       eFineTune("Fine tune", -8400, 8400),  
       ePitchbendRange("Pitchbend range", 0, 12),  
       ePianoReleaseMode("Piano release mode"),  
       eDimensionKeyRangeLow("Keyswitching range low"),  
       eDimensionKeyRangeHigh("Keyswitching range high"),  
       update_model(0)  
2791  {  {
2792      set_title("Instrument Properties");      m->MIDIProgram = value;
2793    }
2794    
2795    InstrumentProps::InstrumentProps() :
2796    #if HAS_GTKMM_STOCK
2797        quitButton(Gtk::Stock::CLOSE),
2798    #else
2799        quitButton(_("_Close")),
2800    #endif
2801        table(2,1),
2802        eName(_("Name")),
2803        eIsDrum(_("Is drum")),
2804        eMIDIBank(_("MIDI bank"), 0, 16383),
2805        eMIDIProgram(_("MIDI program")),
2806        eAttenuation(_("Attenuation"), 0, 96, 0, 1),
2807        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2808        eEffectSend(_("Effect send"), 0, 65535),
2809        eFineTune(_("Fine tune"), -8400, 8400),
2810        ePitchbendRange(_("Pitchbend range"), 0, 48),
2811        ePianoReleaseMode(_("Piano release mode")),
2812        eDimensionKeyRangeLow(_("Keyswitching range low")),
2813        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"));
2821    
2822      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
2823          _("start of the keyboard area which should switch the "          _("start of the keyboard area which should switch the "
# Line 1069  InstrumentProps::InstrumentProps() Line 2828  InstrumentProps::InstrumentProps()
2828            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
2829      );      );
2830    
2831        connect(eName, &InstrumentProps::set_Name);
2832      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
2833      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2834      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1078  InstrumentProps::InstrumentProps() Line 2838  InstrumentProps::InstrumentProps()
2838      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
2839      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
2840      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
2841      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
2842              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
2843      connect(eDimensionKeyRangeHigh,  
2844              &InstrumentProps::set_DimensionKeyRange_high);      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 1099  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_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
2883      quitButton.grab_focus();      quitButton.grab_focus();
2884    
2885      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 1115  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)
2896  {  {
2897      this->instrument = instrument;      update(instrument);
2898    
2899      update_model++;      update_model++;
2900      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
2901      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
2902      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
2903      eMIDIProgram.set_value(instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
     eAttenuation.set_value(instrument->Attenuation);  
     eGainPlus6.set_value(instrument->Attenuation);  
     eEffectSend.set_value(instrument->EffectSend);  
     eFineTune.set_value(instrument->FineTune);  
     ePitchbendRange.set_value(instrument->PitchbendRange);  
     ePianoReleaseMode.set_value(instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high);  
2904      update_model--;      update_model--;
2905  }  }
2906    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
2907    
2908  void MainWindow::file_changed()  void MainWindow::file_changed()
2909  {  {
# Line 1151  void MainWindow::file_changed() Line 2913  void MainWindow::file_changed()
2913      }      }
2914  }  }
2915    
2916    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
2917        sample_ref_count.clear();
2918        
2919        if (!gig) return;
2920    
2921        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
2922             instrument = gig->GetNextInstrument())
2923        {
2924            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2925                 rgn = instrument->GetNextRegion())
2926            {
2927                for (int i = 0; i < 256; ++i) {
2928                    if (!rgn->pDimensionRegions[i]) continue;
2929                    if (rgn->pDimensionRegions[i]->pSample) {
2930                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
2931                    }
2932                }
2933            }
2934        }
2935    }
2936    
2937  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
2938  {  {
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;
2949    
2950        propDialog.set_file(gig);
2951      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2952    
2953      Gtk::MenuItem* instrument_menu =      instrument_name_connection.block();
2954          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));      int index = 0;
   
     int instrument_index = 0;  
     Gtk::RadioMenuItem::Group instrument_group;  
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));
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_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_nr] = index;
2963            row[m_Columns.m_col_name] = name;
2964          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2965          // create a menu item for this instrument          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2966          Gtk::RadioMenuItem* item =  
2967              new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str());  #if !USE_GTKMM_BUILDER
2968          instrument_menu->get_submenu()->append(*item);          add_instrument_to_menu(name);
2969          item->signal_activate().connect(  #endif
             sigc::bind(  
                 sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),  
                 instrument_index  
             )  
         );  
         instrument_index++;  
2970      }      }
2971      instrument_menu->show();      instrument_name_connection.unblock();
2972      instrument_menu->get_submenu()->show_all_children();  #if !USE_GTKMM_BUILDER
2973        uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
2974    #endif
2975    
2976        updateSampleRefCountMap(gig);
2977    
2978      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
2979          if (group->Name != "") {          if (group->Name != "") {
2980              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
2981              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
2982              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
2983              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
2984              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
2985              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1201  void MainWindow::load_gig(gig::File* gig Line 2987  void MainWindow::load_gig(gig::File* gig
2987                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
2988                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
2989                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
2990                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
2991                        gig_to_utf8(sample->pInfo->Name);
2992                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
2993                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
2994                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
2995                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2996                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2997              }              }
2998          }          }
2999      }      }
3000        
3001        for (int i = 0; gig->GetScriptGroup(i); ++i) {
3002            gig::ScriptGroup* group = gig->GetScriptGroup(i);
3003    
3004            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3005            Gtk::TreeModel::Row rowGroup = *iterGroup;
3006            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
3007            rowGroup[m_ScriptsModel.m_col_group]  = group;
3008            rowGroup[m_ScriptsModel.m_col_script] = NULL;
3009            for (int s = 0; group->GetScript(s); ++s) {
3010                gig::Script* script = group->GetScript(s);
3011    
3012                Gtk::TreeModel::iterator iterScript =
3013                    m_refScriptsTreeModel->append(rowGroup.children());
3014                Gtk::TreeModel::Row rowScript = *iterScript;
3015                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
3016                rowScript[m_ScriptsModel.m_col_script] = script;
3017                rowScript[m_ScriptsModel.m_col_group]  = NULL;
3018            }
3019        }
3020        // unfold all sample groups & script groups by default
3021        m_TreeViewSamples.expand_all();
3022        m_TreeViewScripts.expand_all();
3023    
3024      file = gig;      file = gig;
3025    
3026      // select the first instrument      // select the first instrument
3027      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
3028      tree_sel_ref->select(Gtk::TreePath("0"));  
3029        instr_props_set_instrument();
3030        gig::Instrument* instrument = get_instrument();
3031        if (instrument) {
3032            midiRules.set_instrument(instrument);
3033        }
3034  }  }
3035    
3036  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
3037  {  {
3038      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
3039      if (instrument)  
3040      {      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3041        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) {
3048            Gtk::TreeModel::Row row = *it;
3049            gig::Instrument* instrument = row[m_Columns.m_col_instr];
3050    
3051          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
3052    
3053            // make sure instrument tree is updated when user changes the
3054            // instrument name in instrument properties window
3055            instrumentProps.signal_name_changed().connect(
3056                sigc::bind(
3057                    sigc::mem_fun(*this,
3058                                  &MainWindow::instr_name_changed_by_instr_props),
3059                    it));
3060        } else {
3061            instrumentProps.hide();
3062        }
3063        //NOTE: explicit boolean cast required for GTKMM4 development branch here
3064        return it ? true : false;
3065    }
3066    
3067    void MainWindow::show_instr_props()
3068    {
3069        if (instr_props_set_instrument()) {
3070          instrumentProps.show();          instrumentProps.show();
3071          instrumentProps.deiconify();          instrumentProps.deiconify();
3072      }      }
3073  }  }
3074    
3075    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3076    {
3077        Gtk::TreeModel::Row row = *it;
3078        Glib::ustring name = row[m_Columns.m_col_name];
3079    
3080        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3081        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3082        if (gigname != name) {
3083            row[m_Columns.m_col_name] = gigname;
3084        }
3085    }
3086    
3087    void MainWindow::show_midi_rules()
3088    {
3089        if (gig::Instrument* instrument = get_instrument())
3090        {
3091            midiRules.set_instrument(instrument);
3092            midiRules.show();
3093            midiRules.deiconify();
3094        }
3095    }
3096    
3097    void MainWindow::show_script_slots() {
3098        if (!file) return;
3099        // get selected instrument
3100        std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3101        if (rows.empty()) return;
3102        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3103        if (!it) return;
3104        Gtk::TreeModel::Row row = *it;
3105        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3106        if (!instrument) return;
3107    
3108        ScriptSlots* window = new ScriptSlots;
3109        window->setInstrument(instrument);
3110        window->signal_script_slots_changed().connect(
3111            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3112        );
3113        //window->reparent(*this);
3114        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 1235  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_button_release(GdkEventButton* button)  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 {
3220    #if USE_GLIB_ACTION
3221        bool active = false;
3222        m_actionToggleCopySampleUnity->get_state(active);
3223        return active;
3224    #else
3225        Gtk::CheckMenuItem* item =
3226            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3227        if (!item) {
3228            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
3229            return true;
3230        }
3231        return item->get_active();
3232    #endif
3233    }
3234    
3235    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 =
3242            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3243        if (!item) {
3244            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
3245            return true;
3246        }
3247        return item->get_active();
3248    #endif
3249    }
3250    
3251    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 =
3258            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3259        if (!item) {
3260            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
3261            return true;
3262        }
3263        return item->get_active();
3264    #endif
3265    }
3266    
3267    #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
3277            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*>(
3282                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3283                    bEnabled
3284                );
3285            static_cast<Gtk::MenuItem*>(
3286                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3287                    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  void MainWindow::on_instrument_selection_change(int index) {  #if !USE_GTKMM_BUILDER
3298      m_RegionChooser.set_instrument(file->GetInstrument(index));  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3299        if (item->get_active()) {
3300            const std::vector<Gtk::Widget*> children =
3301                instrument_menu->get_children();
3302            std::vector<Gtk::Widget*>::const_iterator it =
3303                find(children.begin(), children.end(), item);
3304            if (it != children.end()) {
3305                int index = it - children.begin();
3306                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
3307    
3308                m_RegionChooser.set_instrument(file->GetInstrument(index));
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) {
3386        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3387        for (int g = 0; g < model->children().size(); ++g) {
3388            Gtk::TreeModel::Row rowGroup = model->children()[g];
3389            for (int s = 0; s < rowGroup.children().size(); ++s) {
3390                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3391                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3392                    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]);
3399    #endif
3400                    std::vector<Gtk::TreeModel::Path> rows =
3401                        m_TreeViewSamples.get_selection()->get_selected_rows();
3402                    if (rows.empty()) return;
3403                    m_TreeViewSamples.scroll_to_row(rows[0]);
3404                    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"))->
3470                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"))->
3479                set_sensitive(n == 1);
3480            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
3481                set_sensitive(n);
3482            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
3483                set_sensitive(file);
3484            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
3485                set_sensitive(nSamples == 1);
3486            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3487                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  void MainWindow::on_action_add_instrument() {  #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      static int __instrument_indexer = 0;  bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3498      if (!file) return;      GdkEventButton* button = _button.gobj();
3499      gig::Instrument* instrument = file->AddInstrument();  #else
3500      __instrument_indexer++;  void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3501      instrument->pInfo->Name =  #endif
3502          "Unnamed Instrument " + ToString(__instrument_indexer);      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3503    #if !USE_GTKMM_BUILDER
3504            Gtk::Menu* script_popup =
3505                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3506    #endif
3507            // update enabled/disabled state of sample popup items
3508            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3509            Gtk::TreeModel::iterator it = sel->get_selected();
3510            bool group_selected  = false;
3511            bool script_selected = false;
3512            if (it) {
3513                Gtk::TreeModel::Row row = *it;
3514                group_selected  = row[m_ScriptsModel.m_col_group];
3515                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"))->
3524                set_sensitive(group_selected || script_selected);
3525            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
3526                set_sensitive(file);
3527            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
3528                set_sensitive(script_selected);    
3529            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3530                set_sensitive(group_selected || script_selected);
3531    #endif
3532            // show sample popup
3533            script_popup->popup(button->button, button->time);
3534    
3535    #if !USE_GTKMM_BUILDER
3536            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3537                set_sensitive(group_selected || script_selected);
3538            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
3539                set_sensitive(file);
3540            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
3541                set_sensitive(script_selected);    
3542            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3543                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(
3601        const Glib::ustring& name, int position) {
3602    
3603        Gtk::RadioMenuItem::Group instrument_group;
3604        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
3605        if (!children.empty()) {
3606            instrument_group =
3607                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
3608        }
3609        Gtk::RadioMenuItem* item =
3610            new Gtk::RadioMenuItem(instrument_group, name);
3611        if (position < 0) {
3612            instrument_menu->append(*item);
3613        } else {
3614            instrument_menu->insert(*item, position);
3615        }
3616        item->show();
3617        item->signal_activate().connect(
3618            sigc::bind(
3619                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
3620                item));
3621        return item;
3622    }
3623    #endif
3624    
3625    #if !USE_GTKMM_BUILDER
3626    void MainWindow::remove_instrument_from_menu(int index) {
3627        const std::vector<Gtk::Widget*> children =
3628            instrument_menu->get_children();
3629        Gtk::Widget* child = children[index];
3630        instrument_menu->remove(*child);
3631        delete child;
3632    }
3633    #endif
3634    
3635    void MainWindow::add_instrument(gig::Instrument* instrument) {
3636        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3637    
3638      // update instrument tree view      // update instrument tree view
3639        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_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
3643        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();
3647    
3648    #if !USE_GTKMM_BUILDER
3649        add_instrument_to_menu(name);
3650    #endif
3651        select_instrument(instrument);
3652      file_changed();      file_changed();
3653  }  }
3654    
3655    void MainWindow::on_action_add_instrument() {
3656        static int __instrument_indexer = 0;
3657        if (!file) return;
3658        gig::Instrument* instrument = file->AddInstrument();
3659        __instrument_indexer++;
3660        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
3661                                                ToString(__instrument_indexer));
3662    
3663        add_instrument(instrument);
3664    }
3665    
3666    void MainWindow::on_action_duplicate_instrument() {
3667        if (!file) return;
3668    
3669        // retrieve the currently selected instrument
3670        // (being the original instrument to be duplicated)
3671        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3672        std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3673        for (int r = 0; r < rows.size(); ++r) {
3674            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3675            if (it) {
3676                Gtk::TreeModel::Row row = *it;
3677                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
3678                if (instrOrig) {
3679                    // duplicate the orginal instrument
3680                    gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
3681                    instrNew->pInfo->Name =
3682                        instrOrig->pInfo->Name +
3683                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
3684    
3685                    add_instrument(instrNew);
3686                }
3687            }
3688        }
3689    }
3690    
3691  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
3692      if (!file) return;      if (!file) return;
3693      if (file_is_shared) {      if (file_is_shared) {
# Line 1306  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 {
3712                Gtk::TreePath path(it);
3713                int index = path[0];
3714    
3715              // remove instrument from the gig file              // remove instrument from the gig file
3716              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
3717              file_changed();              file_changed();
3718    
3719    #if !USE_GTKMM_BUILDER
3720                remove_instrument_from_menu(index);
3721    #endif
3722    
3723                // remove row from instruments tree view
3724                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
3737                // select another instrument (in gtk3 this is done
3738                // automatically)
3739                if (!m_refTreeModel->children().empty()) {
3740                    if (index == m_refTreeModel->children().size()) {
3741                        index--;
3742                    }
3743                    m_TreeView.get_selection()->select(
3744                        Gtk::TreePath(ToString(index)));
3745                }
3746    #endif
3747                instr_props_set_instrument();
3748                instr = get_instrument();
3749                if (instr) {
3750                    midiRules.set_instrument(instr);
3751                } else {
3752                    midiRules.hide();
3753                }
3754          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
3755              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3756              msg.run();              msg.run();
# Line 1326  void MainWindow::on_action_remove_instru Line 3761  void MainWindow::on_action_remove_instru
3761  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
3762      //TODO: show a dialog where the selected sample's properties can be edited      //TODO: show a dialog where the selected sample's properties can be edited
3763      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
3764          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
3765      );      );
3766      msg.run();      msg.run();
3767  }  }
3768    
3769    void MainWindow::on_action_add_script_group() {
3770        static int __script_indexer = 0;
3771        if (!file) return;
3772        gig::ScriptGroup* group = file->AddScriptGroup();
3773        group->Name = gig_from_utf8(_("Unnamed Group"));
3774        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
3775        __script_indexer++;
3776        // update sample tree view
3777        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3778        Gtk::TreeModel::Row rowGroup = *iterGroup;
3779        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3780        rowGroup[m_ScriptsModel.m_col_script] = NULL;
3781        rowGroup[m_ScriptsModel.m_col_group] = group;
3782        file_changed();
3783    }
3784    
3785    void MainWindow::on_action_add_script() {
3786        if (!file) return;
3787        // get selected group
3788        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3789        Gtk::TreeModel::iterator it = sel->get_selected();
3790        if (!it) return;
3791        Gtk::TreeModel::Row row = *it;
3792        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3793        if (!group) { // not a group, but a script is selected (probably)
3794            gig::Script* script = row[m_ScriptsModel.m_col_script];
3795            if (!script) return;
3796            it = row.parent(); // resolve parent (that is the script's group)
3797            if (!it) return;
3798            row = *it;
3799            group = row[m_ScriptsModel.m_col_group];
3800            if (!group) return;
3801        }
3802    
3803        // add a new script to the .gig file
3804        gig::Script* script = group->AddScript();    
3805        Glib::ustring name = _("Unnamed Script");
3806        script->Name = gig_from_utf8(name);
3807    
3808        // add script to the tree view
3809        Gtk::TreeModel::iterator iterScript =
3810            m_refScriptsTreeModel->append(row.children());
3811        Gtk::TreeModel::Row rowScript = *iterScript;
3812        rowScript[m_ScriptsModel.m_col_name] = name;
3813        rowScript[m_ScriptsModel.m_col_script] = script;
3814        rowScript[m_ScriptsModel.m_col_group]  = NULL;
3815    
3816        // unfold group of new script item in treeview
3817        Gtk::TreeModel::Path path(iterScript);
3818        m_TreeViewScripts.expand_to_path(path);
3819    }
3820    
3821    void MainWindow::on_action_edit_script() {
3822        if (!file) return;
3823        // get selected script
3824        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3825        Gtk::TreeModel::iterator it = sel->get_selected();
3826        if (!it) return;
3827        Gtk::TreeModel::Row row = *it;
3828        gig::Script* script = row[m_ScriptsModel.m_col_script];
3829        if (!script) return;
3830    
3831        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);
3839        //editor->reparent(*this);
3840        editor->show();
3841    }
3842    
3843    void MainWindow::on_action_remove_script() {
3844        if (!file) return;
3845        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3846        Gtk::TreeModel::iterator it = sel->get_selected();
3847        if (it) {
3848            Gtk::TreeModel::Row row = *it;
3849            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3850            gig::Script* script     = row[m_ScriptsModel.m_col_script];
3851            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
3852            try {
3853                // remove script group or script from the gig file
3854                if (group) {
3855                    // notify everybody that we're going to remove these samples
3856    //TODO:         scripts_to_be_removed_signal.emit(members);
3857                    // delete the group in the .gig file including the
3858                    // samples that belong to the group
3859                    file->DeleteScriptGroup(group);
3860                    // notify that we're done with removal
3861    //TODO:         scripts_removed_signal.emit();
3862                    file_changed();
3863                } else if (script) {
3864                    // notify everybody that we're going to remove this sample
3865    //TODO:         std::list<gig::Script*> lscripts;
3866    //TODO:         lscripts.push_back(script);
3867    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
3868                    // remove sample from the .gig file
3869                    script->GetGroup()->DeleteScript(script);
3870                    // notify that we're done with removal
3871    //TODO:         scripts_removed_signal.emit();
3872                    dimreg_changed();
3873                    file_changed();
3874                }
3875                // remove respective row(s) from samples tree view
3876                m_refScriptsTreeModel->erase(it);
3877            } catch (RIFF::Exception e) {
3878                // pretend we're done with removal (i.e. to avoid dead locks)
3879    //TODO:     scripts_removed_signal.emit();
3880                // show error message
3881                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3882                msg.run();
3883            }
3884        }
3885    }
3886    
3887  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
3888      static int __sample_indexer = 0;      static int __sample_indexer = 0;
3889      if (!file) return;      if (!file) return;
3890      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
3891      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
3892      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
3893      __sample_indexer++;      __sample_indexer++;
3894      // update sample tree view      // update sample tree view
3895      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3896      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
3897      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3898      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
3899      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = 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      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile      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
3946    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3947        Gtk::FileFilter soundfilter;
3948    #else
3949        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
3950    #endif
3951      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
3952          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
3953          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1377  void MainWindow::on_action_add_sample() Line 3955  void MainWindow::on_action_add_sample()
3955          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
3956          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
3957      };      };
3958        const char* soundfiles = _("Sound Files");
3959        const char* allfiles = _("All Files");
3960    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3961      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
3962          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
3963      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
3964      Gtk::FileFilter allpassfilter; // matches every file  
3965        // matches every file
3966        Gtk::FileFilter allpassfilter;
3967      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
3968      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
3969    #else
3970        for (int i = 0; supportedFileTypes[i]; i++)
3971            soundfilter->add_pattern(supportedFileTypes[i]);
3972        soundfilter->set_name(soundfiles);
3973    
3974        // matches every file
3975        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
3976        allpassfilter->add_pattern("*.*");
3977        allpassfilter->set_name(allfiles);
3978    #endif
3979      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
3980      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
3981        if (current_sample_dir != "") {
3982            dialog.set_current_folder(current_sample_dir);
3983        }
3984      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3985            current_sample_dir = dialog.get_current_folder();
3986          Glib::ustring error_files;          Glib::ustring error_files;
3987          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3988          for (Glib::SListHandle<Glib::ustring>::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 informations
# Line 1396  void MainWindow::on_action_add_sample() Line 3993  void MainWindow::on_action_add_sample()
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);
3995              try {              try {
3996                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
3997                  int bitdepth;                  int bitdepth;
3998                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
3999                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1412  void MainWindow::on_action_add_sample() Line 4009  void MainWindow::on_action_add_sample()
4009                          break;                          break;
4010                      default:                      default:
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 1425  void MainWindow::on_action_add_sample() Line 4022  void MainWindow::on_action_add_sample()
4022                          break;                          break;
4023                      }                      }
4024                  }                  }
4025                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
4026                  sample->Channels = info.channels;                  sample->Channels = info.channels;
4027                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
4028                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1439  void MainWindow::on_action_add_sample() Line 4036  void MainWindow::on_action_add_sample()
4036                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
4037                  {                  {
4038                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
4039                        sample->FineTune      = instrument.detune;
4040    
 #if HAVE_SF_INSTRUMENT_LOOPS  
4041                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
4042                          sample->Loops = 1;                          sample->Loops = 1;
4043    
# Line 1460  void MainWindow::on_action_add_sample() Line 4057  void MainWindow::on_action_add_sample()
4057                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
4058                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
4059                      }                      }
 #endif  
4060                  }                  }
4061    
4062                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
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]   = filename;                      Gtk::TreeModel::iterator iterSample =
4078                  rowSample[m_SamplesModel.m_col_sample] = sample;                          m_refSamplesTreeModel->append(row.children());
4079                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      Gtk::TreeModel::Row rowSample = *iterSample;
4080                        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();
4088              } catch (std::string what) { // remember the files that made trouble (and their cause)              } catch (std::string what) { // remember the files that made trouble (and their cause)
4089                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
4090                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
4091              }              }
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.size()) {          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 1503  void MainWindow::on_action_replace_all_s Line 4108  void MainWindow::on_action_replace_all_s
4108      if (!file) return;      if (!file) return;
4109      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
4110                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
4111      Gtk::Label description(      const char* str =
4112          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
4113            "in the current gig file by samples located in the directory chosen "            "in the current gig file by samples located in the chosen "
4114            "by you above.\n\n"            "directory.\n\n"
4115            "It works like this: For each sample in the gig file it tries to "            "It works like this: For each sample in the gig file, it tries to "
4116            "find a sample file in the selected directory with the same name as "            "find a sample file in the selected directory with the same name as "
4117            "the sample in the gig file. Optionally you can add a filename "            "the sample in the gig file. Optionally, you can add a filename "
4118            "postfix below, which will be added to the filename expected to be "            "extension below, which will be added to the filename expected to be "
4119            "found. That is, assume you have a gig file with a sample called "            "found. That is, assume you have a gig file with a sample called "
4120            "'Snare', if you enter '.wav' below (like it's done by default), it "            "'Snare', if you enter '.wav' below (like it's done by default), it "
4121            "assumes to find a sample file called 'Snare.wav' and will replace "            "expects to find a sample file called 'Snare.wav' and will replace "
4122            "the sample in the gig file accordingly. If you don't need such a "            "the sample in the gig file accordingly. If you don't need an "
4123            "postfix, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
4124            "appropriate sample file could be found, will be reported and left "            "appropriate sample file could be found will be reported and left "
4125            "untouched.\n\n")            "untouched.\n");
4126      );  #if GTKMM_MAJOR_VERSION < 3
4127      description.set_line_wrap(true);      view::WrapLabel description(str);
4128      Gtk::HBox entryArea;  #else
4129      Gtk::Label entryLabel( _("Add Filename Extension: "), Gtk::ALIGN_RIGHT);      Gtk::Label description(str);
4130        description.set_line_wrap();
4131    #endif
4132        HBox entryArea;
4133        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      entryLabel.show();  
4147      postfixEntryBox.show();  #if HAS_GTKMM_SHOW_ALL_CHILDREN
4148        entryArea.show_all();
4149    #else
4150      entryArea.show();      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      // fix label width (because Gtk by design doesn't      if (current_sample_dir != "") {
4161      // know anything about the parent's size)          dialog.set_current_folder(current_sample_dir);
4162  #if 0 //FIXME: doesn't work      }
     int dialogW, dialogH, labelW, labelH;  
     dialog.get_size_request(dialogW, dialogH);  
     description.get_size_request(labelW, labelH);  
     std::cout << "dialog(" << dialogW << "," << dialogH << ")\nlabel(" << labelW << "," << labelH << ")\n" << std::flush;  
     description.set_size_request(dialogW, labelH);  
 #endif  
4163      if (dialog.run() == Gtk::RESPONSE_OK)      if (dialog.run() == Gtk::RESPONSE_OK)
4164      {      {
4165            current_sample_dir = dialog.get_current_folder();
4166          Glib::ustring error_files;          Glib::ustring error_files;
4167          Glib::ustring folder = dialog.get_filename();          std::string folder = dialog.get_filename();
4168          for (gig::Sample* sample = file->GetFirstSample();          for (gig::Sample* sample = file->GetFirstSample();
4169               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
4170          {          {
4171              std::string filename =              std::string filename =
4172                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
4173                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
4174                                             postfixEntryBox.get_text());
4175              SF_INFO info;              SF_INFO info;
4176              info.format = 0;              info.format = 0;
4177              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
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);
4192                          throw std::string("format not supported");                          throw std::string(_("format not supported"));
4193                  }                  }
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              }              }
4201              catch (std::string what)              catch (std::string what)
4202              {              {
4203                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
4204                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
4205                        " (" + what + ")";
4206              }              }
4207          }          }
4208          // 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
4209          if (error_files.size()) {          if (!error_files.empty()) {
4210              Glib::ustring txt =              Glib::ustring txt =
4211                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
4212              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1603  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 1612  void MainWindow::on_action_remove_sample Line 4229  void MainWindow::on_action_remove_sample
4229          try {          try {
4230              // remove group or sample from the gig file              // remove group or sample from the gig file
4231              if (group) {              if (group) {
4232                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
4233                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
4234                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
4235                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1629  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 1652  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 1676  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()
4350    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4351    {
4352        first_call_to_drag_data_get = true;
4353    }
4354    
4355    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4356                                                       Gtk::SelectionData& selection_data, guint, guint)
4357    {
4358        if (!first_call_to_drag_data_get) return;
4359        first_call_to_drag_data_get = false;
4360    
4361        // get selected script
4362        gig::Script* script = NULL;
4363        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4364        Gtk::TreeModel::iterator it = sel->get_selected();
4365        if (it) {
4366            Gtk::TreeModel::Row row = *it;
4367            script = row[m_ScriptsModel.m_col_script];
4368        }
4369        // pass the gig::Script as pointer
4370        selection_data.set(selection_data.get_target(), 0/*unused*/,
4371                           (const guchar*)&script,
4372                           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 1694  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 1734  void MainWindow::on_sample_label_drop_dr Line 4492  void MainWindow::on_sample_label_drop_dr
4492          bool channels_changed = false;          bool channels_changed = false;
4493          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
4494              // remove the samplechannel dimension              // remove the samplechannel dimension
4495    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
4496              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
4497              channels_changed = true;              channels_changed = true;
4498              region_changed();              region_changed();
4499    */
4500          }          }
4501          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
4502                sample,
4503                is_copy_samples_unity_note_enabled(),
4504                is_copy_samples_fine_tune_enabled(),
4505                is_copy_samples_loop_enabled()
4506            );
4507    
4508          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
4509              // add samplechannel dimension              // add samplechannel dimension
# Line 1781  void MainWindow::sample_name_changed(con Line 4546  void MainWindow::sample_name_changed(con
4546      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
4547      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
4548      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4549        gig::String gigname(gig_from_utf8(name));
4550      if (group) {      if (group) {
4551          if (group->Name != name) {          if (group->Name != gigname) {
4552              group->Name = name;              group->Name = gigname;
4553              printf("group name changed\n");              printf("group name changed\n");
4554              file_changed();              file_changed();
4555          }          }
4556      } else if (sample) {      } else if (sample) {
4557          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
4558              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
4559              printf("sample name changed\n");              printf("sample name changed\n");
4560              file_changed();              file_changed();
4561          }          }
4562      }      }
4563  }  }
4564    
4565    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
4566                                         const Gtk::TreeModel::iterator& iter) {
4567        if (!iter) return;
4568        Gtk::TreeModel::Row row = *iter;
4569        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
4570        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
4571        gig::Script* script     = row[m_ScriptsModel.m_col_script];
4572        gig::String gigname(gig_from_utf8(name));
4573        if (group) {
4574            if (group->Name != gigname) {
4575                group->Name = gigname;
4576                printf("script group name changed\n");
4577                file_changed();
4578            }
4579        } else if (script) {
4580            if (script->Name != gigname) {
4581                script->Name = gigname;
4582                printf("script name changed\n");
4583                file_changed();
4584            }
4585        }
4586    }
4587    
4588    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
4589                                           Gtk::TreeViewColumn* column)
4590    {
4591        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
4592        if (!iter) return;
4593        Gtk::TreeModel::Row row = *iter;
4594        gig::Script* script = row[m_ScriptsModel.m_col_script];
4595        if (!script) return;
4596    
4597        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);
4605        //editor->reparent(*this);
4606        editor->show();
4607    }
4608    
4609  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
4610                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
4611      if (!iter) return;      if (!iter) return;
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
4617        int index = path[0];
4618        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
4619        if (index < children.size()) {
4620    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
4621            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
4622    #else
4623            remove_instrument_from_menu(index);
4624            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
4625            item->set_active();
4626    #endif
4627        }
4628    #endif
4629    
4630        // change name in gig
4631      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
4632      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
4633          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
4634            instrument->pInfo->Name = gigname;
4635    
4636            // change name in the instrument properties window
4637            if (instrumentProps.get_instrument() == instrument) {
4638                instrumentProps.update_name();
4639            }
4640    
4641          file_changed();          file_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() {
4671        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();
4692    #else
4693        d->show();
4694    #endif
4695        d->run();
4696        if (d->fileWasChanged()) {
4697            // update GUI with new instrument just created
4698            add_instrument(d->newCombinedInstrument());
4699        }
4700        delete d;
4701    }
4702    
4703    void MainWindow::on_action_view_references() {
4704        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4705        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;
4709        Gtk::TreeModel::Row row = *it;
4710        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4711        if (!sample) return;
4712    
4713        ReferencesView* d = new ReferencesView(*this);
4714        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();
4720    #else
4721        d->show();
4722    #endif
4723        d->resize(500, 400);
4724        d->run();
4725        delete d;
4726    }
4727    
4728    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
4729        struct _Source {
4730            std::vector<RIFF::File*> riffs;
4731            std::vector<gig::File*> gigs;
4732            
4733            ~_Source() {
4734                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
4735                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
4736                riffs.clear();
4737                gigs.clear();
4738            }
4739        } sources;
4740    
4741        if (filenames.empty())
4742            throw RIFF::Exception(_("No files selected, so nothing done."));
4743    
4744        // first open all input files (to avoid output file corruption)
4745        int i;
4746        try {
4747            for (i = 0; i < filenames.size(); ++i) {
4748                const std::string& filename = filenames[i];
4749                printf("opening file=%s\n", filename.c_str());
4750    
4751                RIFF::File* riff = new RIFF::File(filename);
4752                sources.riffs.push_back(riff);
4753    
4754                gig::File* gig = new gig::File(riff);
4755                sources.gigs.push_back(gig);
4756            }
4757        } catch (RIFF::Exception e) {
4758            throw RIFF::Exception(
4759                _("Error occurred while opening '") +
4760                filenames[i] +
4761                "': " +
4762                e.Message
4763            );
4764        } catch (...) {
4765            throw RIFF::Exception(
4766                _("Unknown exception occurred while opening '") +
4767                filenames[i] + "'"
4768            );
4769        }
4770    
4771        // now merge the opened .gig files to the main .gig file currently being
4772        // open in gigedit
4773        try {
4774            for (i = 0; i < filenames.size(); ++i) {
4775                const std::string& filename = filenames[i];
4776                printf("merging file=%s\n", filename.c_str());
4777                assert(i < sources.gigs.size());
4778    
4779                this->file->AddContentOf(sources.gigs[i]);
4780            }
4781        } catch (RIFF::Exception e) {
4782            throw RIFF::Exception(
4783                _("Error occurred while merging '") +
4784                filenames[i] +
4785                "': " +
4786                e.Message
4787            );
4788        } catch (...) {
4789            throw RIFF::Exception(
4790                _("Unknown exception occurred while merging '") +
4791                filenames[i] + "'"
4792            );
4793        }
4794    
4795        // Finally save gig file persistently to disk ...
4796        //NOTE: requires that this gig file already has a filename !
4797        {
4798            std::cout << "Saving file\n" << std::flush;
4799            file_structure_to_be_changed_signal.emit(this->file);
4800    
4801            progress_dialog = new ProgressDialog( //FIXME: memory leak!
4802                _("Saving") +  Glib::ustring(" '") +
4803                Glib::filename_display_basename(this->filename) + "' ...",
4804                *this
4805            );
4806    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4807            progress_dialog->show_all();
4808    #else
4809            progress_dialog->show();
4810    #endif
4811            saver = new Saver(this->file); //FIXME: memory leak!
4812            saver->signal_progress().connect(
4813                sigc::mem_fun(*this, &MainWindow::on_saver_progress));
4814            saver->signal_finished().connect(
4815                sigc::mem_fun(*this, &MainWindow::on_saver_finished));
4816            saver->signal_error().connect(
4817                sigc::mem_fun(*this, &MainWindow::on_saver_error));
4818            saver->launch();
4819        }
4820    }
4821    
4822    void MainWindow::on_action_merge_files() {
4823        if (this->file->GetFileName().empty()) {
4824            Glib::ustring txt = _(
4825                "You seem to have a new .gig file open that has not been saved "
4826                "yet. You must save it somewhere before starting to merge it with "
4827                "other .gig files though, because during the merge operation the "
4828                "other files' sample data must be written on file level to the "
4829                "target .gig file."
4830            );
4831            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4832            msg.run();
4833            return;
4834        }
4835    
4836        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4837    #if HAS_GTKMM_STOCK
4838        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);
4843        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4844    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4845        Gtk::FileFilter filter;
4846        filter.add_pattern("*.gig");
4847    #else
4848        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
4849        filter->add_pattern("*.gig");
4850    #endif
4851        dialog.set_filter(filter);
4852        if (current_gig_dir != "") {
4853            dialog.set_current_folder(current_gig_dir);
4854        }
4855        dialog.set_select_multiple(true);
4856    
4857        // show warning in the file picker dialog
4858        HBox descriptionArea;
4859        descriptionArea.set_spacing(15);
4860        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);
4864    #if GTKMM_MAJOR_VERSION < 3
4865        view::WrapLabel description;
4866    #else
4867        Gtk::Label description;
4868        description.set_line_wrap();
4869    #endif
4870        description.set_markup(_(
4871            "\nSelect at least one .gig file that shall be merged to the .gig file "
4872            "currently being open in gigedit.\n\n"
4873            "<b>Please Note:</b> Merging with other files will modify your "
4874            "currently open .gig file on file level! And be aware that the current "
4875            "merge algorithm does not detect duplicate samples yet. So if you are "
4876            "merging files which are using equivalent sample data, those "
4877            "equivalent samples will currently be treated as separate samples and "
4878            "will accordingly be stored separately in the target .gig file!"
4879        ));
4880        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);
4885    #endif
4886    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4887        descriptionArea.show_all();
4888    #else
4889        descriptionArea.show();
4890    #endif
4891    
4892        if (dialog.run() == Gtk::RESPONSE_OK) {
4893            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();
4896    
4897            // merge the selected files to the currently open .gig file
4898            try {
4899                mergeFiles(filenames);
4900            } catch (RIFF::Exception e) {
4901                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
4902                msg.run();
4903            }
4904    
4905            // update GUI
4906            __refreshEntireGUI();
4907        }
4908    }
4909    
4910  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
4911      this->file_is_shared = b;      this->file_is_shared = b;
4912    
# Line 1822  void MainWindow::set_file_is_shared(bool Line 4921  void MainWindow::set_file_is_shared(bool
4921              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
4922          );          );
4923      }      }
4924    
4925        {
4926    #if USE_GTKMM_BUILDER
4927            m_actionToggleSyncSamplerSelection->property_enabled() = b;
4928    #else
4929            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
4930                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
4931            if (item) item->set_sensitive(b);
4932    #endif
4933        }
4934    }
4935    
4936    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
4937        if (!sample) return;
4938        sample_ref_count[sample] += offset;
4939        const int refcount = sample_ref_count[sample];
4940    
4941        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
4942        for (int g = 0; g < model->children().size(); ++g) {
4943            Gtk::TreeModel::Row rowGroup = model->children()[g];
4944            for (int s = 0; s < rowGroup.children().size(); ++s) {
4945                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
4946                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
4947                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
4948                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
4949            }
4950        }
4951    }
4952    
4953    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
4954        on_sample_ref_count_incremented(oldSample, -1);
4955        on_sample_ref_count_incremented(newSample, +1);
4956    }
4957    
4958    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
4959        // just in case a new sample is added later with exactly the same memory
4960        // address, which would lead to incorrect refcount if not deleted here
4961        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
4962             it != samples.end(); ++it)
4963        {
4964            sample_ref_count.erase(*it);
4965        }
4966    }
4967    
4968    void MainWindow::show_samples_tab() {
4969        m_TreeViewNotebook.set_current_page(0);
4970    }
4971    
4972    void MainWindow::show_intruments_tab() {
4973        m_TreeViewNotebook.set_current_page(1);
4974    }
4975    
4976    void MainWindow::show_scripts_tab() {
4977        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() {
# Line 1848  sigc::signal<void, gig::Region*>& MainWi Line 5204  sigc::signal<void, gig::Region*>& MainWi
5204      return region_changed_signal;      return region_changed_signal;
5205  }  }
5206    
5207    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
5208        return sample_changed_signal;
5209    }
5210    
5211  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
5212      return sample_ref_changed_signal;      return sample_ref_changed_signal;
5213  }  }
# Line 1875  sigc::signal<void, int/*key*/, int/*velo Line 5235  sigc::signal<void, int/*key*/, int/*velo
5235  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
5236      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
5237  }  }
5238    
5239    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
5240        return switch_sampler_instrument_signal;
5241    }

Legend:
Removed from v.1673  
changed lines
  Added in v.3368

  ViewVC Help
Powered by ViewVC