/[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 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC revision 3148 by schoenebeck, Thu May 4 11:47:45 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 156  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 179  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)
306      );                      );                
307    
308      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
309      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("About", _("_About")),
                                          action->property_label()));  
     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),  
310                       sigc::mem_fun(                       sigc::mem_fun(
311                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
312      actionGroup->add(      actionGroup->add(
# Line 206  MainWindow::MainWindow() : Line 318  MainWindow::MainWindow() :
318          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
319      );      );
320      actionGroup->add(      actionGroup->add(
321          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
322          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
323      );      );
324    
# Line 253  MainWindow::MainWindow() : Line 365  MainWindow::MainWindow() :
365    
366      // sample right-click popup actions      // sample right-click popup actions
367      actionGroup->add(      actionGroup->add(
368          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
369          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
370      );      );
371      actionGroup->add(      actionGroup->add(
# Line 265  MainWindow::MainWindow() : Line 377  MainWindow::MainWindow() :
377          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
378      );      );
379      actionGroup->add(      actionGroup->add(
380          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
381          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
382      );      );
383      actionGroup->add(      actionGroup->add(
# Line 301  MainWindow::MainWindow() : Line 413  MainWindow::MainWindow() :
413          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
414      );      );
415      actionGroup->add(      actionGroup->add(
416          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
417          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
418      );      );
419    
# Line 324  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 360  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 371  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 458  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 495  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 525  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 676  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 702  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 746  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_RegionChooser.setModifyAllRegions(all_regions);
893        m_DimRegionChooser.setModifyAllRegions(all_regions);
894        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
895        m_DimRegionChooser.setModifyBothChannels(stereo);
896    
897        updateClipboardCopyAvailable();
898  }  }
899    
900  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 763  void MainWindow::dimreg_changed() Line 912  void MainWindow::dimreg_changed()
912  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
913  {  {
914      // select item in instrument menu      // select item in instrument menu
915      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
916      if (it) {      if (!rows.empty()) {
917          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
918          int index = path[0];          if (it) {
919          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
920              instrument_menu->get_children();              int index = path[0];
921          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
922                    instrument_menu->get_children();
923                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
924            }
925      }      }
926    
927      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 794  void Loader::progress_callback(float fra Line 946  void Loader::progress_callback(float fra
946      progress_dispatcher();      progress_dispatcher();
947  }  }
948    
949    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
950    // make sure stack is 16-byte aligned for SSE instructions
951    __attribute__((force_align_arg_pointer))
952    #endif
953  void Loader::thread_function()  void Loader::thread_function()
954  {  {
955      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
956               static_cast<void*>(Glib::Threads::Thread::self()));
957      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
958      try {      try {
959          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 818  void Loader::thread_function() Line 975  void Loader::thread_function()
975  }  }
976    
977  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
978      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
979  {  {
980  }  }
981    
# Line 829  void Loader::launch() Line 986  void Loader::launch()
986  #else  #else
987      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
988  #endif  #endif
989      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
990  }  }
991    
992  float Loader::get_progress()  float Loader::get_progress()
# Line 872  void Saver::progress_callback(float frac Line 1029  void Saver::progress_callback(float frac
1029      progress_dispatcher.emit();      progress_dispatcher.emit();
1030  }  }
1031    
1032    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1033    // make sure stack is 16-byte aligned for SSE instructions
1034    __attribute__((force_align_arg_pointer))
1035    #endif
1036  void Saver::thread_function()  void Saver::thread_function()
1037  {  {
1038      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1039               static_cast<void*>(Glib::Threads::Thread::self()));
1040      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1041      try {      try {
1042          gig::progress_t progress;          gig::progress_t progress;
# Line 883  void Saver::thread_function() Line 1045  void Saver::thread_function()
1045    
1046          // 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"
1047          if (filename.empty()) {          if (filename.empty()) {
1048              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1049                    // save directly over the existing .gig file
1050                    // (requires less disk space than solution below
1051                    // but may be slower)
1052                    gig->Save(&progress);
1053                } else {
1054                    // save the file as separate temporary file first,
1055                    // then move the saved file over the old file
1056                    // (may result in performance speedup during save)
1057                    String tmpname = filename + ".TMP";
1058                    gig->Save(tmpname, &progress);
1059                    #if defined(WIN32)
1060                    if (!DeleteFile(filename.c_str())) {
1061                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1062                    }
1063                    #else // POSIX ...
1064                    if (unlink(filename.c_str())) {
1065                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1066                    }
1067                    #endif
1068                    if (rename(tmpname.c_str(), filename.c_str())) {
1069                        #if defined(WIN32)
1070                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1071                        #else
1072                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1073                        #endif
1074                    }
1075                }
1076          } else {          } else {
1077              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1078          }          }
# Line 911  void Saver::launch() Line 1100  void Saver::launch()
1100  #else  #else
1101      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1102  #endif  #endif
1103      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1104  }  }
1105    
1106  float Saver::get_progress()  float Saver::get_progress()
# Line 1008  bool MainWindow::close_confirmation_dial Line 1197  bool MainWindow::close_confirmation_dial
1197      g_free(msg);      g_free(msg);
1198      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."));
1199      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1200      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1201      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);
1202      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1203      int response = dialog.run();      int response = dialog.run();
1204      dialog.hide();      dialog.hide();
# Line 1040  bool MainWindow::leaving_shared_mode_dia Line 1229  bool MainWindow::leaving_shared_mode_dia
1229            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1230            "load it."));            "load it."));
1231      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1232      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1233      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1234      int response = dialog.run();      int response = dialog.run();
1235      dialog.hide();      dialog.hide();
# Line 1054  void MainWindow::on_action_file_open() Line 1243  void MainWindow::on_action_file_open()
1243      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1244    
1245      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1246      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1247      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1248      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1249  #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
1250      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1071  void MainWindow::on_action_file_open() Line 1260  void MainWindow::on_action_file_open()
1260      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1261          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1262          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1263          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1264                   static_cast<void*>(Glib::Threads::Thread::self()));
1265          load_file(filename.c_str());          load_file(filename.c_str());
1266          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1267      }      }
# Line 1141  void MainWindow::on_loader_progress() Line 1331  void MainWindow::on_loader_progress()
1331  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1332  {  {
1333      printf("Loader finished!\n");      printf("Loader finished!\n");
1334      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1335               static_cast<void*>(Glib::Threads::Thread::self()));
1336      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1337      progress_dialog->hide();      progress_dialog->hide();
1338  }  }
# Line 1248  void MainWindow::on_action_file_save_as( Line 1439  void MainWindow::on_action_file_save_as(
1439    
1440  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1441  {  {
1442      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1443      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1444      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1445      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1446      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1447    
# Line 1281  bool MainWindow::file_save_as() Line 1472  bool MainWindow::file_save_as()
1472      // show warning in the dialog      // show warning in the dialog
1473      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1474      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1475      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1476        warningIcon.set_from_icon_name("dialog-warning",
1477                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1478      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1479  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1480      view::WrapLabel description;      view::WrapLabel description;
# Line 1333  bool MainWindow::file_save_as() Line 1526  bool MainWindow::file_save_as()
1526  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1527      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1528      Glib::ustring error_files;      Glib::ustring error_files;
1529      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1530      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1531           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1532          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1533          SF_INFO info;          SF_INFO info;
1534          info.format = 0;          info.format = 0;
1535          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);
1536          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1537          try {          try {
1538              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1362  void MainWindow::__import_queued_samples Line 1555  void MainWindow::__import_queued_samples
1555                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1556              }              }
1557    
1558                // reset write position for sample
1559                iter->first->SetPos(0);
1560    
1561              const int bufsize = 10000;              const int bufsize = 10000;
1562              switch (bitdepth) {              switch (bitdepth) {
1563                  case 16: {                  case 16: {
# Line 1371  void MainWindow::__import_queued_samples Line 1567  void MainWindow::__import_queued_samples
1567                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1568                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1569                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1570                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1571                          cnt -= n;                          cnt -= n;
1572                      }                      }
1573                      delete[] buffer;                      delete[] buffer;
# Line 1391  void MainWindow::__import_queued_samples Line 1587  void MainWindow::__import_queued_samples
1587                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1588                          }                          }
1589                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1590                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1591                          cnt -= n;                          cnt -= n;
1592                      }                      }
1593                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1402  void MainWindow::__import_queued_samples Line 1598  void MainWindow::__import_queued_samples
1598              // cleanup              // cleanup
1599              sf_close(hFile);              sf_close(hFile);
1600              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1601              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1602              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1603              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1604              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1605              ++iter;              ++iter;
1606              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1607          } catch (std::string what) {          } catch (std::string what) {
1608              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1609              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1610              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1611              ++iter;              ++iter;
1612          }          }
1613      }      }
# Line 1453  void MainWindow::on_action_help_about() Line 1649  void MainWindow::on_action_help_about()
1649      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1650  #endif  #endif
1651      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1652      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1653      const std::string sComment =      const std::string sComment =
1654          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1655          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1490  PropDialog::PropDialog() Line 1686  PropDialog::PropDialog()
1686        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1687        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1688        eSubject(_("Subject")),        eSubject(_("Subject")),
1689        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1690        table(2, 1),        table(2, 1),
1691        m_file(NULL)        m_file(NULL)
1692  {  {
# Line 1613  void InstrumentProps::set_MIDIProgram(ui Line 1809  void InstrumentProps::set_MIDIProgram(ui
1809  }  }
1810    
1811  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1812      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1813      table(2,1),      table(2,1),
1814      eName(_("Name")),      eName(_("Name")),
1815      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1748  void MainWindow::load_gig(gig::File* gig Line 1944  void MainWindow::load_gig(gig::File* gig
1944      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1945    
1946      instrument_name_connection.block();      instrument_name_connection.block();
1947        int index = 0;
1948      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1949           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1950          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1951    
1952          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1953          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1954            row[m_Columns.m_col_nr] = index;
1955          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1956          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1957    
# Line 1826  bool MainWindow::instr_props_set_instrum Line 2024  bool MainWindow::instr_props_set_instrum
2024  {  {
2025      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2026    
2027      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2028          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2029            instrumentProps.hide();
2030            return false;
2031        }
2032        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2033      if (it) {      if (it) {
2034          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2035          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1880  void MainWindow::show_midi_rules() Line 2082  void MainWindow::show_midi_rules()
2082  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2083      if (!file) return;      if (!file) return;
2084      // get selected instrument      // get selected instrument
2085      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2086      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2087        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2088      if (!it) return;      if (!it) return;
2089      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2090      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1908  void MainWindow::on_action_view_status_b Line 2111  void MainWindow::on_action_view_status_b
2111      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2112  }  }
2113    
2114    void MainWindow::on_auto_restore_win_dim() {
2115        Gtk::CheckMenuItem* item =
2116            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2117        if (!item) {
2118            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2119            return;
2120        }
2121        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2122    }
2123    
2124    void MainWindow::on_save_with_temporary_file() {
2125        Gtk::CheckMenuItem* item =
2126            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2127        if (!item) {
2128            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2129            return;
2130        }
2131        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2132    }
2133    
2134  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2135      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2136          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1981  void MainWindow::select_instrument(gig:: Line 2204  void MainWindow::select_instrument(gig::
2204          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2205              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2206              show_intruments_tab();              show_intruments_tab();
2207                m_TreeView.get_selection()->unselect_all();
2208              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2209              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2210                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2211              );              if (!rows.empty())
2212              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2213              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2214          }          }
2215      }      }
# Line 2002  bool MainWindow::select_dimension_region Line 2226  bool MainWindow::select_dimension_region
2226          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2227              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2228              show_intruments_tab();              show_intruments_tab();
2229                m_TreeView.get_selection()->unselect_all();
2230              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2231              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2232                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2233              );              if (!rows.empty())
2234              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2235              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2236    
2237              // select respective region in the region selector              // select respective region in the region selector
# Line 2032  void MainWindow::select_sample(gig::Samp Line 2257  void MainWindow::select_sample(gig::Samp
2257              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2258              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2259                  show_samples_tab();                  show_samples_tab();
2260                    m_TreeViewSamples.get_selection()->unselect_all();
2261                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2262                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2263                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2264                  );                  if (rows.empty()) return;
2265                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2266                  return;                  return;
2267              }              }
2268          }          }
# Line 2045  void MainWindow::select_sample(gig::Samp Line 2271  void MainWindow::select_sample(gig::Samp
2271    
2272  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2273      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2274            // by default if Ctrl keys is pressed down, then a mouse right-click
2275            // does not select the respective row, so we must assure this
2276            // programmatically ...
2277            /*{
2278                Gtk::TreeModel::Path path;
2279                Gtk::TreeViewColumn* pColumn = NULL;
2280                int cellX, cellY;
2281                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2282                    (int)button->x, (int)button->y,
2283                    path, pColumn, cellX, cellY
2284                );
2285                if (bSuccess) {
2286                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2287                        printf("not selected !!!\n");
2288                        m_TreeViewSamples.get_selection()->select(path);
2289                    }
2290                }
2291            }*/
2292    
2293          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2294              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2295          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2296          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2297          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2298          bool group_selected  = false;          const int n = rows.size();
2299          bool sample_selected = false;          int nGroups  = 0;
2300          if (it) {          int nSamples = 0;
2301            for (int r = 0; r < n; ++r) {
2302                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2303                if (!it) continue;
2304              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2305              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2306              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2307          }          }
2308            
               
2309          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2310              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2311          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2312              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2313          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2314              set_sensitive(file);              set_sensitive(file);
2315          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2316              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2317          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2318              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2319          // show sample popup          // show sample popup
2320          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2321    
2322          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2323              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2324          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2325              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2326          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2327              set_sensitive(file);              set_sensitive(file);
2328          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2329              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2330          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2331              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2332      }      }
2333  }  }
2334    
# Line 2160  void MainWindow::add_instrument(gig::Ins Line 2407  void MainWindow::add_instrument(gig::Ins
2407      instrument_name_connection.block();      instrument_name_connection.block();
2408      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2409      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2410        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2411      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2412      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2413      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2188  void MainWindow::on_action_duplicate_ins Line 2436  void MainWindow::on_action_duplicate_ins
2436      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2437      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2438      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2439      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2440      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2441      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2442      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2443      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2444                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2445      // duplicate the orginal instrument              if (instrOrig) {
2446      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2447      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2448          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2449          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2450                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2451    
2452      add_instrument(instrNew);                  add_instrument(instrNew);
2453                }
2454            }
2455        }
2456  }  }
2457    
2458  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2217  void MainWindow::on_action_remove_instru Line 2469  void MainWindow::on_action_remove_instru
2469      }      }
2470    
2471      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2472      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2473      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2474            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2475            if (!it) continue;
2476          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2477          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2478          try {          try {
# Line 2233  void MainWindow::on_action_remove_instru Line 2487  void MainWindow::on_action_remove_instru
2487    
2488              // remove row from instruments tree view              // remove row from instruments tree view
2489              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2490                // update "Nr" column of all instrument rows
2491                {
2492                    int index = 0;
2493                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2494                         it != m_refTreeModel->children().end(); ++it, ++index)
2495                    {
2496                        Gtk::TreeModel::Row row = *it;
2497                        row[m_Columns.m_col_nr] = index;
2498                    }
2499                }
2500    
2501  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2502              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2330  void MainWindow::on_action_edit_script() Line 2594  void MainWindow::on_action_edit_script()
2594      if (!script) return;      if (!script) return;
2595    
2596      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2597        editor->signal_script_to_be_changed.connect(
2598            signal_script_to_be_changed.make_slot()
2599        );
2600        editor->signal_script_changed.connect(
2601            signal_script_changed.make_slot()
2602        );
2603      editor->setScript(script);      editor->setScript(script);
2604      //editor->reparent(*this);      //editor->reparent(*this);
2605      editor->show();      editor->show();
# Line 2408  void MainWindow::add_or_replace_sample(b Line 2678  void MainWindow::add_or_replace_sample(b
2678    
2679      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2680      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2681      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2682        if (rows.empty()) return;
2683        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2684      if (!it) return;      if (!it) return;
2685      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2686      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2426  void MainWindow::add_or_replace_sample(b Line 2698  void MainWindow::add_or_replace_sample(b
2698    
2699      // show 'browse for file' dialog      // show 'browse for file' dialog
2700      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2701      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2702      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2703      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2704    
2705      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2557  void MainWindow::add_or_replace_sample(b Line 2829  void MainWindow::add_or_replace_sample(b
2829                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2830                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2831                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2832                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2833                  // add sample to the tree view                  // add sample to the tree view
2834                  if (replace) {                  if (replace) {
2835                      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 2627  void MainWindow::on_action_replace_all_s Line 2899  void MainWindow::on_action_replace_all_s
2899      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2900      description.show();      description.show();
2901      entryArea.show_all();      entryArea.show_all();
2902      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2903      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2904      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2905      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2651  void MainWindow::on_action_replace_all_s Line 2923  void MainWindow::on_action_replace_all_s
2923              try              try
2924              {              {
2925                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2926                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2927                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2928                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2929                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2930                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2931                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2932                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2933                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2934                          break;                          break;
2935                      default:                      default:
2936                          sf_close(hFile);                          sf_close(hFile);
# Line 2671  void MainWindow::on_action_replace_all_s Line 2939  void MainWindow::on_action_replace_all_s
2939                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2940                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2941                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
2942                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2943                  sf_close(hFile);                  sf_close(hFile);
2944                  file_changed();                  file_changed();
2945              }              }
# Line 2695  void MainWindow::on_action_replace_all_s Line 2963  void MainWindow::on_action_replace_all_s
2963  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2964      if (!file) return;      if (!file) return;
2965      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2966      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2967      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2968            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2969            if (!it) continue;
2970          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2971          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2972          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2721  void MainWindow::on_action_remove_sample Line 2991  void MainWindow::on_action_remove_sample
2991                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
2992                  // them from the import queue                  // them from the import queue
2993                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
2994                       member != members.end(); ++member) {                       member != members.end(); ++member)
2995                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
2996                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
2997                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
2998                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
2999                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3000                      }                      }
3001                  }                  }
3002                  file_changed();                  file_changed();
# Line 2744  void MainWindow::on_action_remove_sample Line 3011  void MainWindow::on_action_remove_sample
3011                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3012                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3013                  // the import queue                  // the import queue
3014                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3015                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3016                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3017                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3018                  }                  }
3019                  dimreg_changed();                  dimreg_changed();
3020                  file_changed();                  file_changed();
# Line 2807  void MainWindow::on_action_remove_unused Line 3070  void MainWindow::on_action_remove_unused
3070              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3071              // remove sample from the .gig file              // remove sample from the .gig file
3072              file->DeleteSample(sample);              file->DeleteSample(sample);
3073              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3074              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3075                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3076              {                         m_SampleImportQueue[sample].sample_path.c_str());
3077                  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;  
                 }  
3078              }              }
3079          }          }
3080      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2875  void MainWindow::on_instruments_treeview Line 3133  void MainWindow::on_instruments_treeview
3133      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3134      {      {
3135          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3136          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3137          if (it) {          if (!rows.empty()) {
3138              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3139              src = row[m_Columns.m_col_instr];              if (it) {
3140                    Gtk::TreeModel::Row row = *it;
3141                    src = row[m_Columns.m_col_instr];
3142                }
3143          }          }
3144      }      }
3145      if (!src) return;      if (!src) return;
# Line 2933  void MainWindow::on_sample_treeview_drag Line 3194  void MainWindow::on_sample_treeview_drag
3194      // get selected sample      // get selected sample
3195      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3196      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3197      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3198      if (it) {      if (!rows.empty()) {
3199          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3200          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3201                Gtk::TreeModel::Row row = *it;
3202                sample = row[m_SamplesModel.m_col_sample];
3203            }
3204      }      }
3205      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3206      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 3076  void MainWindow::script_double_clicked(c Line 3340  void MainWindow::script_double_clicked(c
3340      if (!script) return;      if (!script) return;
3341    
3342      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3343        editor->signal_script_to_be_changed.connect(
3344            signal_script_to_be_changed.make_slot()
3345        );
3346        editor->signal_script_changed.connect(
3347            signal_script_changed.make_slot()
3348        );
3349      editor->setScript(script);      editor->setScript(script);
3350      //editor->reparent(*this);      //editor->reparent(*this);
3351      editor->show();      editor->show();
# Line 3129  void MainWindow::on_action_combine_instr Line 3399  void MainWindow::on_action_combine_instr
3399    
3400  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3401      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3402      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3403        if (rows.empty()) return;
3404        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3405      if (!it) return;      if (!it) return;
3406      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3407      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3251  void MainWindow::on_action_merge_files() Line 3523  void MainWindow::on_action_merge_files()
3523      }      }
3524    
3525      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3526      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3527      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3528      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3529  #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 3270  void MainWindow::on_action_merge_files() Line 3542  void MainWindow::on_action_merge_files()
3542      // show warning in the file picker dialog      // show warning in the file picker dialog
3543      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3544      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3545      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3546        warningIcon.set_from_icon_name("dialog-warning",
3547                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3548      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3549  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3550      view::WrapLabel description;      view::WrapLabel description;
# Line 3293  void MainWindow::on_action_merge_files() Line 3567  void MainWindow::on_action_merge_files()
3567      descriptionArea.show_all();      descriptionArea.show_all();
3568    
3569      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3570          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3571                   static_cast<void*>(Glib::Threads::Thread::self()));
3572          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3573    
3574          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3375  void MainWindow::show_scripts_tab() { Line 3650  void MainWindow::show_scripts_tab() {
3650      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3651  }  }
3652    
3653    void MainWindow::select_prev_region() {
3654        m_RegionChooser.select_prev_region();
3655    }
3656    
3657    void MainWindow::select_next_region() {
3658        m_RegionChooser.select_next_region();
3659    }
3660    
3661    void MainWindow::select_next_dim_rgn_zone() {
3662        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3663        m_DimRegionChooser.select_next_dimzone();
3664    }
3665    
3666    void MainWindow::select_prev_dim_rgn_zone() {
3667        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3668        m_DimRegionChooser.select_prev_dimzone();
3669    }
3670    
3671    void MainWindow::select_add_next_dim_rgn_zone() {
3672        m_DimRegionChooser.select_next_dimzone(true);
3673    }
3674    
3675    void MainWindow::select_add_prev_dim_rgn_zone() {
3676        m_DimRegionChooser.select_prev_dimzone(true);
3677    }
3678    
3679    void MainWindow::select_prev_dimension() {
3680        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3681        m_DimRegionChooser.select_prev_dimension();
3682    }
3683    
3684    void MainWindow::select_next_dimension() {
3685        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3686        m_DimRegionChooser.select_next_dimension();
3687    }
3688    
3689    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3690        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3691    
3692    void MainWindow::copy_selected_dimrgn() {
3693        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3694        if (!pDimRgn) {
3695            updateClipboardPasteAvailable();
3696            updateClipboardCopyAvailable();
3697            return;
3698        }
3699    
3700        std::vector<Gtk::TargetEntry> targets;
3701        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3702    
3703        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3704        clipboard->set(
3705            targets,
3706            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3707            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3708        );
3709    
3710        m_serializationArchive.serialize(pDimRgn);
3711    
3712        updateClipboardPasteAvailable();
3713    }
3714    
3715    void MainWindow::paste_copied_dimrgn() {
3716        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3717        clipboard->request_contents(
3718            CLIPBOARD_DIMENSIONREGION_TARGET,
3719            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3720        );
3721        updateClipboardPasteAvailable();
3722    }
3723    
3724    void MainWindow::updateClipboardPasteAvailable() {
3725        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3726        clipboard->request_targets(
3727            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3728        );
3729    }
3730    
3731    void MainWindow::updateClipboardCopyAvailable() {
3732        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3733        static_cast<Gtk::MenuItem*>(
3734            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3735        )->set_sensitive(bDimensionRegionCopyIsPossible);
3736    }
3737    
3738    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3739        updateClipboardPasteAvailable();
3740    }
3741    
3742    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3743        const std::string target = selection_data.get_target();
3744        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3745            selection_data.set(
3746                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3747                &m_serializationArchive.rawData()[0],
3748                m_serializationArchive.rawData().size()
3749            );
3750        } else {
3751            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3752        }
3753    }
3754    
3755    void MainWindow::on_clipboard_clear() {
3756        m_serializationArchive.clear();
3757        updateClipboardPasteAvailable();
3758        updateClipboardCopyAvailable();
3759    }
3760    
3761    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3762        const std::string target = selection_data.get_target();
3763        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3764            gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3765            if (!pDimRgn) return;
3766    
3767            Glib::ustring errorText;
3768            try {
3769                m_serializationArchive.decode(
3770                    selection_data.get_data(), selection_data.get_length()
3771                );
3772    
3773                for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3774                     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3775                {
3776                    gig::DimensionRegion* pDimRgn = *itDimReg;
3777    
3778                    dimreg_to_be_changed_signal.emit(pDimRgn);
3779    
3780                    m_serializationArchive.deserialize(pDimRgn);
3781    
3782                    dimreg_changed_signal.emit(pDimRgn);
3783                }
3784    
3785                //region_changed()
3786                file_changed();
3787                dimreg_changed();
3788    
3789            } catch (Serialization::Exception e) {
3790                errorText = e.Message;
3791            } catch (...) {
3792                errorText = _("Unknown exception during deserialization decoding");
3793            }
3794            if (!errorText.empty()) {
3795                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3796                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3797                msg.run();
3798            }
3799        }
3800    }
3801    
3802    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3803        const bool bDimensionRegionPasteIsPossible =
3804            std::find(targets.begin(), targets.end(),
3805                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3806    
3807        static_cast<Gtk::MenuItem*>(
3808            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3809        )->set_sensitive(bDimensionRegionPasteIsPossible);
3810    }
3811    
3812  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3813      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3814  }  }

Legend:
Removed from v.2773  
changed lines
  Added in v.3148

  ViewVC Help
Powered by ViewVC