/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2845 by persson, Sun Sep 20 10:18:22 2015 UTC revision 3158 by schoenebeck, Mon May 8 18:05:35 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 35  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>
38    #include <gtkmm/stock.h>
39  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
40  #include <gtkmm/main.h>  #include <gtkmm/main.h>
41  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
42    #include <gtkmm/accelmap.h>
43  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
44  #include "wrapLabel.hh"  #include "wrapLabel.hh"
45  #endif  #endif
# Line 57  Line 59 
59  #include "ReferencesView.h"  #include "ReferencesView.h"
60  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
61  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
62    #include "gfx/builtinpix.h"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    
66  MainWindow::MainWindow() :  MainWindow::MainWindow() :
67      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
68      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
69      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
70      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
71      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
72        labelLegend(_("Legend:")),
73        labelNoSample(_(" No Sample")),
74        labelMissingSample(_(" Missing some Sample(s)")),
75        labelLooped(_(" Looped")),
76        labelSomeLoops(_(" Some Loop(s)"))
77  {  {
78        loadBuiltInPix();
79    
80  //    set_border_width(5);  //    set_border_width(5);
81  //    set_default_size(400, 200);  //    set_default_size(400, 200);
82    
   
83      add(m_VBox);      add(m_VBox);
84    
85      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 113  MainWindow::MainWindow() :
113      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
114      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
115      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
116        {
117            legend_hbox.add(labelLegend);
118    
119            imageNoSample.set(redDot);
120            imageNoSample.set_alignment(Gtk::ALIGN_END);
121            labelNoSample.set_alignment(Gtk::ALIGN_START);
122            legend_hbox.add(imageNoSample);
123            legend_hbox.add(labelNoSample);
124    
125            imageMissingSample.set(yellowDot);
126            imageMissingSample.set_alignment(Gtk::ALIGN_END);
127            labelMissingSample.set_alignment(Gtk::ALIGN_START);
128            legend_hbox.add(imageMissingSample);
129            legend_hbox.add(labelMissingSample);
130    
131            imageLooped.set(blackLoop);
132            imageLooped.set_alignment(Gtk::ALIGN_END);
133            labelLooped.set_alignment(Gtk::ALIGN_START);
134            legend_hbox.add(imageLooped);
135            legend_hbox.add(labelLooped);
136    
137            imageSomeLoops.set(grayLoop);
138            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
139            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
140            legend_hbox.add(imageSomeLoops);
141            legend_hbox.add(labelSomeLoops);
142    
143            legend_hbox.show_all_children();
144        }
145        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
146      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
147    
148      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 117  MainWindow::MainWindow() : Line 157  MainWindow::MainWindow() :
157      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
158    
159      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
160      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
161                       sigc::mem_fun(                       sigc::mem_fun(
162                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
163      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
164                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
165        action->property_label() = action->property_label() + "...";
166        actionGroup->add(action,
167                       sigc::mem_fun(                       sigc::mem_fun(
168                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
169      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
170                       sigc::mem_fun(                       sigc::mem_fun(
171                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
172      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
173        action->property_label() = action->property_label() + "...";
174        actionGroup->add(action,
175                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
176                       sigc::mem_fun(                       sigc::mem_fun(
177                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
178      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
179                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
180                       sigc::mem_fun(                       sigc::mem_fun(
181                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
182      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
183                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
184                       sigc::mem_fun(                       sigc::mem_fun(
185                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
186      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 149  MainWindow::MainWindow() : Line 191  MainWindow::MainWindow() :
191                                           _("_Script Slots...")),                                           _("_Script Slots...")),
192                       sigc::mem_fun(                       sigc::mem_fun(
193                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
194      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
195                       sigc::mem_fun(                       sigc::mem_fun(
196                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
197      actionGroup->add(      actionGroup->add(
# Line 162  MainWindow::MainWindow() : Line 203  MainWindow::MainWindow() :
203          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
204      );      );
205      actionGroup->add(      actionGroup->add(
206          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
207          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
208      );      );
209      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
210    
211      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
212    
213        const Gdk::ModifierType primaryModifierKey =
214    #if defined(__APPLE__)
215        Gdk::META_MASK; // Cmd key on Mac
216    #else
217        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
218    #endif
219    
220        actionGroup->add(Gtk::Action::create("CopyDimRgn",
221                                             _("Copy selected dimension region")),
222                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("PasteDimRgn",
226                                             _("Paste dimension region")),
227                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
228                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
229    
230        actionGroup->add(Gtk::Action::create("AdjustClipboard",
231                                             _("Adjust Clipboard Content")),
232                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
233                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
236                                             _("Select Previous Region")),
237                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextRegion",
241                                             _("Select Next Region")),
242                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
243                         sigc::mem_fun(*this, &MainWindow::select_next_region));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
246                                             _("Select Previous Dimension Region Zone")),
247                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
251                                             _("Select Next Dimension Region Zone")),
252                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
254    
255        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
256                                             _("Select Previous Dimension")),
257                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
259    
260        actionGroup->add(Gtk::Action::create("SelectNextDimension",
261                                             _("Select Next Dimension")),
262                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
264    
265        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
266                                             _("Add Previous Dimension Region Zone to Selection")),
267                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
268                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
269    
270        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
271                                             _("Add Next Dimension Region Zone to Selection")),
272                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
273                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
274    
275      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
276          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
277      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 185  MainWindow::MainWindow() : Line 288  MainWindow::MainWindow() :
288      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
289    
290    
291      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
292    
293    
294        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
295      toggle_action =      toggle_action =
296          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
297      toggle_action->set_active(true);      toggle_action->set_active(true);
298      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
299                       sigc::mem_fun(                       sigc::mem_fun(
300                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
301    
302        toggle_action =
303            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
304        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
305        actionGroup->add(toggle_action,
306                         sigc::mem_fun(
307                             *this, &MainWindow::on_auto_restore_win_dim));
308    
309        toggle_action =
310            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
311        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
312        actionGroup->add(toggle_action,
313                         sigc::mem_fun(
314                             *this, &MainWindow::on_save_with_temporary_file));
315    
316      actionGroup->add(      actionGroup->add(
317          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
318          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
319      );                      );                
320    
321      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
322      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
323                                             action->property_label()));
324        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
325                       sigc::mem_fun(                       sigc::mem_fun(
326                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
327      actionGroup->add(      actionGroup->add(
# Line 210  MainWindow::MainWindow() : Line 333  MainWindow::MainWindow() :
333          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
334      );      );
335      actionGroup->add(      actionGroup->add(
336          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
337          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
338      );      );
339    
# Line 257  MainWindow::MainWindow() : Line 380  MainWindow::MainWindow() :
380    
381      // sample right-click popup actions      // sample right-click popup actions
382      actionGroup->add(      actionGroup->add(
383          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
384          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
385      );      );
386      actionGroup->add(      actionGroup->add(
# Line 269  MainWindow::MainWindow() : Line 392  MainWindow::MainWindow() :
392          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
393      );      );
394      actionGroup->add(      actionGroup->add(
395          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
396          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
397      );      );
398      actionGroup->add(      actionGroup->add(
# Line 305  MainWindow::MainWindow() : Line 428  MainWindow::MainWindow() :
428          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
429      );      );
430      actionGroup->add(      actionGroup->add(
431          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
432          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
433      );      );
434    
# Line 328  MainWindow::MainWindow() : Line 451  MainWindow::MainWindow() :
451          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
452          "    </menu>"          "    </menu>"
453          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
454            "      <menuitem action='CopyDimRgn'/>"
455            "      <menuitem action='AdjustClipboard'/>"
456            "      <menuitem action='PasteDimRgn'/>"
457            "      <separator/>"
458            "      <menuitem action='SelectPrevRegion'/>"
459            "      <menuitem action='SelectNextRegion'/>"
460            "      <separator/>"
461            "      <menuitem action='SelectPrevDimension'/>"
462            "      <menuitem action='SelectNextDimension'/>"
463            "      <menuitem action='SelectPrevDimRgnZone'/>"
464            "      <menuitem action='SelectNextDimRgnZone'/>"
465            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
466            "      <menuitem action='SelectAddNextDimRgnZone'/>"
467            "      <separator/>"
468          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
469          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
470          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
471          "    </menu>"          "    </menu>"
472            "    <menu action='MenuMacro'>"
473            "    </menu>"
474          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
475          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
476          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 364  MainWindow::MainWindow() : Line 503  MainWindow::MainWindow() :
503          "    </menu>"          "    </menu>"
504          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
505          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
506            "      <menuitem action='AutoRestoreWinDim'/>"
507          "      <separator/>"          "      <separator/>"
508          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
509          "    </menu>"          "    </menu>"
# Line 375  MainWindow::MainWindow() : Line 515  MainWindow::MainWindow() :
515          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
516          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
517          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
518            "      <menuitem action='SaveWithTemporaryFile'/>"
519          "    </menu>"          "    </menu>"
520          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
521          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 462  MainWindow::MainWindow() : Line 603  MainWindow::MainWindow() :
603      }      }
604      {      {
605          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
606                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
607            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
608        }
609        {
610            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
611              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
612          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."));
613      }      }
# Line 499  MainWindow::MainWindow() : Line 645  MainWindow::MainWindow() :
645      // Create the Tree model:      // Create the Tree model:
646      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
647      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
648        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
649      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."));
650      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
651          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
652      );      );
653    
654      // Add the TreeView's view columns:      // Add the TreeView's view columns:
655      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
656      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
657        m_TreeView.set_headers_visible(true);
658            
659      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
660      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 529  MainWindow::MainWindow() : Line 677  MainWindow::MainWindow() :
677      // create samples treeview (including its data model)      // create samples treeview (including its data model)
678      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
679      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
680        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
681      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."));
682      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
683      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 680  MainWindow::MainWindow() : Line 829  MainWindow::MainWindow() :
829    
830      // select 'Instruments' tab by default      // select 'Instruments' tab by default
831      // (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)
832      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
833    
834        Gtk::Clipboard::get()->signal_owner_change().connect(
835            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
836        );
837        updateClipboardPasteAvailable();
838        updateClipboardCopyAvailable();
839    
840        // setup macros and their keyboard accelerators
841        {
842            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
843                uiManager->get_widget("/MenuBar/MenuMacro")
844            )->get_submenu();
845    
846            const Gdk::ModifierType primaryModifierKey =
847    #if defined(__APPLE__)
848                Gdk::META_MASK; // Cmd key on Mac
849    #else
850                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
851    #endif
852    
853            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
854            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
855            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
856            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
857            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
858            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
859            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
867    
868            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
869            menuMacro->set_accel_group(accelGroup);
870    
871            updateMacroMenu();
872        }
873  }  }
874    
875  MainWindow::~MainWindow()  MainWindow::~MainWindow()
876  {  {
877  }  }
878    
879    void MainWindow::updateMacroMenu() {
880        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
881            uiManager->get_widget("/MenuBar/MenuMacro")
882        )->get_submenu();
883    
884        // remove all entries from "Macro" menu
885        {
886            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
887            for (int i = 0; i < children.size(); ++i) {
888                Gtk::Widget* child = children[i];
889                menuMacro->remove(*child);
890                delete child;
891            }
892        }
893    
894        // (re)load all macros from config file
895        try {
896            Settings::singleton()->loadMacros(m_macros);
897        } catch (Serialization::Exception e) {
898            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
899        } catch (...) {
900            std::cerr << "Unknown exception while loading macros!" << std::endl;
901        }
902    
903        // add all configured macros as menu items to the "Macro" menu
904        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
905            const Serialization::Archive& macro = m_macros[iMacro];
906            std::string name =
907                macro.name().empty() ?
908                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
909            Gtk::MenuItem* item = new Gtk::MenuItem(name);
910            item->signal_activate().connect(
911                sigc::bind(
912                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
913                )
914            );
915            menuMacro->append(*item);
916            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
917        }
918        // if there are no macros configured at all, then show a dummy entry instead
919        if (m_macros.empty()) {
920            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
921            item->set_sensitive(false);
922            menuMacro->append(*item);
923        }
924    
925        // add separator line to menu
926        menuMacro->append(*new Gtk::SeparatorMenuItem);
927    
928        {
929            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
930            item->signal_activate().connect(
931                sigc::mem_fun(*this, &MainWindow::setupMacros)
932            );
933            menuMacro->append(*item);
934            item->set_accel_path("<Macros>/SetupMacros");
935        }
936    
937        menuMacro->show_all_children();
938    }
939    
940    void MainWindow::onMacroSelected(int iMacro) {
941        printf("onMacroSelected(%d)\n", iMacro);
942        if (iMacro < 0 || iMacro >= m_macros.size()) return;
943        Glib::ustring errorText;
944        try {
945            applyMacro(m_macros[iMacro]);
946        } catch (Serialization::Exception e) {
947            errorText = e.Message;
948        } catch (...) {
949            errorText = _("Unknown exception while applying macro");
950        }
951        if (!errorText.empty()) {
952            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
953            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
954            msg.run();
955        }
956    }
957    
958    void MainWindow::setupMacros() {
959        MacrosSetup* setup = new MacrosSetup();
960        setup->setMacros(m_macros);
961        setup->signal_macros_changed().connect(
962            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
963        );
964        setup->show();
965    }
966    
967    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
968        m_macros = macros;
969        Settings::singleton()->saveMacros(m_macros);
970        updateMacroMenu();
971    }
972    
973  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
974  {  {
975      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 706  void MainWindow::region_changed() Line 989  void MainWindow::region_changed()
989  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
990  {  {
991      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
992      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
993          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
994        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
995      if (it) {      if (it) {
996          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
997          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 750  void MainWindow::update_dimregs() Line 1034  void MainWindow::update_dimregs()
1034              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1035          }          }
1036      }      }
1037    
1038        m_RegionChooser.setModifyAllRegions(all_regions);
1039        m_DimRegionChooser.setModifyAllRegions(all_regions);
1040        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1041        m_DimRegionChooser.setModifyBothChannels(stereo);
1042    
1043        updateClipboardCopyAvailable();
1044  }  }
1045    
1046  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 767  void MainWindow::dimreg_changed() Line 1058  void MainWindow::dimreg_changed()
1058  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1059  {  {
1060      // select item in instrument menu      // select item in instrument menu
1061      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1062      if (it) {      if (!rows.empty()) {
1063          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1064          int index = path[0];          if (it) {
1065          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1066              instrument_menu->get_children();              int index = path[0];
1067          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1068                    instrument_menu->get_children();
1069                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1070            }
1071      }      }
1072    
1073      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 798  void Loader::progress_callback(float fra Line 1092  void Loader::progress_callback(float fra
1092      progress_dispatcher();      progress_dispatcher();
1093  }  }
1094    
1095    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1096    // make sure stack is 16-byte aligned for SSE instructions
1097    __attribute__((force_align_arg_pointer))
1098    #endif
1099  void Loader::thread_function()  void Loader::thread_function()
1100  {  {
1101      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 877  void Saver::progress_callback(float frac Line 1175  void Saver::progress_callback(float frac
1175      progress_dispatcher.emit();      progress_dispatcher.emit();
1176  }  }
1177    
1178    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1179    // make sure stack is 16-byte aligned for SSE instructions
1180    __attribute__((force_align_arg_pointer))
1181    #endif
1182  void Saver::thread_function()  void Saver::thread_function()
1183  {  {
1184      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 889  void Saver::thread_function() Line 1191  void Saver::thread_function()
1191    
1192          // 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"
1193          if (filename.empty()) {          if (filename.empty()) {
1194              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1195                    // save directly over the existing .gig file
1196                    // (requires less disk space than solution below
1197                    // but may be slower)
1198                    gig->Save(&progress);
1199                } else {
1200                    // save the file as separate temporary file first,
1201                    // then move the saved file over the old file
1202                    // (may result in performance speedup during save)
1203                    String tmpname = filename + ".TMP";
1204                    gig->Save(tmpname, &progress);
1205                    #if defined(WIN32)
1206                    if (!DeleteFile(filename.c_str())) {
1207                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1208                    }
1209                    #else // POSIX ...
1210                    if (unlink(filename.c_str())) {
1211                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1212                    }
1213                    #endif
1214                    if (rename(tmpname.c_str(), filename.c_str())) {
1215                        #if defined(WIN32)
1216                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1217                        #else
1218                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1219                        #endif
1220                    }
1221                }
1222          } else {          } else {
1223              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1224          }          }
# Line 1014  bool MainWindow::close_confirmation_dial Line 1343  bool MainWindow::close_confirmation_dial
1343      g_free(msg);      g_free(msg);
1344      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."));
1345      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1346      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1347      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
1348      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1349      int response = dialog.run();      int response = dialog.run();
1350      dialog.hide();      dialog.hide();
# Line 1046  bool MainWindow::leaving_shared_mode_dia Line 1375  bool MainWindow::leaving_shared_mode_dia
1375            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1376            "load it."));            "load it."));
1377      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1378      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1379      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1380      int response = dialog.run();      int response = dialog.run();
1381      dialog.hide();      dialog.hide();
# Line 1060  void MainWindow::on_action_file_open() Line 1389  void MainWindow::on_action_file_open()
1389      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1390    
1391      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1392      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1393      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1394      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1395  #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
1396      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1256  void MainWindow::on_action_file_save_as( Line 1585  void MainWindow::on_action_file_save_as(
1585    
1586  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1587  {  {
1588      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1589      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1590      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1591      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1592      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1593    
# Line 1344  void MainWindow::__import_queued_samples Line 1673  void MainWindow::__import_queued_samples
1673      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1674      Glib::ustring error_files;      Glib::ustring error_files;
1675      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1676      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1677           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1678          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1679          SF_INFO info;          SF_INFO info;
1680          info.format = 0;          info.format = 0;
1681          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);
1682          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1683          try {          try {
1684              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1372  void MainWindow::__import_queued_samples Line 1701  void MainWindow::__import_queued_samples
1701                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1702              }              }
1703    
1704                // reset write position for sample
1705                iter->first->SetPos(0);
1706    
1707              const int bufsize = 10000;              const int bufsize = 10000;
1708              switch (bitdepth) {              switch (bitdepth) {
1709                  case 16: {                  case 16: {
# Line 1381  void MainWindow::__import_queued_samples Line 1713  void MainWindow::__import_queued_samples
1713                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1714                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1715                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1716                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1717                          cnt -= n;                          cnt -= n;
1718                      }                      }
1719                      delete[] buffer;                      delete[] buffer;
# Line 1401  void MainWindow::__import_queued_samples Line 1733  void MainWindow::__import_queued_samples
1733                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1734                          }                          }
1735                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1736                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1737                          cnt -= n;                          cnt -= n;
1738                      }                      }
1739                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1412  void MainWindow::__import_queued_samples Line 1744  void MainWindow::__import_queued_samples
1744              // cleanup              // cleanup
1745              sf_close(hFile);              sf_close(hFile);
1746              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1747              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1748              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1749              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1750              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1751              ++iter;              ++iter;
1752              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1753          } catch (std::string what) {          } catch (std::string what) {
1754              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1755              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1756              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1757              ++iter;              ++iter;
1758          }          }
1759      }      }
# Line 1463  void MainWindow::on_action_help_about() Line 1795  void MainWindow::on_action_help_about()
1795      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1796  #endif  #endif
1797      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1798      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1799      const std::string sComment =      const std::string sComment =
1800          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1801          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1500  PropDialog::PropDialog() Line 1832  PropDialog::PropDialog()
1832        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1833        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1834        eSubject(_("Subject")),        eSubject(_("Subject")),
1835        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1836        table(2, 1),        table(2, 1),
1837        m_file(NULL)        m_file(NULL)
1838  {  {
# Line 1623  void InstrumentProps::set_MIDIProgram(ui Line 1955  void InstrumentProps::set_MIDIProgram(ui
1955  }  }
1956    
1957  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1958      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1959      table(2,1),      table(2,1),
1960      eName(_("Name")),      eName(_("Name")),
1961      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1758  void MainWindow::load_gig(gig::File* gig Line 2090  void MainWindow::load_gig(gig::File* gig
2090      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2091    
2092      instrument_name_connection.block();      instrument_name_connection.block();
2093        int index = 0;
2094      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2095           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2096          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2097    
2098          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2099          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2100            row[m_Columns.m_col_nr] = index;
2101          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2102          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2103    
# Line 1836  bool MainWindow::instr_props_set_instrum Line 2170  bool MainWindow::instr_props_set_instrum
2170  {  {
2171      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2172    
2173      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2174          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2175            instrumentProps.hide();
2176            return false;
2177        }
2178        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2179      if (it) {      if (it) {
2180          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2181          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1890  void MainWindow::show_midi_rules() Line 2228  void MainWindow::show_midi_rules()
2228  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2229      if (!file) return;      if (!file) return;
2230      // get selected instrument      // get selected instrument
2231      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2232      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2233        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2234      if (!it) return;      if (!it) return;
2235      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2236      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1918  void MainWindow::on_action_view_status_b Line 2257  void MainWindow::on_action_view_status_b
2257      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2258  }  }
2259    
2260    void MainWindow::on_auto_restore_win_dim() {
2261        Gtk::CheckMenuItem* item =
2262            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2263        if (!item) {
2264            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2265            return;
2266        }
2267        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2268    }
2269    
2270    void MainWindow::on_save_with_temporary_file() {
2271        Gtk::CheckMenuItem* item =
2272            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2273        if (!item) {
2274            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2275            return;
2276        }
2277        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2278    }
2279    
2280  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2281      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2282          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1991  void MainWindow::select_instrument(gig:: Line 2350  void MainWindow::select_instrument(gig::
2350          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2351              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2352              show_intruments_tab();              show_intruments_tab();
2353                m_TreeView.get_selection()->unselect_all();
2354              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2355              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2356                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2357              );              if (!rows.empty())
2358              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2359              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2360          }          }
2361      }      }
# Line 2012  bool MainWindow::select_dimension_region Line 2372  bool MainWindow::select_dimension_region
2372          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2373              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2374              show_intruments_tab();              show_intruments_tab();
2375                m_TreeView.get_selection()->unselect_all();
2376              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2377              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2378                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2379              );              if (!rows.empty())
2380              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2381              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2382    
2383              // select respective region in the region selector              // select respective region in the region selector
# Line 2042  void MainWindow::select_sample(gig::Samp Line 2403  void MainWindow::select_sample(gig::Samp
2403              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2404              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2405                  show_samples_tab();                  show_samples_tab();
2406                    m_TreeViewSamples.get_selection()->unselect_all();
2407                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2408                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2409                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2410                  );                  if (rows.empty()) return;
2411                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2412                  return;                  return;
2413              }              }
2414          }          }
# Line 2055  void MainWindow::select_sample(gig::Samp Line 2417  void MainWindow::select_sample(gig::Samp
2417    
2418  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2419      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2420            // by default if Ctrl keys is pressed down, then a mouse right-click
2421            // does not select the respective row, so we must assure this
2422            // programmatically ...
2423            /*{
2424                Gtk::TreeModel::Path path;
2425                Gtk::TreeViewColumn* pColumn = NULL;
2426                int cellX, cellY;
2427                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2428                    (int)button->x, (int)button->y,
2429                    path, pColumn, cellX, cellY
2430                );
2431                if (bSuccess) {
2432                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2433                        printf("not selected !!!\n");
2434                        m_TreeViewSamples.get_selection()->select(path);
2435                    }
2436                }
2437            }*/
2438    
2439          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2440              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2441          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2442          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2443          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2444          bool group_selected  = false;          const int n = rows.size();
2445          bool sample_selected = false;          int nGroups  = 0;
2446          if (it) {          int nSamples = 0;
2447            for (int r = 0; r < n; ++r) {
2448                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2449                if (!it) continue;
2450              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2451              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2452              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2453          }          }
2454            
               
2455          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2456              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2457          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2458              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2459          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2460              set_sensitive(file);              set_sensitive(file);
2461          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2462              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2463          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2464              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2465          // show sample popup          // show sample popup
2466          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2467    
2468          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2469              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2470          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2471              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2472          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2473              set_sensitive(file);              set_sensitive(file);
2474          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2475              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2476          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2477              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2478      }      }
2479  }  }
2480    
# Line 2170  void MainWindow::add_instrument(gig::Ins Line 2553  void MainWindow::add_instrument(gig::Ins
2553      instrument_name_connection.block();      instrument_name_connection.block();
2554      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2555      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2556        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2557      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2558      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2559      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2198  void MainWindow::on_action_duplicate_ins Line 2582  void MainWindow::on_action_duplicate_ins
2582      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2583      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2584      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2585      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2586      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2587      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2588      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2589      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2590                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2591      // duplicate the orginal instrument              if (instrOrig) {
2592      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2593      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2594          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2595          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2596                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2597    
2598      add_instrument(instrNew);                  add_instrument(instrNew);
2599                }
2600            }
2601        }
2602  }  }
2603    
2604  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2227  void MainWindow::on_action_remove_instru Line 2615  void MainWindow::on_action_remove_instru
2615      }      }
2616    
2617      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2618      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2619      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2620            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2621            if (!it) continue;
2622          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2623          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2624          try {          try {
# Line 2243  void MainWindow::on_action_remove_instru Line 2633  void MainWindow::on_action_remove_instru
2633    
2634              // remove row from instruments tree view              // remove row from instruments tree view
2635              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2636                // update "Nr" column of all instrument rows
2637                {
2638                    int index = 0;
2639                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2640                         it != m_refTreeModel->children().end(); ++it, ++index)
2641                    {
2642                        Gtk::TreeModel::Row row = *it;
2643                        row[m_Columns.m_col_nr] = index;
2644                    }
2645                }
2646    
2647  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2648              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2340  void MainWindow::on_action_edit_script() Line 2740  void MainWindow::on_action_edit_script()
2740      if (!script) return;      if (!script) return;
2741    
2742      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2743        editor->signal_script_to_be_changed.connect(
2744            signal_script_to_be_changed.make_slot()
2745        );
2746        editor->signal_script_changed.connect(
2747            signal_script_changed.make_slot()
2748        );
2749      editor->setScript(script);      editor->setScript(script);
2750      //editor->reparent(*this);      //editor->reparent(*this);
2751      editor->show();      editor->show();
# Line 2418  void MainWindow::add_or_replace_sample(b Line 2824  void MainWindow::add_or_replace_sample(b
2824    
2825      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2826      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2827      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2828        if (rows.empty()) return;
2829        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2830      if (!it) return;      if (!it) return;
2831      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2832      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2436  void MainWindow::add_or_replace_sample(b Line 2844  void MainWindow::add_or_replace_sample(b
2844    
2845      // show 'browse for file' dialog      // show 'browse for file' dialog
2846      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2847      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2848      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2849      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
2850    
2851      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2567  void MainWindow::add_or_replace_sample(b Line 2975  void MainWindow::add_or_replace_sample(b
2975                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2976                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2977                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2978                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2979                  // add sample to the tree view                  // add sample to the tree view
2980                  if (replace) {                  if (replace) {
2981                      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 2637  void MainWindow::on_action_replace_all_s Line 3045  void MainWindow::on_action_replace_all_s
3045      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3046      description.show();      description.show();
3047      entryArea.show_all();      entryArea.show_all();
3048      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3049      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3050      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3051      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2677  void MainWindow::on_action_replace_all_s Line 3085  void MainWindow::on_action_replace_all_s
3085                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3086                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3087                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3088                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3089                  sf_close(hFile);                  sf_close(hFile);
3090                  file_changed();                  file_changed();
3091              }              }
# Line 2701  void MainWindow::on_action_replace_all_s Line 3109  void MainWindow::on_action_replace_all_s
3109  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
3110      if (!file) return;      if (!file) return;
3111      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3112      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3113      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3114            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3115            if (!it) continue;
3116          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3117          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
3118          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2727  void MainWindow::on_action_remove_sample Line 3137  void MainWindow::on_action_remove_sample
3137                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3138                  // them from the import queue                  // them from the import queue
3139                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3140                       member != members.end(); ++member) {                       member != members.end(); ++member)
3141                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3142                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3143                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3144                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3145                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3146                      }                      }
3147                  }                  }
3148                  file_changed();                  file_changed();
# Line 2750  void MainWindow::on_action_remove_sample Line 3157  void MainWindow::on_action_remove_sample
3157                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3158                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3159                  // the import queue                  // the import queue
3160                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3161                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3162                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3163                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3164                  }                  }
3165                  dimreg_changed();                  dimreg_changed();
3166                  file_changed();                  file_changed();
# Line 2813  void MainWindow::on_action_remove_unused Line 3216  void MainWindow::on_action_remove_unused
3216              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3217              // remove sample from the .gig file              // remove sample from the .gig file
3218              file->DeleteSample(sample);              file->DeleteSample(sample);
3219              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3220              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3221                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3222              {                         m_SampleImportQueue[sample].sample_path.c_str());
3223                  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;  
                 }  
3224              }              }
3225          }          }
3226      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2881  void MainWindow::on_instruments_treeview Line 3279  void MainWindow::on_instruments_treeview
3279      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3280      {      {
3281          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3282          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3283          if (it) {          if (!rows.empty()) {
3284              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3285              src = row[m_Columns.m_col_instr];              if (it) {
3286                    Gtk::TreeModel::Row row = *it;
3287                    src = row[m_Columns.m_col_instr];
3288                }
3289          }          }
3290      }      }
3291      if (!src) return;      if (!src) return;
# Line 2939  void MainWindow::on_sample_treeview_drag Line 3340  void MainWindow::on_sample_treeview_drag
3340      // get selected sample      // get selected sample
3341      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3342      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3343      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3344      if (it) {      if (!rows.empty()) {
3345          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3346          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3347                Gtk::TreeModel::Row row = *it;
3348                sample = row[m_SamplesModel.m_col_sample];
3349            }
3350      }      }
3351      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3352      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 3082  void MainWindow::script_double_clicked(c Line 3486  void MainWindow::script_double_clicked(c
3486      if (!script) return;      if (!script) return;
3487    
3488      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3489        editor->signal_script_to_be_changed.connect(
3490            signal_script_to_be_changed.make_slot()
3491        );
3492        editor->signal_script_changed.connect(
3493            signal_script_changed.make_slot()
3494        );
3495      editor->setScript(script);      editor->setScript(script);
3496      //editor->reparent(*this);      //editor->reparent(*this);
3497      editor->show();      editor->show();
# Line 3135  void MainWindow::on_action_combine_instr Line 3545  void MainWindow::on_action_combine_instr
3545    
3546  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3547      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3548      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3549        if (rows.empty()) return;
3550        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3551      if (!it) return;      if (!it) return;
3552      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3553      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3257  void MainWindow::on_action_merge_files() Line 3669  void MainWindow::on_action_merge_files()
3669      }      }
3670    
3671      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3672      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3673      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3674      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3675  #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 3384  void MainWindow::show_scripts_tab() { Line 3796  void MainWindow::show_scripts_tab() {
3796      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3797  }  }
3798    
3799    void MainWindow::select_prev_region() {
3800        m_RegionChooser.select_prev_region();
3801    }
3802    
3803    void MainWindow::select_next_region() {
3804        m_RegionChooser.select_next_region();
3805    }
3806    
3807    void MainWindow::select_next_dim_rgn_zone() {
3808        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3809        m_DimRegionChooser.select_next_dimzone();
3810    }
3811    
3812    void MainWindow::select_prev_dim_rgn_zone() {
3813        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3814        m_DimRegionChooser.select_prev_dimzone();
3815    }
3816    
3817    void MainWindow::select_add_next_dim_rgn_zone() {
3818        m_DimRegionChooser.select_next_dimzone(true);
3819    }
3820    
3821    void MainWindow::select_add_prev_dim_rgn_zone() {
3822        m_DimRegionChooser.select_prev_dimzone(true);
3823    }
3824    
3825    void MainWindow::select_prev_dimension() {
3826        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3827        m_DimRegionChooser.select_prev_dimension();
3828    }
3829    
3830    void MainWindow::select_next_dimension() {
3831        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3832        m_DimRegionChooser.select_next_dimension();
3833    }
3834    
3835    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3836        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3837    
3838    void MainWindow::copy_selected_dimrgn() {
3839        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3840        if (!pDimRgn) {
3841            updateClipboardPasteAvailable();
3842            updateClipboardCopyAvailable();
3843            return;
3844        }
3845    
3846        std::vector<Gtk::TargetEntry> targets;
3847        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3848    
3849        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3850        clipboard->set(
3851            targets,
3852            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3853            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3854        );
3855    
3856        m_serializationArchive.serialize(pDimRgn);
3857    
3858        updateClipboardPasteAvailable();
3859    }
3860    
3861    void MainWindow::paste_copied_dimrgn() {
3862        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3863        clipboard->request_contents(
3864            CLIPBOARD_DIMENSIONREGION_TARGET,
3865            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3866        );
3867        updateClipboardPasteAvailable();
3868    }
3869    
3870    void MainWindow::adjust_clipboard_content() {
3871        MacroEditor* editor = new MacroEditor();
3872        editor->setMacro(&m_serializationArchive);
3873        editor->show();
3874    }
3875    
3876    void MainWindow::updateClipboardPasteAvailable() {
3877        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3878        clipboard->request_targets(
3879            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3880        );
3881    }
3882    
3883    void MainWindow::updateClipboardCopyAvailable() {
3884        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3885        static_cast<Gtk::MenuItem*>(
3886            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3887        )->set_sensitive(bDimensionRegionCopyIsPossible);
3888    }
3889    
3890    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3891        updateClipboardPasteAvailable();
3892    }
3893    
3894    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3895        const std::string target = selection_data.get_target();
3896        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3897            selection_data.set(
3898                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3899                &m_serializationArchive.rawData()[0],
3900                m_serializationArchive.rawData().size()
3901            );
3902        } else {
3903            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3904        }
3905    }
3906    
3907    void MainWindow::on_clipboard_clear() {
3908        m_serializationArchive.clear();
3909        updateClipboardPasteAvailable();
3910        updateClipboardCopyAvailable();
3911    }
3912    
3913    //NOTE: Might throw exception !!!
3914    void MainWindow::applyMacro(Serialization::Archive& macro) {
3915        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3916        if (!pDimRgn) return;
3917    
3918        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3919             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3920        {
3921            gig::DimensionRegion* pDimRgn = *itDimReg;
3922            dimreg_to_be_changed_signal.emit(pDimRgn);
3923            m_serializationArchive.deserialize(pDimRgn);
3924            dimreg_changed_signal.emit(pDimRgn);
3925        }
3926        //region_changed()
3927        file_changed();
3928        dimreg_changed();
3929    }
3930    
3931    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3932        const std::string target = selection_data.get_target();
3933        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3934            Glib::ustring errorText;
3935            try {
3936                m_serializationArchive.decode(
3937                    selection_data.get_data(), selection_data.get_length()
3938                );
3939                applyMacro(m_serializationArchive);
3940            } catch (Serialization::Exception e) {
3941                errorText = e.Message;
3942            } catch (...) {
3943                errorText = _("Unknown exception while pasting DimensionRegion");
3944            }
3945            if (!errorText.empty()) {
3946                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3947                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3948                msg.run();
3949            }
3950        }
3951    }
3952    
3953    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3954        const bool bDimensionRegionPasteIsPossible =
3955            std::find(targets.begin(), targets.end(),
3956                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3957    
3958        static_cast<Gtk::MenuItem*>(
3959            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3960        )->set_sensitive(bDimensionRegionPasteIsPossible);
3961    
3962        static_cast<Gtk::MenuItem*>(
3963            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3964        )->set_sensitive(bDimensionRegionPasteIsPossible);
3965    }
3966    
3967  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3968      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3969  }  }

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

  ViewVC Help
Powered by ViewVC