/[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 2772 by schoenebeck, Thu Jun 11 20:29:22 2015 UTC revision 3021 by persson, Sun Oct 23 07:24:40 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 186  MainWindow::MainWindow() : Line 192  MainWindow::MainWindow() :
192      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
193                       sigc::mem_fun(                       sigc::mem_fun(
194                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
195    
196        toggle_action =
197            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
198        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
199        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(      actionGroup->add(
211          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
212          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
213      );                      );                
214    
215      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
216      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("About", _("_About")),
                                          action->property_label()));  
     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::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 206  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 229  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 245  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 257  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(
# Line 293  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 352  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/>"          "      <separator/>"
384          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
385          "    </menu>"          "    </menu>"
# Line 362  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 430  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"));              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)."));          item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
470          // copy tooltip to popup menu          // copy tooltip to popup menu
# Line 444  MainWindow::MainWindow() : Line 479  MainWindow::MainWindow() :
479      }      }
480      {      {
481          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          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 481  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.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."));      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      // establish drag&drop within the instrument tree view, allowing to reorder
536      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 511  MainWindow::MainWindow() : Line 553  MainWindow::MainWindow() :
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 591  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 686  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 747  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 778  void Loader::progress_callback(float fra Line 827  void Loader::progress_callback(float fra
827      progress_dispatcher();      progress_dispatcher();
828  }  }
829    
830    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
831    // make sure stack is 16-byte aligned for SSE instructions
832    __attribute__((force_align_arg_pointer))
833    #endif
834  void Loader::thread_function()  void Loader::thread_function()
835  {  {
836      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
837               static_cast<void*>(Glib::Threads::Thread::self()));
838      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
839      try {      try {
840          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 802  void Loader::thread_function() Line 856  void Loader::thread_function()
856  }  }
857    
858  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
859      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
860  {  {
861  }  }
862    
# Line 813  void Loader::launch() Line 867  void Loader::launch()
867  #else  #else
868      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
869  #endif  #endif
870      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
871  }  }
872    
873  float Loader::get_progress()  float Loader::get_progress()
# Line 856  void Saver::progress_callback(float frac Line 910  void Saver::progress_callback(float frac
910      progress_dispatcher.emit();      progress_dispatcher.emit();
911  }  }
912    
913    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
914    // make sure stack is 16-byte aligned for SSE instructions
915    __attribute__((force_align_arg_pointer))
916    #endif
917  void Saver::thread_function()  void Saver::thread_function()
918  {  {
919      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
920               static_cast<void*>(Glib::Threads::Thread::self()));
921      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
922      try {      try {
923          gig::progress_t progress;          gig::progress_t progress;
# Line 867  void Saver::thread_function() Line 926  void Saver::thread_function()
926    
927          // 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"
928          if (filename.empty()) {          if (filename.empty()) {
929              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
930                    // save directly over the existing .gig file
931                    // (requires less disk space than solution below
932                    // but may be slower)
933                    gig->Save(&progress);
934                } else {
935                    // save the file as separate temporary file first,
936                    // then move the saved file over the old file
937                    // (may result in performance speedup during save)
938                    String tmpname = filename + ".TMP";
939                    gig->Save(tmpname, &progress);
940                    #if defined(WIN32)
941                    if (!DeleteFile(filename.c_str())) {
942                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
943                    }
944                    #else // POSIX ...
945                    if (unlink(filename.c_str())) {
946                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
947                    }
948                    #endif
949                    if (rename(tmpname.c_str(), filename.c_str())) {
950                        #if defined(WIN32)
951                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
952                        #else
953                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
954                        #endif
955                    }
956                }
957          } else {          } else {
958              gig->Save(filename, &progress);              gig->Save(filename, &progress);
959          }          }
# Line 895  void Saver::launch() Line 981  void Saver::launch()
981  #else  #else
982      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
983  #endif  #endif
984      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
985  }  }
986    
987  float Saver::get_progress()  float Saver::get_progress()
# Line 992  bool MainWindow::close_confirmation_dial Line 1078  bool MainWindow::close_confirmation_dial
1078      g_free(msg);      g_free(msg);
1079      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."));
1080      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1081      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1082      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);
1083      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1084      int response = dialog.run();      int response = dialog.run();
1085      dialog.hide();      dialog.hide();
# Line 1024  bool MainWindow::leaving_shared_mode_dia Line 1110  bool MainWindow::leaving_shared_mode_dia
1110            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1111            "load it."));            "load it."));
1112      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1113      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1114      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1115      int response = dialog.run();      int response = dialog.run();
1116      dialog.hide();      dialog.hide();
# Line 1038  void MainWindow::on_action_file_open() Line 1124  void MainWindow::on_action_file_open()
1124      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1125    
1126      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1127      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1128      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1129      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1130  #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
1131      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1055  void MainWindow::on_action_file_open() Line 1141  void MainWindow::on_action_file_open()
1141      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1142          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1143          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1144          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1145                   static_cast<void*>(Glib::Threads::Thread::self()));
1146          load_file(filename.c_str());          load_file(filename.c_str());
1147          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1148      }      }
# Line 1125  void MainWindow::on_loader_progress() Line 1212  void MainWindow::on_loader_progress()
1212  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1213  {  {
1214      printf("Loader finished!\n");      printf("Loader finished!\n");
1215      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1216               static_cast<void*>(Glib::Threads::Thread::self()));
1217      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1218      progress_dialog->hide();      progress_dialog->hide();
1219  }  }
# Line 1232  void MainWindow::on_action_file_save_as( Line 1320  void MainWindow::on_action_file_save_as(
1320    
1321  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1322  {  {
1323      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1324      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1325      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1326      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1327      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1328    
# Line 1265  bool MainWindow::file_save_as() Line 1353  bool MainWindow::file_save_as()
1353      // show warning in the dialog      // show warning in the dialog
1354      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1355      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1356      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1357        warningIcon.set_from_icon_name("dialog-warning",
1358                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1359      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1360  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1361      view::WrapLabel description;      view::WrapLabel description;
# Line 1317  bool MainWindow::file_save_as() Line 1407  bool MainWindow::file_save_as()
1407  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1408      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1409      Glib::ustring error_files;      Glib::ustring error_files;
1410      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1411      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1412           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1413          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
# Line 1423  void MainWindow::on_action_sync_sampler_ Line 1513  void MainWindow::on_action_sync_sampler_
1513          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1514  }  }
1515    
1516    void MainWindow::on_action_move_root_note_with_region_moved() {
1517        Settings::singleton()->moveRootNoteWithRegionMoved =
1518            !Settings::singleton()->moveRootNoteWithRegionMoved;
1519    }
1520    
1521  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1522  {  {
1523      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1432  void MainWindow::on_action_help_about() Line 1527  void MainWindow::on_action_help_about()
1527      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1528  #endif  #endif
1529      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1530      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");
1531      const std::string sComment =      const std::string sComment =
1532          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1533          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1469  PropDialog::PropDialog() Line 1564  PropDialog::PropDialog()
1564        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1565        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1566        eSubject(_("Subject")),        eSubject(_("Subject")),
1567        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1568        table(2, 1),        table(2, 1),
1569        m_file(NULL)        m_file(NULL)
1570  {  {
# Line 1592  void InstrumentProps::set_MIDIProgram(ui Line 1687  void InstrumentProps::set_MIDIProgram(ui
1687  }  }
1688    
1689  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1690      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1691      table(2,1),      table(2,1),
1692      eName(_("Name")),      eName(_("Name")),
1693      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1727  void MainWindow::load_gig(gig::File* gig Line 1822  void MainWindow::load_gig(gig::File* gig
1822      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1823    
1824      instrument_name_connection.block();      instrument_name_connection.block();
1825        int index = 0;
1826      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1827           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1828          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1829    
1830          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1831          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1832            row[m_Columns.m_col_nr] = index;
1833          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1834          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1835    
# Line 1805  bool MainWindow::instr_props_set_instrum Line 1902  bool MainWindow::instr_props_set_instrum
1902  {  {
1903      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1904    
1905      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1906          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1907            instrumentProps.hide();
1908            return false;
1909        }
1910        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1911      if (it) {      if (it) {
1912          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1913          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1859  void MainWindow::show_midi_rules() Line 1960  void MainWindow::show_midi_rules()
1960  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
1961      if (!file) return;      if (!file) return;
1962      // get selected instrument      // get selected instrument
1963      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1964      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
1965        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1966      if (!it) return;      if (!it) return;
1967      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
1968      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1887  void MainWindow::on_action_view_status_b Line 1989  void MainWindow::on_action_view_status_b
1989      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1990  }  }
1991    
1992    void MainWindow::on_auto_restore_win_dim() {
1993        Gtk::CheckMenuItem* item =
1994            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1995        if (!item) {
1996            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
1997            return;
1998        }
1999        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2000    }
2001    
2002    void MainWindow::on_save_with_temporary_file() {
2003        Gtk::CheckMenuItem* item =
2004            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2005        if (!item) {
2006            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2007            return;
2008        }
2009        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2010    }
2011    
2012  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2013      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2014          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1960  void MainWindow::select_instrument(gig:: Line 2082  void MainWindow::select_instrument(gig::
2082          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2083              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2084              show_intruments_tab();              show_intruments_tab();
2085                m_TreeView.get_selection()->unselect_all();
2086              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2087              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2088                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2089              );              if (!rows.empty())
2090              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2091              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2092          }          }
2093      }      }
# Line 1981  bool MainWindow::select_dimension_region Line 2104  bool MainWindow::select_dimension_region
2104          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2105              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2106              show_intruments_tab();              show_intruments_tab();
2107                m_TreeView.get_selection()->unselect_all();
2108              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2109              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2110                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2111              );              if (!rows.empty())
2112              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2113              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2114    
2115              // select respective region in the region selector              // select respective region in the region selector
# Line 2011  void MainWindow::select_sample(gig::Samp Line 2135  void MainWindow::select_sample(gig::Samp
2135              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2136              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2137                  show_samples_tab();                  show_samples_tab();
2138                    m_TreeViewSamples.get_selection()->unselect_all();
2139                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2140                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2141                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2142                  );                  if (rows.empty()) return;
2143                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2144                  return;                  return;
2145              }              }
2146          }          }
# Line 2024  void MainWindow::select_sample(gig::Samp Line 2149  void MainWindow::select_sample(gig::Samp
2149    
2150  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2151      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2152            // by default if Ctrl keys is pressed down, then a mouse right-click
2153            // does not select the respective row, so we must assure this
2154            // programmatically ...
2155            /*{
2156                Gtk::TreeModel::Path path;
2157                Gtk::TreeViewColumn* pColumn = NULL;
2158                int cellX, cellY;
2159                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2160                    (int)button->x, (int)button->y,
2161                    path, pColumn, cellX, cellY
2162                );
2163                if (bSuccess) {
2164                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2165                        printf("not selected !!!\n");
2166                        m_TreeViewSamples.get_selection()->select(path);
2167                    }
2168                }
2169            }*/
2170    
2171          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2172              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2173          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2174          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2175          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2176          bool group_selected  = false;          const int n = rows.size();
2177          bool sample_selected = false;          int nGroups  = 0;
2178          if (it) {          int nSamples = 0;
2179            for (int r = 0; r < n; ++r) {
2180                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2181                if (!it) continue;
2182              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2183              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2184              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2185          }          }
2186            
               
2187          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2188              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2189          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2190              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2191          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2192              set_sensitive(file);              set_sensitive(file);
2193          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2194              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2195          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2196              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2197          // show sample popup          // show sample popup
2198          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2199    
2200          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2201              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2202          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2203              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2204          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2205              set_sensitive(file);              set_sensitive(file);
2206          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2207              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2208          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2209              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2210      }      }
2211  }  }
2212    
# Line 2139  void MainWindow::add_instrument(gig::Ins Line 2285  void MainWindow::add_instrument(gig::Ins
2285      instrument_name_connection.block();      instrument_name_connection.block();
2286      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2287      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2288        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2289      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2290      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2291      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2167  void MainWindow::on_action_duplicate_ins Line 2314  void MainWindow::on_action_duplicate_ins
2314      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2315      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2316      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2317      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2318      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2319      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2320      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2321      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2322                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2323      // duplicate the orginal instrument              if (instrOrig) {
2324      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2325      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2326          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2327          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2328                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2329    
2330      add_instrument(instrNew);                  add_instrument(instrNew);
2331                }
2332            }
2333        }
2334  }  }
2335    
2336  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2196  void MainWindow::on_action_remove_instru Line 2347  void MainWindow::on_action_remove_instru
2347      }      }
2348    
2349      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2350      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2351      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2352            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2353            if (!it) continue;
2354          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2355          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2356          try {          try {
# Line 2212  void MainWindow::on_action_remove_instru Line 2365  void MainWindow::on_action_remove_instru
2365    
2366              // remove row from instruments tree view              // remove row from instruments tree view
2367              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2368                // update "Nr" column of all instrument rows
2369                {
2370                    int index = 0;
2371                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2372                         it != m_refTreeModel->children().end(); ++it, ++index)
2373                    {
2374                        Gtk::TreeModel::Row row = *it;
2375                        row[m_Columns.m_col_nr] = index;
2376                    }
2377                }
2378    
2379  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2380              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2309  void MainWindow::on_action_edit_script() Line 2472  void MainWindow::on_action_edit_script()
2472      if (!script) return;      if (!script) return;
2473    
2474      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2475        editor->signal_script_to_be_changed.connect(
2476            signal_script_to_be_changed.make_slot()
2477        );
2478        editor->signal_script_changed.connect(
2479            signal_script_changed.make_slot()
2480        );
2481      editor->setScript(script);      editor->setScript(script);
2482      //editor->reparent(*this);      //editor->reparent(*this);
2483      editor->show();      editor->show();
# Line 2387  void MainWindow::add_or_replace_sample(b Line 2556  void MainWindow::add_or_replace_sample(b
2556    
2557      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2558      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2559      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2560        if (rows.empty()) return;
2561        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2562      if (!it) return;      if (!it) return;
2563      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2564      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2405  void MainWindow::add_or_replace_sample(b Line 2576  void MainWindow::add_or_replace_sample(b
2576    
2577      // show 'browse for file' dialog      // show 'browse for file' dialog
2578      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2579      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2580      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2581      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2582    
2583      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2606  void MainWindow::on_action_replace_all_s Line 2777  void MainWindow::on_action_replace_all_s
2777      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2778      description.show();      description.show();
2779      entryArea.show_all();      entryArea.show_all();
2780      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2781      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2782      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2783      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2630  void MainWindow::on_action_replace_all_s Line 2801  void MainWindow::on_action_replace_all_s
2801              try              try
2802              {              {
2803                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2804                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2805                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2806                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2807                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2808                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2809                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2810                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2811                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2812                          break;                          break;
2813                      default:                      default:
2814                          sf_close(hFile);                          sf_close(hFile);
# Line 2674  void MainWindow::on_action_replace_all_s Line 2841  void MainWindow::on_action_replace_all_s
2841  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2842      if (!file) return;      if (!file) return;
2843      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2844      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2845      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2846            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2847            if (!it) continue;
2848          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2849          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2850          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2854  void MainWindow::on_instruments_treeview Line 3023  void MainWindow::on_instruments_treeview
3023      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3024      {      {
3025          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3026          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3027          if (it) {          if (!rows.empty()) {
3028              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3029              src = row[m_Columns.m_col_instr];              if (it) {
3030                    Gtk::TreeModel::Row row = *it;
3031                    src = row[m_Columns.m_col_instr];
3032                }
3033          }          }
3034      }      }
3035      if (!src) return;      if (!src) return;
# Line 2912  void MainWindow::on_sample_treeview_drag Line 3084  void MainWindow::on_sample_treeview_drag
3084      // get selected sample      // get selected sample
3085      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3086      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3087      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3088      if (it) {      if (!rows.empty()) {
3089          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3090          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3091                Gtk::TreeModel::Row row = *it;
3092                sample = row[m_SamplesModel.m_col_sample];
3093            }
3094      }      }
3095      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3096      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 3055  void MainWindow::script_double_clicked(c Line 3230  void MainWindow::script_double_clicked(c
3230      if (!script) return;      if (!script) return;
3231    
3232      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3233        editor->signal_script_to_be_changed.connect(
3234            signal_script_to_be_changed.make_slot()
3235        );
3236        editor->signal_script_changed.connect(
3237            signal_script_changed.make_slot()
3238        );
3239      editor->setScript(script);      editor->setScript(script);
3240      //editor->reparent(*this);      //editor->reparent(*this);
3241      editor->show();      editor->show();
# Line 3108  void MainWindow::on_action_combine_instr Line 3289  void MainWindow::on_action_combine_instr
3289    
3290  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3291      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3292      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3293        if (rows.empty()) return;
3294        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3295      if (!it) return;      if (!it) return;
3296      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3297      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3230  void MainWindow::on_action_merge_files() Line 3413  void MainWindow::on_action_merge_files()
3413      }      }
3414    
3415      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3416      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3417      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3418      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3419  #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 3249  void MainWindow::on_action_merge_files() Line 3432  void MainWindow::on_action_merge_files()
3432      // show warning in the file picker dialog      // show warning in the file picker dialog
3433      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3434      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3435      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3436        warningIcon.set_from_icon_name("dialog-warning",
3437                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3438      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3439  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3440      view::WrapLabel description;      view::WrapLabel description;
# Line 3272  void MainWindow::on_action_merge_files() Line 3457  void MainWindow::on_action_merge_files()
3457      descriptionArea.show_all();      descriptionArea.show_all();
3458    
3459      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3460          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3461                   static_cast<void*>(Glib::Threads::Thread::self()));
3462          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3463    
3464          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file

Legend:
Removed from v.2772  
changed lines
  Added in v.3021

  ViewVC Help
Powered by ViewVC