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

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

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

revision 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC revision 3155 by schoenebeck, Sun May 7 15:32:43 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
# Line 27  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
 #include <gtkmm/stock.h>  
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
# Line 50  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    #include "MacroEditor.h"
62    
63  MainWindow::MainWindow() :  MainWindow::MainWindow() :
64      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
65      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
66      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
67      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
68      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
69        labelLegend(_("Legend:")),
70        labelNoSample(_(" No Sample")),
71        labelMissingSample(_(" Missing some Sample(s)")),
72        labelLooped(_(" Looped")),
73        labelSomeLoops(_(" Some Loop(s)"))
74  {  {
75        loadBuiltInPix();
76    
77  //    set_border_width(5);  //    set_border_width(5);
78  //    set_default_size(400, 200);  //    set_default_size(400, 200);
79    
   
80      add(m_VBox);      add(m_VBox);
81    
82      // Handle selection      // Handle selection
# Line 96  MainWindow::MainWindow() : Line 110  MainWindow::MainWindow() :
110      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
111      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
112      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
113        {
114            legend_hbox.add(labelLegend);
115    
116            imageNoSample.set(redDot);
117            imageNoSample.set_alignment(Gtk::ALIGN_END);
118            labelNoSample.set_alignment(Gtk::ALIGN_START);
119            legend_hbox.add(imageNoSample);
120            legend_hbox.add(labelNoSample);
121    
122            imageMissingSample.set(yellowDot);
123            imageMissingSample.set_alignment(Gtk::ALIGN_END);
124            labelMissingSample.set_alignment(Gtk::ALIGN_START);
125            legend_hbox.add(imageMissingSample);
126            legend_hbox.add(labelMissingSample);
127    
128            imageLooped.set(blackLoop);
129            imageLooped.set_alignment(Gtk::ALIGN_END);
130            labelLooped.set_alignment(Gtk::ALIGN_START);
131            legend_hbox.add(imageLooped);
132            legend_hbox.add(labelLooped);
133    
134            imageSomeLoops.set(grayLoop);
135            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
136            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
137            legend_hbox.add(imageSomeLoops);
138            legend_hbox.add(labelSomeLoops);
139    
140            legend_hbox.show_all_children();
141        }
142        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
143      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
144    
145      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 110  MainWindow::MainWindow() : Line 154  MainWindow::MainWindow() :
154      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
155    
156      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
157      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),      actionGroup->add(Gtk::Action::create("New", _("_New")),
158                         Gtk::AccelKey("<control>n"),
159                       sigc::mem_fun(                       sigc::mem_fun(
160                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
161      Glib::RefPtr<Gtk::Action> action =      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),
162          Gtk::Action::create("Open", Gtk::Stock::OPEN);                       Gtk::AccelKey("<control>o"),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
163                       sigc::mem_fun(                       sigc::mem_fun(
164                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
165      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),      actionGroup->add(Gtk::Action::create("Save", _("_Save")),
166                         Gtk::AccelKey("<control>s"),
167                       sigc::mem_fun(                       sigc::mem_fun(
168                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
169      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),
     action->property_label() = action->property_label() + "...";  
     actionGroup->add(action,  
170                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
171                       sigc::mem_fun(                       sigc::mem_fun(
172                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
173      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
174                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
175                       sigc::mem_fun(                       sigc::mem_fun(
176                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
177      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
178                                           Gtk::Stock::PROPERTIES),                                           _("_Properties")),
179                       sigc::mem_fun(                       sigc::mem_fun(
180                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
181      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 144  MainWindow::MainWindow() : Line 186  MainWindow::MainWindow() :
186                                           _("_Script Slots...")),                                           _("_Script Slots...")),
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
189      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),
190                         Gtk::AccelKey("<control>q"),
191                       sigc::mem_fun(                       sigc::mem_fun(
192                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
193      actionGroup->add(      actionGroup->add(
# Line 156  MainWindow::MainWindow() : Line 199  MainWindow::MainWindow() :
199          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
200      );      );
201      actionGroup->add(      actionGroup->add(
202          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
203          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
204      );      );
205      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
206    
207      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
208    
209        const Gdk::ModifierType primaryModifierKey =
210    #if defined(__APPLE__)
211        Gdk::META_MASK; // Cmd key on Mac
212    #else
213        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
214    #endif
215    
216        actionGroup->add(Gtk::Action::create("CopyDimRgn",
217                                             _("Copy selected dimension region")),
218                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
219                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
220    
221        actionGroup->add(Gtk::Action::create("PasteDimRgn",
222                                             _("Paste dimension region")),
223                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
224                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
225    
226        actionGroup->add(Gtk::Action::create("AdjustClipboard",
227                                             _("Adjust Clipboard Content")),
228                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
229                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
230    
231        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
232                                             _("Select Previous Region")),
233                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
234                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
235    
236        actionGroup->add(Gtk::Action::create("SelectNextRegion",
237                                             _("Select Next Region")),
238                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
239                         sigc::mem_fun(*this, &MainWindow::select_next_region));
240    
241        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
242                                             _("Select Previous Dimension Region Zone")),
243                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
244                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
245    
246        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
247                                             _("Select Next Dimension Region Zone")),
248                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
249                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
250    
251        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
252                                             _("Select Previous Dimension")),
253                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
254                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
255    
256        actionGroup->add(Gtk::Action::create("SelectNextDimension",
257                                             _("Select Next Dimension")),
258                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
259                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
260    
261        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
262                                             _("Add Previous Dimension Region Zone to Selection")),
263                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
264                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
265    
266        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
267                                             _("Add Next Dimension Region Zone to Selection")),
268                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
269                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
270    
271      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
272          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
273      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 179  MainWindow::MainWindow() : Line 284  MainWindow::MainWindow() :
284      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
285    
286    
287      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
288      toggle_action =      toggle_action =
289          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
290      toggle_action->set_active(true);      toggle_action->set_active(true);
291      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
292                       sigc::mem_fun(                       sigc::mem_fun(
293                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
294    
295        toggle_action =
296            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
297        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
298        actionGroup->add(toggle_action,
299                         sigc::mem_fun(
300                             *this, &MainWindow::on_auto_restore_win_dim));
301    
302        toggle_action =
303            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
304        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
305        actionGroup->add(toggle_action,
306                         sigc::mem_fun(
307                             *this, &MainWindow::on_save_with_temporary_file));
308    
309      actionGroup->add(      actionGroup->add(
310          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
311          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
312      );                      );                
313    
314      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
315      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("About", _("_About")),
                                          action->property_label()));  
     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),  
316                       sigc::mem_fun(                       sigc::mem_fun(
317                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
318      actionGroup->add(      actionGroup->add(
# Line 206  MainWindow::MainWindow() : Line 324  MainWindow::MainWindow() :
324          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
325      );      );
326      actionGroup->add(      actionGroup->add(
327          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", _("_Remove")),
328          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
329      );      );
330    
# Line 253  MainWindow::MainWindow() : Line 371  MainWindow::MainWindow() :
371    
372      // sample right-click popup actions      // sample right-click popup actions
373      actionGroup->add(      actionGroup->add(
374          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", _("_Properties")),
375          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
376      );      );
377      actionGroup->add(      actionGroup->add(
# Line 265  MainWindow::MainWindow() : Line 383  MainWindow::MainWindow() :
383          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
384      );      );
385      actionGroup->add(      actionGroup->add(
386          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", _("_Remove")),
387          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
388      );      );
389      actionGroup->add(      actionGroup->add(
# Line 301  MainWindow::MainWindow() : Line 419  MainWindow::MainWindow() :
419          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
420      );      );
421      actionGroup->add(      actionGroup->add(
422          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveScript", _("_Remove")),
423          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
424      );      );
425    
# Line 324  MainWindow::MainWindow() : Line 442  MainWindow::MainWindow() :
442          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
443          "    </menu>"          "    </menu>"
444          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
445            "      <menuitem action='CopyDimRgn'/>"
446            "      <menuitem action='AdjustClipboard'/>"
447            "      <menuitem action='PasteDimRgn'/>"
448            "      <separator/>"
449            "      <menuitem action='SelectPrevRegion'/>"
450            "      <menuitem action='SelectNextRegion'/>"
451            "      <separator/>"
452            "      <menuitem action='SelectPrevDimension'/>"
453            "      <menuitem action='SelectNextDimension'/>"
454            "      <menuitem action='SelectPrevDimRgnZone'/>"
455            "      <menuitem action='SelectNextDimRgnZone'/>"
456            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
457            "      <menuitem action='SelectAddNextDimRgnZone'/>"
458            "      <separator/>"
459          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
460          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
461          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
# Line 360  MainWindow::MainWindow() : Line 492  MainWindow::MainWindow() :
492          "    </menu>"          "    </menu>"
493          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
494          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
495            "      <menuitem action='AutoRestoreWinDim'/>"
496          "      <separator/>"          "      <separator/>"
497          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
498          "    </menu>"          "    </menu>"
# Line 371  MainWindow::MainWindow() : Line 504  MainWindow::MainWindow() :
504          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
505          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
506          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
507            "      <menuitem action='SaveWithTemporaryFile'/>"
508          "    </menu>"          "    </menu>"
509          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
510          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 458  MainWindow::MainWindow() : Line 592  MainWindow::MainWindow() :
592      }      }
593      {      {
594          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
595                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
596            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
597        }
598        {
599            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
600              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
601          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."));
602      }      }
# Line 495  MainWindow::MainWindow() : Line 634  MainWindow::MainWindow() :
634      // Create the Tree model:      // Create the Tree model:
635      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
636      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
637        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
638      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."));
639      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
640          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
641      );      );
642    
643      // Add the TreeView's view columns:      // Add the TreeView's view columns:
644      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
645      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
646        m_TreeView.set_headers_visible(true);
647            
648      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
649      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 525  MainWindow::MainWindow() : Line 666  MainWindow::MainWindow() :
666      // create samples treeview (including its data model)      // create samples treeview (including its data model)
667      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
668      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
669        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
670      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."));
671      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
672      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 676  MainWindow::MainWindow() : Line 818  MainWindow::MainWindow() :
818    
819      // select 'Instruments' tab by default      // select 'Instruments' tab by default
820      // (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)
821      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
822    
823        Gtk::Clipboard::get()->signal_owner_change().connect(
824            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
825        );
826        updateClipboardPasteAvailable();
827        updateClipboardCopyAvailable();
828  }  }
829    
830  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 702  void MainWindow::region_changed() Line 850  void MainWindow::region_changed()
850  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
851  {  {
852      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
853      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
854          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
855        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
856      if (it) {      if (it) {
857          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
858          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 746  void MainWindow::update_dimregs() Line 895  void MainWindow::update_dimregs()
895              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
896          }          }
897      }      }
898    
899        m_RegionChooser.setModifyAllRegions(all_regions);
900        m_DimRegionChooser.setModifyAllRegions(all_regions);
901        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
902        m_DimRegionChooser.setModifyBothChannels(stereo);
903    
904        updateClipboardCopyAvailable();
905  }  }
906    
907  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 763  void MainWindow::dimreg_changed() Line 919  void MainWindow::dimreg_changed()
919  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
920  {  {
921      // select item in instrument menu      // select item in instrument menu
922      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
923      if (it) {      if (!rows.empty()) {
924          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
925          int index = path[0];          if (it) {
926          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
927              instrument_menu->get_children();              int index = path[0];
928          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
929                    instrument_menu->get_children();
930                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
931            }
932      }      }
933    
934      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 794  void Loader::progress_callback(float fra Line 953  void Loader::progress_callback(float fra
953      progress_dispatcher();      progress_dispatcher();
954  }  }
955    
956    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
957    // make sure stack is 16-byte aligned for SSE instructions
958    __attribute__((force_align_arg_pointer))
959    #endif
960  void Loader::thread_function()  void Loader::thread_function()
961  {  {
962      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
963               static_cast<void*>(Glib::Threads::Thread::self()));
964      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
965      try {      try {
966          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 818  void Loader::thread_function() Line 982  void Loader::thread_function()
982  }  }
983    
984  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
985      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
986  {  {
987  }  }
988    
# Line 829  void Loader::launch() Line 993  void Loader::launch()
993  #else  #else
994      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
995  #endif  #endif
996      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
997  }  }
998    
999  float Loader::get_progress()  float Loader::get_progress()
# Line 872  void Saver::progress_callback(float frac Line 1036  void Saver::progress_callback(float frac
1036      progress_dispatcher.emit();      progress_dispatcher.emit();
1037  }  }
1038    
1039    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1040    // make sure stack is 16-byte aligned for SSE instructions
1041    __attribute__((force_align_arg_pointer))
1042    #endif
1043  void Saver::thread_function()  void Saver::thread_function()
1044  {  {
1045      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1046               static_cast<void*>(Glib::Threads::Thread::self()));
1047      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1048      try {      try {
1049          gig::progress_t progress;          gig::progress_t progress;
# Line 883  void Saver::thread_function() Line 1052  void Saver::thread_function()
1052    
1053          // 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"
1054          if (filename.empty()) {          if (filename.empty()) {
1055              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1056                    // save directly over the existing .gig file
1057                    // (requires less disk space than solution below
1058                    // but may be slower)
1059                    gig->Save(&progress);
1060                } else {
1061                    // save the file as separate temporary file first,
1062                    // then move the saved file over the old file
1063                    // (may result in performance speedup during save)
1064                    String tmpname = filename + ".TMP";
1065                    gig->Save(tmpname, &progress);
1066                    #if defined(WIN32)
1067                    if (!DeleteFile(filename.c_str())) {
1068                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1069                    }
1070                    #else // POSIX ...
1071                    if (unlink(filename.c_str())) {
1072                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1073                    }
1074                    #endif
1075                    if (rename(tmpname.c_str(), filename.c_str())) {
1076                        #if defined(WIN32)
1077                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1078                        #else
1079                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1080                        #endif
1081                    }
1082                }
1083          } else {          } else {
1084              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1085          }          }
# Line 911  void Saver::launch() Line 1107  void Saver::launch()
1107  #else  #else
1108      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1109  #endif  #endif
1110      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1111  }  }
1112    
1113  float Saver::get_progress()  float Saver::get_progress()
# Line 1008  bool MainWindow::close_confirmation_dial Line 1204  bool MainWindow::close_confirmation_dial
1204      g_free(msg);      g_free(msg);
1205      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."));
1206      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1207      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1208      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);
1209      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1210      int response = dialog.run();      int response = dialog.run();
1211      dialog.hide();      dialog.hide();
# Line 1040  bool MainWindow::leaving_shared_mode_dia Line 1236  bool MainWindow::leaving_shared_mode_dia
1236            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1237            "load it."));            "load it."));
1238      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1239      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1240      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1241      int response = dialog.run();      int response = dialog.run();
1242      dialog.hide();      dialog.hide();
# Line 1054  void MainWindow::on_action_file_open() Line 1250  void MainWindow::on_action_file_open()
1250      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1251    
1252      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1253      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1254      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
1255      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1256  #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
1257      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1071  void MainWindow::on_action_file_open() Line 1267  void MainWindow::on_action_file_open()
1267      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1268          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1269          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1270          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1271                   static_cast<void*>(Glib::Threads::Thread::self()));
1272          load_file(filename.c_str());          load_file(filename.c_str());
1273          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1274      }      }
# Line 1141  void MainWindow::on_loader_progress() Line 1338  void MainWindow::on_loader_progress()
1338  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1339  {  {
1340      printf("Loader finished!\n");      printf("Loader finished!\n");
1341      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1342               static_cast<void*>(Glib::Threads::Thread::self()));
1343      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1344      progress_dialog->hide();      progress_dialog->hide();
1345  }  }
# Line 1248  void MainWindow::on_action_file_save_as( Line 1446  void MainWindow::on_action_file_save_as(
1446    
1447  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1448  {  {
1449      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1450      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
1451      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
1452      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1453      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1454    
# Line 1281  bool MainWindow::file_save_as() Line 1479  bool MainWindow::file_save_as()
1479      // show warning in the dialog      // show warning in the dialog
1480      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1481      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1482      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1483        warningIcon.set_from_icon_name("dialog-warning",
1484                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1485      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1486  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1487      view::WrapLabel description;      view::WrapLabel description;
# Line 1333  bool MainWindow::file_save_as() Line 1533  bool MainWindow::file_save_as()
1533  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1534      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1535      Glib::ustring error_files;      Glib::ustring error_files;
1536      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1537      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1538           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1539          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1540          SF_INFO info;          SF_INFO info;
1541          info.format = 0;          info.format = 0;
1542          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);
1543          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1544          try {          try {
1545              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1362  void MainWindow::__import_queued_samples Line 1562  void MainWindow::__import_queued_samples
1562                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1563              }              }
1564    
1565                // reset write position for sample
1566                iter->first->SetPos(0);
1567    
1568              const int bufsize = 10000;              const int bufsize = 10000;
1569              switch (bitdepth) {              switch (bitdepth) {
1570                  case 16: {                  case 16: {
# Line 1371  void MainWindow::__import_queued_samples Line 1574  void MainWindow::__import_queued_samples
1574                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1575                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1576                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1577                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1578                          cnt -= n;                          cnt -= n;
1579                      }                      }
1580                      delete[] buffer;                      delete[] buffer;
# Line 1391  void MainWindow::__import_queued_samples Line 1594  void MainWindow::__import_queued_samples
1594                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1595                          }                          }
1596                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1597                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1598                          cnt -= n;                          cnt -= n;
1599                      }                      }
1600                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1402  void MainWindow::__import_queued_samples Line 1605  void MainWindow::__import_queued_samples
1605              // cleanup              // cleanup
1606              sf_close(hFile);              sf_close(hFile);
1607              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1608              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1609              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1610              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1611              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1612              ++iter;              ++iter;
1613              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1614          } catch (std::string what) {          } catch (std::string what) {
1615              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1616              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1617              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1618              ++iter;              ++iter;
1619          }          }
1620      }      }
# Line 1453  void MainWindow::on_action_help_about() Line 1656  void MainWindow::on_action_help_about()
1656      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1657  #endif  #endif
1658      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1659      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1660      const std::string sComment =      const std::string sComment =
1661          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1662          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1490  PropDialog::PropDialog() Line 1693  PropDialog::PropDialog()
1693        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1694        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1695        eSubject(_("Subject")),        eSubject(_("Subject")),
1696        quitButton(Gtk::Stock::CLOSE),        quitButton(_("_Close"), true),
1697        table(2, 1),        table(2, 1),
1698        m_file(NULL)        m_file(NULL)
1699  {  {
# Line 1613  void InstrumentProps::set_MIDIProgram(ui Line 1816  void InstrumentProps::set_MIDIProgram(ui
1816  }  }
1817    
1818  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1819      quitButton(Gtk::Stock::CLOSE),      quitButton(_("_Close"), true),
1820      table(2,1),      table(2,1),
1821      eName(_("Name")),      eName(_("Name")),
1822      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1748  void MainWindow::load_gig(gig::File* gig Line 1951  void MainWindow::load_gig(gig::File* gig
1951      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1952    
1953      instrument_name_connection.block();      instrument_name_connection.block();
1954        int index = 0;
1955      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1956           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1957          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1958    
1959          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1960          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1961            row[m_Columns.m_col_nr] = index;
1962          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1963          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1964    
# Line 1826  bool MainWindow::instr_props_set_instrum Line 2031  bool MainWindow::instr_props_set_instrum
2031  {  {
2032      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2033    
2034      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2035          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2036            instrumentProps.hide();
2037            return false;
2038        }
2039        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2040      if (it) {      if (it) {
2041          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2042          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1880  void MainWindow::show_midi_rules() Line 2089  void MainWindow::show_midi_rules()
2089  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2090      if (!file) return;      if (!file) return;
2091      // get selected instrument      // get selected instrument
2092      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2093      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2094        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2095      if (!it) return;      if (!it) return;
2096      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2097      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1908  void MainWindow::on_action_view_status_b Line 2118  void MainWindow::on_action_view_status_b
2118      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2119  }  }
2120    
2121    void MainWindow::on_auto_restore_win_dim() {
2122        Gtk::CheckMenuItem* item =
2123            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2124        if (!item) {
2125            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2126            return;
2127        }
2128        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2129    }
2130    
2131    void MainWindow::on_save_with_temporary_file() {
2132        Gtk::CheckMenuItem* item =
2133            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2134        if (!item) {
2135            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2136            return;
2137        }
2138        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2139    }
2140    
2141  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2142      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2143          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1981  void MainWindow::select_instrument(gig:: Line 2211  void MainWindow::select_instrument(gig::
2211          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2212              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2213              show_intruments_tab();              show_intruments_tab();
2214                m_TreeView.get_selection()->unselect_all();
2215              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2216              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2217                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2218              );              if (!rows.empty())
2219              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2220              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2221          }          }
2222      }      }
# Line 2002  bool MainWindow::select_dimension_region Line 2233  bool MainWindow::select_dimension_region
2233          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2234              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2235              show_intruments_tab();              show_intruments_tab();
2236                m_TreeView.get_selection()->unselect_all();
2237              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2238              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2239                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2240              );              if (!rows.empty())
2241              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2242              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2243    
2244              // select respective region in the region selector              // select respective region in the region selector
# Line 2032  void MainWindow::select_sample(gig::Samp Line 2264  void MainWindow::select_sample(gig::Samp
2264              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2265              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2266                  show_samples_tab();                  show_samples_tab();
2267                    m_TreeViewSamples.get_selection()->unselect_all();
2268                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2269                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2270                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2271                  );                  if (rows.empty()) return;
2272                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2273                  return;                  return;
2274              }              }
2275          }          }
# Line 2045  void MainWindow::select_sample(gig::Samp Line 2278  void MainWindow::select_sample(gig::Samp
2278    
2279  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2280      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2281            // by default if Ctrl keys is pressed down, then a mouse right-click
2282            // does not select the respective row, so we must assure this
2283            // programmatically ...
2284            /*{
2285                Gtk::TreeModel::Path path;
2286                Gtk::TreeViewColumn* pColumn = NULL;
2287                int cellX, cellY;
2288                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2289                    (int)button->x, (int)button->y,
2290                    path, pColumn, cellX, cellY
2291                );
2292                if (bSuccess) {
2293                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2294                        printf("not selected !!!\n");
2295                        m_TreeViewSamples.get_selection()->select(path);
2296                    }
2297                }
2298            }*/
2299    
2300          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2301              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2302          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2303          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2304          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2305          bool group_selected  = false;          const int n = rows.size();
2306          bool sample_selected = false;          int nGroups  = 0;
2307          if (it) {          int nSamples = 0;
2308            for (int r = 0; r < n; ++r) {
2309                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2310                if (!it) continue;
2311              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2312              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2313              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2314          }          }
2315            
               
2316          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2317              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2318          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2319              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2320          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2321              set_sensitive(file);              set_sensitive(file);
2322          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2323              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2324          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2325              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2326          // show sample popup          // show sample popup
2327          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2328    
2329          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2330              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2331          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2332              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2333          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2334              set_sensitive(file);              set_sensitive(file);
2335          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2336              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2337          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2338              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2339      }      }
2340  }  }
2341    
# Line 2160  void MainWindow::add_instrument(gig::Ins Line 2414  void MainWindow::add_instrument(gig::Ins
2414      instrument_name_connection.block();      instrument_name_connection.block();
2415      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2416      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2417        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2418      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2419      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2420      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2188  void MainWindow::on_action_duplicate_ins Line 2443  void MainWindow::on_action_duplicate_ins
2443      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2444      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2445      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2446      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2447      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2448      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2449      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2450      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2451                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2452      // duplicate the orginal instrument              if (instrOrig) {
2453      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2454      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2455          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2456          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2457                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2458    
2459      add_instrument(instrNew);                  add_instrument(instrNew);
2460                }
2461            }
2462        }
2463  }  }
2464    
2465  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2217  void MainWindow::on_action_remove_instru Line 2476  void MainWindow::on_action_remove_instru
2476      }      }
2477    
2478      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2479      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2480      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2481            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2482            if (!it) continue;
2483          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2484          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2485          try {          try {
# Line 2233  void MainWindow::on_action_remove_instru Line 2494  void MainWindow::on_action_remove_instru
2494    
2495              // remove row from instruments tree view              // remove row from instruments tree view
2496              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2497                // update "Nr" column of all instrument rows
2498                {
2499                    int index = 0;
2500                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2501                         it != m_refTreeModel->children().end(); ++it, ++index)
2502                    {
2503                        Gtk::TreeModel::Row row = *it;
2504                        row[m_Columns.m_col_nr] = index;
2505                    }
2506                }
2507    
2508  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2509              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2330  void MainWindow::on_action_edit_script() Line 2601  void MainWindow::on_action_edit_script()
2601      if (!script) return;      if (!script) return;
2602    
2603      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2604        editor->signal_script_to_be_changed.connect(
2605            signal_script_to_be_changed.make_slot()
2606        );
2607        editor->signal_script_changed.connect(
2608            signal_script_changed.make_slot()
2609        );
2610      editor->setScript(script);      editor->setScript(script);
2611      //editor->reparent(*this);      //editor->reparent(*this);
2612      editor->show();      editor->show();
# Line 2408  void MainWindow::add_or_replace_sample(b Line 2685  void MainWindow::add_or_replace_sample(b
2685    
2686      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2687      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2688      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2689        if (rows.empty()) return;
2690        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2691      if (!it) return;      if (!it) return;
2692      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2693      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2426  void MainWindow::add_or_replace_sample(b Line 2705  void MainWindow::add_or_replace_sample(b
2705    
2706      // show 'browse for file' dialog      // show 'browse for file' dialog
2707      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2708      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2709      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2710      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
2711    
2712      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2557  void MainWindow::add_or_replace_sample(b Line 2836  void MainWindow::add_or_replace_sample(b
2836                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2837                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2838                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2839                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2840                  // add sample to the tree view                  // add sample to the tree view
2841                  if (replace) {                  if (replace) {
2842                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2627  void MainWindow::on_action_replace_all_s Line 2906  void MainWindow::on_action_replace_all_s
2906      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2907      description.show();      description.show();
2908      entryArea.show_all();      entryArea.show_all();
2909      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2910      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2911      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
2912      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2651  void MainWindow::on_action_replace_all_s Line 2930  void MainWindow::on_action_replace_all_s
2930              try              try
2931              {              {
2932                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
2933                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
2934                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
2935                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
2936                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
2937                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
2938                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
2939                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
2940                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
2941                          break;                          break;
2942                      default:                      default:
2943                          sf_close(hFile);                          sf_close(hFile);
# Line 2671  void MainWindow::on_action_replace_all_s Line 2946  void MainWindow::on_action_replace_all_s
2946                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2947                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2948                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
2949                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2950                  sf_close(hFile);                  sf_close(hFile);
2951                  file_changed();                  file_changed();
2952              }              }
# Line 2695  void MainWindow::on_action_replace_all_s Line 2970  void MainWindow::on_action_replace_all_s
2970  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2971      if (!file) return;      if (!file) return;
2972      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2973      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2974      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2975            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2976            if (!it) continue;
2977          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2978          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2979          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2721  void MainWindow::on_action_remove_sample Line 2998  void MainWindow::on_action_remove_sample
2998                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
2999                  // them from the import queue                  // them from the import queue
3000                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3001                       member != members.end(); ++member) {                       member != members.end(); ++member)
3002                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3003                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3004                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3005                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3006                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3007                      }                      }
3008                  }                  }
3009                  file_changed();                  file_changed();
# Line 2744  void MainWindow::on_action_remove_sample Line 3018  void MainWindow::on_action_remove_sample
3018                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3019                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3020                  // the import queue                  // the import queue
3021                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3022                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3023                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3024                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3025                  }                  }
3026                  dimreg_changed();                  dimreg_changed();
3027                  file_changed();                  file_changed();
# Line 2807  void MainWindow::on_action_remove_unused Line 3077  void MainWindow::on_action_remove_unused
3077              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3078              // remove sample from the .gig file              // remove sample from the .gig file
3079              file->DeleteSample(sample);              file->DeleteSample(sample);
3080              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3081              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3082                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3083              {                         m_SampleImportQueue[sample].sample_path.c_str());
3084                  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;  
                 }  
3085              }              }
3086          }          }
3087      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2875  void MainWindow::on_instruments_treeview Line 3140  void MainWindow::on_instruments_treeview
3140      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3141      {      {
3142          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3143          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3144          if (it) {          if (!rows.empty()) {
3145              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3146              src = row[m_Columns.m_col_instr];              if (it) {
3147                    Gtk::TreeModel::Row row = *it;
3148                    src = row[m_Columns.m_col_instr];
3149                }
3150          }          }
3151      }      }
3152      if (!src) return;      if (!src) return;
# Line 2933  void MainWindow::on_sample_treeview_drag Line 3201  void MainWindow::on_sample_treeview_drag
3201      // get selected sample      // get selected sample
3202      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3203      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3204      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3205      if (it) {      if (!rows.empty()) {
3206          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3207          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3208                Gtk::TreeModel::Row row = *it;
3209                sample = row[m_SamplesModel.m_col_sample];
3210            }
3211      }      }
3212      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3213      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 3076  void MainWindow::script_double_clicked(c Line 3347  void MainWindow::script_double_clicked(c
3347      if (!script) return;      if (!script) return;
3348    
3349      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3350        editor->signal_script_to_be_changed.connect(
3351            signal_script_to_be_changed.make_slot()
3352        );
3353        editor->signal_script_changed.connect(
3354            signal_script_changed.make_slot()
3355        );
3356      editor->setScript(script);      editor->setScript(script);
3357      //editor->reparent(*this);      //editor->reparent(*this);
3358      editor->show();      editor->show();
# Line 3129  void MainWindow::on_action_combine_instr Line 3406  void MainWindow::on_action_combine_instr
3406    
3407  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3408      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3409      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3410        if (rows.empty()) return;
3411        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3412      if (!it) return;      if (!it) return;
3413      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3414      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3251  void MainWindow::on_action_merge_files() Line 3530  void MainWindow::on_action_merge_files()
3530      }      }
3531    
3532      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3533      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3534      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3535      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3536  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 3270  void MainWindow::on_action_merge_files() Line 3549  void MainWindow::on_action_merge_files()
3549      // show warning in the file picker dialog      // show warning in the file picker dialog
3550      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3551      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3552      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3553        warningIcon.set_from_icon_name("dialog-warning",
3554                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3555      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3556  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3557      view::WrapLabel description;      view::WrapLabel description;
# Line 3293  void MainWindow::on_action_merge_files() Line 3574  void MainWindow::on_action_merge_files()
3574      descriptionArea.show_all();      descriptionArea.show_all();
3575    
3576      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3577          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3578                   static_cast<void*>(Glib::Threads::Thread::self()));
3579          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3580    
3581          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3375  void MainWindow::show_scripts_tab() { Line 3657  void MainWindow::show_scripts_tab() {
3657      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3658  }  }
3659    
3660    void MainWindow::select_prev_region() {
3661        m_RegionChooser.select_prev_region();
3662    }
3663    
3664    void MainWindow::select_next_region() {
3665        m_RegionChooser.select_next_region();
3666    }
3667    
3668    void MainWindow::select_next_dim_rgn_zone() {
3669        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3670        m_DimRegionChooser.select_next_dimzone();
3671    }
3672    
3673    void MainWindow::select_prev_dim_rgn_zone() {
3674        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3675        m_DimRegionChooser.select_prev_dimzone();
3676    }
3677    
3678    void MainWindow::select_add_next_dim_rgn_zone() {
3679        m_DimRegionChooser.select_next_dimzone(true);
3680    }
3681    
3682    void MainWindow::select_add_prev_dim_rgn_zone() {
3683        m_DimRegionChooser.select_prev_dimzone(true);
3684    }
3685    
3686    void MainWindow::select_prev_dimension() {
3687        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3688        m_DimRegionChooser.select_prev_dimension();
3689    }
3690    
3691    void MainWindow::select_next_dimension() {
3692        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3693        m_DimRegionChooser.select_next_dimension();
3694    }
3695    
3696    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3697        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3698    
3699    void MainWindow::copy_selected_dimrgn() {
3700        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3701        if (!pDimRgn) {
3702            updateClipboardPasteAvailable();
3703            updateClipboardCopyAvailable();
3704            return;
3705        }
3706    
3707        std::vector<Gtk::TargetEntry> targets;
3708        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3709    
3710        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3711        clipboard->set(
3712            targets,
3713            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3714            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3715        );
3716    
3717        m_serializationArchive.serialize(pDimRgn);
3718    
3719        updateClipboardPasteAvailable();
3720    }
3721    
3722    void MainWindow::paste_copied_dimrgn() {
3723        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3724        clipboard->request_contents(
3725            CLIPBOARD_DIMENSIONREGION_TARGET,
3726            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3727        );
3728        updateClipboardPasteAvailable();
3729    }
3730    
3731    void MainWindow::adjust_clipboard_content() {
3732        MacroEditor* editor = new MacroEditor();
3733        editor->setMacro(&m_serializationArchive);
3734        editor->show();
3735    }
3736    
3737    void MainWindow::updateClipboardPasteAvailable() {
3738        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3739        clipboard->request_targets(
3740            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3741        );
3742    }
3743    
3744    void MainWindow::updateClipboardCopyAvailable() {
3745        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3746        static_cast<Gtk::MenuItem*>(
3747            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3748        )->set_sensitive(bDimensionRegionCopyIsPossible);
3749    }
3750    
3751    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3752        updateClipboardPasteAvailable();
3753    }
3754    
3755    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3756        const std::string target = selection_data.get_target();
3757        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3758            selection_data.set(
3759                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3760                &m_serializationArchive.rawData()[0],
3761                m_serializationArchive.rawData().size()
3762            );
3763        } else {
3764            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3765        }
3766    }
3767    
3768    void MainWindow::on_clipboard_clear() {
3769        m_serializationArchive.clear();
3770        updateClipboardPasteAvailable();
3771        updateClipboardCopyAvailable();
3772    }
3773    
3774    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3775        const std::string target = selection_data.get_target();
3776        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3777            gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3778            if (!pDimRgn) return;
3779    
3780            Glib::ustring errorText;
3781            try {
3782                m_serializationArchive.decode(
3783                    selection_data.get_data(), selection_data.get_length()
3784                );
3785    
3786                for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3787                     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3788                {
3789                    gig::DimensionRegion* pDimRgn = *itDimReg;
3790    
3791                    dimreg_to_be_changed_signal.emit(pDimRgn);
3792    
3793                    m_serializationArchive.deserialize(pDimRgn);
3794    
3795                    dimreg_changed_signal.emit(pDimRgn);
3796                }
3797    
3798                //region_changed()
3799                file_changed();
3800                dimreg_changed();
3801    
3802            } catch (Serialization::Exception e) {
3803                errorText = e.Message;
3804            } catch (...) {
3805                errorText = _("Unknown exception during deserialization decoding");
3806            }
3807            if (!errorText.empty()) {
3808                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3809                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3810                msg.run();
3811            }
3812        }
3813    }
3814    
3815    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3816        const bool bDimensionRegionPasteIsPossible =
3817            std::find(targets.begin(), targets.end(),
3818                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3819    
3820        static_cast<Gtk::MenuItem*>(
3821            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3822        )->set_sensitive(bDimensionRegionPasteIsPossible);
3823    
3824        static_cast<Gtk::MenuItem*>(
3825            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3826        )->set_sensitive(bDimensionRegionPasteIsPossible);
3827    }
3828    
3829  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3830      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3831  }  }

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

  ViewVC Help
Powered by ViewVC