/[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 2689 by schoenebeck, Sun Jan 4 17:19:19 2015 UTC revision 3144 by schoenebeck, Wed May 3 19:00:11 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
# Line 27  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
 #include <gtkmm/stock.h>  
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
# Line 50  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
67      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
68        labelLegend(_("Legend:")),
69        labelNoSample(_(" No Sample")),
70        labelMissingSample(_(" Missing some Sample(s)")),
71        labelLooped(_(" Looped")),
72        labelSomeLoops(_(" Some Loop(s)"))
73  {  {
74        loadBuiltInPix();
75    
76  //    set_border_width(5);  //    set_border_width(5);
77  //    set_default_size(400, 200);  //    set_default_size(400, 200);
78    
   
79      add(m_VBox);      add(m_VBox);
80    
81      // Handle selection      // Handle selection
# Line 96  MainWindow::MainWindow() : Line 109  MainWindow::MainWindow() :
109      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
110      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
111      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
112        {
113            legend_hbox.add(labelLegend);
114    
115            imageNoSample.set(redDot);
116            imageNoSample.set_alignment(Gtk::ALIGN_END);
117            labelNoSample.set_alignment(Gtk::ALIGN_START);
118            legend_hbox.add(imageNoSample);
119            legend_hbox.add(labelNoSample);
120    
121            imageMissingSample.set(yellowDot);
122            imageMissingSample.set_alignment(Gtk::ALIGN_END);
123            labelMissingSample.set_alignment(Gtk::ALIGN_START);
124            legend_hbox.add(imageMissingSample);
125            legend_hbox.add(labelMissingSample);
126    
127            imageLooped.set(blackLoop);
128            imageLooped.set_alignment(Gtk::ALIGN_END);
129            labelLooped.set_alignment(Gtk::ALIGN_START);
130            legend_hbox.add(imageLooped);
131            legend_hbox.add(labelLooped);
132    
133            imageSomeLoops.set(grayLoop);
134            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
135            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageSomeLoops);
137            legend_hbox.add(labelSomeLoops);
138    
139            legend_hbox.show_all_children();
140        }
141        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
142      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
143    
144      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 110  MainWindow::MainWindow() : Line 153  MainWindow::MainWindow() :
153      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
154    
155      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
156      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
157                         Gtk::AccelKey("<control>n"),
158                       sigc::mem_fun(                       sigc::mem_fun(
159                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
160      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
161          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
162                       sigc::mem_fun(                       sigc::mem_fun(
163                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
164      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
165                         Gtk::AccelKey("<control>s"),
166                       sigc::mem_fun(                       sigc::mem_fun(
167                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
168      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
169                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
172      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
173                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
174                       sigc::mem_fun(                       sigc::mem_fun(
175                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
176      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
177                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
178                       sigc::mem_fun(                       sigc::mem_fun(
179                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
180      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 144  MainWindow::MainWindow() : Line 185  MainWindow::MainWindow() :
185                                           _("_Script Slots...")),                                           _("_Script Slots...")),
186                       sigc::mem_fun(                       sigc::mem_fun(
187                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
188      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
189                         Gtk::AccelKey("<control>q"),
190                       sigc::mem_fun(                       sigc::mem_fun(
191                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
192      actionGroup->add(      actionGroup->add(
# Line 156  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
199      );      );
200      actionGroup->add(      actionGroup->add(
201          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
202          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
203      );      );
204      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
205    
206      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
207    
208        const Gdk::ModifierType primaryModifierKey =
209    #if defined(__APPLE__)
210        Gdk::META_MASK; // Cmd key on Mac
211    #else
212        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
213    #endif
214    
215        actionGroup->add(Gtk::Action::create("CopyDimRgn",
216                                             _("Copy selected dimension region")),
217                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
218                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
219    
220        actionGroup->add(Gtk::Action::create("PasteDimRgn",
221                                             _("Paste dimension region")),
222                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
226                                             _("Select Previous Region")),
227                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
228                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
229    
230        actionGroup->add(Gtk::Action::create("SelectNextRegion",
231                                             _("Select Next Region")),
232                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
233                         sigc::mem_fun(*this, &MainWindow::select_next_region));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
236                                             _("Select Previous Dimension Region Zone")),
237                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
241                                             _("Select Next Dimension Region Zone")),
242                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
243                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
246                                             _("Select Previous Dimension")),
247                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimension",
251                                             _("Select Next Dimension")),
252                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
254    
255        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
256                                             _("Add Previous Dimension Region Zone to Selection")),
257                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
259    
260        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
261                                             _("Add Next Dimension Region Zone to Selection")),
262                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
264    
265      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
266          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
267      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 179  MainWindow::MainWindow() : Line 278  MainWindow::MainWindow() :
278      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
279    
280    
281      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
282      toggle_action =      toggle_action =
283          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
284      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 187  MainWindow::MainWindow() : Line 286  MainWindow::MainWindow() :
286                       sigc::mem_fun(                       sigc::mem_fun(
287                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
288    
289      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      toggle_action =
290      actionGroup->add(Gtk::Action::create("MenuHelp",          Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
291                                           action->property_label()));      toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
292      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(toggle_action,
293                         sigc::mem_fun(
294                             *this, &MainWindow::on_auto_restore_win_dim));
295    
296        toggle_action =
297            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
298        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
299        actionGroup->add(toggle_action,
300                         sigc::mem_fun(
301                             *this, &MainWindow::on_save_with_temporary_file));
302    
303        actionGroup->add(
304            Gtk::Action::create("RefreshAll", _("_Refresh All")),
305            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
306        );                
307    
308        actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
309        actionGroup->add(Gtk::Action::create("About", _("_About")),
310                       sigc::mem_fun(                       sigc::mem_fun(
311                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
312      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 318  MainWindow::MainWindow() :
318          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
319      );      );
320      actionGroup->add(      actionGroup->add(
321          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
322          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
323      );      );
324    
# Line 225  MainWindow::MainWindow() : Line 341  MainWindow::MainWindow() :
341          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
342      );      );
343    
344        toggle_action =
345            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
346        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
347        actionGroup->add(
348            toggle_action,
349            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
350        );
351    
352    
353      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
354    
# Line 241  MainWindow::MainWindow() : Line 365  MainWindow::MainWindow() :
365    
366      // sample right-click popup actions      // sample right-click popup actions
367      actionGroup->add(      actionGroup->add(
368          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
369          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
370      );      );
371      actionGroup->add(      actionGroup->add(
# Line 253  MainWindow::MainWindow() : Line 377  MainWindow::MainWindow() :
377          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
378      );      );
379      actionGroup->add(      actionGroup->add(
380          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
381          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
382      );      );
383      actionGroup->add(      actionGroup->add(
384            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
385            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
386        );
387        actionGroup->add(
388          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
389          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
390      );      );
391      actionGroup->add(      actionGroup->add(
392            Gtk::Action::create("ReplaceSample",
393                                _("Replace Sample...")),
394            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
395        );
396        actionGroup->add(
397          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
398                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
399          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)
# Line 280  MainWindow::MainWindow() : Line 413  MainWindow::MainWindow() :
413          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
414      );      );
415      actionGroup->add(      actionGroup->add(
416          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
417          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
418      );      );
419    
# Line 303  MainWindow::MainWindow() : Line 436  MainWindow::MainWindow() :
436          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
437          "    </menu>"          "    </menu>"
438          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
439            "      <menuitem action='CopyDimRgn'/>"
440            "      <menuitem action='PasteDimRgn'/>"
441            "      <separator/>"
442            "      <menuitem action='SelectPrevRegion'/>"
443            "      <menuitem action='SelectNextRegion'/>"
444            "      <separator/>"
445            "      <menuitem action='SelectPrevDimension'/>"
446            "      <menuitem action='SelectNextDimension'/>"
447            "      <menuitem action='SelectPrevDimRgnZone'/>"
448            "      <menuitem action='SelectNextDimRgnZone'/>"
449            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
450            "      <menuitem action='SelectAddNextDimRgnZone'/>"
451            "      <separator/>"
452          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
453          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
454          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
# Line 312  MainWindow::MainWindow() : Line 458  MainWindow::MainWindow() :
458          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
459          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
460          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
461            "      <menuitem action='ReplaceSample' />"
462          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
463          "      <separator/>"          "      <separator/>"
464          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
465            "      <menuitem action='RemoveUnusedSamples'/>"
466          "    </menu>"          "    </menu>"
467          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
468          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 337  MainWindow::MainWindow() : Line 485  MainWindow::MainWindow() :
485          "    </menu>"          "    </menu>"
486          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
487          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
488            "      <menuitem action='AutoRestoreWinDim'/>"
489            "      <separator/>"
490            "      <menuitem action='RefreshAll'/>"
491          "    </menu>"          "    </menu>"
492          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
493          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 496  MainWindow::MainWindow() :
496          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
497          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
498          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
499            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
500            "      <menuitem action='SaveWithTemporaryFile'/>"
501          "    </menu>"          "    </menu>"
502          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
503          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 364  MainWindow::MainWindow() : Line 517  MainWindow::MainWindow() :
517          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
518          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
519          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
520            "    <menuitem action='ReplaceSample' />"
521          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
522          "    <separator/>"          "    <separator/>"
523          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
524            "    <menuitem action='RemoveUnusedSamples'/>"
525          "  </popup>"          "  </popup>"
526          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
527          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 411  MainWindow::MainWindow() : Line 566  MainWindow::MainWindow() :
566      }      }
567      {      {
568          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
569                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
570            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."));
571        }
572        {
573            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
574                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
575            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
576            // copy tooltip to popup menu
577            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
578                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
579            item2->set_tooltip_text(item->get_tooltip_text());
580        }
581        {
582            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
583                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
584            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
585        }
586        {
587            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
588                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
589            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
590        }
591        {
592            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
593              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
594          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
595      }      }
# Line 448  MainWindow::MainWindow() : Line 627  MainWindow::MainWindow() :
627      // Create the Tree model:      // Create the Tree model:
628      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
629      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
630      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
631        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
632      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
633          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
634      );      );
635    
636      // Add the TreeView's view columns:      // Add the TreeView's view columns:
637      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
638      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
639        m_TreeView.set_headers_visible(true);
640        
641        // establish drag&drop within the instrument tree view, allowing to reorder
642        // the sequence of instruments within the gig file
643        {
644            std::vector<Gtk::TargetEntry> drag_target_instrument;
645            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
646            m_TreeView.drag_source_set(drag_target_instrument);
647            m_TreeView.drag_dest_set(drag_target_instrument);
648            m_TreeView.signal_drag_begin().connect(
649                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
650            );
651            m_TreeView.signal_drag_data_get().connect(
652                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
653            );
654            m_TreeView.signal_drag_data_received().connect(
655                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
656            );
657        }
658    
659      // create samples treeview (including its data model)      // create samples treeview (including its data model)
660      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
661      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
662        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
663      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
664      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
665      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 503  MainWindow::MainWindow() : Line 703  MainWindow::MainWindow() :
703      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
704          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
705      );      );
706      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?      //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
707      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
708          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
709      );      );
# Line 540  MainWindow::MainWindow() : Line 740  MainWindow::MainWindow() :
740          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
741      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
742          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
743        m_RegionChooser.signal_instrument_changed().connect(
744            sigc::mem_fun(*this, &MainWindow::region_changed));
745      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
746          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
747      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 562  MainWindow::MainWindow() : Line 764  MainWindow::MainWindow() :
764          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
765      );      );
766    
767        dimreg_edit.signal_select_sample().connect(
768            sigc::mem_fun(*this, &MainWindow::select_sample)
769        );
770    
771      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
772          sigc::hide(          sigc::hide(
773              sigc::bind(              sigc::bind(
# Line 605  MainWindow::MainWindow() : Line 811  MainWindow::MainWindow() :
811    
812      // select 'Instruments' tab by default      // select 'Instruments' tab by default
813      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
814      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
815    
816        Gtk::Clipboard::get()->signal_owner_change().connect(
817            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
818        );
819        updateClipboardPasteAvailable();
820        updateClipboardCopyAvailable();
821  }  }
822    
823  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 631  void MainWindow::region_changed() Line 843  void MainWindow::region_changed()
843  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
844  {  {
845      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
846      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
847          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
848        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
849      if (it) {      if (it) {
850          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
851          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 675  void MainWindow::update_dimregs() Line 888  void MainWindow::update_dimregs()
888              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
889          }          }
890      }      }
891    
892        m_DimRegionChooser.setModifyAllRegions(all_regions);
893        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
894        m_DimRegionChooser.setModifyBothChannels(stereo);
895    
896        updateClipboardCopyAvailable();
897  }  }
898    
899  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 692  void MainWindow::dimreg_changed() Line 911  void MainWindow::dimreg_changed()
911  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
912  {  {
913      // select item in instrument menu      // select item in instrument menu
914      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
915      if (it) {      if (!rows.empty()) {
916          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
917          int index = path[0];          if (it) {
918          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
919              instrument_menu->get_children();              int index = path[0];
920          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
921                    instrument_menu->get_children();
922                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
923            }
924      }      }
925    
926      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 723  void Loader::progress_callback(float fra Line 945  void Loader::progress_callback(float fra
945      progress_dispatcher();      progress_dispatcher();
946  }  }
947    
948    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
949    // make sure stack is 16-byte aligned for SSE instructions
950    __attribute__((force_align_arg_pointer))
951    #endif
952  void Loader::thread_function()  void Loader::thread_function()
953  {  {
954      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
955               static_cast<void*>(Glib::Threads::Thread::self()));
956      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
957      try {      try {
958          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 747  void Loader::thread_function() Line 974  void Loader::thread_function()
974  }  }
975    
976  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
977      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
978  {  {
979  }  }
980    
# Line 758  void Loader::launch() Line 985  void Loader::launch()
985  #else  #else
986      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
987  #endif  #endif
988      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
989  }  }
990    
991  float Loader::get_progress()  float Loader::get_progress()
# Line 801  void Saver::progress_callback(float frac Line 1028  void Saver::progress_callback(float frac
1028      progress_dispatcher.emit();      progress_dispatcher.emit();
1029  }  }
1030    
1031    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1032    // make sure stack is 16-byte aligned for SSE instructions
1033    __attribute__((force_align_arg_pointer))
1034    #endif
1035  void Saver::thread_function()  void Saver::thread_function()
1036  {  {
1037      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1038               static_cast<void*>(Glib::Threads::Thread::self()));
1039      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1040      try {      try {
1041          gig::progress_t progress;          gig::progress_t progress;
# Line 812  void Saver::thread_function() Line 1044  void Saver::thread_function()
1044    
1045          // if no filename was provided, that means "save", if filename was provided means "save as"          // if no filename was provided, that means "save", if filename was provided means "save as"
1046          if (filename.empty()) {          if (filename.empty()) {
1047              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1048                    // save directly over the existing .gig file
1049                    // (requires less disk space than solution below
1050                    // but may be slower)
1051                    gig->Save(&progress);
1052                } else {
1053                    // save the file as separate temporary file first,
1054                    // then move the saved file over the old file
1055                    // (may result in performance speedup during save)
1056                    String tmpname = filename + ".TMP";
1057                    gig->Save(tmpname, &progress);
1058                    #if defined(WIN32)
1059                    if (!DeleteFile(filename.c_str())) {
1060                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1061                    }
1062                    #else // POSIX ...
1063                    if (unlink(filename.c_str())) {
1064                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1065                    }
1066                    #endif
1067                    if (rename(tmpname.c_str(), filename.c_str())) {
1068                        #if defined(WIN32)
1069                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1070                        #else
1071                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1072                        #endif
1073                    }
1074                }
1075          } else {          } else {
1076              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1077          }          }
# Line 840  void Saver::launch() Line 1099  void Saver::launch()
1099  #else  #else
1100      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1101  #endif  #endif
1102      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1103  }  }
1104    
1105  float Saver::get_progress()  float Saver::get_progress()
# Line 937  bool MainWindow::close_confirmation_dial Line 1196  bool MainWindow::close_confirmation_dial
1196      g_free(msg);      g_free(msg);
1197      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."));
1198      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1199      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1200      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);
1201      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1202      int response = dialog.run();      int response = dialog.run();
1203      dialog.hide();      dialog.hide();
1204    
1205        // user decided to exit app without saving
1206        if (response == Gtk::RESPONSE_NO) return true;
1207    
1208        // user cancelled dialog, thus don't close app
1209        if (response == Gtk::RESPONSE_CANCEL) return false;
1210    
1211      // TODO: the following return valid is disabled and hard coded instead for      // TODO: the following return valid is disabled and hard coded instead for
1212      // now, due to the fact that saving with progress bar is now implemented      // now, due to the fact that saving with progress bar is now implemented
1213      // asynchronously, as a result the app does not close automatically anymore      // asynchronously, as a result the app does not close automatically anymore
# Line 963  bool MainWindow::leaving_shared_mode_dia Line 1228  bool MainWindow::leaving_shared_mode_dia
1228            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1229            "load it."));            "load it."));
1230      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1231      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1232      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1233      int response = dialog.run();      int response = dialog.run();
1234      dialog.hide();      dialog.hide();
# Line 977  void MainWindow::on_action_file_open() Line 1242  void MainWindow::on_action_file_open()
1242      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1243    
1244      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1245      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1246      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1247      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1248  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1249      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 994  void MainWindow::on_action_file_open() Line 1259  void MainWindow::on_action_file_open()
1259      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1260          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1261          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1262          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1263                   static_cast<void*>(Glib::Threads::Thread::self()));
1264          load_file(filename.c_str());          load_file(filename.c_str());
1265          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1266      }      }
# Line 1064  void MainWindow::on_loader_progress() Line 1330  void MainWindow::on_loader_progress()
1330  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1331  {  {
1332      printf("Loader finished!\n");      printf("Loader finished!\n");
1333      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1334               static_cast<void*>(Glib::Threads::Thread::self()));
1335      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1336      progress_dialog->hide();      progress_dialog->hide();
1337  }  }
# Line 1159  void MainWindow::on_saver_finished() Line 1426  void MainWindow::on_saver_finished()
1426    
1427      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1428    
1429      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1430      progress_dialog->hide();      progress_dialog->hide();
1431  }  }
1432    
# Line 1171  void MainWindow::on_action_file_save_as( Line 1438  void MainWindow::on_action_file_save_as(
1438    
1439  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1440  {  {
1441      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1442      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1443      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1444      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1445      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1446    
# Line 1204  bool MainWindow::file_save_as() Line 1471  bool MainWindow::file_save_as()
1471      // show warning in the dialog      // show warning in the dialog
1472      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1473      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1474      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1475        warningIcon.set_from_icon_name("dialog-warning",
1476                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1477      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1478  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1479      view::WrapLabel description;      view::WrapLabel description;
# Line 1256  bool MainWindow::file_save_as() Line 1525  bool MainWindow::file_save_as()
1525  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1526      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1527      Glib::ustring error_files;      Glib::ustring error_files;
1528      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1529      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1530           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1531          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1532          SF_INFO info;          SF_INFO info;
1533          info.format = 0;          info.format = 0;
1534          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);
1535          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1536          try {          try {
1537              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1285  void MainWindow::__import_queued_samples Line 1554  void MainWindow::__import_queued_samples
1554                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1555              }              }
1556    
1557                // reset write position for sample
1558                iter->first->SetPos(0);
1559    
1560              const int bufsize = 10000;              const int bufsize = 10000;
1561              switch (bitdepth) {              switch (bitdepth) {
1562                  case 16: {                  case 16: {
# Line 1294  void MainWindow::__import_queued_samples Line 1566  void MainWindow::__import_queued_samples
1566                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1567                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1568                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1569                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1570                          cnt -= n;                          cnt -= n;
1571                      }                      }
1572                      delete[] buffer;                      delete[] buffer;
# Line 1314  void MainWindow::__import_queued_samples Line 1586  void MainWindow::__import_queued_samples
1586                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1587                          }                          }
1588                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1589                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1590                          cnt -= n;                          cnt -= n;
1591                      }                      }
1592                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1325  void MainWindow::__import_queued_samples Line 1597  void MainWindow::__import_queued_samples
1597              // cleanup              // cleanup
1598              sf_close(hFile);              sf_close(hFile);
1599              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1600              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1601              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1602              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1603              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1604              ++iter;              ++iter;
1605              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1606          } catch (std::string what) {          } catch (std::string what) {
1607              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1608              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1609              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1610              ++iter;              ++iter;
1611          }          }
1612      }      }
# Line 1362  void MainWindow::on_action_sync_sampler_ Line 1634  void MainWindow::on_action_sync_sampler_
1634          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1635  }  }
1636    
1637    void MainWindow::on_action_move_root_note_with_region_moved() {
1638        Settings::singleton()->moveRootNoteWithRegionMoved =
1639            !Settings::singleton()->moveRootNoteWithRegionMoved;
1640    }
1641    
1642  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1643  {  {
1644      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1371  void MainWindow::on_action_help_about() Line 1648  void MainWindow::on_action_help_about()
1648      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1649  #endif  #endif
1650      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1651      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1652      const std::string sComment =      const std::string sComment =
1653          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1654          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1408  PropDialog::PropDialog() Line 1685  PropDialog::PropDialog()
1685        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1686        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1687        eSubject(_("Subject")),        eSubject(_("Subject")),
1688        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1689        table(2, 1),        table(2, 1),
1690        m_file(NULL)        m_file(NULL)
1691  {  {
# Line 1531  void InstrumentProps::set_MIDIProgram(ui Line 1808  void InstrumentProps::set_MIDIProgram(ui
1808  }  }
1809    
1810  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1811      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1812      table(2,1),      table(2,1),
1813      eName(_("Name")),      eName(_("Name")),
1814      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1654  void MainWindow::load_gig(gig::File* gig Line 1931  void MainWindow::load_gig(gig::File* gig
1931      file = 0;      file = 0;
1932      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1933    
1934      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1935            (filename && strlen(filename) > 0) ?
1936                filename : (!gig->GetFileName().empty()) ?
1937                    gig->GetFileName() : _("Unsaved Gig File");
1938      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1939      file_has_name = filename;      file_has_name = filename;
1940      file_is_changed = false;      file_is_changed = false;
# Line 1663  void MainWindow::load_gig(gig::File* gig Line 1943  void MainWindow::load_gig(gig::File* gig
1943      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1944    
1945      instrument_name_connection.block();      instrument_name_connection.block();
1946        int index = 0;
1947      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1948           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1949          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1950    
1951          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1952          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1953            row[m_Columns.m_col_nr] = index;
1954          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1955          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1956    
# Line 1741  bool MainWindow::instr_props_set_instrum Line 2023  bool MainWindow::instr_props_set_instrum
2023  {  {
2024      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2025    
2026      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2027          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2028            instrumentProps.hide();
2029            return false;
2030        }
2031        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2032      if (it) {      if (it) {
2033          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2034          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1795  void MainWindow::show_midi_rules() Line 2081  void MainWindow::show_midi_rules()
2081  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2082      if (!file) return;      if (!file) return;
2083      // get selected instrument      // get selected instrument
2084      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2085      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2086        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2087      if (!it) return;      if (!it) return;
2088      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2089      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1808  void MainWindow::show_script_slots() { Line 2095  void MainWindow::show_script_slots() {
2095      window->show();      window->show();
2096  }  }
2097    
2098    void MainWindow::on_action_refresh_all() {
2099        __refreshEntireGUI();
2100    }
2101    
2102  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
2103      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2104          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1819  void MainWindow::on_action_view_status_b Line 2110  void MainWindow::on_action_view_status_b
2110      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2111  }  }
2112    
2113    void MainWindow::on_auto_restore_win_dim() {
2114        Gtk::CheckMenuItem* item =
2115            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2116        if (!item) {
2117            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2118            return;
2119        }
2120        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2121    }
2122    
2123    void MainWindow::on_save_with_temporary_file() {
2124        Gtk::CheckMenuItem* item =
2125            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2126        if (!item) {
2127            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2128            return;
2129        }
2130        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2131    }
2132    
2133  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2134      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2135          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1883  void MainWindow::on_instrument_selection Line 2194  void MainWindow::on_instrument_selection
2194      }      }
2195  }  }
2196    
2197    void MainWindow::select_instrument(gig::Instrument* instrument) {
2198        if (!instrument) return;
2199    
2200        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2201        for (int i = 0; i < model->children().size(); ++i) {
2202            Gtk::TreeModel::Row row = model->children()[i];
2203            if (row[m_Columns.m_col_instr] == instrument) {
2204                // select and show the respective instrument in the list view
2205                show_intruments_tab();
2206                m_TreeView.get_selection()->unselect_all();
2207                m_TreeView.get_selection()->select(model->children()[i]);
2208                std::vector<Gtk::TreeModel::Path> rows =
2209                    m_TreeView.get_selection()->get_selected_rows();
2210                if (!rows.empty())
2211                    m_TreeView.scroll_to_row(rows[0]);
2212                on_sel_change(); // the regular instrument selection change callback
2213            }
2214        }
2215    }
2216    
2217    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2218    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2219        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2220        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2221    
2222        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2223        for (int i = 0; i < model->children().size(); ++i) {
2224            Gtk::TreeModel::Row row = model->children()[i];
2225            if (row[m_Columns.m_col_instr] == pInstrument) {
2226                // select and show the respective instrument in the list view
2227                show_intruments_tab();
2228                m_TreeView.get_selection()->unselect_all();
2229                m_TreeView.get_selection()->select(model->children()[i]);
2230                std::vector<Gtk::TreeModel::Path> rows =
2231                    m_TreeView.get_selection()->get_selected_rows();
2232                if (!rows.empty())
2233                    m_TreeView.scroll_to_row(rows[0]);
2234                on_sel_change(); // the regular instrument selection change callback
2235    
2236                // select respective region in the region selector
2237                m_RegionChooser.set_region(pRegion);
2238    
2239                // select and show the respective dimension region in the editor
2240                //update_dimregs();
2241                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2242                //dimreg_edit.set_dim_region(dimRgn);
2243    
2244                return true;
2245            }
2246        }
2247    
2248        return false;
2249    }
2250    
2251    void MainWindow::select_sample(gig::Sample* sample) {
2252        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2253        for (int g = 0; g < model->children().size(); ++g) {
2254            Gtk::TreeModel::Row rowGroup = model->children()[g];
2255            for (int s = 0; s < rowGroup.children().size(); ++s) {
2256                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2257                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2258                    show_samples_tab();
2259                    m_TreeViewSamples.get_selection()->unselect_all();
2260                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2261                    std::vector<Gtk::TreeModel::Path> rows =
2262                        m_TreeViewSamples.get_selection()->get_selected_rows();
2263                    if (rows.empty()) return;
2264                    m_TreeViewSamples.scroll_to_row(rows[0]);
2265                    return;
2266                }
2267            }
2268        }
2269    }
2270    
2271  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2272      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2273            // by default if Ctrl keys is pressed down, then a mouse right-click
2274            // does not select the respective row, so we must assure this
2275            // programmatically ...
2276            /*{
2277                Gtk::TreeModel::Path path;
2278                Gtk::TreeViewColumn* pColumn = NULL;
2279                int cellX, cellY;
2280                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2281                    (int)button->x, (int)button->y,
2282                    path, pColumn, cellX, cellY
2283                );
2284                if (bSuccess) {
2285                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2286                        printf("not selected !!!\n");
2287                        m_TreeViewSamples.get_selection()->select(path);
2288                    }
2289                }
2290            }*/
2291    
2292          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2293              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2294          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2295          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2296          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2297          bool group_selected  = false;          const int n = rows.size();
2298          bool sample_selected = false;          int nGroups  = 0;
2299          if (it) {          int nSamples = 0;
2300            for (int r = 0; r < n; ++r) {
2301                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2302                if (!it) continue;
2303              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2304              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2305              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2306          }          }
2307            
               
2308          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2309              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2310          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2311              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2312          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2313              set_sensitive(file);              set_sensitive(file);
2314          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2315              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2316          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2317              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2318          // show sample popup          // show sample popup
2319          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2320    
2321          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2322              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2323          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2324              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2325          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2326              set_sensitive(file);              set_sensitive(file);
2327          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2328              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2329          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2330              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2331      }      }
2332  }  }
2333    
# Line 2000  void MainWindow::add_instrument(gig::Ins Line 2406  void MainWindow::add_instrument(gig::Ins
2406      instrument_name_connection.block();      instrument_name_connection.block();
2407      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2408      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2409        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2410      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2411      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2412      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2028  void MainWindow::on_action_duplicate_ins Line 2435  void MainWindow::on_action_duplicate_ins
2435      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2436      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2437      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2438      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2439      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2440      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2441      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2442      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2443                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2444      // duplicate the orginal instrument              if (instrOrig) {
2445      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2446      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2447          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2448          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2449                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2450    
2451      add_instrument(instrNew);                  add_instrument(instrNew);
2452                }
2453            }
2454        }
2455  }  }
2456    
2457  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2057  void MainWindow::on_action_remove_instru Line 2468  void MainWindow::on_action_remove_instru
2468      }      }
2469    
2470      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2471      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2472      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2473            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2474            if (!it) continue;
2475          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2476          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2477          try {          try {
# Line 2073  void MainWindow::on_action_remove_instru Line 2486  void MainWindow::on_action_remove_instru
2486    
2487              // remove row from instruments tree view              // remove row from instruments tree view
2488              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2489                // update "Nr" column of all instrument rows
2490                {
2491                    int index = 0;
2492                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2493                         it != m_refTreeModel->children().end(); ++it, ++index)
2494                    {
2495                        Gtk::TreeModel::Row row = *it;
2496                        row[m_Columns.m_col_nr] = index;
2497                    }
2498                }
2499    
2500  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2501              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2170  void MainWindow::on_action_edit_script() Line 2593  void MainWindow::on_action_edit_script()
2593      if (!script) return;      if (!script) return;
2594    
2595      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2596        editor->signal_script_to_be_changed.connect(
2597            signal_script_to_be_changed.make_slot()
2598        );
2599        editor->signal_script_changed.connect(
2600            signal_script_changed.make_slot()
2601        );
2602      editor->setScript(script);      editor->setScript(script);
2603      //editor->reparent(*this);      //editor->reparent(*this);
2604      editor->show();      editor->show();
# Line 2235  void MainWindow::on_action_add_group() { Line 2664  void MainWindow::on_action_add_group() {
2664      file_changed();      file_changed();
2665  }  }
2666    
2667    void MainWindow::on_action_replace_sample() {
2668        add_or_replace_sample(true);
2669    }
2670    
2671  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2672        add_or_replace_sample(false);
2673    }
2674    
2675    void MainWindow::add_or_replace_sample(bool replace) {
2676      if (!file) return;      if (!file) return;
2677      // get selected group  
2678        // get selected group (and probably selected sample)
2679      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2680      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2681        if (rows.empty()) return;
2682        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2683      if (!it) return;      if (!it) return;
2684      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2685        gig::Sample* sample = NULL;
2686      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2687      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2688          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2689          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2690          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2691          if (!it) return;          if (!it) return;
2692          row = *it;          if (!replace) row = *it;
2693          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2694          if (!group) return;          if (!group) return;
2695      }      }
2696        if (replace && !sample) return;
2697    
2698      // show 'browse for file' dialog      // show 'browse for file' dialog
2699      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2700      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2701      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2702      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2703    
2704      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2705  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 2327  void MainWindow::on_action_add_sample() Line 2770  void MainWindow::on_action_add_sample()
2770                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2771                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2772                  }                  }
2773                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2774                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2775                  // file name without path                  // file name without path
2776                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2777                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2379  void MainWindow::on_action_add_sample() Line 2822  void MainWindow::on_action_add_sample()
2822                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2823                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2824                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2825                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2826                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2827                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2828                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2829                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2830                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2831                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2832                  // add sample to the tree view                  // add sample to the tree view
2833                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2834                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2835                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2836                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2837                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2838                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2839                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2840                            gig_to_utf8(sample->pInfo->Name);
2841                        rowSample[m_SamplesModel.m_col_sample] = sample;
2842                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2843                    }
2844                  // close sound file                  // close sound file
2845                  sf_close(hFile);                  sf_close(hFile);
2846                  file_changed();                  file_changed();
# Line 2404  void MainWindow::on_action_add_sample() Line 2851  void MainWindow::on_action_add_sample()
2851          }          }
2852          // 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
2853          if (!error_files.empty()) {          if (!error_files.empty()) {
2854              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2855                    (replace
2856                        ? _("Failed to replace sample with:\n")
2857                        : _("Could not add the following sample(s):\n"))
2858                    + error_files;
2859              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2860              msg.run();              msg.run();
2861          }          }
# Line 2447  void MainWindow::on_action_replace_all_s Line 2898  void MainWindow::on_action_replace_all_s
2898      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2899      description.show();      description.show();
2900      entryArea.show_all();      entryArea.show_all();
2901      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2902      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2903      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2904      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2471  void MainWindow::on_action_replace_all_s Line 2922  void MainWindow::on_action_replace_all_s
2922              try              try
2923              {              {
2924                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2925                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2926                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2927                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2928                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2929                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2930                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2931                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2932                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2933                          break;                          break;
2934                      default:                      default:
2935                          sf_close(hFile);                          sf_close(hFile);
# Line 2491  void MainWindow::on_action_replace_all_s Line 2938  void MainWindow::on_action_replace_all_s
2938                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2939                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2940                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
2941                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2942                  sf_close(hFile);                  sf_close(hFile);
2943                  file_changed();                  file_changed();
2944              }              }
# Line 2515  void MainWindow::on_action_replace_all_s Line 2962  void MainWindow::on_action_replace_all_s
2962  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2963      if (!file) return;      if (!file) return;
2964      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2965      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2966      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2967            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2968            if (!it) continue;
2969          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2970          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2971          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2541  void MainWindow::on_action_remove_sample Line 2990  void MainWindow::on_action_remove_sample
2990                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
2991                  // them from the import queue                  // them from the import queue
2992                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
2993                       member != members.end(); ++member) {                       member != members.end(); ++member)
2994                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
2995                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
2996                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
2997                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
2998                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
2999                      }                      }
3000                  }                  }
3001                  file_changed();                  file_changed();
# Line 2564  void MainWindow::on_action_remove_sample Line 3010  void MainWindow::on_action_remove_sample
3010                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3011                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3012                  // the import queue                  // the import queue
3013                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3014                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3015                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3016                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3017                  }                  }
3018                  dimreg_changed();                  dimreg_changed();
3019                  file_changed();                  file_changed();
# Line 2588  void MainWindow::on_action_remove_sample Line 3030  void MainWindow::on_action_remove_sample
3030      }      }
3031  }  }
3032    
3033    void MainWindow::on_action_remove_unused_samples() {
3034        if (!file) return;
3035    
3036        // collect all samples that are not referenced by any instrument
3037        std::list<gig::Sample*> lsamples;
3038        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
3039            gig::Sample* sample = file->GetSample(iSample);
3040            bool isUsed = false;
3041            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
3042                                  instrument = file->GetNextInstrument())
3043            {
3044                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
3045                                  rgn = instrument->GetNextRegion())
3046                {
3047                    for (int i = 0; i < 256; ++i) {
3048                        if (!rgn->pDimensionRegions[i]) continue;
3049                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
3050                        isUsed = true;
3051                        goto endOfRefSearch;
3052                    }
3053                }
3054            }
3055            endOfRefSearch:
3056            if (!isUsed) lsamples.push_back(sample);
3057        }
3058    
3059        if (lsamples.empty()) return;
3060    
3061        // notify everybody that we're going to remove these samples
3062        samples_to_be_removed_signal.emit(lsamples);
3063    
3064        // remove collected samples
3065        try {
3066            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
3067                 itSample != lsamples.end(); ++itSample)
3068            {
3069                gig::Sample* sample = *itSample;
3070                // remove sample from the .gig file
3071                file->DeleteSample(sample);
3072                // if sample was just previously added, remove it from the import queue
3073                if (m_SampleImportQueue.count(sample)) {
3074                    printf("Removing previously added sample '%s'\n",
3075                           m_SampleImportQueue[sample].sample_path.c_str());
3076                    m_SampleImportQueue.erase(sample);
3077                }
3078            }
3079        } catch (RIFF::Exception e) {
3080            // show error message
3081            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3082            msg.run();
3083        }
3084    
3085        // notify everybody that we're done with removal
3086        samples_removed_signal.emit();
3087    
3088        dimreg_changed();
3089        file_changed();
3090        __refreshEntireGUI();
3091    }
3092    
3093  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
3094  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3095  {  {
# Line 2614  void MainWindow::on_scripts_treeview_dra Line 3116  void MainWindow::on_scripts_treeview_dra
3116                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
3117  }  }
3118    
3119    // see comment on on_sample_treeview_drag_begin()
3120    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3121    {
3122        first_call_to_drag_data_get = true;
3123    }
3124    
3125    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
3126                                                           Gtk::SelectionData& selection_data, guint, guint)
3127    {
3128        if (!first_call_to_drag_data_get) return;
3129        first_call_to_drag_data_get = false;
3130    
3131        // get selected source instrument
3132        gig::Instrument* src = NULL;
3133        {
3134            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3135            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3136            if (!rows.empty()) {
3137                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3138                if (it) {
3139                    Gtk::TreeModel::Row row = *it;
3140                    src = row[m_Columns.m_col_instr];
3141                }
3142            }
3143        }
3144        if (!src) return;
3145    
3146        // pass the source gig::Instrument as pointer
3147        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
3148                           sizeof(src)/*length of data in bytes*/);
3149    }
3150    
3151    void MainWindow::on_instruments_treeview_drop_drag_data_received(
3152        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
3153        const Gtk::SelectionData& selection_data, guint, guint time)
3154    {
3155        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
3156        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
3157            return;
3158    
3159        gig::Instrument* dst = NULL;
3160        {
3161            Gtk::TreeModel::Path path;
3162            const bool found = m_TreeView.get_path_at_pos(x, y, path);
3163            if (!found) return;
3164    
3165            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
3166            if (!iter) return;
3167            Gtk::TreeModel::Row row = *iter;
3168            dst = row[m_Columns.m_col_instr];
3169        }
3170        if (!dst) return;
3171    
3172        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
3173        src->MoveTo(dst);
3174        __refreshEntireGUI();
3175        select_instrument(src);
3176    }
3177    
3178  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
3179  // 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
3180  // 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 2632  void MainWindow::on_sample_treeview_drag Line 3193  void MainWindow::on_sample_treeview_drag
3193      // get selected sample      // get selected sample
3194      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3195      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3196      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3197      if (it) {      if (!rows.empty()) {
3198          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3199          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3200                Gtk::TreeModel::Row row = *it;
3201                sample = row[m_SamplesModel.m_col_sample];
3202            }
3203      }      }
3204      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3205      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 2775  void MainWindow::script_double_clicked(c Line 3339  void MainWindow::script_double_clicked(c
3339      if (!script) return;      if (!script) return;
3340    
3341      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3342        editor->signal_script_to_be_changed.connect(
3343            signal_script_to_be_changed.make_slot()
3344        );
3345        editor->signal_script_changed.connect(
3346            signal_script_changed.make_slot()
3347        );
3348      editor->setScript(script);      editor->setScript(script);
3349      //editor->reparent(*this);      //editor->reparent(*this);
3350      editor->show();      editor->show();
# Line 2828  void MainWindow::on_action_combine_instr Line 3398  void MainWindow::on_action_combine_instr
3398    
3399  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3400      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3401      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3402        if (rows.empty()) return;
3403        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3404      if (!it) return;      if (!it) return;
3405      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3406      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2836  void MainWindow::on_action_view_referenc Line 3408  void MainWindow::on_action_view_referenc
3408    
3409      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3410      d->setSample(sample);      d->setSample(sample);
3411        d->dimension_region_selected.connect(
3412            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3413        );
3414      d->show_all();      d->show_all();
3415      d->resize(500, 400);      d->resize(500, 400);
3416      d->run();      d->run();
# Line 2947  void MainWindow::on_action_merge_files() Line 3522  void MainWindow::on_action_merge_files()
3522      }      }
3523    
3524      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3525      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3526      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3527      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3528  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 2966  void MainWindow::on_action_merge_files() Line 3541  void MainWindow::on_action_merge_files()
3541      // show warning in the file picker dialog      // show warning in the file picker dialog
3542      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3543      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3544      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3545        warningIcon.set_from_icon_name("dialog-warning",
3546                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3547      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3548  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3549      view::WrapLabel description;      view::WrapLabel description;
# Line 2989  void MainWindow::on_action_merge_files() Line 3566  void MainWindow::on_action_merge_files()
3566      descriptionArea.show_all();      descriptionArea.show_all();
3567    
3568      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3569          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3570                   static_cast<void*>(Glib::Threads::Thread::self()));
3571          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3572    
3573          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3001  void MainWindow::on_action_merge_files() Line 3579  void MainWindow::on_action_merge_files()
3579          }          }
3580    
3581          // update GUI          // update GUI
3582          __refreshEntireGUI();                  __refreshEntireGUI();
3583      }      }
3584  }  }
3585    
# Line 3071  void MainWindow::show_scripts_tab() { Line 3649  void MainWindow::show_scripts_tab() {
3649      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3650  }  }
3651    
3652    void MainWindow::select_prev_region() {
3653        m_RegionChooser.select_prev_region();
3654    }
3655    
3656    void MainWindow::select_next_region() {
3657        m_RegionChooser.select_next_region();
3658    }
3659    
3660    void MainWindow::select_next_dim_rgn_zone() {
3661        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3662        m_DimRegionChooser.select_next_dimzone();
3663    }
3664    
3665    void MainWindow::select_prev_dim_rgn_zone() {
3666        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3667        m_DimRegionChooser.select_prev_dimzone();
3668    }
3669    
3670    void MainWindow::select_add_next_dim_rgn_zone() {
3671        m_DimRegionChooser.select_next_dimzone(true);
3672    }
3673    
3674    void MainWindow::select_add_prev_dim_rgn_zone() {
3675        m_DimRegionChooser.select_prev_dimzone(true);
3676    }
3677    
3678    void MainWindow::select_prev_dimension() {
3679        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3680        m_DimRegionChooser.select_prev_dimension();
3681    }
3682    
3683    void MainWindow::select_next_dimension() {
3684        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3685        m_DimRegionChooser.select_next_dimension();
3686    }
3687    
3688    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3689        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3690    
3691    void MainWindow::copy_selected_dimrgn() {
3692        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3693        if (!pDimRgn) {
3694            updateClipboardPasteAvailable();
3695            updateClipboardCopyAvailable();
3696            return;
3697        }
3698    
3699        std::vector<Gtk::TargetEntry> targets;
3700        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3701    
3702        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3703        clipboard->set(
3704            targets,
3705            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3706            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3707        );
3708    
3709        m_serializationArchive.serialize(pDimRgn);
3710    
3711        updateClipboardPasteAvailable();
3712    }
3713    
3714    void MainWindow::paste_copied_dimrgn() {
3715        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3716        clipboard->request_contents(
3717            CLIPBOARD_DIMENSIONREGION_TARGET,
3718            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3719        );
3720        updateClipboardPasteAvailable();
3721    }
3722    
3723    void MainWindow::updateClipboardPasteAvailable() {
3724        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3725        clipboard->request_targets(
3726            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3727        );
3728    }
3729    
3730    void MainWindow::updateClipboardCopyAvailable() {
3731        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3732        static_cast<Gtk::MenuItem*>(
3733            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3734        )->set_sensitive(bDimensionRegionCopyIsPossible);
3735    }
3736    
3737    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3738        updateClipboardPasteAvailable();
3739    }
3740    
3741    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3742        const std::string target = selection_data.get_target();
3743        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3744            selection_data.set(
3745                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3746                &m_serializationArchive.rawData()[0],
3747                m_serializationArchive.rawData().size()
3748            );
3749        } else {
3750            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3751        }
3752    }
3753    
3754    void MainWindow::on_clipboard_clear() {
3755        m_serializationArchive.clear();
3756        updateClipboardPasteAvailable();
3757        updateClipboardCopyAvailable();
3758    }
3759    
3760    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3761        const std::string target = selection_data.get_target();
3762        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3763            gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3764            if (!pDimRgn) return;
3765    
3766            Glib::ustring errorText;
3767            try {
3768                m_serializationArchive.decode(
3769                    selection_data.get_data(), selection_data.get_length()
3770                );
3771    
3772                for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3773                     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3774                {
3775                    gig::DimensionRegion* pDimRgn = *itDimReg;
3776    
3777                    dimreg_to_be_changed_signal.emit(pDimRgn);
3778    
3779                    m_serializationArchive.deserialize(pDimRgn);
3780    
3781                    dimreg_changed_signal.emit(pDimRgn);
3782                }
3783    
3784                //region_changed()
3785                file_changed();
3786                dimreg_changed();
3787    
3788            } catch (Serialization::Exception e) {
3789                errorText = e.Message;
3790            } catch (...) {
3791                errorText = _("Unknown exception during deserialization decoding");
3792            }
3793            if (!errorText.empty()) {
3794                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3795                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3796                msg.run();
3797            }
3798        }
3799    }
3800    
3801    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3802        const bool bDimensionRegionPasteIsPossible =
3803            std::find(targets.begin(), targets.end(),
3804                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3805    
3806        static_cast<Gtk::MenuItem*>(
3807            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3808        )->set_sensitive(bDimensionRegionPasteIsPossible);
3809    }
3810    
3811  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3812      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3813  }  }

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

  ViewVC Help
Powered by ViewVC