/[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 2845 by persson, Sun Sep 20 10:18:22 2015 UTC revision 3144 by schoenebeck, Wed May 3 19:00:11 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 57  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
67      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
68        labelLegend(_("Legend:")),
69        labelNoSample(_(" No Sample")),
70        labelMissingSample(_(" Missing some Sample(s)")),
71        labelLooped(_(" Looped")),
72        labelSomeLoops(_(" Some Loop(s)"))
73  {  {
74        loadBuiltInPix();
75    
76  //    set_border_width(5);  //    set_border_width(5);
77  //    set_default_size(400, 200);  //    set_default_size(400, 200);
78    
   
79      add(m_VBox);      add(m_VBox);
80    
81      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 109  MainWindow::MainWindow() :
109      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
110      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
111      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
112        {
113            legend_hbox.add(labelLegend);
114    
115            imageNoSample.set(redDot);
116            imageNoSample.set_alignment(Gtk::ALIGN_END);
117            labelNoSample.set_alignment(Gtk::ALIGN_START);
118            legend_hbox.add(imageNoSample);
119            legend_hbox.add(labelNoSample);
120    
121            imageMissingSample.set(yellowDot);
122            imageMissingSample.set_alignment(Gtk::ALIGN_END);
123            labelMissingSample.set_alignment(Gtk::ALIGN_START);
124            legend_hbox.add(imageMissingSample);
125            legend_hbox.add(labelMissingSample);
126    
127            imageLooped.set(blackLoop);
128            imageLooped.set_alignment(Gtk::ALIGN_END);
129            labelLooped.set_alignment(Gtk::ALIGN_START);
130            legend_hbox.add(imageLooped);
131            legend_hbox.add(labelLooped);
132    
133            imageSomeLoops.set(grayLoop);
134            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
135            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageSomeLoops);
137            legend_hbox.add(labelSomeLoops);
138    
139            legend_hbox.show_all_children();
140        }
141        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
142      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
143    
144      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 162  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
199      );      );
200      actionGroup->add(      actionGroup->add(
201          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
202          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
203      );      );
204      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
205    
206      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
207    
208        const Gdk::ModifierType primaryModifierKey =
209    #if defined(__APPLE__)
210        Gdk::META_MASK; // Cmd key on Mac
211    #else
212        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
213    #endif
214    
215        actionGroup->add(Gtk::Action::create("CopyDimRgn",
216                                             _("Copy selected dimension region")),
217                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
218                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
219    
220        actionGroup->add(Gtk::Action::create("PasteDimRgn",
221                                             _("Paste dimension region")),
222                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
226                                             _("Select Previous Region")),
227                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
228                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
229    
230        actionGroup->add(Gtk::Action::create("SelectNextRegion",
231                                             _("Select Next Region")),
232                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
233                         sigc::mem_fun(*this, &MainWindow::select_next_region));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
236                                             _("Select Previous Dimension Region Zone")),
237                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
241                                             _("Select Next Dimension Region Zone")),
242                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
243                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
246                                             _("Select Previous Dimension")),
247                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimension",
251                                             _("Select Next Dimension")),
252                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
254    
255        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
256                                             _("Add Previous Dimension Region Zone to Selection")),
257                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
259    
260        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
261                                             _("Add Next Dimension Region Zone to Selection")),
262                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
264    
265      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
266          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
267      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 185  MainWindow::MainWindow() : Line 278  MainWindow::MainWindow() :
278      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
279    
280    
281      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
282      toggle_action =      toggle_action =
283          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
284      toggle_action->set_active(true);      toggle_action->set_active(true);
285      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
286                       sigc::mem_fun(                       sigc::mem_fun(
287                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
288    
289        toggle_action =
290            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
291        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
292        actionGroup->add(toggle_action,
293                         sigc::mem_fun(
294                             *this, &MainWindow::on_auto_restore_win_dim));
295    
296        toggle_action =
297            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
298        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
299        actionGroup->add(toggle_action,
300                         sigc::mem_fun(
301                             *this, &MainWindow::on_save_with_temporary_file));
302    
303      actionGroup->add(      actionGroup->add(
304          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
305          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
# Line 328  MainWindow::MainWindow() : Line 436  MainWindow::MainWindow() :
436          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
437          "    </menu>"          "    </menu>"
438          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
439            "      <menuitem action='CopyDimRgn'/>"
440            "      <menuitem action='PasteDimRgn'/>"
441            "      <separator/>"
442            "      <menuitem action='SelectPrevRegion'/>"
443            "      <menuitem action='SelectNextRegion'/>"
444            "      <separator/>"
445            "      <menuitem action='SelectPrevDimension'/>"
446            "      <menuitem action='SelectNextDimension'/>"
447            "      <menuitem action='SelectPrevDimRgnZone'/>"
448            "      <menuitem action='SelectNextDimRgnZone'/>"
449            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
450            "      <menuitem action='SelectAddNextDimRgnZone'/>"
451            "      <separator/>"
452          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
453          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
454          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
# Line 364  MainWindow::MainWindow() : Line 485  MainWindow::MainWindow() :
485          "    </menu>"          "    </menu>"
486          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
487          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
488            "      <menuitem action='AutoRestoreWinDim'/>"
489          "      <separator/>"          "      <separator/>"
490          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
491          "    </menu>"          "    </menu>"
# Line 375  MainWindow::MainWindow() : Line 497  MainWindow::MainWindow() :
497          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
498          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
499          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
500            "      <menuitem action='SaveWithTemporaryFile'/>"
501          "    </menu>"          "    </menu>"
502          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
503          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 462  MainWindow::MainWindow() : Line 585  MainWindow::MainWindow() :
585      }      }
586      {      {
587          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
588                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
589            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
590        }
591        {
592            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
593              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
594          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
595      }      }
# Line 499  MainWindow::MainWindow() : Line 627  MainWindow::MainWindow() :
627      // Create the Tree model:      // Create the Tree model:
628      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
629      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
630        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
631      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
632      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
633          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
634      );      );
635    
636      // Add the TreeView's view columns:      // Add the TreeView's view columns:
637      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
638      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
639        m_TreeView.set_headers_visible(true);
640            
641      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
642      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 529  MainWindow::MainWindow() : Line 659  MainWindow::MainWindow() :
659      // create samples treeview (including its data model)      // create samples treeview (including its data model)
660      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
661      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
662        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
663      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
664      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
665      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 680  MainWindow::MainWindow() : Line 811  MainWindow::MainWindow() :
811    
812      // select 'Instruments' tab by default      // select 'Instruments' tab by default
813      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
814      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
815    
816        Gtk::Clipboard::get()->signal_owner_change().connect(
817            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
818        );
819        updateClipboardPasteAvailable();
820        updateClipboardCopyAvailable();
821  }  }
822    
823  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 706  void MainWindow::region_changed() Line 843  void MainWindow::region_changed()
843  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
844  {  {
845      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
846      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
847          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
848        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
849      if (it) {      if (it) {
850          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
851          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 750  void MainWindow::update_dimregs() Line 888  void MainWindow::update_dimregs()
888              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
889          }          }
890      }      }
891    
892        m_DimRegionChooser.setModifyAllRegions(all_regions);
893        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
894        m_DimRegionChooser.setModifyBothChannels(stereo);
895    
896        updateClipboardCopyAvailable();
897  }  }
898    
899  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 767  void MainWindow::dimreg_changed() Line 911  void MainWindow::dimreg_changed()
911  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
912  {  {
913      // select item in instrument menu      // select item in instrument menu
914      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
915      if (it) {      if (!rows.empty()) {
916          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
917          int index = path[0];          if (it) {
918          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
919              instrument_menu->get_children();              int index = path[0];
920          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
921                    instrument_menu->get_children();
922                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
923            }
924      }      }
925    
926      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 798  void Loader::progress_callback(float fra Line 945  void Loader::progress_callback(float fra
945      progress_dispatcher();      progress_dispatcher();
946  }  }
947    
948    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
949    // make sure stack is 16-byte aligned for SSE instructions
950    __attribute__((force_align_arg_pointer))
951    #endif
952  void Loader::thread_function()  void Loader::thread_function()
953  {  {
954      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 877  void Saver::progress_callback(float frac Line 1028  void Saver::progress_callback(float frac
1028      progress_dispatcher.emit();      progress_dispatcher.emit();
1029  }  }
1030    
1031    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1032    // make sure stack is 16-byte aligned for SSE instructions
1033    __attribute__((force_align_arg_pointer))
1034    #endif
1035  void Saver::thread_function()  void Saver::thread_function()
1036  {  {
1037      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 889  void Saver::thread_function() Line 1044  void Saver::thread_function()
1044    
1045          // if no filename was provided, that means "save", if filename was provided means "save as"          // if no filename was provided, that means "save", if filename was provided means "save as"
1046          if (filename.empty()) {          if (filename.empty()) {
1047              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1048                    // save directly over the existing .gig file
1049                    // (requires less disk space than solution below
1050                    // but may be slower)
1051                    gig->Save(&progress);
1052                } else {
1053                    // save the file as separate temporary file first,
1054                    // then move the saved file over the old file
1055                    // (may result in performance speedup during save)
1056                    String tmpname = filename + ".TMP";
1057                    gig->Save(tmpname, &progress);
1058                    #if defined(WIN32)
1059                    if (!DeleteFile(filename.c_str())) {
1060                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1061                    }
1062                    #else // POSIX ...
1063                    if (unlink(filename.c_str())) {
1064                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1065                    }
1066                    #endif
1067                    if (rename(tmpname.c_str(), filename.c_str())) {
1068                        #if defined(WIN32)
1069                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1070                        #else
1071                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1072                        #endif
1073                    }
1074                }
1075          } else {          } else {
1076              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1077          }          }
# Line 1344  void MainWindow::__import_queued_samples Line 1526  void MainWindow::__import_queued_samples
1526      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1527      Glib::ustring error_files;      Glib::ustring error_files;
1528      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1529      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1530           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1531          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1532          SF_INFO info;          SF_INFO info;
1533          info.format = 0;          info.format = 0;
1534          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
1535          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1536          try {          try {
1537              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1372  void MainWindow::__import_queued_samples Line 1554  void MainWindow::__import_queued_samples
1554                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1555              }              }
1556    
1557                // reset write position for sample
1558                iter->first->SetPos(0);
1559    
1560              const int bufsize = 10000;              const int bufsize = 10000;
1561              switch (bitdepth) {              switch (bitdepth) {
1562                  case 16: {                  case 16: {
# Line 1381  void MainWindow::__import_queued_samples Line 1566  void MainWindow::__import_queued_samples
1566                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1567                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1568                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1569                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1570                          cnt -= n;                          cnt -= n;
1571                      }                      }
1572                      delete[] buffer;                      delete[] buffer;
# Line 1401  void MainWindow::__import_queued_samples Line 1586  void MainWindow::__import_queued_samples
1586                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1587                          }                          }
1588                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1589                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1590                          cnt -= n;                          cnt -= n;
1591                      }                      }
1592                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1412  void MainWindow::__import_queued_samples Line 1597  void MainWindow::__import_queued_samples
1597              // cleanup              // cleanup
1598              sf_close(hFile);              sf_close(hFile);
1599              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1600              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1601              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1602              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1603              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1604              ++iter;              ++iter;
1605              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1606          } catch (std::string what) {          } catch (std::string what) {
1607              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1608              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1609              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1610              ++iter;              ++iter;
1611          }          }
1612      }      }
# Line 1463  void MainWindow::on_action_help_about() Line 1648  void MainWindow::on_action_help_about()
1648      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1649  #endif  #endif
1650      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1651      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1652      const std::string sComment =      const std::string sComment =
1653          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1654          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1758  void MainWindow::load_gig(gig::File* gig Line 1943  void MainWindow::load_gig(gig::File* gig
1943      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1944    
1945      instrument_name_connection.block();      instrument_name_connection.block();
1946        int index = 0;
1947      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1948           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1949          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1950    
1951          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1952          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1953            row[m_Columns.m_col_nr] = index;
1954          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1955          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1956    
# Line 1836  bool MainWindow::instr_props_set_instrum Line 2023  bool MainWindow::instr_props_set_instrum
2023  {  {
2024      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2025    
2026      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2027          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2028            instrumentProps.hide();
2029            return false;
2030        }
2031        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2032      if (it) {      if (it) {
2033          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2034          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1890  void MainWindow::show_midi_rules() Line 2081  void MainWindow::show_midi_rules()
2081  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2082      if (!file) return;      if (!file) return;
2083      // get selected instrument      // get selected instrument
2084      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2085      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2086        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2087      if (!it) return;      if (!it) return;
2088      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2089      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1918  void MainWindow::on_action_view_status_b Line 2110  void MainWindow::on_action_view_status_b
2110      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2111  }  }
2112    
2113    void MainWindow::on_auto_restore_win_dim() {
2114        Gtk::CheckMenuItem* item =
2115            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2116        if (!item) {
2117            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2118            return;
2119        }
2120        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2121    }
2122    
2123    void MainWindow::on_save_with_temporary_file() {
2124        Gtk::CheckMenuItem* item =
2125            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2126        if (!item) {
2127            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2128            return;
2129        }
2130        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2131    }
2132    
2133  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2134      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2135          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1991  void MainWindow::select_instrument(gig:: Line 2203  void MainWindow::select_instrument(gig::
2203          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2204              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2205              show_intruments_tab();              show_intruments_tab();
2206                m_TreeView.get_selection()->unselect_all();
2207              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2208              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2209                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2210              );              if (!rows.empty())
2211              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2212              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2213          }          }
2214      }      }
# Line 2012  bool MainWindow::select_dimension_region Line 2225  bool MainWindow::select_dimension_region
2225          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2226              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2227              show_intruments_tab();              show_intruments_tab();
2228                m_TreeView.get_selection()->unselect_all();
2229              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2230              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2231                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2232              );              if (!rows.empty())
2233              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2234              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2235    
2236              // select respective region in the region selector              // select respective region in the region selector
# Line 2042  void MainWindow::select_sample(gig::Samp Line 2256  void MainWindow::select_sample(gig::Samp
2256              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2257              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2258                  show_samples_tab();                  show_samples_tab();
2259                    m_TreeViewSamples.get_selection()->unselect_all();
2260                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2261                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2262                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2263                  );                  if (rows.empty()) return;
2264                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2265                  return;                  return;
2266              }              }
2267          }          }
# Line 2055  void MainWindow::select_sample(gig::Samp Line 2270  void MainWindow::select_sample(gig::Samp
2270    
2271  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2272      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2273            // by default if Ctrl keys is pressed down, then a mouse right-click
2274            // does not select the respective row, so we must assure this
2275            // programmatically ...
2276            /*{
2277                Gtk::TreeModel::Path path;
2278                Gtk::TreeViewColumn* pColumn = NULL;
2279                int cellX, cellY;
2280                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2281                    (int)button->x, (int)button->y,
2282                    path, pColumn, cellX, cellY
2283                );
2284                if (bSuccess) {
2285                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2286                        printf("not selected !!!\n");
2287                        m_TreeViewSamples.get_selection()->select(path);
2288                    }
2289                }
2290            }*/
2291    
2292          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2293              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2294          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2295          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2296          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2297          bool group_selected  = false;          const int n = rows.size();
2298          bool sample_selected = false;          int nGroups  = 0;
2299          if (it) {          int nSamples = 0;
2300            for (int r = 0; r < n; ++r) {
2301                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2302                if (!it) continue;
2303              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2304              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2305              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2306          }          }
2307            
               
2308          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2309              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2310          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2311              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2312          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2313              set_sensitive(file);              set_sensitive(file);
2314          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2315              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2316          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2317              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2318          // show sample popup          // show sample popup
2319          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2320    
2321          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2322              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2323          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2324              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2325          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2326              set_sensitive(file);              set_sensitive(file);
2327          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2328              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2329          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2330              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2331      }      }
2332  }  }
2333    
# Line 2170  void MainWindow::add_instrument(gig::Ins Line 2406  void MainWindow::add_instrument(gig::Ins
2406      instrument_name_connection.block();      instrument_name_connection.block();
2407      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2408      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2409        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2410      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2411      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2412      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2198  void MainWindow::on_action_duplicate_ins Line 2435  void MainWindow::on_action_duplicate_ins
2435      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2436      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2437      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2438      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2439      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2440      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2441      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2442      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2443                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2444      // duplicate the orginal instrument              if (instrOrig) {
2445      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2446      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2447          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2448          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2449                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2450    
2451      add_instrument(instrNew);                  add_instrument(instrNew);
2452                }
2453            }
2454        }
2455  }  }
2456    
2457  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2227  void MainWindow::on_action_remove_instru Line 2468  void MainWindow::on_action_remove_instru
2468      }      }
2469    
2470      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2471      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2472      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2473            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2474            if (!it) continue;
2475          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2476          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2477          try {          try {
# Line 2243  void MainWindow::on_action_remove_instru Line 2486  void MainWindow::on_action_remove_instru
2486    
2487              // remove row from instruments tree view              // remove row from instruments tree view
2488              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2489                // update "Nr" column of all instrument rows
2490                {
2491                    int index = 0;
2492                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2493                         it != m_refTreeModel->children().end(); ++it, ++index)
2494                    {
2495                        Gtk::TreeModel::Row row = *it;
2496                        row[m_Columns.m_col_nr] = index;
2497                    }
2498                }
2499    
2500  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2501              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2340  void MainWindow::on_action_edit_script() Line 2593  void MainWindow::on_action_edit_script()
2593      if (!script) return;      if (!script) return;
2594    
2595      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2596        editor->signal_script_to_be_changed.connect(
2597            signal_script_to_be_changed.make_slot()
2598        );
2599        editor->signal_script_changed.connect(
2600            signal_script_changed.make_slot()
2601        );
2602      editor->setScript(script);      editor->setScript(script);
2603      //editor->reparent(*this);      //editor->reparent(*this);
2604      editor->show();      editor->show();
# Line 2418  void MainWindow::add_or_replace_sample(b Line 2677  void MainWindow::add_or_replace_sample(b
2677    
2678      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2679      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2680      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2681        if (rows.empty()) return;
2682        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2683      if (!it) return;      if (!it) return;
2684      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2685      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2567  void MainWindow::add_or_replace_sample(b Line 2828  void MainWindow::add_or_replace_sample(b
2828                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2829                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2830                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2831                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2832                  // add sample to the tree view                  // add sample to the tree view
2833                  if (replace) {                  if (replace) {
2834                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2677  void MainWindow::on_action_replace_all_s Line 2938  void MainWindow::on_action_replace_all_s
2938                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2939                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2940                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
2941                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2942                  sf_close(hFile);                  sf_close(hFile);
2943                  file_changed();                  file_changed();
2944              }              }
# Line 2701  void MainWindow::on_action_replace_all_s Line 2962  void MainWindow::on_action_replace_all_s
2962  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2963      if (!file) return;      if (!file) return;
2964      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2965      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2966      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2967            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2968            if (!it) continue;
2969          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2970          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2971          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2727  void MainWindow::on_action_remove_sample Line 2990  void MainWindow::on_action_remove_sample
2990                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
2991                  // them from the import queue                  // them from the import queue
2992                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
2993                       member != members.end(); ++member) {                       member != members.end(); ++member)
2994                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
2995                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
2996                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
2997                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
2998                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
2999                      }                      }
3000                  }                  }
3001                  file_changed();                  file_changed();
# Line 2750  void MainWindow::on_action_remove_sample Line 3010  void MainWindow::on_action_remove_sample
3010                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3011                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3012                  // the import queue                  // the import queue
3013                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3014                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3015                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3016                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3017                  }                  }
3018                  dimreg_changed();                  dimreg_changed();
3019                  file_changed();                  file_changed();
# Line 2813  void MainWindow::on_action_remove_unused Line 3069  void MainWindow::on_action_remove_unused
3069              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3070              // remove sample from the .gig file              // remove sample from the .gig file
3071              file->DeleteSample(sample);              file->DeleteSample(sample);
3072              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3073              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3074                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3075              {                         m_SampleImportQueue[sample].sample_path.c_str());
3076                  if ((*iter).gig_sample == sample) {                  m_SampleImportQueue.erase(sample);
                     printf("Removing previously added sample '%s'\n",  
                            (*iter).sample_path.c_str());  
                     m_SampleImportQueue.erase(iter);  
                     break;  
                 }  
3077              }              }
3078          }          }
3079      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2881  void MainWindow::on_instruments_treeview Line 3132  void MainWindow::on_instruments_treeview
3132      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3133      {      {
3134          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3135          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3136          if (it) {          if (!rows.empty()) {
3137              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3138              src = row[m_Columns.m_col_instr];              if (it) {
3139                    Gtk::TreeModel::Row row = *it;
3140                    src = row[m_Columns.m_col_instr];
3141                }
3142          }          }
3143      }      }
3144      if (!src) return;      if (!src) return;
# Line 2939  void MainWindow::on_sample_treeview_drag Line 3193  void MainWindow::on_sample_treeview_drag
3193      // get selected sample      // get selected sample
3194      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3195      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3196      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3197      if (it) {      if (!rows.empty()) {
3198          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3199          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3200                Gtk::TreeModel::Row row = *it;
3201                sample = row[m_SamplesModel.m_col_sample];
3202            }
3203      }      }
3204      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3205      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 3082  void MainWindow::script_double_clicked(c Line 3339  void MainWindow::script_double_clicked(c
3339      if (!script) return;      if (!script) return;
3340    
3341      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3342        editor->signal_script_to_be_changed.connect(
3343            signal_script_to_be_changed.make_slot()
3344        );
3345        editor->signal_script_changed.connect(
3346            signal_script_changed.make_slot()
3347        );
3348      editor->setScript(script);      editor->setScript(script);
3349      //editor->reparent(*this);      //editor->reparent(*this);
3350      editor->show();      editor->show();
# Line 3135  void MainWindow::on_action_combine_instr Line 3398  void MainWindow::on_action_combine_instr
3398    
3399  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3400      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3401      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3402        if (rows.empty()) return;
3403        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3404      if (!it) return;      if (!it) return;
3405      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3406      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3384  void MainWindow::show_scripts_tab() { Line 3649  void MainWindow::show_scripts_tab() {
3649      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3650  }  }
3651    
3652    void MainWindow::select_prev_region() {
3653        m_RegionChooser.select_prev_region();
3654    }
3655    
3656    void MainWindow::select_next_region() {
3657        m_RegionChooser.select_next_region();
3658    }
3659    
3660    void MainWindow::select_next_dim_rgn_zone() {
3661        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3662        m_DimRegionChooser.select_next_dimzone();
3663    }
3664    
3665    void MainWindow::select_prev_dim_rgn_zone() {
3666        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3667        m_DimRegionChooser.select_prev_dimzone();
3668    }
3669    
3670    void MainWindow::select_add_next_dim_rgn_zone() {
3671        m_DimRegionChooser.select_next_dimzone(true);
3672    }
3673    
3674    void MainWindow::select_add_prev_dim_rgn_zone() {
3675        m_DimRegionChooser.select_prev_dimzone(true);
3676    }
3677    
3678    void MainWindow::select_prev_dimension() {
3679        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3680        m_DimRegionChooser.select_prev_dimension();
3681    }
3682    
3683    void MainWindow::select_next_dimension() {
3684        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3685        m_DimRegionChooser.select_next_dimension();
3686    }
3687    
3688    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3689        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3690    
3691    void MainWindow::copy_selected_dimrgn() {
3692        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3693        if (!pDimRgn) {
3694            updateClipboardPasteAvailable();
3695            updateClipboardCopyAvailable();
3696            return;
3697        }
3698    
3699        std::vector<Gtk::TargetEntry> targets;
3700        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3701    
3702        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3703        clipboard->set(
3704            targets,
3705            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3706            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3707        );
3708    
3709        m_serializationArchive.serialize(pDimRgn);
3710    
3711        updateClipboardPasteAvailable();
3712    }
3713    
3714    void MainWindow::paste_copied_dimrgn() {
3715        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3716        clipboard->request_contents(
3717            CLIPBOARD_DIMENSIONREGION_TARGET,
3718            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3719        );
3720        updateClipboardPasteAvailable();
3721    }
3722    
3723    void MainWindow::updateClipboardPasteAvailable() {
3724        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3725        clipboard->request_targets(
3726            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3727        );
3728    }
3729    
3730    void MainWindow::updateClipboardCopyAvailable() {
3731        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3732        static_cast<Gtk::MenuItem*>(
3733            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3734        )->set_sensitive(bDimensionRegionCopyIsPossible);
3735    }
3736    
3737    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3738        updateClipboardPasteAvailable();
3739    }
3740    
3741    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3742        const std::string target = selection_data.get_target();
3743        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3744            selection_data.set(
3745                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3746                &m_serializationArchive.rawData()[0],
3747                m_serializationArchive.rawData().size()
3748            );
3749        } else {
3750            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3751        }
3752    }
3753    
3754    void MainWindow::on_clipboard_clear() {
3755        m_serializationArchive.clear();
3756        updateClipboardPasteAvailable();
3757        updateClipboardCopyAvailable();
3758    }
3759    
3760    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3761        const std::string target = selection_data.get_target();
3762        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3763            gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3764            if (!pDimRgn) return;
3765    
3766            Glib::ustring errorText;
3767            try {
3768                m_serializationArchive.decode(
3769                    selection_data.get_data(), selection_data.get_length()
3770                );
3771    
3772                for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3773                     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3774                {
3775                    gig::DimensionRegion* pDimRgn = *itDimReg;
3776    
3777                    dimreg_to_be_changed_signal.emit(pDimRgn);
3778    
3779                    m_serializationArchive.deserialize(pDimRgn);
3780    
3781                    dimreg_changed_signal.emit(pDimRgn);
3782                }
3783    
3784                //region_changed()
3785                file_changed();
3786                dimreg_changed();
3787    
3788            } catch (Serialization::Exception e) {
3789                errorText = e.Message;
3790            } catch (...) {
3791                errorText = _("Unknown exception during deserialization decoding");
3792            }
3793            if (!errorText.empty()) {
3794                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3795                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3796                msg.run();
3797            }
3798        }
3799    }
3800    
3801    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3802        const bool bDimensionRegionPasteIsPossible =
3803            std::find(targets.begin(), targets.end(),
3804                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3805    
3806        static_cast<Gtk::MenuItem*>(
3807            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3808        )->set_sensitive(bDimensionRegionPasteIsPossible);
3809    }
3810    
3811  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3812      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3813  }  }

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

  ViewVC Help
Powered by ViewVC