/[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 2694 by schoenebeck, Tue Jan 6 16:08:48 2015 UTC revision 2994 by schoenebeck, Sat Sep 24 23:34:37 2016 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2016 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 110  MainWindow::MainWindow() : Line 117  MainWindow::MainWindow() :
117      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
118    
119      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
120      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
121                         Gtk::AccelKey("<control>n"),
122                       sigc::mem_fun(                       sigc::mem_fun(
123                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
124      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
125          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
126                       sigc::mem_fun(                       sigc::mem_fun(
127                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
128      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
129                         Gtk::AccelKey("<control>s"),
130                       sigc::mem_fun(                       sigc::mem_fun(
131                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
132      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,  
133                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
134                       sigc::mem_fun(                       sigc::mem_fun(
135                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
136      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
137                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
138                       sigc::mem_fun(                       sigc::mem_fun(
139                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
140      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
141                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
142                       sigc::mem_fun(                       sigc::mem_fun(
143                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
144      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 144  MainWindow::MainWindow() : Line 149  MainWindow::MainWindow() :
149                                           _("_Script Slots...")),                                           _("_Script Slots...")),
150                       sigc::mem_fun(                       sigc::mem_fun(
151                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
152      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
153                         Gtk::AccelKey("<control>q"),
154                       sigc::mem_fun(                       sigc::mem_fun(
155                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
156      actionGroup->add(      actionGroup->add(
# Line 187  MainWindow::MainWindow() : Line 193  MainWindow::MainWindow() :
193                       sigc::mem_fun(                       sigc::mem_fun(
194                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
195    
196      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      toggle_action =
197      actionGroup->add(Gtk::Action::create("MenuHelp",          Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
198                                           action->property_label()));      toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
199      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(toggle_action,
200                         sigc::mem_fun(
201                             *this, &MainWindow::on_auto_restore_win_dim));
202    
203        toggle_action =
204            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
205        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
206        actionGroup->add(toggle_action,
207                         sigc::mem_fun(
208                             *this, &MainWindow::on_save_with_temporary_file));
209    
210        actionGroup->add(
211            Gtk::Action::create("RefreshAll", _("_Refresh All")),
212            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
213        );                
214    
215        actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
216        actionGroup->add(Gtk::Action::create("About", _("_About")),
217                       sigc::mem_fun(                       sigc::mem_fun(
218                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
219      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 225  MainWindow::MainWindow() :
225          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
226      );      );
227      actionGroup->add(      actionGroup->add(
228          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
229          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
230      );      );
231    
# Line 225  MainWindow::MainWindow() : Line 248  MainWindow::MainWindow() :
248          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
249      );      );
250    
251        toggle_action =
252            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
253        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
254        actionGroup->add(
255            toggle_action,
256            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
257        );
258    
259    
260      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
261    
# Line 241  MainWindow::MainWindow() : Line 272  MainWindow::MainWindow() :
272    
273      // sample right-click popup actions      // sample right-click popup actions
274      actionGroup->add(      actionGroup->add(
275          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
276          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
277      );      );
278      actionGroup->add(      actionGroup->add(
# Line 253  MainWindow::MainWindow() : Line 284  MainWindow::MainWindow() :
284          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
285      );      );
286      actionGroup->add(      actionGroup->add(
287          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
288          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
289      );      );
290      actionGroup->add(      actionGroup->add(
291            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
292            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
293        );
294        actionGroup->add(
295          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
296          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
297      );      );
298      actionGroup->add(      actionGroup->add(
299            Gtk::Action::create("ReplaceSample",
300                                _("Replace Sample...")),
301            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
302        );
303        actionGroup->add(
304          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
305                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
306          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 280  MainWindow::MainWindow() : Line 320  MainWindow::MainWindow() :
320          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
321      );      );
322      actionGroup->add(      actionGroup->add(
323          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
324          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
325      );      );
326    
# Line 312  MainWindow::MainWindow() : Line 352  MainWindow::MainWindow() :
352          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
353          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
354          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
355            "      <menuitem action='ReplaceSample' />"
356          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
357          "      <separator/>"          "      <separator/>"
358          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
359            "      <menuitem action='RemoveUnusedSamples'/>"
360          "    </menu>"          "    </menu>"
361          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
362          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 337  MainWindow::MainWindow() : Line 379  MainWindow::MainWindow() :
379          "    </menu>"          "    </menu>"
380          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
381          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
382            "      <menuitem action='AutoRestoreWinDim'/>"
383            "      <separator/>"
384            "      <menuitem action='RefreshAll'/>"
385          "    </menu>"          "    </menu>"
386          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
387          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 390  MainWindow::MainWindow() :
390          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
391          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
392          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
393            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
394            "      <menuitem action='SaveWithTemporaryFile'/>"
395          "    </menu>"          "    </menu>"
396          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
397          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 364  MainWindow::MainWindow() : Line 411  MainWindow::MainWindow() :
411          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
412          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
413          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
414            "    <menuitem action='ReplaceSample' />"
415          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
416          "    <separator/>"          "    <separator/>"
417          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
418            "    <menuitem action='RemoveUnusedSamples'/>"
419          "  </popup>"          "  </popup>"
420          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
421          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 411  MainWindow::MainWindow() : Line 460  MainWindow::MainWindow() :
460      }      }
461      {      {
462          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
463                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
464            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."));
465        }
466        {
467            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
468                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
469            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
470            // copy tooltip to popup menu
471            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
472                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
473            item2->set_tooltip_text(item->get_tooltip_text());
474        }
475        {
476            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
477                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
478            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
479        }
480        {
481            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
482                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
483            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
484        }
485        {
486            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
487              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
488          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."));
489      }      }
# Line 448  MainWindow::MainWindow() : Line 521  MainWindow::MainWindow() :
521      // Create the Tree model:      // Create the Tree model:
522      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
523      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
524      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
525        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
526      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
527          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
528      );      );
529    
530      // Add the TreeView's view columns:      // Add the TreeView's view columns:
531      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
532      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
533        m_TreeView.set_headers_visible(true);
534        
535        // establish drag&drop within the instrument tree view, allowing to reorder
536        // the sequence of instruments within the gig file
537        {
538            std::vector<Gtk::TargetEntry> drag_target_instrument;
539            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
540            m_TreeView.drag_source_set(drag_target_instrument);
541            m_TreeView.drag_dest_set(drag_target_instrument);
542            m_TreeView.signal_drag_begin().connect(
543                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
544            );
545            m_TreeView.signal_drag_data_get().connect(
546                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
547            );
548            m_TreeView.signal_drag_data_received().connect(
549                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
550            );
551        }
552    
553      // create samples treeview (including its data model)      // create samples treeview (including its data model)
554      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
555      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
556        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
557      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."));
558      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
559      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 503  MainWindow::MainWindow() : Line 597  MainWindow::MainWindow() :
597      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
598          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
599      );      );
600      //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 ?
601      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
602          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
603      );      );
# Line 540  MainWindow::MainWindow() : Line 634  MainWindow::MainWindow() :
634          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
635      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
636          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
637        m_RegionChooser.signal_instrument_changed().connect(
638            sigc::mem_fun(*this, &MainWindow::region_changed));
639      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
640          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
641      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 635  void MainWindow::region_changed() Line 731  void MainWindow::region_changed()
731  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
732  {  {
733      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
734      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
735          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
736        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
737      if (it) {      if (it) {
738          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
739          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 696  void MainWindow::dimreg_changed() Line 793  void MainWindow::dimreg_changed()
793  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
794  {  {
795      // select item in instrument menu      // select item in instrument menu
796      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
797      if (it) {      if (!rows.empty()) {
798          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
799          int index = path[0];          if (it) {
800          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
801              instrument_menu->get_children();              int index = path[0];
802          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
803                    instrument_menu->get_children();
804                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
805            }
806      }      }
807    
808      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 729  void Loader::progress_callback(float fra Line 829  void Loader::progress_callback(float fra
829    
830  void Loader::thread_function()  void Loader::thread_function()
831  {  {
832      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
833               static_cast<void*>(Glib::Threads::Thread::self()));
834      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
835      try {      try {
836          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 751  void Loader::thread_function() Line 852  void Loader::thread_function()
852  }  }
853    
854  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
855      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
856  {  {
857  }  }
858    
# Line 762  void Loader::launch() Line 863  void Loader::launch()
863  #else  #else
864      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
865  #endif  #endif
866      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
867  }  }
868    
869  float Loader::get_progress()  float Loader::get_progress()
# Line 807  void Saver::progress_callback(float frac Line 908  void Saver::progress_callback(float frac
908    
909  void Saver::thread_function()  void Saver::thread_function()
910  {  {
911      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
912               static_cast<void*>(Glib::Threads::Thread::self()));
913      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
914      try {      try {
915          gig::progress_t progress;          gig::progress_t progress;
# Line 816  void Saver::thread_function() Line 918  void Saver::thread_function()
918    
919          // 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"
920          if (filename.empty()) {          if (filename.empty()) {
921              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
922                    // save directly over the existing .gig file
923                    // (requires less disk space than solution below
924                    // but may be slower)
925                    gig->Save(&progress);
926                } else {
927                    // save the file as separate temporary file first,
928                    // then move the saved file over the old file
929                    // (may result in performance speedup during save)
930                    String tmpname = filename + ".TMP";
931                    gig->Save(tmpname, &progress);
932                    #if defined(WIN32)
933                    if (!DeleteFile(filename.c_str())) {
934                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
935                    }
936                    #else // POSIX ...
937                    if (unlink(filename.c_str())) {
938                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
939                    }
940                    #endif
941                    if (rename(tmpname.c_str(), filename.c_str())) {
942                        #if defined(WIN32)
943                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
944                        #else
945                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
946                        #endif
947                    }
948                }
949          } else {          } else {
950              gig->Save(filename, &progress);              gig->Save(filename, &progress);
951          }          }
# Line 844  void Saver::launch() Line 973  void Saver::launch()
973  #else  #else
974      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
975  #endif  #endif
976      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
977  }  }
978    
979  float Saver::get_progress()  float Saver::get_progress()
# Line 941  bool MainWindow::close_confirmation_dial Line 1070  bool MainWindow::close_confirmation_dial
1070      g_free(msg);      g_free(msg);
1071      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."));
1072      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1073      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1074      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);
1075      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1076      int response = dialog.run();      int response = dialog.run();
1077      dialog.hide();      dialog.hide();
# Line 973  bool MainWindow::leaving_shared_mode_dia Line 1102  bool MainWindow::leaving_shared_mode_dia
1102            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1103            "load it."));            "load it."));
1104      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1105      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1106      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1107      int response = dialog.run();      int response = dialog.run();
1108      dialog.hide();      dialog.hide();
# Line 987  void MainWindow::on_action_file_open() Line 1116  void MainWindow::on_action_file_open()
1116      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1117    
1118      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1119      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1120      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1121      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1122  #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
1123      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1004  void MainWindow::on_action_file_open() Line 1133  void MainWindow::on_action_file_open()
1133      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1134          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1135          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1136          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1137                   static_cast<void*>(Glib::Threads::Thread::self()));
1138          load_file(filename.c_str());          load_file(filename.c_str());
1139          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1140      }      }
# Line 1074  void MainWindow::on_loader_progress() Line 1204  void MainWindow::on_loader_progress()
1204  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1205  {  {
1206      printf("Loader finished!\n");      printf("Loader finished!\n");
1207      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1208               static_cast<void*>(Glib::Threads::Thread::self()));
1209      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1210      progress_dialog->hide();      progress_dialog->hide();
1211  }  }
# Line 1169  void MainWindow::on_saver_finished() Line 1300  void MainWindow::on_saver_finished()
1300    
1301      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1302    
1303      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1304      progress_dialog->hide();      progress_dialog->hide();
1305  }  }
1306    
# Line 1181  void MainWindow::on_action_file_save_as( Line 1312  void MainWindow::on_action_file_save_as(
1312    
1313  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1314  {  {
1315      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1316      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1317      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1318      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1319      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1320    
# Line 1214  bool MainWindow::file_save_as() Line 1345  bool MainWindow::file_save_as()
1345      // show warning in the dialog      // show warning in the dialog
1346      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1347      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1348      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1349        warningIcon.set_from_icon_name("dialog-warning",
1350                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1351      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1352  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1353      view::WrapLabel description;      view::WrapLabel description;
# Line 1266  bool MainWindow::file_save_as() Line 1399  bool MainWindow::file_save_as()
1399  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1400      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1401      Glib::ustring error_files;      Glib::ustring error_files;
1402      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1403      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1404           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1405          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
# Line 1372  void MainWindow::on_action_sync_sampler_ Line 1505  void MainWindow::on_action_sync_sampler_
1505          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1506  }  }
1507    
1508    void MainWindow::on_action_move_root_note_with_region_moved() {
1509        Settings::singleton()->moveRootNoteWithRegionMoved =
1510            !Settings::singleton()->moveRootNoteWithRegionMoved;
1511    }
1512    
1513  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1514  {  {
1515      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1381  void MainWindow::on_action_help_about() Line 1519  void MainWindow::on_action_help_about()
1519      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1520  #endif  #endif
1521      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1522      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");
1523      const std::string sComment =      const std::string sComment =
1524          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1525          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1418  PropDialog::PropDialog() Line 1556  PropDialog::PropDialog()
1556        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1557        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1558        eSubject(_("Subject")),        eSubject(_("Subject")),
1559        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1560        table(2, 1),        table(2, 1),
1561        m_file(NULL)        m_file(NULL)
1562  {  {
# Line 1541  void InstrumentProps::set_MIDIProgram(ui Line 1679  void InstrumentProps::set_MIDIProgram(ui
1679  }  }
1680    
1681  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1682      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1683      table(2,1),      table(2,1),
1684      eName(_("Name")),      eName(_("Name")),
1685      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1664  void MainWindow::load_gig(gig::File* gig Line 1802  void MainWindow::load_gig(gig::File* gig
1802      file = 0;      file = 0;
1803      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1804    
1805      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1806            (filename && strlen(filename) > 0) ?
1807                filename : (!gig->GetFileName().empty()) ?
1808                    gig->GetFileName() : _("Unsaved Gig File");
1809      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1810      file_has_name = filename;      file_has_name = filename;
1811      file_is_changed = false;      file_is_changed = false;
# Line 1673  void MainWindow::load_gig(gig::File* gig Line 1814  void MainWindow::load_gig(gig::File* gig
1814      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1815    
1816      instrument_name_connection.block();      instrument_name_connection.block();
1817        int index = 0;
1818      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1819           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1820          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1821    
1822          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1823          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1824            row[m_Columns.m_col_nr] = index;
1825          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1826          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1827    
# Line 1751  bool MainWindow::instr_props_set_instrum Line 1894  bool MainWindow::instr_props_set_instrum
1894  {  {
1895      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1896    
1897      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1898          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1899            instrumentProps.hide();
1900            return false;
1901        }
1902        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1903      if (it) {      if (it) {
1904          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1905          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1805  void MainWindow::show_midi_rules() Line 1952  void MainWindow::show_midi_rules()
1952  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
1953      if (!file) return;      if (!file) return;
1954      // get selected instrument      // get selected instrument
1955      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1956      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
1957        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1958      if (!it) return;      if (!it) return;
1959      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
1960      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1818  void MainWindow::show_script_slots() { Line 1966  void MainWindow::show_script_slots() {
1966      window->show();      window->show();
1967  }  }
1968    
1969    void MainWindow::on_action_refresh_all() {
1970        __refreshEntireGUI();
1971    }
1972    
1973  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1974      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1975          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1829  void MainWindow::on_action_view_status_b Line 1981  void MainWindow::on_action_view_status_b
1981      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1982  }  }
1983    
1984    void MainWindow::on_auto_restore_win_dim() {
1985        Gtk::CheckMenuItem* item =
1986            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1987        if (!item) {
1988            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
1989            return;
1990        }
1991        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
1992    }
1993    
1994    void MainWindow::on_save_with_temporary_file() {
1995        Gtk::CheckMenuItem* item =
1996            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
1997        if (!item) {
1998            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
1999            return;
2000        }
2001        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2002    }
2003    
2004  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2005      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2006          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1893  void MainWindow::on_instrument_selection Line 2065  void MainWindow::on_instrument_selection
2065      }      }
2066  }  }
2067    
2068    void MainWindow::select_instrument(gig::Instrument* instrument) {
2069        if (!instrument) return;
2070    
2071        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2072        for (int i = 0; i < model->children().size(); ++i) {
2073            Gtk::TreeModel::Row row = model->children()[i];
2074            if (row[m_Columns.m_col_instr] == instrument) {
2075                // select and show the respective instrument in the list view
2076                show_intruments_tab();
2077                m_TreeView.get_selection()->unselect_all();
2078                m_TreeView.get_selection()->select(model->children()[i]);
2079                std::vector<Gtk::TreeModel::Path> rows =
2080                    m_TreeView.get_selection()->get_selected_rows();
2081                if (!rows.empty())
2082                    m_TreeView.scroll_to_row(rows[0]);
2083                on_sel_change(); // the regular instrument selection change callback
2084            }
2085        }
2086    }
2087    
2088    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2089    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2090        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2091        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2092    
2093        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2094        for (int i = 0; i < model->children().size(); ++i) {
2095            Gtk::TreeModel::Row row = model->children()[i];
2096            if (row[m_Columns.m_col_instr] == pInstrument) {
2097                // select and show the respective instrument in the list view
2098                show_intruments_tab();
2099                m_TreeView.get_selection()->unselect_all();
2100                m_TreeView.get_selection()->select(model->children()[i]);
2101                std::vector<Gtk::TreeModel::Path> rows =
2102                    m_TreeView.get_selection()->get_selected_rows();
2103                if (!rows.empty())
2104                    m_TreeView.scroll_to_row(rows[0]);
2105                on_sel_change(); // the regular instrument selection change callback
2106    
2107                // select respective region in the region selector
2108                m_RegionChooser.set_region(pRegion);
2109    
2110                // select and show the respective dimension region in the editor
2111                //update_dimregs();
2112                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2113                //dimreg_edit.set_dim_region(dimRgn);
2114    
2115                return true;
2116            }
2117        }
2118    
2119        return false;
2120    }
2121    
2122  void MainWindow::select_sample(gig::Sample* sample) {  void MainWindow::select_sample(gig::Sample* sample) {
2123      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2124      for (int g = 0; g < model->children().size(); ++g) {      for (int g = 0; g < model->children().size(); ++g) {
# Line 1901  void MainWindow::select_sample(gig::Samp Line 2127  void MainWindow::select_sample(gig::Samp
2127              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2128              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2129                  show_samples_tab();                  show_samples_tab();
2130                    m_TreeViewSamples.get_selection()->unselect_all();
2131                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2132                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2133                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2134                  );                  if (rows.empty()) return;
2135                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2136                  return;                  return;
2137              }              }
2138          }          }
# Line 1914  void MainWindow::select_sample(gig::Samp Line 2141  void MainWindow::select_sample(gig::Samp
2141    
2142  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2143      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2144            // by default if Ctrl keys is pressed down, then a mouse right-click
2145            // does not select the respective row, so we must assure this
2146            // programmatically ...
2147            /*{
2148                Gtk::TreeModel::Path path;
2149                Gtk::TreeViewColumn* pColumn = NULL;
2150                int cellX, cellY;
2151                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2152                    (int)button->x, (int)button->y,
2153                    path, pColumn, cellX, cellY
2154                );
2155                if (bSuccess) {
2156                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2157                        printf("not selected !!!\n");
2158                        m_TreeViewSamples.get_selection()->select(path);
2159                    }
2160                }
2161            }*/
2162    
2163          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2164              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2165          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2166          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2167          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2168          bool group_selected  = false;          const int n = rows.size();
2169          bool sample_selected = false;          int nGroups  = 0;
2170          if (it) {          int nSamples = 0;
2171            for (int r = 0; r < n; ++r) {
2172                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2173                if (!it) continue;
2174              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2175              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2176              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2177          }          }
2178            
               
2179          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2180              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2181          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2182              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2183          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2184              set_sensitive(file);              set_sensitive(file);
2185          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2186              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2187          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2188              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2189          // show sample popup          // show sample popup
2190          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2191    
2192          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2193              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2194          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2195              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2196          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2197              set_sensitive(file);              set_sensitive(file);
2198          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2199              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2200          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2201              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2202      }      }
2203  }  }
2204    
# Line 2029  void MainWindow::add_instrument(gig::Ins Line 2277  void MainWindow::add_instrument(gig::Ins
2277      instrument_name_connection.block();      instrument_name_connection.block();
2278      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2279      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2280        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2281      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2282      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2283      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2057  void MainWindow::on_action_duplicate_ins Line 2306  void MainWindow::on_action_duplicate_ins
2306      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2307      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2308      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2309      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2310      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2311      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2312      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2313      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2314                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2315      // duplicate the orginal instrument              if (instrOrig) {
2316      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2317      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2318          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2319          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2320                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2321    
2322      add_instrument(instrNew);                  add_instrument(instrNew);
2323                }
2324            }
2325        }
2326  }  }
2327    
2328  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2086  void MainWindow::on_action_remove_instru Line 2339  void MainWindow::on_action_remove_instru
2339      }      }
2340    
2341      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2342      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2343      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2344            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2345            if (!it) continue;
2346          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2347          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2348          try {          try {
# Line 2102  void MainWindow::on_action_remove_instru Line 2357  void MainWindow::on_action_remove_instru
2357    
2358              // remove row from instruments tree view              // remove row from instruments tree view
2359              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2360                // update "Nr" column of all instrument rows
2361                {
2362                    int index = 0;
2363                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2364                         it != m_refTreeModel->children().end(); ++it, ++index)
2365                    {
2366                        Gtk::TreeModel::Row row = *it;
2367                        row[m_Columns.m_col_nr] = index;
2368                    }
2369                }
2370    
2371  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2372              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2199  void MainWindow::on_action_edit_script() Line 2464  void MainWindow::on_action_edit_script()
2464      if (!script) return;      if (!script) return;
2465    
2466      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2467        editor->signal_script_to_be_changed.connect(
2468            signal_script_to_be_changed.make_slot()
2469        );
2470        editor->signal_script_changed.connect(
2471            signal_script_changed.make_slot()
2472        );
2473      editor->setScript(script);      editor->setScript(script);
2474      //editor->reparent(*this);      //editor->reparent(*this);
2475      editor->show();      editor->show();
# Line 2264  void MainWindow::on_action_add_group() { Line 2535  void MainWindow::on_action_add_group() {
2535      file_changed();      file_changed();
2536  }  }
2537    
2538    void MainWindow::on_action_replace_sample() {
2539        add_or_replace_sample(true);
2540    }
2541    
2542  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2543        add_or_replace_sample(false);
2544    }
2545    
2546    void MainWindow::add_or_replace_sample(bool replace) {
2547      if (!file) return;      if (!file) return;
2548      // get selected group  
2549        // get selected group (and probably selected sample)
2550      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2551      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2552        if (rows.empty()) return;
2553        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2554      if (!it) return;      if (!it) return;
2555      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2556        gig::Sample* sample = NULL;
2557      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2558      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2559          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2560          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2561          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2562          if (!it) return;          if (!it) return;
2563          row = *it;          if (!replace) row = *it;
2564          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2565          if (!group) return;          if (!group) return;
2566      }      }
2567        if (replace && !sample) return;
2568    
2569      // show 'browse for file' dialog      // show 'browse for file' dialog
2570      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2571      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2572      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2573      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
2574    
2575      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2576  #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 2356  void MainWindow::on_action_add_sample() Line 2641  void MainWindow::on_action_add_sample()
2641                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2642                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2643                  }                  }
2644                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2645                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2646                  // file name without path                  // file name without path
2647                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2648                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2408  void MainWindow::on_action_add_sample() Line 2693  void MainWindow::on_action_add_sample()
2693                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2694                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2695                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2696                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2697                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2698                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2699                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2416  void MainWindow::on_action_add_sample() Line 2701  void MainWindow::on_action_add_sample()
2701                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2702                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2703                  // add sample to the tree view                  // add sample to the tree view
2704                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2705                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2706                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2707                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2708                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2709                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2710                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2711                            gig_to_utf8(sample->pInfo->Name);
2712                        rowSample[m_SamplesModel.m_col_sample] = sample;
2713                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2714                    }
2715                  // close sound file                  // close sound file
2716                  sf_close(hFile);                  sf_close(hFile);
2717                  file_changed();                  file_changed();
# Line 2433  void MainWindow::on_action_add_sample() Line 2722  void MainWindow::on_action_add_sample()
2722          }          }
2723          // 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
2724          if (!error_files.empty()) {          if (!error_files.empty()) {
2725              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2726                    (replace
2727                        ? _("Failed to replace sample with:\n")
2728                        : _("Could not add the following sample(s):\n"))
2729                    + error_files;
2730              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2731              msg.run();              msg.run();
2732          }          }
# Line 2476  void MainWindow::on_action_replace_all_s Line 2769  void MainWindow::on_action_replace_all_s
2769      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2770      description.show();      description.show();
2771      entryArea.show_all();      entryArea.show_all();
2772      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2773      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2774      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2775      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2500  void MainWindow::on_action_replace_all_s Line 2793  void MainWindow::on_action_replace_all_s
2793              try              try
2794              {              {
2795                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2796                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2797                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2798                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2799                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2800                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2801                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2802                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2803                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2804                          break;                          break;
2805                      default:                      default:
2806                          sf_close(hFile);                          sf_close(hFile);
# Line 2544  void MainWindow::on_action_replace_all_s Line 2833  void MainWindow::on_action_replace_all_s
2833  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2834      if (!file) return;      if (!file) return;
2835      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2836      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2837      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2838            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2839            if (!it) continue;
2840          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2841          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2842          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2617  void MainWindow::on_action_remove_sample Line 2908  void MainWindow::on_action_remove_sample
2908      }      }
2909  }  }
2910    
2911    void MainWindow::on_action_remove_unused_samples() {
2912        if (!file) return;
2913    
2914        // collect all samples that are not referenced by any instrument
2915        std::list<gig::Sample*> lsamples;
2916        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2917            gig::Sample* sample = file->GetSample(iSample);
2918            bool isUsed = false;
2919            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2920                                  instrument = file->GetNextInstrument())
2921            {
2922                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2923                                  rgn = instrument->GetNextRegion())
2924                {
2925                    for (int i = 0; i < 256; ++i) {
2926                        if (!rgn->pDimensionRegions[i]) continue;
2927                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2928                        isUsed = true;
2929                        goto endOfRefSearch;
2930                    }
2931                }
2932            }
2933            endOfRefSearch:
2934            if (!isUsed) lsamples.push_back(sample);
2935        }
2936    
2937        if (lsamples.empty()) return;
2938    
2939        // notify everybody that we're going to remove these samples
2940        samples_to_be_removed_signal.emit(lsamples);
2941    
2942        // remove collected samples
2943        try {
2944            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2945                 itSample != lsamples.end(); ++itSample)
2946            {
2947                gig::Sample* sample = *itSample;
2948                // remove sample from the .gig file
2949                file->DeleteSample(sample);
2950                // if sample was just previously added, remove it fro the import queue
2951                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2952                     iter != m_SampleImportQueue.end(); ++iter)
2953                {
2954                    if ((*iter).gig_sample == sample) {
2955                        printf("Removing previously added sample '%s'\n",
2956                               (*iter).sample_path.c_str());
2957                        m_SampleImportQueue.erase(iter);
2958                        break;
2959                    }
2960                }
2961            }
2962        } catch (RIFF::Exception e) {
2963            // show error message
2964            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2965            msg.run();
2966        }
2967    
2968        // notify everybody that we're done with removal
2969        samples_removed_signal.emit();
2970    
2971        dimreg_changed();
2972        file_changed();
2973        __refreshEntireGUI();
2974    }
2975    
2976  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
2977  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)
2978  {  {
# Line 2643  void MainWindow::on_scripts_treeview_dra Line 2999  void MainWindow::on_scripts_treeview_dra
2999                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
3000  }  }
3001    
3002    // see comment on on_sample_treeview_drag_begin()
3003    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3004    {
3005        first_call_to_drag_data_get = true;
3006    }
3007    
3008    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
3009                                                           Gtk::SelectionData& selection_data, guint, guint)
3010    {
3011        if (!first_call_to_drag_data_get) return;
3012        first_call_to_drag_data_get = false;
3013    
3014        // get selected source instrument
3015        gig::Instrument* src = NULL;
3016        {
3017            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3018            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3019            if (!rows.empty()) {
3020                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3021                if (it) {
3022                    Gtk::TreeModel::Row row = *it;
3023                    src = row[m_Columns.m_col_instr];
3024                }
3025            }
3026        }
3027        if (!src) return;
3028    
3029        // pass the source gig::Instrument as pointer
3030        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
3031                           sizeof(src)/*length of data in bytes*/);
3032    }
3033    
3034    void MainWindow::on_instruments_treeview_drop_drag_data_received(
3035        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
3036        const Gtk::SelectionData& selection_data, guint, guint time)
3037    {
3038        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
3039        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
3040            return;
3041    
3042        gig::Instrument* dst = NULL;
3043        {
3044            Gtk::TreeModel::Path path;
3045            const bool found = m_TreeView.get_path_at_pos(x, y, path);
3046            if (!found) return;
3047    
3048            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
3049            if (!iter) return;
3050            Gtk::TreeModel::Row row = *iter;
3051            dst = row[m_Columns.m_col_instr];
3052        }
3053        if (!dst) return;
3054    
3055        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
3056        src->MoveTo(dst);
3057        __refreshEntireGUI();
3058        select_instrument(src);
3059    }
3060    
3061  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
3062  // 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
3063  // 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 2661  void MainWindow::on_sample_treeview_drag Line 3076  void MainWindow::on_sample_treeview_drag
3076      // get selected sample      // get selected sample
3077      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3078      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3079      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3080      if (it) {      if (!rows.empty()) {
3081          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3082          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3083                Gtk::TreeModel::Row row = *it;
3084                sample = row[m_SamplesModel.m_col_sample];
3085            }
3086      }      }
3087      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3088      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 2804  void MainWindow::script_double_clicked(c Line 3222  void MainWindow::script_double_clicked(c
3222      if (!script) return;      if (!script) return;
3223    
3224      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3225        editor->signal_script_to_be_changed.connect(
3226            signal_script_to_be_changed.make_slot()
3227        );
3228        editor->signal_script_changed.connect(
3229            signal_script_changed.make_slot()
3230        );
3231      editor->setScript(script);      editor->setScript(script);
3232      //editor->reparent(*this);      //editor->reparent(*this);
3233      editor->show();      editor->show();
# Line 2857  void MainWindow::on_action_combine_instr Line 3281  void MainWindow::on_action_combine_instr
3281    
3282  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3283      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3284      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3285        if (rows.empty()) return;
3286        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3287      if (!it) return;      if (!it) return;
3288      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3289      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2865  void MainWindow::on_action_view_referenc Line 3291  void MainWindow::on_action_view_referenc
3291    
3292      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3293      d->setSample(sample);      d->setSample(sample);
3294        d->dimension_region_selected.connect(
3295            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3296        );
3297      d->show_all();      d->show_all();
3298      d->resize(500, 400);      d->resize(500, 400);
3299      d->run();      d->run();
# Line 2976  void MainWindow::on_action_merge_files() Line 3405  void MainWindow::on_action_merge_files()
3405      }      }
3406    
3407      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3408      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3409      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3410      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3411  #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 2995  void MainWindow::on_action_merge_files() Line 3424  void MainWindow::on_action_merge_files()
3424      // show warning in the file picker dialog      // show warning in the file picker dialog
3425      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3426      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3427      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3428        warningIcon.set_from_icon_name("dialog-warning",
3429                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3430      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3431  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3432      view::WrapLabel description;      view::WrapLabel description;
# Line 3018  void MainWindow::on_action_merge_files() Line 3449  void MainWindow::on_action_merge_files()
3449      descriptionArea.show_all();      descriptionArea.show_all();
3450    
3451      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3452          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3453                   static_cast<void*>(Glib::Threads::Thread::self()));
3454          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3455    
3456          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3030  void MainWindow::on_action_merge_files() Line 3462  void MainWindow::on_action_merge_files()
3462          }          }
3463    
3464          // update GUI          // update GUI
3465          __refreshEntireGUI();                  __refreshEntireGUI();
3466      }      }
3467  }  }
3468    

Legend:
Removed from v.2694  
changed lines
  Added in v.2994

  ViewVC Help
Powered by ViewVC