/[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 2683 by schoenebeck, Mon Dec 29 16:30:21 2014 UTC revision 3106 by schoenebeck, Sat Feb 11 17:04:48 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 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        labelNoSample(_(" No Sample")),
69        labelMissingSample(_(" Missing some Sample(s)")),
70        labelLooped(_(" Looped")),
71        labelSomeLoops(_(" Some Loop(s)"))
72  {  {
73        loadBuiltInPix();
74    
75  //    set_border_width(5);  //    set_border_width(5);
76  //    set_default_size(400, 200);  //    set_default_size(400, 200);
77    
   
78      add(m_VBox);      add(m_VBox);
79    
80      // Handle selection      // Handle selection
# Line 96  MainWindow::MainWindow() : Line 108  MainWindow::MainWindow() :
108      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
109      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
110      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
111        {
112            imageNoSample.set(redDot);
113            imageNoSample.set_alignment(Gtk::ALIGN_RIGHT);
114            labelNoSample.set_alignment(Gtk::ALIGN_LEFT);
115            legend_hbox.add(imageNoSample);
116            legend_hbox.add(labelNoSample);
117    
118            imageMissingSample.set(yellowDot);
119            imageMissingSample.set_alignment(Gtk::ALIGN_RIGHT);
120            labelMissingSample.set_alignment(Gtk::ALIGN_LEFT);
121            legend_hbox.add(imageMissingSample);
122            legend_hbox.add(labelMissingSample);
123    
124            imageLooped.set(blackLoop);
125            imageLooped.set_alignment(Gtk::ALIGN_RIGHT);
126            labelLooped.set_alignment(Gtk::ALIGN_LEFT);
127            legend_hbox.add(imageLooped);
128            legend_hbox.add(labelLooped);
129    
130            imageSomeLoops.set(grayLoop);
131            imageSomeLoops.set_alignment(Gtk::ALIGN_RIGHT);
132            labelSomeLoops.set_alignment(Gtk::ALIGN_LEFT);
133            legend_hbox.add(imageSomeLoops);
134            legend_hbox.add(labelSomeLoops);
135    
136            legend_hbox.show_all_children();
137        }
138        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
139      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
140    
141      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 150  MainWindow::MainWindow() :
150      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
151    
152      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
153      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
154                         Gtk::AccelKey("<control>n"),
155                       sigc::mem_fun(                       sigc::mem_fun(
156                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
157      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
158          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
159                       sigc::mem_fun(                       sigc::mem_fun(
160                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
161      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
162                         Gtk::AccelKey("<control>s"),
163                       sigc::mem_fun(                       sigc::mem_fun(
164                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
165      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,  
166                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
167                       sigc::mem_fun(                       sigc::mem_fun(
168                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
169      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
170                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
171                       sigc::mem_fun(                       sigc::mem_fun(
172                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
173      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
174                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
175                       sigc::mem_fun(                       sigc::mem_fun(
176                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
177      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 144  MainWindow::MainWindow() : Line 182  MainWindow::MainWindow() :
182                                           _("_Script Slots...")),                                           _("_Script Slots...")),
183                       sigc::mem_fun(                       sigc::mem_fun(
184                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
185      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
186                         Gtk::AccelKey("<control>q"),
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
189      actionGroup->add(      actionGroup->add(
# Line 187  MainWindow::MainWindow() : Line 226  MainWindow::MainWindow() :
226                       sigc::mem_fun(                       sigc::mem_fun(
227                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
228    
229      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      toggle_action =
230      actionGroup->add(Gtk::Action::create("MenuHelp",          Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
231                                           action->property_label()));      toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
232      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(toggle_action,
233                         sigc::mem_fun(
234                             *this, &MainWindow::on_auto_restore_win_dim));
235    
236        toggle_action =
237            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
238        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
239        actionGroup->add(toggle_action,
240                         sigc::mem_fun(
241                             *this, &MainWindow::on_save_with_temporary_file));
242    
243        actionGroup->add(
244            Gtk::Action::create("RefreshAll", _("_Refresh All")),
245            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
246        );                
247    
248        actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
249        actionGroup->add(Gtk::Action::create("About", _("_About")),
250                       sigc::mem_fun(                       sigc::mem_fun(
251                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
252      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 258  MainWindow::MainWindow() :
258          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
259      );      );
260      actionGroup->add(      actionGroup->add(
261          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
262          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
263      );      );
264    
# Line 217  MainWindow::MainWindow() : Line 273  MainWindow::MainWindow() :
273          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
274      );      );
275    
276        toggle_action =
277            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
278        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
279        actionGroup->add(
280            toggle_action,
281            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
282        );
283    
284        toggle_action =
285            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
286        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
287        actionGroup->add(
288            toggle_action,
289            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
290        );
291    
292    
293      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
294    
# Line 233  MainWindow::MainWindow() : Line 305  MainWindow::MainWindow() :
305    
306      // sample right-click popup actions      // sample right-click popup actions
307      actionGroup->add(      actionGroup->add(
308          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
309          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
310      );      );
311      actionGroup->add(      actionGroup->add(
# Line 245  MainWindow::MainWindow() : Line 317  MainWindow::MainWindow() :
317          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
318      );      );
319      actionGroup->add(      actionGroup->add(
320          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
321          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
322      );      );
323      actionGroup->add(      actionGroup->add(
324            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
325            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
326        );
327        actionGroup->add(
328          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
329          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
330      );      );
331      actionGroup->add(      actionGroup->add(
332            Gtk::Action::create("ReplaceSample",
333                                _("Replace Sample...")),
334            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
335        );
336        actionGroup->add(
337          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
338                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
339          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 272  MainWindow::MainWindow() : Line 353  MainWindow::MainWindow() :
353          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
354      );      );
355      actionGroup->add(      actionGroup->add(
356          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
357          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
358      );      );
359    
# Line 304  MainWindow::MainWindow() : Line 385  MainWindow::MainWindow() :
385          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
386          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
387          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
388            "      <menuitem action='ReplaceSample' />"
389          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
390          "      <separator/>"          "      <separator/>"
391          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
392            "      <menuitem action='RemoveUnusedSamples'/>"
393          "    </menu>"          "    </menu>"
394          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
395          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 329  MainWindow::MainWindow() : Line 412  MainWindow::MainWindow() :
412          "    </menu>"          "    </menu>"
413          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
414          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
415            "      <menuitem action='AutoRestoreWinDim'/>"
416            "      <separator/>"
417            "      <menuitem action='RefreshAll'/>"
418          "    </menu>"          "    </menu>"
419          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
420          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 336  MainWindow::MainWindow() : Line 422  MainWindow::MainWindow() :
422          "    </menu>"          "    </menu>"
423          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
424          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
425            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
426            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
427            "      <menuitem action='SaveWithTemporaryFile'/>"
428          "    </menu>"          "    </menu>"
429          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
430          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 355  MainWindow::MainWindow() : Line 444  MainWindow::MainWindow() :
444          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
445          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
446          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
447            "    <menuitem action='ReplaceSample' />"
448          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
449          "    <separator/>"          "    <separator/>"
450          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
451            "    <menuitem action='RemoveUnusedSamples'/>"
452          "  </popup>"          "  </popup>"
453          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
454          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 397  MainWindow::MainWindow() : Line 488  MainWindow::MainWindow() :
488      }      }
489      {      {
490          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
491                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
492            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
493        }
494        {
495            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
496                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
497            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."));
498        }
499        {
500            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
501                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
502            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
503            // copy tooltip to popup menu
504            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
505                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
506            item2->set_tooltip_text(item->get_tooltip_text());
507        }
508        {
509            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
510                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
511            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
512        }
513        {
514            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
515                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
516            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
517        }
518        {
519            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
520              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
521          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."));
522      }      }
# Line 434  MainWindow::MainWindow() : Line 554  MainWindow::MainWindow() :
554      // Create the Tree model:      // Create the Tree model:
555      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
556      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
557      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
558        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
559      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
560          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
561      );      );
562    
563      // Add the TreeView's view columns:      // Add the TreeView's view columns:
564      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
565      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
566        m_TreeView.set_headers_visible(true);
567        
568        // establish drag&drop within the instrument tree view, allowing to reorder
569        // the sequence of instruments within the gig file
570        {
571            std::vector<Gtk::TargetEntry> drag_target_instrument;
572            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
573            m_TreeView.drag_source_set(drag_target_instrument);
574            m_TreeView.drag_dest_set(drag_target_instrument);
575            m_TreeView.signal_drag_begin().connect(
576                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
577            );
578            m_TreeView.signal_drag_data_get().connect(
579                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
580            );
581            m_TreeView.signal_drag_data_received().connect(
582                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
583            );
584        }
585    
586      // create samples treeview (including its data model)      // create samples treeview (including its data model)
587      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
588      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
589        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
590      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."));
591      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
592      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 489  MainWindow::MainWindow() : Line 630  MainWindow::MainWindow() :
630      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
631          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
632      );      );
633      //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 ?
634      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
635          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
636      );      );
# Line 526  MainWindow::MainWindow() : Line 667  MainWindow::MainWindow() :
667          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
668      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
669          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
670        m_RegionChooser.signal_instrument_changed().connect(
671            sigc::mem_fun(*this, &MainWindow::region_changed));
672      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
673          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
674      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 548  MainWindow::MainWindow() : Line 691  MainWindow::MainWindow() :
691          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
692      );      );
693    
694        dimreg_edit.signal_select_sample().connect(
695            sigc::mem_fun(*this, &MainWindow::select_sample)
696        );
697    
698      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
699          sigc::hide(          sigc::hide(
700              sigc::bind(              sigc::bind(
# Line 617  void MainWindow::region_changed() Line 764  void MainWindow::region_changed()
764  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
765  {  {
766      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
767      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
768          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
769        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
770      if (it) {      if (it) {
771          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
772          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 661  void MainWindow::update_dimregs() Line 809  void MainWindow::update_dimregs()
809              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
810          }          }
811      }      }
812    
813        m_DimRegionChooser.setModifyAllRegions(all_regions);
814        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
815        m_DimRegionChooser.setModifyBothChannels(stereo);
816  }  }
817    
818  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 678  void MainWindow::dimreg_changed() Line 830  void MainWindow::dimreg_changed()
830  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
831  {  {
832      // select item in instrument menu      // select item in instrument menu
833      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
834      if (it) {      if (!rows.empty()) {
835          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
836          int index = path[0];          if (it) {
837          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
838              instrument_menu->get_children();              int index = path[0];
839          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
840                    instrument_menu->get_children();
841                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
842            }
843      }      }
844    
845      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
846    
847        if (Settings::singleton()->syncSamplerInstrumentSelection) {
848            switch_sampler_instrument_signal.emit(get_instrument());
849        }
850  }  }
851    
852  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 705  void Loader::progress_callback(float fra Line 864  void Loader::progress_callback(float fra
864      progress_dispatcher();      progress_dispatcher();
865  }  }
866    
867    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
868    // make sure stack is 16-byte aligned for SSE instructions
869    __attribute__((force_align_arg_pointer))
870    #endif
871  void Loader::thread_function()  void Loader::thread_function()
872  {  {
873      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
874               static_cast<void*>(Glib::Threads::Thread::self()));
875      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
876      try {      try {
877          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 729  void Loader::thread_function() Line 893  void Loader::thread_function()
893  }  }
894    
895  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
896      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
897  {  {
898  }  }
899    
# Line 740  void Loader::launch() Line 904  void Loader::launch()
904  #else  #else
905      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
906  #endif  #endif
907      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
908  }  }
909    
910  float Loader::get_progress()  float Loader::get_progress()
# Line 783  void Saver::progress_callback(float frac Line 947  void Saver::progress_callback(float frac
947      progress_dispatcher.emit();      progress_dispatcher.emit();
948  }  }
949    
950    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
951    // make sure stack is 16-byte aligned for SSE instructions
952    __attribute__((force_align_arg_pointer))
953    #endif
954  void Saver::thread_function()  void Saver::thread_function()
955  {  {
956      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
957               static_cast<void*>(Glib::Threads::Thread::self()));
958      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
959      try {      try {
960          gig::progress_t progress;          gig::progress_t progress;
# Line 794  void Saver::thread_function() Line 963  void Saver::thread_function()
963    
964          // 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"
965          if (filename.empty()) {          if (filename.empty()) {
966              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
967                    // save directly over the existing .gig file
968                    // (requires less disk space than solution below
969                    // but may be slower)
970                    gig->Save(&progress);
971                } else {
972                    // save the file as separate temporary file first,
973                    // then move the saved file over the old file
974                    // (may result in performance speedup during save)
975                    String tmpname = filename + ".TMP";
976                    gig->Save(tmpname, &progress);
977                    #if defined(WIN32)
978                    if (!DeleteFile(filename.c_str())) {
979                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
980                    }
981                    #else // POSIX ...
982                    if (unlink(filename.c_str())) {
983                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
984                    }
985                    #endif
986                    if (rename(tmpname.c_str(), filename.c_str())) {
987                        #if defined(WIN32)
988                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
989                        #else
990                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
991                        #endif
992                    }
993                }
994          } else {          } else {
995              gig->Save(filename, &progress);              gig->Save(filename, &progress);
996          }          }
# Line 822  void Saver::launch() Line 1018  void Saver::launch()
1018  #else  #else
1019      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1020  #endif  #endif
1021      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1022  }  }
1023    
1024  float Saver::get_progress()  float Saver::get_progress()
# Line 919  bool MainWindow::close_confirmation_dial Line 1115  bool MainWindow::close_confirmation_dial
1115      g_free(msg);      g_free(msg);
1116      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."));
1117      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1118      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1119      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);
1120      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1121      int response = dialog.run();      int response = dialog.run();
1122      dialog.hide();      dialog.hide();
1123    
1124        // user decided to exit app without saving
1125        if (response == Gtk::RESPONSE_NO) return true;
1126    
1127        // user cancelled dialog, thus don't close app
1128        if (response == Gtk::RESPONSE_CANCEL) return false;
1129    
1130      // TODO: the following return valid is disabled and hard coded instead for      // TODO: the following return valid is disabled and hard coded instead for
1131      // 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
1132      // asynchronously, as a result the app does not close automatically anymore      // asynchronously, as a result the app does not close automatically anymore
# Line 945  bool MainWindow::leaving_shared_mode_dia Line 1147  bool MainWindow::leaving_shared_mode_dia
1147            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1148            "load it."));            "load it."));
1149      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1150      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1151      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1152      int response = dialog.run();      int response = dialog.run();
1153      dialog.hide();      dialog.hide();
# Line 959  void MainWindow::on_action_file_open() Line 1161  void MainWindow::on_action_file_open()
1161      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1162    
1163      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1164      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1165      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1166      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1167  #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
1168      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 976  void MainWindow::on_action_file_open() Line 1178  void MainWindow::on_action_file_open()
1178      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1179          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1180          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1181          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1182                   static_cast<void*>(Glib::Threads::Thread::self()));
1183          load_file(filename.c_str());          load_file(filename.c_str());
1184          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1185      }      }
# Line 1046  void MainWindow::on_loader_progress() Line 1249  void MainWindow::on_loader_progress()
1249  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1250  {  {
1251      printf("Loader finished!\n");      printf("Loader finished!\n");
1252      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1253               static_cast<void*>(Glib::Threads::Thread::self()));
1254      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1255      progress_dialog->hide();      progress_dialog->hide();
1256  }  }
# Line 1141  void MainWindow::on_saver_finished() Line 1345  void MainWindow::on_saver_finished()
1345    
1346      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1347    
1348      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1349      progress_dialog->hide();      progress_dialog->hide();
1350  }  }
1351    
# Line 1153  void MainWindow::on_action_file_save_as( Line 1357  void MainWindow::on_action_file_save_as(
1357    
1358  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1359  {  {
1360      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1361      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1362      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1363      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1364      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1365    
# Line 1186  bool MainWindow::file_save_as() Line 1390  bool MainWindow::file_save_as()
1390      // show warning in the dialog      // show warning in the dialog
1391      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1392      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1393      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1394        warningIcon.set_from_icon_name("dialog-warning",
1395                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1396      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1397  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1398      view::WrapLabel description;      view::WrapLabel description;
# Line 1238  bool MainWindow::file_save_as() Line 1444  bool MainWindow::file_save_as()
1444  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1445      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1446      Glib::ustring error_files;      Glib::ustring error_files;
1447      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1448      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1449           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1450          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
# Line 1339  void MainWindow::on_action_warn_user_on_ Line 1545  void MainWindow::on_action_warn_user_on_
1545          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
1546  }  }
1547    
1548    void MainWindow::on_action_sync_sampler_instrument_selection() {
1549        Settings::singleton()->syncSamplerInstrumentSelection =
1550            !Settings::singleton()->syncSamplerInstrumentSelection;
1551    }
1552    
1553    void MainWindow::on_action_move_root_note_with_region_moved() {
1554        Settings::singleton()->moveRootNoteWithRegionMoved =
1555            !Settings::singleton()->moveRootNoteWithRegionMoved;
1556    }
1557    
1558  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1559  {  {
1560      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1348  void MainWindow::on_action_help_about() Line 1564  void MainWindow::on_action_help_about()
1564      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1565  #endif  #endif
1566      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1567      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1568      const std::string sComment =      const std::string sComment =
1569          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1570          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1385  PropDialog::PropDialog() Line 1601  PropDialog::PropDialog()
1601        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1602        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1603        eSubject(_("Subject")),        eSubject(_("Subject")),
1604        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1605        table(2, 1),        table(2, 1),
1606        m_file(NULL)        m_file(NULL)
1607  {  {
# Line 1508  void InstrumentProps::set_MIDIProgram(ui Line 1724  void InstrumentProps::set_MIDIProgram(ui
1724  }  }
1725    
1726  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1727      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1728      table(2,1),      table(2,1),
1729      eName(_("Name")),      eName(_("Name")),
1730      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1631  void MainWindow::load_gig(gig::File* gig Line 1847  void MainWindow::load_gig(gig::File* gig
1847      file = 0;      file = 0;
1848      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1849    
1850      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1851            (filename && strlen(filename) > 0) ?
1852                filename : (!gig->GetFileName().empty()) ?
1853                    gig->GetFileName() : _("Unsaved Gig File");
1854      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1855      file_has_name = filename;      file_has_name = filename;
1856      file_is_changed = false;      file_is_changed = false;
# Line 1640  void MainWindow::load_gig(gig::File* gig Line 1859  void MainWindow::load_gig(gig::File* gig
1859      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1860    
1861      instrument_name_connection.block();      instrument_name_connection.block();
1862        int index = 0;
1863      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1864           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1865          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1866    
1867          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1868          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1869            row[m_Columns.m_col_nr] = index;
1870          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1871          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1872    
# Line 1718  bool MainWindow::instr_props_set_instrum Line 1939  bool MainWindow::instr_props_set_instrum
1939  {  {
1940      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1941    
1942      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1943          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1944            instrumentProps.hide();
1945            return false;
1946        }
1947        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1948      if (it) {      if (it) {
1949          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1950          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1772  void MainWindow::show_midi_rules() Line 1997  void MainWindow::show_midi_rules()
1997  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
1998      if (!file) return;      if (!file) return;
1999      // get selected instrument      // get selected instrument
2000      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2001      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2002        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2003      if (!it) return;      if (!it) return;
2004      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2005      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1785  void MainWindow::show_script_slots() { Line 2011  void MainWindow::show_script_slots() {
2011      window->show();      window->show();
2012  }  }
2013    
2014    void MainWindow::on_action_refresh_all() {
2015        __refreshEntireGUI();
2016    }
2017    
2018  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
2019      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2020          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1796  void MainWindow::on_action_view_status_b Line 2026  void MainWindow::on_action_view_status_b
2026      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2027  }  }
2028    
2029    void MainWindow::on_auto_restore_win_dim() {
2030        Gtk::CheckMenuItem* item =
2031            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2032        if (!item) {
2033            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2034            return;
2035        }
2036        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2037    }
2038    
2039    void MainWindow::on_save_with_temporary_file() {
2040        Gtk::CheckMenuItem* item =
2041            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2042        if (!item) {
2043            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2044            return;
2045        }
2046        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2047    }
2048    
2049  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2050      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2051          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1860  void MainWindow::on_instrument_selection Line 2110  void MainWindow::on_instrument_selection
2110      }      }
2111  }  }
2112    
2113    void MainWindow::select_instrument(gig::Instrument* instrument) {
2114        if (!instrument) return;
2115    
2116        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2117        for (int i = 0; i < model->children().size(); ++i) {
2118            Gtk::TreeModel::Row row = model->children()[i];
2119            if (row[m_Columns.m_col_instr] == instrument) {
2120                // select and show the respective instrument in the list view
2121                show_intruments_tab();
2122                m_TreeView.get_selection()->unselect_all();
2123                m_TreeView.get_selection()->select(model->children()[i]);
2124                std::vector<Gtk::TreeModel::Path> rows =
2125                    m_TreeView.get_selection()->get_selected_rows();
2126                if (!rows.empty())
2127                    m_TreeView.scroll_to_row(rows[0]);
2128                on_sel_change(); // the regular instrument selection change callback
2129            }
2130        }
2131    }
2132    
2133    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2134    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2135        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2136        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2137    
2138        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2139        for (int i = 0; i < model->children().size(); ++i) {
2140            Gtk::TreeModel::Row row = model->children()[i];
2141            if (row[m_Columns.m_col_instr] == pInstrument) {
2142                // select and show the respective instrument in the list view
2143                show_intruments_tab();
2144                m_TreeView.get_selection()->unselect_all();
2145                m_TreeView.get_selection()->select(model->children()[i]);
2146                std::vector<Gtk::TreeModel::Path> rows =
2147                    m_TreeView.get_selection()->get_selected_rows();
2148                if (!rows.empty())
2149                    m_TreeView.scroll_to_row(rows[0]);
2150                on_sel_change(); // the regular instrument selection change callback
2151    
2152                // select respective region in the region selector
2153                m_RegionChooser.set_region(pRegion);
2154    
2155                // select and show the respective dimension region in the editor
2156                //update_dimregs();
2157                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2158                //dimreg_edit.set_dim_region(dimRgn);
2159    
2160                return true;
2161            }
2162        }
2163    
2164        return false;
2165    }
2166    
2167    void MainWindow::select_sample(gig::Sample* sample) {
2168        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2169        for (int g = 0; g < model->children().size(); ++g) {
2170            Gtk::TreeModel::Row rowGroup = model->children()[g];
2171            for (int s = 0; s < rowGroup.children().size(); ++s) {
2172                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2173                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2174                    show_samples_tab();
2175                    m_TreeViewSamples.get_selection()->unselect_all();
2176                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2177                    std::vector<Gtk::TreeModel::Path> rows =
2178                        m_TreeViewSamples.get_selection()->get_selected_rows();
2179                    if (rows.empty()) return;
2180                    m_TreeViewSamples.scroll_to_row(rows[0]);
2181                    return;
2182                }
2183            }
2184        }
2185    }
2186    
2187  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2188      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2189            // by default if Ctrl keys is pressed down, then a mouse right-click
2190            // does not select the respective row, so we must assure this
2191            // programmatically ...
2192            /*{
2193                Gtk::TreeModel::Path path;
2194                Gtk::TreeViewColumn* pColumn = NULL;
2195                int cellX, cellY;
2196                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2197                    (int)button->x, (int)button->y,
2198                    path, pColumn, cellX, cellY
2199                );
2200                if (bSuccess) {
2201                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2202                        printf("not selected !!!\n");
2203                        m_TreeViewSamples.get_selection()->select(path);
2204                    }
2205                }
2206            }*/
2207    
2208          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2209              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2210          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2211          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2212          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2213          bool group_selected  = false;          const int n = rows.size();
2214          bool sample_selected = false;          int nGroups  = 0;
2215          if (it) {          int nSamples = 0;
2216            for (int r = 0; r < n; ++r) {
2217                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2218                if (!it) continue;
2219              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2220              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2221              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2222          }          }
2223            
               
2224          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2225              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2226          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2227              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2228          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2229              set_sensitive(file);              set_sensitive(file);
2230          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2231              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2232          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2233              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2234          // show sample popup          // show sample popup
2235          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2236    
2237          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2238              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2239          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2240              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2241          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2242              set_sensitive(file);              set_sensitive(file);
2243          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2244              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2245          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2246              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2247      }      }
2248  }  }
2249    
# Line 1977  void MainWindow::add_instrument(gig::Ins Line 2322  void MainWindow::add_instrument(gig::Ins
2322      instrument_name_connection.block();      instrument_name_connection.block();
2323      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2324      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2325        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2326      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2327      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2328      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2005  void MainWindow::on_action_duplicate_ins Line 2351  void MainWindow::on_action_duplicate_ins
2351      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2352      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2353      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2354      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2355      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2356      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2357      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2358      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2359                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2360      // duplicate the orginal instrument              if (instrOrig) {
2361      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2362      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2363          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2364          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2365                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2366    
2367      add_instrument(instrNew);                  add_instrument(instrNew);
2368                }
2369            }
2370        }
2371  }  }
2372    
2373  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2034  void MainWindow::on_action_remove_instru Line 2384  void MainWindow::on_action_remove_instru
2384      }      }
2385    
2386      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2387      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2388      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2389            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2390            if (!it) continue;
2391          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2392          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2393          try {          try {
# Line 2050  void MainWindow::on_action_remove_instru Line 2402  void MainWindow::on_action_remove_instru
2402    
2403              // remove row from instruments tree view              // remove row from instruments tree view
2404              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2405                // update "Nr" column of all instrument rows
2406                {
2407                    int index = 0;
2408                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2409                         it != m_refTreeModel->children().end(); ++it, ++index)
2410                    {
2411                        Gtk::TreeModel::Row row = *it;
2412                        row[m_Columns.m_col_nr] = index;
2413                    }
2414                }
2415    
2416  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2417              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2147  void MainWindow::on_action_edit_script() Line 2509  void MainWindow::on_action_edit_script()
2509      if (!script) return;      if (!script) return;
2510    
2511      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2512        editor->signal_script_to_be_changed.connect(
2513            signal_script_to_be_changed.make_slot()
2514        );
2515        editor->signal_script_changed.connect(
2516            signal_script_changed.make_slot()
2517        );
2518      editor->setScript(script);      editor->setScript(script);
2519      //editor->reparent(*this);      //editor->reparent(*this);
2520      editor->show();      editor->show();
# Line 2212  void MainWindow::on_action_add_group() { Line 2580  void MainWindow::on_action_add_group() {
2580      file_changed();      file_changed();
2581  }  }
2582    
2583    void MainWindow::on_action_replace_sample() {
2584        add_or_replace_sample(true);
2585    }
2586    
2587  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2588        add_or_replace_sample(false);
2589    }
2590    
2591    void MainWindow::add_or_replace_sample(bool replace) {
2592      if (!file) return;      if (!file) return;
2593      // get selected group  
2594        // get selected group (and probably selected sample)
2595      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2596      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2597        if (rows.empty()) return;
2598        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2599      if (!it) return;      if (!it) return;
2600      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2601        gig::Sample* sample = NULL;
2602      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2603      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2604          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2605          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2606          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2607          if (!it) return;          if (!it) return;
2608          row = *it;          if (!replace) row = *it;
2609          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2610          if (!group) return;          if (!group) return;
2611      }      }
2612        if (replace && !sample) return;
2613    
2614      // show 'browse for file' dialog      // show 'browse for file' dialog
2615      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2616      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2617      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2618      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
2619    
2620      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2621  #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 2304  void MainWindow::on_action_add_sample() Line 2686  void MainWindow::on_action_add_sample()
2686                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2687                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2688                  }                  }
2689                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2690                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2691                  // file name without path                  // file name without path
2692                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2693                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2356  void MainWindow::on_action_add_sample() Line 2738  void MainWindow::on_action_add_sample()
2738                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2739                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2740                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2741                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2742                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2743                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2744                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2364  void MainWindow::on_action_add_sample() Line 2746  void MainWindow::on_action_add_sample()
2746                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2747                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2748                  // add sample to the tree view                  // add sample to the tree view
2749                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2750                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2751                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2752                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2753                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2754                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2755                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2756                            gig_to_utf8(sample->pInfo->Name);
2757                        rowSample[m_SamplesModel.m_col_sample] = sample;
2758                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2759                    }
2760                  // close sound file                  // close sound file
2761                  sf_close(hFile);                  sf_close(hFile);
2762                  file_changed();                  file_changed();
# Line 2381  void MainWindow::on_action_add_sample() Line 2767  void MainWindow::on_action_add_sample()
2767          }          }
2768          // 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
2769          if (!error_files.empty()) {          if (!error_files.empty()) {
2770              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2771                    (replace
2772                        ? _("Failed to replace sample with:\n")
2773                        : _("Could not add the following sample(s):\n"))
2774                    + error_files;
2775              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2776              msg.run();              msg.run();
2777          }          }
# Line 2424  void MainWindow::on_action_replace_all_s Line 2814  void MainWindow::on_action_replace_all_s
2814      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2815      description.show();      description.show();
2816      entryArea.show_all();      entryArea.show_all();
2817      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2818      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2819      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2820      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2448  void MainWindow::on_action_replace_all_s Line 2838  void MainWindow::on_action_replace_all_s
2838              try              try
2839              {              {
2840                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2841                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2842                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2843                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2844                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2845                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2846                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2847                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2848                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2849                          break;                          break;
2850                      default:                      default:
2851                          sf_close(hFile);                          sf_close(hFile);
# Line 2492  void MainWindow::on_action_replace_all_s Line 2878  void MainWindow::on_action_replace_all_s
2878  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2879      if (!file) return;      if (!file) return;
2880      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2881      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2882      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2883            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2884            if (!it) continue;
2885          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2886          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2887          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2565  void MainWindow::on_action_remove_sample Line 2953  void MainWindow::on_action_remove_sample
2953      }      }
2954  }  }
2955    
2956    void MainWindow::on_action_remove_unused_samples() {
2957        if (!file) return;
2958    
2959        // collect all samples that are not referenced by any instrument
2960        std::list<gig::Sample*> lsamples;
2961        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2962            gig::Sample* sample = file->GetSample(iSample);
2963            bool isUsed = false;
2964            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2965                                  instrument = file->GetNextInstrument())
2966            {
2967                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2968                                  rgn = instrument->GetNextRegion())
2969                {
2970                    for (int i = 0; i < 256; ++i) {
2971                        if (!rgn->pDimensionRegions[i]) continue;
2972                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2973                        isUsed = true;
2974                        goto endOfRefSearch;
2975                    }
2976                }
2977            }
2978            endOfRefSearch:
2979            if (!isUsed) lsamples.push_back(sample);
2980        }
2981    
2982        if (lsamples.empty()) return;
2983    
2984        // notify everybody that we're going to remove these samples
2985        samples_to_be_removed_signal.emit(lsamples);
2986    
2987        // remove collected samples
2988        try {
2989            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2990                 itSample != lsamples.end(); ++itSample)
2991            {
2992                gig::Sample* sample = *itSample;
2993                // remove sample from the .gig file
2994                file->DeleteSample(sample);
2995                // if sample was just previously added, remove it fro the import queue
2996                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2997                     iter != m_SampleImportQueue.end(); ++iter)
2998                {
2999                    if ((*iter).gig_sample == sample) {
3000                        printf("Removing previously added sample '%s'\n",
3001                               (*iter).sample_path.c_str());
3002                        m_SampleImportQueue.erase(iter);
3003                        break;
3004                    }
3005                }
3006            }
3007        } catch (RIFF::Exception e) {
3008            // show error message
3009            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3010            msg.run();
3011        }
3012    
3013        // notify everybody that we're done with removal
3014        samples_removed_signal.emit();
3015    
3016        dimreg_changed();
3017        file_changed();
3018        __refreshEntireGUI();
3019    }
3020    
3021  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
3022  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)
3023  {  {
# Line 2591  void MainWindow::on_scripts_treeview_dra Line 3044  void MainWindow::on_scripts_treeview_dra
3044                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
3045  }  }
3046    
3047    // see comment on on_sample_treeview_drag_begin()
3048    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3049    {
3050        first_call_to_drag_data_get = true;
3051    }
3052    
3053    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
3054                                                           Gtk::SelectionData& selection_data, guint, guint)
3055    {
3056        if (!first_call_to_drag_data_get) return;
3057        first_call_to_drag_data_get = false;
3058    
3059        // get selected source instrument
3060        gig::Instrument* src = NULL;
3061        {
3062            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3063            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3064            if (!rows.empty()) {
3065                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3066                if (it) {
3067                    Gtk::TreeModel::Row row = *it;
3068                    src = row[m_Columns.m_col_instr];
3069                }
3070            }
3071        }
3072        if (!src) return;
3073    
3074        // pass the source gig::Instrument as pointer
3075        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
3076                           sizeof(src)/*length of data in bytes*/);
3077    }
3078    
3079    void MainWindow::on_instruments_treeview_drop_drag_data_received(
3080        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
3081        const Gtk::SelectionData& selection_data, guint, guint time)
3082    {
3083        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
3084        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
3085            return;
3086    
3087        gig::Instrument* dst = NULL;
3088        {
3089            Gtk::TreeModel::Path path;
3090            const bool found = m_TreeView.get_path_at_pos(x, y, path);
3091            if (!found) return;
3092    
3093            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
3094            if (!iter) return;
3095            Gtk::TreeModel::Row row = *iter;
3096            dst = row[m_Columns.m_col_instr];
3097        }
3098        if (!dst) return;
3099    
3100        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
3101        src->MoveTo(dst);
3102        __refreshEntireGUI();
3103        select_instrument(src);
3104    }
3105    
3106  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
3107  // 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
3108  // 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 2609  void MainWindow::on_sample_treeview_drag Line 3121  void MainWindow::on_sample_treeview_drag
3121      // get selected sample      // get selected sample
3122      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3123      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3124      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3125      if (it) {      if (!rows.empty()) {
3126          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3127          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3128                Gtk::TreeModel::Row row = *it;
3129                sample = row[m_SamplesModel.m_col_sample];
3130            }
3131      }      }
3132      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3133      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 2752  void MainWindow::script_double_clicked(c Line 3267  void MainWindow::script_double_clicked(c
3267      if (!script) return;      if (!script) return;
3268    
3269      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3270        editor->signal_script_to_be_changed.connect(
3271            signal_script_to_be_changed.make_slot()
3272        );
3273        editor->signal_script_changed.connect(
3274            signal_script_changed.make_slot()
3275        );
3276      editor->setScript(script);      editor->setScript(script);
3277      //editor->reparent(*this);      //editor->reparent(*this);
3278      editor->show();      editor->show();
# Line 2805  void MainWindow::on_action_combine_instr Line 3326  void MainWindow::on_action_combine_instr
3326    
3327  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3328      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3329      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3330        if (rows.empty()) return;
3331        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3332      if (!it) return;      if (!it) return;
3333      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3334      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2813  void MainWindow::on_action_view_referenc Line 3336  void MainWindow::on_action_view_referenc
3336    
3337      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3338      d->setSample(sample);      d->setSample(sample);
3339        d->dimension_region_selected.connect(
3340            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3341        );
3342      d->show_all();      d->show_all();
3343      d->resize(500, 400);      d->resize(500, 400);
3344      d->run();      d->run();
# Line 2924  void MainWindow::on_action_merge_files() Line 3450  void MainWindow::on_action_merge_files()
3450      }      }
3451    
3452      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3453      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3454      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3455      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3456  #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 2943  void MainWindow::on_action_merge_files() Line 3469  void MainWindow::on_action_merge_files()
3469      // show warning in the file picker dialog      // show warning in the file picker dialog
3470      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3471      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3472      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3473        warningIcon.set_from_icon_name("dialog-warning",
3474                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3475      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3476  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3477      view::WrapLabel description;      view::WrapLabel description;
# Line 2966  void MainWindow::on_action_merge_files() Line 3494  void MainWindow::on_action_merge_files()
3494      descriptionArea.show_all();      descriptionArea.show_all();
3495    
3496      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3497          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3498                   static_cast<void*>(Glib::Threads::Thread::self()));
3499          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3500    
3501          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 2978  void MainWindow::on_action_merge_files() Line 3507  void MainWindow::on_action_merge_files()
3507          }          }
3508    
3509          // update GUI          // update GUI
3510          __refreshEntireGUI();                  __refreshEntireGUI();
3511      }      }
3512  }  }
3513    
# Line 2996  void MainWindow::set_file_is_shared(bool Line 3525  void MainWindow::set_file_is_shared(bool
3525              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3526          );          );
3527      }      }
3528    
3529        {
3530            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3531                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3532            if (item) item->set_sensitive(b);
3533        }
3534  }  }
3535    
3536  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
# Line 3097  sigc::signal<void, int/*key*/, int/*velo Line 3632  sigc::signal<void, int/*key*/, int/*velo
3632  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3633      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3634  }  }
3635    
3636    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3637        return switch_sampler_instrument_signal;
3638    }

Legend:
Removed from v.2683  
changed lines
  Added in v.3106

  ViewVC Help
Powered by ViewVC