/[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 2695 by schoenebeck, Tue Jan 6 18:11:27 2015 UTC revision 3109 by schoenebeck, Sun Feb 12 16:35:03 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
# Line 27  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
 #include <gtkmm/stock.h>  
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
# Line 50  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
67      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
68        labelLegend(_("Legend:")),
69        labelNoSample(_(" No Sample")),
70        labelMissingSample(_(" Missing some Sample(s)")),
71        labelLooped(_(" Looped")),
72        labelSomeLoops(_(" Some Loop(s)"))
73  {  {
74        loadBuiltInPix();
75    
76  //    set_border_width(5);  //    set_border_width(5);
77  //    set_default_size(400, 200);  //    set_default_size(400, 200);
78    
   
79      add(m_VBox);      add(m_VBox);
80    
81      // Handle selection      // Handle selection
# Line 96  MainWindow::MainWindow() : Line 109  MainWindow::MainWindow() :
109      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
110      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
111      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
112        {
113            legend_hbox.add(labelLegend);
114    
115            imageNoSample.set(redDot);
116            imageNoSample.set_alignment(Gtk::ALIGN_END);
117            labelNoSample.set_alignment(Gtk::ALIGN_START);
118            legend_hbox.add(imageNoSample);
119            legend_hbox.add(labelNoSample);
120    
121            imageMissingSample.set(yellowDot);
122            imageMissingSample.set_alignment(Gtk::ALIGN_END);
123            labelMissingSample.set_alignment(Gtk::ALIGN_START);
124            legend_hbox.add(imageMissingSample);
125            legend_hbox.add(labelMissingSample);
126    
127            imageLooped.set(blackLoop);
128            imageLooped.set_alignment(Gtk::ALIGN_END);
129            labelLooped.set_alignment(Gtk::ALIGN_START);
130            legend_hbox.add(imageLooped);
131            legend_hbox.add(labelLooped);
132    
133            imageSomeLoops.set(grayLoop);
134            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
135            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageSomeLoops);
137            legend_hbox.add(labelSomeLoops);
138    
139            legend_hbox.show_all_children();
140        }
141        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
142      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
143    
144      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 110  MainWindow::MainWindow() : Line 153  MainWindow::MainWindow() :
153      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
154    
155      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
156      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
157                         Gtk::AccelKey("<control>n"),
158                       sigc::mem_fun(                       sigc::mem_fun(
159                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
160      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
161          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
162                       sigc::mem_fun(                       sigc::mem_fun(
163                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
164      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
165                         Gtk::AccelKey("<control>s"),
166                       sigc::mem_fun(                       sigc::mem_fun(
167                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
168      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
169                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
172      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
173                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
174                       sigc::mem_fun(                       sigc::mem_fun(
175                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
176      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
177                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
178                       sigc::mem_fun(                       sigc::mem_fun(
179                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
180      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 144  MainWindow::MainWindow() : Line 185  MainWindow::MainWindow() :
185                                           _("_Script Slots...")),                                           _("_Script Slots...")),
186                       sigc::mem_fun(                       sigc::mem_fun(
187                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
188      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
189                         Gtk::AccelKey("<control>q"),
190                       sigc::mem_fun(                       sigc::mem_fun(
191                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
192      actionGroup->add(      actionGroup->add(
# Line 187  MainWindow::MainWindow() : Line 229  MainWindow::MainWindow() :
229                       sigc::mem_fun(                       sigc::mem_fun(
230                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
231    
232      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      toggle_action =
233      actionGroup->add(Gtk::Action::create("MenuHelp",          Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
234                                           action->property_label()));      toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
235      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(toggle_action,
236                         sigc::mem_fun(
237                             *this, &MainWindow::on_auto_restore_win_dim));
238    
239        toggle_action =
240            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
241        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
242        actionGroup->add(toggle_action,
243                         sigc::mem_fun(
244                             *this, &MainWindow::on_save_with_temporary_file));
245    
246        actionGroup->add(
247            Gtk::Action::create("RefreshAll", _("_Refresh All")),
248            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
249        );                
250    
251        actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
252        actionGroup->add(Gtk::Action::create("About", _("_About")),
253                       sigc::mem_fun(                       sigc::mem_fun(
254                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
255      actionGroup->add(      actionGroup->add(
# Line 202  MainWindow::MainWindow() : Line 261  MainWindow::MainWindow() :
261          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
262      );      );
263      actionGroup->add(      actionGroup->add(
264          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
265          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
266      );      );
267    
# Line 225  MainWindow::MainWindow() : Line 284  MainWindow::MainWindow() :
284          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
285      );      );
286    
287        toggle_action =
288            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
289        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
290        actionGroup->add(
291            toggle_action,
292            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
293        );
294    
295    
296      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
297    
# Line 241  MainWindow::MainWindow() : Line 308  MainWindow::MainWindow() :
308    
309      // sample right-click popup actions      // sample right-click popup actions
310      actionGroup->add(      actionGroup->add(
311          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
312          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
313      );      );
314      actionGroup->add(      actionGroup->add(
# Line 253  MainWindow::MainWindow() : Line 320  MainWindow::MainWindow() :
320          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
321      );      );
322      actionGroup->add(      actionGroup->add(
323          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
324          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
325      );      );
326      actionGroup->add(      actionGroup->add(
327            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
328            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
329        );
330        actionGroup->add(
331          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
332          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
333      );      );
334      actionGroup->add(      actionGroup->add(
335            Gtk::Action::create("ReplaceSample",
336                                _("Replace Sample...")),
337            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
338        );
339        actionGroup->add(
340          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
341                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
342          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 280  MainWindow::MainWindow() : Line 356  MainWindow::MainWindow() :
356          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
357      );      );
358      actionGroup->add(      actionGroup->add(
359          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
360          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
361      );      );
362    
# Line 312  MainWindow::MainWindow() : Line 388  MainWindow::MainWindow() :
388          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
389          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
390          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
391            "      <menuitem action='ReplaceSample' />"
392          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
393          "      <separator/>"          "      <separator/>"
394          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
395            "      <menuitem action='RemoveUnusedSamples'/>"
396          "    </menu>"          "    </menu>"
397          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
398          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 337  MainWindow::MainWindow() : Line 415  MainWindow::MainWindow() :
415          "    </menu>"          "    </menu>"
416          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
417          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
418            "      <menuitem action='AutoRestoreWinDim'/>"
419            "      <separator/>"
420            "      <menuitem action='RefreshAll'/>"
421          "    </menu>"          "    </menu>"
422          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
423          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 426  MainWindow::MainWindow() :
426          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
427          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
428          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
429            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
430            "      <menuitem action='SaveWithTemporaryFile'/>"
431          "    </menu>"          "    </menu>"
432          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
433          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 364  MainWindow::MainWindow() : Line 447  MainWindow::MainWindow() :
447          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
448          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
449          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
450            "    <menuitem action='ReplaceSample' />"
451          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
452          "    <separator/>"          "    <separator/>"
453          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
454            "    <menuitem action='RemoveUnusedSamples'/>"
455          "  </popup>"          "  </popup>"
456          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
457          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 411  MainWindow::MainWindow() : Line 496  MainWindow::MainWindow() :
496      }      }
497      {      {
498          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
499                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
500            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."));
501        }
502        {
503            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
504                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
505            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
506            // copy tooltip to popup menu
507            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
508                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
509            item2->set_tooltip_text(item->get_tooltip_text());
510        }
511        {
512            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
513                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
514            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
515        }
516        {
517            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
518                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
519            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
520        }
521        {
522            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
523              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
524          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."));
525      }      }
# Line 448  MainWindow::MainWindow() : Line 557  MainWindow::MainWindow() :
557      // Create the Tree model:      // Create the Tree model:
558      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
559      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
560      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
561        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
562      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
563          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
564      );      );
565    
566      // Add the TreeView's view columns:      // Add the TreeView's view columns:
567      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
568      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
569        m_TreeView.set_headers_visible(true);
570        
571        // establish drag&drop within the instrument tree view, allowing to reorder
572        // the sequence of instruments within the gig file
573        {
574            std::vector<Gtk::TargetEntry> drag_target_instrument;
575            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
576            m_TreeView.drag_source_set(drag_target_instrument);
577            m_TreeView.drag_dest_set(drag_target_instrument);
578            m_TreeView.signal_drag_begin().connect(
579                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
580            );
581            m_TreeView.signal_drag_data_get().connect(
582                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
583            );
584            m_TreeView.signal_drag_data_received().connect(
585                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
586            );
587        }
588    
589      // create samples treeview (including its data model)      // create samples treeview (including its data model)
590      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
591      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
592        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
593      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."));
594      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
595      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 540  MainWindow::MainWindow() : Line 670  MainWindow::MainWindow() :
670          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
671      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
672          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
673        m_RegionChooser.signal_instrument_changed().connect(
674            sigc::mem_fun(*this, &MainWindow::region_changed));
675      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
676          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
677      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 635  void MainWindow::region_changed() Line 767  void MainWindow::region_changed()
767  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
768  {  {
769      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
770      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
771          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
772        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
773      if (it) {      if (it) {
774          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
775          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 679  void MainWindow::update_dimregs() Line 812  void MainWindow::update_dimregs()
812              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
813          }          }
814      }      }
815    
816        m_DimRegionChooser.setModifyAllRegions(all_regions);
817        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
818        m_DimRegionChooser.setModifyBothChannels(stereo);
819  }  }
820    
821  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 696  void MainWindow::dimreg_changed() Line 833  void MainWindow::dimreg_changed()
833  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
834  {  {
835      // select item in instrument menu      // select item in instrument menu
836      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
837      if (it) {      if (!rows.empty()) {
838          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
839          int index = path[0];          if (it) {
840          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
841              instrument_menu->get_children();              int index = path[0];
842          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
843                    instrument_menu->get_children();
844                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
845            }
846      }      }
847    
848      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 727  void Loader::progress_callback(float fra Line 867  void Loader::progress_callback(float fra
867      progress_dispatcher();      progress_dispatcher();
868  }  }
869    
870    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
871    // make sure stack is 16-byte aligned for SSE instructions
872    __attribute__((force_align_arg_pointer))
873    #endif
874  void Loader::thread_function()  void Loader::thread_function()
875  {  {
876      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
877               static_cast<void*>(Glib::Threads::Thread::self()));
878      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
879      try {      try {
880          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 751  void Loader::thread_function() Line 896  void Loader::thread_function()
896  }  }
897    
898  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
899      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
900  {  {
901  }  }
902    
# Line 762  void Loader::launch() Line 907  void Loader::launch()
907  #else  #else
908      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
909  #endif  #endif
910      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
911  }  }
912    
913  float Loader::get_progress()  float Loader::get_progress()
# Line 805  void Saver::progress_callback(float frac Line 950  void Saver::progress_callback(float frac
950      progress_dispatcher.emit();      progress_dispatcher.emit();
951  }  }
952    
953    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
954    // make sure stack is 16-byte aligned for SSE instructions
955    __attribute__((force_align_arg_pointer))
956    #endif
957  void Saver::thread_function()  void Saver::thread_function()
958  {  {
959      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
960               static_cast<void*>(Glib::Threads::Thread::self()));
961      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
962      try {      try {
963          gig::progress_t progress;          gig::progress_t progress;
# Line 816  void Saver::thread_function() Line 966  void Saver::thread_function()
966    
967          // 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"
968          if (filename.empty()) {          if (filename.empty()) {
969              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
970                    // save directly over the existing .gig file
971                    // (requires less disk space than solution below
972                    // but may be slower)
973                    gig->Save(&progress);
974                } else {
975                    // save the file as separate temporary file first,
976                    // then move the saved file over the old file
977                    // (may result in performance speedup during save)
978                    String tmpname = filename + ".TMP";
979                    gig->Save(tmpname, &progress);
980                    #if defined(WIN32)
981                    if (!DeleteFile(filename.c_str())) {
982                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
983                    }
984                    #else // POSIX ...
985                    if (unlink(filename.c_str())) {
986                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
987                    }
988                    #endif
989                    if (rename(tmpname.c_str(), filename.c_str())) {
990                        #if defined(WIN32)
991                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
992                        #else
993                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
994                        #endif
995                    }
996                }
997          } else {          } else {
998              gig->Save(filename, &progress);              gig->Save(filename, &progress);
999          }          }
# Line 844  void Saver::launch() Line 1021  void Saver::launch()
1021  #else  #else
1022      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1023  #endif  #endif
1024      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1025  }  }
1026    
1027  float Saver::get_progress()  float Saver::get_progress()
# Line 941  bool MainWindow::close_confirmation_dial Line 1118  bool MainWindow::close_confirmation_dial
1118      g_free(msg);      g_free(msg);
1119      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."));
1120      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1121      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1122      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);
1123      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1124      int response = dialog.run();      int response = dialog.run();
1125      dialog.hide();      dialog.hide();
# Line 973  bool MainWindow::leaving_shared_mode_dia Line 1150  bool MainWindow::leaving_shared_mode_dia
1150            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1151            "load it."));            "load it."));
1152      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1153      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1154      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1155      int response = dialog.run();      int response = dialog.run();
1156      dialog.hide();      dialog.hide();
# Line 987  void MainWindow::on_action_file_open() Line 1164  void MainWindow::on_action_file_open()
1164      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1165    
1166      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1167      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1168      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1169      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1170  #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
1171      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1004  void MainWindow::on_action_file_open() Line 1181  void MainWindow::on_action_file_open()
1181      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1182          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1183          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1184          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1185                   static_cast<void*>(Glib::Threads::Thread::self()));
1186          load_file(filename.c_str());          load_file(filename.c_str());
1187          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1188      }      }
# Line 1074  void MainWindow::on_loader_progress() Line 1252  void MainWindow::on_loader_progress()
1252  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1253  {  {
1254      printf("Loader finished!\n");      printf("Loader finished!\n");
1255      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1256               static_cast<void*>(Glib::Threads::Thread::self()));
1257      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1258      progress_dialog->hide();      progress_dialog->hide();
1259  }  }
# Line 1169  void MainWindow::on_saver_finished() Line 1348  void MainWindow::on_saver_finished()
1348    
1349      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1350    
1351      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1352      progress_dialog->hide();      progress_dialog->hide();
1353  }  }
1354    
# Line 1181  void MainWindow::on_action_file_save_as( Line 1360  void MainWindow::on_action_file_save_as(
1360    
1361  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1362  {  {
1363      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1364      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1365      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1366      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1367      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1368    
# Line 1214  bool MainWindow::file_save_as() Line 1393  bool MainWindow::file_save_as()
1393      // show warning in the dialog      // show warning in the dialog
1394      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1395      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1396      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1397        warningIcon.set_from_icon_name("dialog-warning",
1398                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1399      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1400  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1401      view::WrapLabel description;      view::WrapLabel description;
# Line 1266  bool MainWindow::file_save_as() Line 1447  bool MainWindow::file_save_as()
1447  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1448      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1449      Glib::ustring error_files;      Glib::ustring error_files;
1450      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1451      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1452           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1453          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",(*iter).sample_path.c_str());
# Line 1372  void MainWindow::on_action_sync_sampler_ Line 1553  void MainWindow::on_action_sync_sampler_
1553          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1554  }  }
1555    
1556    void MainWindow::on_action_move_root_note_with_region_moved() {
1557        Settings::singleton()->moveRootNoteWithRegionMoved =
1558            !Settings::singleton()->moveRootNoteWithRegionMoved;
1559    }
1560    
1561  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1562  {  {
1563      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1381  void MainWindow::on_action_help_about() Line 1567  void MainWindow::on_action_help_about()
1567      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1568  #endif  #endif
1569      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1570      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1571      const std::string sComment =      const std::string sComment =
1572          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1573          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1418  PropDialog::PropDialog() Line 1604  PropDialog::PropDialog()
1604        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1605        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1606        eSubject(_("Subject")),        eSubject(_("Subject")),
1607        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1608        table(2, 1),        table(2, 1),
1609        m_file(NULL)        m_file(NULL)
1610  {  {
# Line 1541  void InstrumentProps::set_MIDIProgram(ui Line 1727  void InstrumentProps::set_MIDIProgram(ui
1727  }  }
1728    
1729  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1730      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1731      table(2,1),      table(2,1),
1732      eName(_("Name")),      eName(_("Name")),
1733      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1664  void MainWindow::load_gig(gig::File* gig Line 1850  void MainWindow::load_gig(gig::File* gig
1850      file = 0;      file = 0;
1851      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1852    
1853      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1854            (filename && strlen(filename) > 0) ?
1855                filename : (!gig->GetFileName().empty()) ?
1856                    gig->GetFileName() : _("Unsaved Gig File");
1857      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1858      file_has_name = filename;      file_has_name = filename;
1859      file_is_changed = false;      file_is_changed = false;
# Line 1673  void MainWindow::load_gig(gig::File* gig Line 1862  void MainWindow::load_gig(gig::File* gig
1862      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1863    
1864      instrument_name_connection.block();      instrument_name_connection.block();
1865        int index = 0;
1866      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1867           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1868          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1869    
1870          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1871          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1872            row[m_Columns.m_col_nr] = index;
1873          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1874          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1875    
# Line 1751  bool MainWindow::instr_props_set_instrum Line 1942  bool MainWindow::instr_props_set_instrum
1942  {  {
1943      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1944    
1945      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1946          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1947            instrumentProps.hide();
1948            return false;
1949        }
1950        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1951      if (it) {      if (it) {
1952          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1953          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1805  void MainWindow::show_midi_rules() Line 2000  void MainWindow::show_midi_rules()
2000  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2001      if (!file) return;      if (!file) return;
2002      // get selected instrument      // get selected instrument
2003      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2004      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2005        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2006      if (!it) return;      if (!it) return;
2007      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2008      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1818  void MainWindow::show_script_slots() { Line 2014  void MainWindow::show_script_slots() {
2014      window->show();      window->show();
2015  }  }
2016    
2017    void MainWindow::on_action_refresh_all() {
2018        __refreshEntireGUI();
2019    }
2020    
2021  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
2022      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2023          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1829  void MainWindow::on_action_view_status_b Line 2029  void MainWindow::on_action_view_status_b
2029      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2030  }  }
2031    
2032    void MainWindow::on_auto_restore_win_dim() {
2033        Gtk::CheckMenuItem* item =
2034            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2035        if (!item) {
2036            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2037            return;
2038        }
2039        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2040    }
2041    
2042    void MainWindow::on_save_with_temporary_file() {
2043        Gtk::CheckMenuItem* item =
2044            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2045        if (!item) {
2046            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2047            return;
2048        }
2049        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2050    }
2051    
2052  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2053      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2054          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1893  void MainWindow::on_instrument_selection Line 2113  void MainWindow::on_instrument_selection
2113      }      }
2114  }  }
2115    
2116    void MainWindow::select_instrument(gig::Instrument* instrument) {
2117        if (!instrument) return;
2118    
2119        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2120        for (int i = 0; i < model->children().size(); ++i) {
2121            Gtk::TreeModel::Row row = model->children()[i];
2122            if (row[m_Columns.m_col_instr] == instrument) {
2123                // select and show the respective instrument in the list view
2124                show_intruments_tab();
2125                m_TreeView.get_selection()->unselect_all();
2126                m_TreeView.get_selection()->select(model->children()[i]);
2127                std::vector<Gtk::TreeModel::Path> rows =
2128                    m_TreeView.get_selection()->get_selected_rows();
2129                if (!rows.empty())
2130                    m_TreeView.scroll_to_row(rows[0]);
2131                on_sel_change(); // the regular instrument selection change callback
2132            }
2133        }
2134    }
2135    
2136  /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.  /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2137  bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {  bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2138      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
# Line 1904  bool MainWindow::select_dimension_region Line 2144  bool MainWindow::select_dimension_region
2144          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2145              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2146              show_intruments_tab();              show_intruments_tab();
2147                m_TreeView.get_selection()->unselect_all();
2148              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2149              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2150                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2151              );              if (!rows.empty())
2152              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2153              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2154    
2155              // select respective region in the region selector              // select respective region in the region selector
# Line 1934  void MainWindow::select_sample(gig::Samp Line 2175  void MainWindow::select_sample(gig::Samp
2175              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2176              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2177                  show_samples_tab();                  show_samples_tab();
2178                    m_TreeViewSamples.get_selection()->unselect_all();
2179                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2180                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2181                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2182                  );                  if (rows.empty()) return;
2183                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2184                  return;                  return;
2185              }              }
2186          }          }
# Line 1947  void MainWindow::select_sample(gig::Samp Line 2189  void MainWindow::select_sample(gig::Samp
2189    
2190  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2191      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2192            // by default if Ctrl keys is pressed down, then a mouse right-click
2193            // does not select the respective row, so we must assure this
2194            // programmatically ...
2195            /*{
2196                Gtk::TreeModel::Path path;
2197                Gtk::TreeViewColumn* pColumn = NULL;
2198                int cellX, cellY;
2199                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2200                    (int)button->x, (int)button->y,
2201                    path, pColumn, cellX, cellY
2202                );
2203                if (bSuccess) {
2204                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2205                        printf("not selected !!!\n");
2206                        m_TreeViewSamples.get_selection()->select(path);
2207                    }
2208                }
2209            }*/
2210    
2211          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2212              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2213          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2214          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2215          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2216          bool group_selected  = false;          const int n = rows.size();
2217          bool sample_selected = false;          int nGroups  = 0;
2218          if (it) {          int nSamples = 0;
2219            for (int r = 0; r < n; ++r) {
2220                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2221                if (!it) continue;
2222              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2223              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2224              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2225          }          }
2226            
               
2227          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2228              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2229          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2230              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2231          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2232              set_sensitive(file);              set_sensitive(file);
2233          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2234              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2235          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2236              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2237          // show sample popup          // show sample popup
2238          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2239    
2240          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2241              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2242          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2243              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2244          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2245              set_sensitive(file);              set_sensitive(file);
2246          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2247              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2248          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2249              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2250      }      }
2251  }  }
2252    
# Line 2062  void MainWindow::add_instrument(gig::Ins Line 2325  void MainWindow::add_instrument(gig::Ins
2325      instrument_name_connection.block();      instrument_name_connection.block();
2326      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2327      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2328        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2329      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2330      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2331      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2090  void MainWindow::on_action_duplicate_ins Line 2354  void MainWindow::on_action_duplicate_ins
2354      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2355      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2356      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2357      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2358      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2359      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2360      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2361      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2362                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2363      // duplicate the orginal instrument              if (instrOrig) {
2364      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2365      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2366          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2367          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2368                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2369    
2370      add_instrument(instrNew);                  add_instrument(instrNew);
2371                }
2372            }
2373        }
2374  }  }
2375    
2376  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2119  void MainWindow::on_action_remove_instru Line 2387  void MainWindow::on_action_remove_instru
2387      }      }
2388    
2389      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2390      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2391      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2392            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2393            if (!it) continue;
2394          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2395          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2396          try {          try {
# Line 2135  void MainWindow::on_action_remove_instru Line 2405  void MainWindow::on_action_remove_instru
2405    
2406              // remove row from instruments tree view              // remove row from instruments tree view
2407              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2408                // update "Nr" column of all instrument rows
2409                {
2410                    int index = 0;
2411                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2412                         it != m_refTreeModel->children().end(); ++it, ++index)
2413                    {
2414                        Gtk::TreeModel::Row row = *it;
2415                        row[m_Columns.m_col_nr] = index;
2416                    }
2417                }
2418    
2419  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2420              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2232  void MainWindow::on_action_edit_script() Line 2512  void MainWindow::on_action_edit_script()
2512      if (!script) return;      if (!script) return;
2513    
2514      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2515        editor->signal_script_to_be_changed.connect(
2516            signal_script_to_be_changed.make_slot()
2517        );
2518        editor->signal_script_changed.connect(
2519            signal_script_changed.make_slot()
2520        );
2521      editor->setScript(script);      editor->setScript(script);
2522      //editor->reparent(*this);      //editor->reparent(*this);
2523      editor->show();      editor->show();
# Line 2297  void MainWindow::on_action_add_group() { Line 2583  void MainWindow::on_action_add_group() {
2583      file_changed();      file_changed();
2584  }  }
2585    
2586    void MainWindow::on_action_replace_sample() {
2587        add_or_replace_sample(true);
2588    }
2589    
2590  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2591        add_or_replace_sample(false);
2592    }
2593    
2594    void MainWindow::add_or_replace_sample(bool replace) {
2595      if (!file) return;      if (!file) return;
2596      // get selected group  
2597        // get selected group (and probably selected sample)
2598      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2599      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2600        if (rows.empty()) return;
2601        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2602      if (!it) return;      if (!it) return;
2603      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2604        gig::Sample* sample = NULL;
2605      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2606      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2607          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2608          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2609          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2610          if (!it) return;          if (!it) return;
2611          row = *it;          if (!replace) row = *it;
2612          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2613          if (!group) return;          if (!group) return;
2614      }      }
2615        if (replace && !sample) return;
2616    
2617      // show 'browse for file' dialog      // show 'browse for file' dialog
2618      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2619      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2620      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2621      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2622    
2623      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2624  #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 2389  void MainWindow::on_action_add_sample() Line 2689  void MainWindow::on_action_add_sample()
2689                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2690                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2691                  }                  }
2692                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2693                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2694                  // file name without path                  // file name without path
2695                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2696                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2441  void MainWindow::on_action_add_sample() Line 2741  void MainWindow::on_action_add_sample()
2741                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2742                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2743                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2744                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2745                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2746                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2747                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2449  void MainWindow::on_action_add_sample() Line 2749  void MainWindow::on_action_add_sample()
2749                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2750                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2751                  // add sample to the tree view                  // add sample to the tree view
2752                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2753                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2754                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2755                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2756                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2757                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2758                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2759                            gig_to_utf8(sample->pInfo->Name);
2760                        rowSample[m_SamplesModel.m_col_sample] = sample;
2761                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2762                    }
2763                  // close sound file                  // close sound file
2764                  sf_close(hFile);                  sf_close(hFile);
2765                  file_changed();                  file_changed();
# Line 2466  void MainWindow::on_action_add_sample() Line 2770  void MainWindow::on_action_add_sample()
2770          }          }
2771          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
2772          if (!error_files.empty()) {          if (!error_files.empty()) {
2773              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2774                    (replace
2775                        ? _("Failed to replace sample with:\n")
2776                        : _("Could not add the following sample(s):\n"))
2777                    + error_files;
2778              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2779              msg.run();              msg.run();
2780          }          }
# Line 2509  void MainWindow::on_action_replace_all_s Line 2817  void MainWindow::on_action_replace_all_s
2817      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2818      description.show();      description.show();
2819      entryArea.show_all();      entryArea.show_all();
2820      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2821      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2822      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2823      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2533  void MainWindow::on_action_replace_all_s Line 2841  void MainWindow::on_action_replace_all_s
2841              try              try
2842              {              {
2843                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2844                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2845                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2846                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2847                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2848                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2849                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2850                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2851                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2852                          break;                          break;
2853                      default:                      default:
2854                          sf_close(hFile);                          sf_close(hFile);
# Line 2577  void MainWindow::on_action_replace_all_s Line 2881  void MainWindow::on_action_replace_all_s
2881  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2882      if (!file) return;      if (!file) return;
2883      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2884      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2885      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2886            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2887            if (!it) continue;
2888          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2889          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2890          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2650  void MainWindow::on_action_remove_sample Line 2956  void MainWindow::on_action_remove_sample
2956      }      }
2957  }  }
2958    
2959    void MainWindow::on_action_remove_unused_samples() {
2960        if (!file) return;
2961    
2962        // collect all samples that are not referenced by any instrument
2963        std::list<gig::Sample*> lsamples;
2964        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2965            gig::Sample* sample = file->GetSample(iSample);
2966            bool isUsed = false;
2967            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2968                                  instrument = file->GetNextInstrument())
2969            {
2970                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2971                                  rgn = instrument->GetNextRegion())
2972                {
2973                    for (int i = 0; i < 256; ++i) {
2974                        if (!rgn->pDimensionRegions[i]) continue;
2975                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2976                        isUsed = true;
2977                        goto endOfRefSearch;
2978                    }
2979                }
2980            }
2981            endOfRefSearch:
2982            if (!isUsed) lsamples.push_back(sample);
2983        }
2984    
2985        if (lsamples.empty()) return;
2986    
2987        // notify everybody that we're going to remove these samples
2988        samples_to_be_removed_signal.emit(lsamples);
2989    
2990        // remove collected samples
2991        try {
2992            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2993                 itSample != lsamples.end(); ++itSample)
2994            {
2995                gig::Sample* sample = *itSample;
2996                // remove sample from the .gig file
2997                file->DeleteSample(sample);
2998                // if sample was just previously added, remove it fro the import queue
2999                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
3000                     iter != m_SampleImportQueue.end(); ++iter)
3001                {
3002                    if ((*iter).gig_sample == sample) {
3003                        printf("Removing previously added sample '%s'\n",
3004                               (*iter).sample_path.c_str());
3005                        m_SampleImportQueue.erase(iter);
3006                        break;
3007                    }
3008                }
3009            }
3010        } catch (RIFF::Exception e) {
3011            // show error message
3012            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3013            msg.run();
3014        }
3015    
3016        // notify everybody that we're done with removal
3017        samples_removed_signal.emit();
3018    
3019        dimreg_changed();
3020        file_changed();
3021        __refreshEntireGUI();
3022    }
3023    
3024  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
3025  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3026  {  {
# Line 2676  void MainWindow::on_scripts_treeview_dra Line 3047  void MainWindow::on_scripts_treeview_dra
3047                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
3048  }  }
3049    
3050    // see comment on on_sample_treeview_drag_begin()
3051    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3052    {
3053        first_call_to_drag_data_get = true;
3054    }
3055    
3056    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
3057                                                           Gtk::SelectionData& selection_data, guint, guint)
3058    {
3059        if (!first_call_to_drag_data_get) return;
3060        first_call_to_drag_data_get = false;
3061    
3062        // get selected source instrument
3063        gig::Instrument* src = NULL;
3064        {
3065            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3066            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3067            if (!rows.empty()) {
3068                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3069                if (it) {
3070                    Gtk::TreeModel::Row row = *it;
3071                    src = row[m_Columns.m_col_instr];
3072                }
3073            }
3074        }
3075        if (!src) return;
3076    
3077        // pass the source gig::Instrument as pointer
3078        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
3079                           sizeof(src)/*length of data in bytes*/);
3080    }
3081    
3082    void MainWindow::on_instruments_treeview_drop_drag_data_received(
3083        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
3084        const Gtk::SelectionData& selection_data, guint, guint time)
3085    {
3086        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
3087        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
3088            return;
3089    
3090        gig::Instrument* dst = NULL;
3091        {
3092            Gtk::TreeModel::Path path;
3093            const bool found = m_TreeView.get_path_at_pos(x, y, path);
3094            if (!found) return;
3095    
3096            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
3097            if (!iter) return;
3098            Gtk::TreeModel::Row row = *iter;
3099            dst = row[m_Columns.m_col_instr];
3100        }
3101        if (!dst) return;
3102    
3103        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
3104        src->MoveTo(dst);
3105        __refreshEntireGUI();
3106        select_instrument(src);
3107    }
3108    
3109  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
3110  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
3111  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2694  void MainWindow::on_sample_treeview_drag Line 3124  void MainWindow::on_sample_treeview_drag
3124      // get selected sample      // get selected sample
3125      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3126      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3127      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3128      if (it) {      if (!rows.empty()) {
3129          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3130          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3131                Gtk::TreeModel::Row row = *it;
3132                sample = row[m_SamplesModel.m_col_sample];
3133            }
3134      }      }
3135      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3136      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 2837  void MainWindow::script_double_clicked(c Line 3270  void MainWindow::script_double_clicked(c
3270      if (!script) return;      if (!script) return;
3271    
3272      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3273        editor->signal_script_to_be_changed.connect(
3274            signal_script_to_be_changed.make_slot()
3275        );
3276        editor->signal_script_changed.connect(
3277            signal_script_changed.make_slot()
3278        );
3279      editor->setScript(script);      editor->setScript(script);
3280      //editor->reparent(*this);      //editor->reparent(*this);
3281      editor->show();      editor->show();
# Line 2890  void MainWindow::on_action_combine_instr Line 3329  void MainWindow::on_action_combine_instr
3329    
3330  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3331      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3332      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3333        if (rows.empty()) return;
3334        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3335      if (!it) return;      if (!it) return;
3336      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3337      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3012  void MainWindow::on_action_merge_files() Line 3453  void MainWindow::on_action_merge_files()
3453      }      }
3454    
3455      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3456      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3457      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3458      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3459  #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 3031  void MainWindow::on_action_merge_files() Line 3472  void MainWindow::on_action_merge_files()
3472      // show warning in the file picker dialog      // show warning in the file picker dialog
3473      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3474      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3475      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3476        warningIcon.set_from_icon_name("dialog-warning",
3477                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3478      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3479  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3480      view::WrapLabel description;      view::WrapLabel description;
# Line 3054  void MainWindow::on_action_merge_files() Line 3497  void MainWindow::on_action_merge_files()
3497      descriptionArea.show_all();      descriptionArea.show_all();
3498    
3499      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3500          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3501                   static_cast<void*>(Glib::Threads::Thread::self()));
3502          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3503    
3504          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3066  void MainWindow::on_action_merge_files() Line 3510  void MainWindow::on_action_merge_files()
3510          }          }
3511    
3512          // update GUI          // update GUI
3513          __refreshEntireGUI();                  __refreshEntireGUI();
3514      }      }
3515  }  }
3516    

Legend:
Removed from v.2695  
changed lines
  Added in v.3109

  ViewVC Help
Powered by ViewVC