/[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 2694 by schoenebeck, Tue Jan 6 16:08:48 2015 UTC revision 3177 by schoenebeck, Thu May 11 20:59:46 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 31  Line 39 
39  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
40  #include <gtkmm/main.h>  #include <gtkmm/main.h>
41  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
42    #include <gtkmm/accelmap.h>
43  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
44  #include "wrapLabel.hh"  #include "wrapLabel.hh"
45  #endif  #endif
# Line 50  Line 59 
59  #include "ReferencesView.h"  #include "ReferencesView.h"
60  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
61  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
62    #include "gfx/builtinpix.h"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    
66  MainWindow::MainWindow() :  MainWindow::MainWindow() :
67      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
68      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
69      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
70      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
71      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
72        labelLegend(_("Legend:")),
73        labelNoSample(_(" No Sample")),
74        labelMissingSample(_(" Missing some Sample(s)")),
75        labelLooped(_(" Looped")),
76        labelSomeLoops(_(" Some Loop(s)"))
77  {  {
78        loadBuiltInPix();
79    
80  //    set_border_width(5);  //    set_border_width(5);
81  //    set_default_size(400, 200);  //    set_default_size(400, 200);
82    
   
83      add(m_VBox);      add(m_VBox);
84    
85      // Handle selection      // Handle selection
# Line 96  MainWindow::MainWindow() : Line 113  MainWindow::MainWindow() :
113      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
114      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
115      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
116        {
117            legend_hbox.add(labelLegend);
118    
119            imageNoSample.set(redDot);
120            imageNoSample.set_alignment(Gtk::ALIGN_END);
121            labelNoSample.set_alignment(Gtk::ALIGN_START);
122            legend_hbox.add(imageNoSample);
123            legend_hbox.add(labelNoSample);
124    
125            imageMissingSample.set(yellowDot);
126            imageMissingSample.set_alignment(Gtk::ALIGN_END);
127            labelMissingSample.set_alignment(Gtk::ALIGN_START);
128            legend_hbox.add(imageMissingSample);
129            legend_hbox.add(labelMissingSample);
130    
131            imageLooped.set(blackLoop);
132            imageLooped.set_alignment(Gtk::ALIGN_END);
133            labelLooped.set_alignment(Gtk::ALIGN_START);
134            legend_hbox.add(imageLooped);
135            legend_hbox.add(labelLooped);
136    
137            imageSomeLoops.set(grayLoop);
138            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
139            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
140            legend_hbox.add(imageSomeLoops);
141            legend_hbox.add(labelSomeLoops);
142    
143            legend_hbox.show_all_children();
144        }
145        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
146      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
147    
148      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 156  MainWindow::MainWindow() : Line 203  MainWindow::MainWindow() :
203          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
204      );      );
205      actionGroup->add(      actionGroup->add(
206          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
207          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
208      );      );
209      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
210    
211      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
212    
213        const Gdk::ModifierType primaryModifierKey =
214    #if defined(__APPLE__)
215        Gdk::META_MASK; // Cmd key on Mac
216    #else
217        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
218    #endif
219    
220        actionGroup->add(Gtk::Action::create("CopyDimRgn",
221                                             _("Copy selected dimension region")),
222                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("PasteDimRgn",
226                                             _("Paste dimension region")),
227                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
228                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
229    
230        actionGroup->add(Gtk::Action::create("AdjustClipboard",
231                                             _("Adjust Clipboard Content")),
232                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
233                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
236                                             _("Select Previous Region")),
237                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextRegion",
241                                             _("Select Next Region")),
242                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
243                         sigc::mem_fun(*this, &MainWindow::select_next_region));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
246                                             _("Select Previous Dimension Region Zone")),
247                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
251                                             _("Select Next Dimension Region Zone")),
252                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
254    
255        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
256                                             _("Select Previous Dimension")),
257                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
259    
260        actionGroup->add(Gtk::Action::create("SelectNextDimension",
261                                             _("Select Next Dimension")),
262                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
264    
265        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
266                                             _("Add Previous Dimension Region Zone to Selection")),
267                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
268                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
269    
270        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
271                                             _("Add Next Dimension Region Zone to Selection")),
272                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
273                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
274    
275      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
276          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
277      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 179  MainWindow::MainWindow() : Line 288  MainWindow::MainWindow() :
288      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
289    
290    
291      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
292    
293    
294        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
295      toggle_action =      toggle_action =
296          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
297      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 187  MainWindow::MainWindow() : Line 299  MainWindow::MainWindow() :
299                       sigc::mem_fun(                       sigc::mem_fun(
300                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
301    
302        toggle_action =
303            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
304        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
305        actionGroup->add(toggle_action,
306                         sigc::mem_fun(
307                             *this, &MainWindow::on_auto_restore_win_dim));
308    
309        toggle_action =
310            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
311        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
312        actionGroup->add(toggle_action,
313                         sigc::mem_fun(
314                             *this, &MainWindow::on_save_with_temporary_file));
315    
316        actionGroup->add(
317            Gtk::Action::create("RefreshAll", _("_Refresh All")),
318            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
319        );                
320    
321      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
322      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
323                                           action->property_label()));                                           action->property_label()));
# Line 225  MainWindow::MainWindow() : Line 356  MainWindow::MainWindow() :
356          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
357      );      );
358    
359        toggle_action =
360            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
361        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
362        actionGroup->add(
363            toggle_action,
364            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
365        );
366    
367    
368      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
369    
# Line 257  MainWindow::MainWindow() : Line 396  MainWindow::MainWindow() :
396          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
397      );      );
398      actionGroup->add(      actionGroup->add(
399            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
400            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
401        );
402        actionGroup->add(
403          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
404          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
405      );      );
406      actionGroup->add(      actionGroup->add(
407            Gtk::Action::create("ReplaceSample",
408                                _("Replace Sample...")),
409            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
410        );
411        actionGroup->add(
412          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
413                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
414          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 303  MainWindow::MainWindow() : Line 451  MainWindow::MainWindow() :
451          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
452          "    </menu>"          "    </menu>"
453          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
454            "      <menuitem action='CopyDimRgn'/>"
455            "      <menuitem action='AdjustClipboard'/>"
456            "      <menuitem action='PasteDimRgn'/>"
457            "      <separator/>"
458            "      <menuitem action='SelectPrevRegion'/>"
459            "      <menuitem action='SelectNextRegion'/>"
460            "      <separator/>"
461            "      <menuitem action='SelectPrevDimension'/>"
462            "      <menuitem action='SelectNextDimension'/>"
463            "      <menuitem action='SelectPrevDimRgnZone'/>"
464            "      <menuitem action='SelectNextDimRgnZone'/>"
465            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
466            "      <menuitem action='SelectAddNextDimRgnZone'/>"
467            "      <separator/>"
468          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
469          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
470          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
471          "    </menu>"          "    </menu>"
472            "    <menu action='MenuMacro'>"
473            "    </menu>"
474          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
475          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
476          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
477          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
478          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
479            "      <menuitem action='ReplaceSample' />"
480          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
481          "      <separator/>"          "      <separator/>"
482          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
483            "      <menuitem action='RemoveUnusedSamples'/>"
484          "    </menu>"          "    </menu>"
485          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
486          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 337  MainWindow::MainWindow() : Line 503  MainWindow::MainWindow() :
503          "    </menu>"          "    </menu>"
504          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
505          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
506            "      <menuitem action='AutoRestoreWinDim'/>"
507            "      <separator/>"
508            "      <menuitem action='RefreshAll'/>"
509          "    </menu>"          "    </menu>"
510          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
511          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 514  MainWindow::MainWindow() :
514          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
515          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
516          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
517            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
518            "      <menuitem action='SaveWithTemporaryFile'/>"
519          "    </menu>"          "    </menu>"
520          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
521          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 364  MainWindow::MainWindow() : Line 535  MainWindow::MainWindow() :
535          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
536          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
537          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
538            "    <menuitem action='ReplaceSample' />"
539          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
540          "    <separator/>"          "    <separator/>"
541          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
542            "    <menuitem action='RemoveUnusedSamples'/>"
543          "  </popup>"          "  </popup>"
544          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
545          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 411  MainWindow::MainWindow() : Line 584  MainWindow::MainWindow() :
584      }      }
585      {      {
586          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
587                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
588            item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
589        }
590        {
591            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
592                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
593            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
594            // copy tooltip to popup menu
595            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
596                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
597            item2->set_tooltip_text(item->get_tooltip_text());
598        }
599        {
600            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
601                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
602            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
603        }
604        {
605            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
606                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
607            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
608        }
609        {
610            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
611              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
612          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
613      }      }
# Line 448  MainWindow::MainWindow() : Line 645  MainWindow::MainWindow() :
645      // Create the Tree model:      // Create the Tree model:
646      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
647      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
648      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
649        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
650      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
651          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
652      );      );
653    
654      // Add the TreeView's view columns:      // Add the TreeView's view columns:
655      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
656      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
657        m_TreeView.set_headers_visible(true);
658        
659        // establish drag&drop within the instrument tree view, allowing to reorder
660        // the sequence of instruments within the gig file
661        {
662            std::vector<Gtk::TargetEntry> drag_target_instrument;
663            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
664            m_TreeView.drag_source_set(drag_target_instrument);
665            m_TreeView.drag_dest_set(drag_target_instrument);
666            m_TreeView.signal_drag_begin().connect(
667                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
668            );
669            m_TreeView.signal_drag_data_get().connect(
670                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
671            );
672            m_TreeView.signal_drag_data_received().connect(
673                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
674            );
675        }
676    
677      // create samples treeview (including its data model)      // create samples treeview (including its data model)
678      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
679      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
680        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
681      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
682      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
683      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 503  MainWindow::MainWindow() : Line 721  MainWindow::MainWindow() :
721      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
722          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
723      );      );
724      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?      //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
725      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
726          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
727      );      );
# Line 540  MainWindow::MainWindow() : Line 758  MainWindow::MainWindow() :
758          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
759      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
760          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
761        m_RegionChooser.signal_instrument_changed().connect(
762            sigc::mem_fun(*this, &MainWindow::region_changed));
763      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
764          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
765      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 609  MainWindow::MainWindow() : Line 829  MainWindow::MainWindow() :
829    
830      // select 'Instruments' tab by default      // select 'Instruments' tab by default
831      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
832      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
833    
834        Gtk::Clipboard::get()->signal_owner_change().connect(
835            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
836        );
837        updateClipboardPasteAvailable();
838        updateClipboardCopyAvailable();
839    
840        // setup macros and their keyboard accelerators
841        {
842            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
843                uiManager->get_widget("/MenuBar/MenuMacro")
844            )->get_submenu();
845    
846            const Gdk::ModifierType primaryModifierKey =
847    #if defined(__APPLE__)
848                Gdk::META_MASK; // Cmd key on Mac
849    #else
850                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
851    #endif
852    
853            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
854            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
855            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
856            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
857            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
858            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
859            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
867    
868            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
869            menuMacro->set_accel_group(accelGroup);
870    
871            updateMacroMenu();
872        }
873  }  }
874    
875  MainWindow::~MainWindow()  MainWindow::~MainWindow()
876  {  {
877  }  }
878    
879    void MainWindow::updateMacroMenu() {
880        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
881            uiManager->get_widget("/MenuBar/MenuMacro")
882        )->get_submenu();
883    
884        // remove all entries from "Macro" menu
885        {
886            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
887            for (int i = 0; i < children.size(); ++i) {
888                Gtk::Widget* child = children[i];
889                menuMacro->remove(*child);
890                delete child;
891            }
892        }
893    
894        // (re)load all macros from config file
895        try {
896            Settings::singleton()->loadMacros(m_macros);
897        } catch (Serialization::Exception e) {
898            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
899        } catch (...) {
900            std::cerr << "Unknown exception while loading macros!" << std::endl;
901        }
902    
903        // add all configured macros as menu items to the "Macro" menu
904        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
905            const Serialization::Archive& macro = m_macros[iMacro];
906            std::string name =
907                macro.name().empty() ?
908                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
909            Gtk::MenuItem* item = new Gtk::MenuItem(name);
910            item->signal_activate().connect(
911                sigc::bind(
912                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
913                )
914            );
915            menuMacro->append(*item);
916            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
917            Glib::ustring comment = macro.comment();
918            if (!comment.empty())
919                item->set_tooltip_text(comment);
920        }
921        // if there are no macros configured at all, then show a dummy entry instead
922        if (m_macros.empty()) {
923            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
924            item->set_sensitive(false);
925            menuMacro->append(*item);
926        }
927    
928        // add separator line to menu
929        menuMacro->append(*new Gtk::SeparatorMenuItem);
930    
931        {
932            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
933            item->signal_activate().connect(
934                sigc::mem_fun(*this, &MainWindow::setupMacros)
935            );
936            menuMacro->append(*item);
937            item->set_accel_path("<Macros>/SetupMacros");
938        }
939    
940        menuMacro->show_all_children();
941    }
942    
943    void MainWindow::onMacroSelected(int iMacro) {
944        printf("onMacroSelected(%d)\n", iMacro);
945        if (iMacro < 0 || iMacro >= m_macros.size()) return;
946        Glib::ustring errorText;
947        try {
948            applyMacro(m_macros[iMacro]);
949        } catch (Serialization::Exception e) {
950            errorText = e.Message;
951        } catch (...) {
952            errorText = _("Unknown exception while applying macro");
953        }
954        if (!errorText.empty()) {
955            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
956            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
957            msg.run();
958        }
959    }
960    
961    void MainWindow::setupMacros() {
962        MacrosSetup* setup = new MacrosSetup();
963        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
964        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
965        setup->signal_macros_changed().connect(
966            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
967        );
968        setup->show();
969    }
970    
971    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
972        m_macros = macros;
973        Settings::singleton()->saveMacros(m_macros);
974        updateMacroMenu();
975    }
976    
977  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
978  {  {
979      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 635  void MainWindow::region_changed() Line 993  void MainWindow::region_changed()
993  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
994  {  {
995      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
996      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
997          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
998        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
999      if (it) {      if (it) {
1000          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1001          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 679  void MainWindow::update_dimregs() Line 1038  void MainWindow::update_dimregs()
1038              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1039          }          }
1040      }      }
1041    
1042        m_RegionChooser.setModifyAllRegions(all_regions);
1043        m_DimRegionChooser.setModifyAllRegions(all_regions);
1044        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1045        m_DimRegionChooser.setModifyBothChannels(stereo);
1046    
1047        updateClipboardCopyAvailable();
1048  }  }
1049    
1050  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 696  void MainWindow::dimreg_changed() Line 1062  void MainWindow::dimreg_changed()
1062  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1063  {  {
1064      // select item in instrument menu      // select item in instrument menu
1065      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1066      if (it) {      if (!rows.empty()) {
1067          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1068          int index = path[0];          if (it) {
1069          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1070              instrument_menu->get_children();              int index = path[0];
1071          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1072                    instrument_menu->get_children();
1073                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1074            }
1075      }      }
1076    
1077      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 727  void Loader::progress_callback(float fra Line 1096  void Loader::progress_callback(float fra
1096      progress_dispatcher();      progress_dispatcher();
1097  }  }
1098    
1099    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1100    // make sure stack is 16-byte aligned for SSE instructions
1101    __attribute__((force_align_arg_pointer))
1102    #endif
1103  void Loader::thread_function()  void Loader::thread_function()
1104  {  {
1105      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1106               static_cast<void*>(Glib::Threads::Thread::self()));
1107      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1108      try {      try {
1109          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 751  void Loader::thread_function() Line 1125  void Loader::thread_function()
1125  }  }
1126    
1127  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1128      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
1129  {  {
1130  }  }
1131    
# Line 762  void Loader::launch() Line 1136  void Loader::launch()
1136  #else  #else
1137      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1138  #endif  #endif
1139      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1140  }  }
1141    
1142  float Loader::get_progress()  float Loader::get_progress()
# Line 805  void Saver::progress_callback(float frac Line 1179  void Saver::progress_callback(float frac
1179      progress_dispatcher.emit();      progress_dispatcher.emit();
1180  }  }
1181    
1182    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1183    // make sure stack is 16-byte aligned for SSE instructions
1184    __attribute__((force_align_arg_pointer))
1185    #endif
1186  void Saver::thread_function()  void Saver::thread_function()
1187  {  {
1188      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1189               static_cast<void*>(Glib::Threads::Thread::self()));
1190      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1191      try {      try {
1192          gig::progress_t progress;          gig::progress_t progress;
# Line 816  void Saver::thread_function() Line 1195  void Saver::thread_function()
1195    
1196          // 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"
1197          if (filename.empty()) {          if (filename.empty()) {
1198              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1199                    // save directly over the existing .gig file
1200                    // (requires less disk space than solution below
1201                    // but may be slower)
1202                    gig->Save(&progress);
1203                } else {
1204                    // save the file as separate temporary file first,
1205                    // then move the saved file over the old file
1206                    // (may result in performance speedup during save)
1207                    String tmpname = filename + ".TMP";
1208                    gig->Save(tmpname, &progress);
1209                    #if defined(WIN32)
1210                    if (!DeleteFile(filename.c_str())) {
1211                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1212                    }
1213                    #else // POSIX ...
1214                    if (unlink(filename.c_str())) {
1215                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1216                    }
1217                    #endif
1218                    if (rename(tmpname.c_str(), filename.c_str())) {
1219                        #if defined(WIN32)
1220                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1221                        #else
1222                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1223                        #endif
1224                    }
1225                }
1226          } else {          } else {
1227              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1228          }          }
# Line 844  void Saver::launch() Line 1250  void Saver::launch()
1250  #else  #else
1251      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1252  #endif  #endif
1253      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1254  }  }
1255    
1256  float Saver::get_progress()  float Saver::get_progress()
# Line 1004  void MainWindow::on_action_file_open() Line 1410  void MainWindow::on_action_file_open()
1410      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1411          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1412          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1413          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1414                   static_cast<void*>(Glib::Threads::Thread::self()));
1415          load_file(filename.c_str());          load_file(filename.c_str());
1416          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1417      }      }
# Line 1074  void MainWindow::on_loader_progress() Line 1481  void MainWindow::on_loader_progress()
1481  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1482  {  {
1483      printf("Loader finished!\n");      printf("Loader finished!\n");
1484      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1485               static_cast<void*>(Glib::Threads::Thread::self()));
1486      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1487      progress_dialog->hide();      progress_dialog->hide();
1488  }  }
# Line 1169  void MainWindow::on_saver_finished() Line 1577  void MainWindow::on_saver_finished()
1577    
1578      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1579    
1580      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1581      progress_dialog->hide();      progress_dialog->hide();
1582  }  }
1583    
# Line 1214  bool MainWindow::file_save_as() Line 1622  bool MainWindow::file_save_as()
1622      // show warning in the dialog      // show warning in the dialog
1623      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1624      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1625      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1626        warningIcon.set_from_icon_name("dialog-warning",
1627                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1628      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1629  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1630      view::WrapLabel description;      view::WrapLabel description;
# Line 1266  bool MainWindow::file_save_as() Line 1676  bool MainWindow::file_save_as()
1676  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1677      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1678      Glib::ustring error_files;      Glib::ustring error_files;
1679      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1680      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1681           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1682          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1683          SF_INFO info;          SF_INFO info;
1684          info.format = 0;          info.format = 0;
1685          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);
1686          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1687          try {          try {
1688              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1295  void MainWindow::__import_queued_samples Line 1705  void MainWindow::__import_queued_samples
1705                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1706              }              }
1707    
1708                // reset write position for sample
1709                iter->first->SetPos(0);
1710    
1711              const int bufsize = 10000;              const int bufsize = 10000;
1712              switch (bitdepth) {              switch (bitdepth) {
1713                  case 16: {                  case 16: {
# Line 1304  void MainWindow::__import_queued_samples Line 1717  void MainWindow::__import_queued_samples
1717                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1718                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1719                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1720                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1721                          cnt -= n;                          cnt -= n;
1722                      }                      }
1723                      delete[] buffer;                      delete[] buffer;
# Line 1324  void MainWindow::__import_queued_samples Line 1737  void MainWindow::__import_queued_samples
1737                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1738                          }                          }
1739                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1740                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1741                          cnt -= n;                          cnt -= n;
1742                      }                      }
1743                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1335  void MainWindow::__import_queued_samples Line 1748  void MainWindow::__import_queued_samples
1748              // cleanup              // cleanup
1749              sf_close(hFile);              sf_close(hFile);
1750              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1751              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1752              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1753              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1754              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1755              ++iter;              ++iter;
1756              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1757          } catch (std::string what) {          } catch (std::string what) {
1758              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1759              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1760              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1761              ++iter;              ++iter;
1762          }          }
1763      }      }
# Line 1372  void MainWindow::on_action_sync_sampler_ Line 1785  void MainWindow::on_action_sync_sampler_
1785          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1786  }  }
1787    
1788    void MainWindow::on_action_move_root_note_with_region_moved() {
1789        Settings::singleton()->moveRootNoteWithRegionMoved =
1790            !Settings::singleton()->moveRootNoteWithRegionMoved;
1791    }
1792    
1793  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1794  {  {
1795      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1381  void MainWindow::on_action_help_about() Line 1799  void MainWindow::on_action_help_about()
1799      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1800  #endif  #endif
1801      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1802      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1803      const std::string sComment =      const std::string sComment =
1804          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1805          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1664  void MainWindow::load_gig(gig::File* gig Line 2082  void MainWindow::load_gig(gig::File* gig
2082      file = 0;      file = 0;
2083      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
2084    
2085      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
2086            (filename && strlen(filename) > 0) ?
2087                filename : (!gig->GetFileName().empty()) ?
2088                    gig->GetFileName() : _("Unsaved Gig File");
2089      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
2090      file_has_name = filename;      file_has_name = filename;
2091      file_is_changed = false;      file_is_changed = false;
# Line 1673  void MainWindow::load_gig(gig::File* gig Line 2094  void MainWindow::load_gig(gig::File* gig
2094      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2095    
2096      instrument_name_connection.block();      instrument_name_connection.block();
2097        int index = 0;
2098      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2099           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2100          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2101    
2102          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2103          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2104            row[m_Columns.m_col_nr] = index;
2105          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2106          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2107    
# Line 1751  bool MainWindow::instr_props_set_instrum Line 2174  bool MainWindow::instr_props_set_instrum
2174  {  {
2175      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2176    
2177      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2178          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2179            instrumentProps.hide();
2180            return false;
2181        }
2182        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2183      if (it) {      if (it) {
2184          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2185          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1805  void MainWindow::show_midi_rules() Line 2232  void MainWindow::show_midi_rules()
2232  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2233      if (!file) return;      if (!file) return;
2234      // get selected instrument      // get selected instrument
2235      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2236      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2237        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2238      if (!it) return;      if (!it) return;
2239      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2240      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1818  void MainWindow::show_script_slots() { Line 2246  void MainWindow::show_script_slots() {
2246      window->show();      window->show();
2247  }  }
2248    
2249    void MainWindow::on_action_refresh_all() {
2250        __refreshEntireGUI();
2251    }
2252    
2253  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
2254      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2255          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1829  void MainWindow::on_action_view_status_b Line 2261  void MainWindow::on_action_view_status_b
2261      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2262  }  }
2263    
2264    void MainWindow::on_auto_restore_win_dim() {
2265        Gtk::CheckMenuItem* item =
2266            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2267        if (!item) {
2268            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2269            return;
2270        }
2271        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2272    }
2273    
2274    void MainWindow::on_save_with_temporary_file() {
2275        Gtk::CheckMenuItem* item =
2276            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2277        if (!item) {
2278            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2279            return;
2280        }
2281        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2282    }
2283    
2284  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2285      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2286          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1893  void MainWindow::on_instrument_selection Line 2345  void MainWindow::on_instrument_selection
2345      }      }
2346  }  }
2347    
2348    void MainWindow::select_instrument(gig::Instrument* instrument) {
2349        if (!instrument) return;
2350    
2351        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2352        for (int i = 0; i < model->children().size(); ++i) {
2353            Gtk::TreeModel::Row row = model->children()[i];
2354            if (row[m_Columns.m_col_instr] == instrument) {
2355                // select and show the respective instrument in the list view
2356                show_intruments_tab();
2357                m_TreeView.get_selection()->unselect_all();
2358                m_TreeView.get_selection()->select(model->children()[i]);
2359                std::vector<Gtk::TreeModel::Path> rows =
2360                    m_TreeView.get_selection()->get_selected_rows();
2361                if (!rows.empty())
2362                    m_TreeView.scroll_to_row(rows[0]);
2363                on_sel_change(); // the regular instrument selection change callback
2364            }
2365        }
2366    }
2367    
2368    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
2369    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
2370        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2371        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2372    
2373        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2374        for (int i = 0; i < model->children().size(); ++i) {
2375            Gtk::TreeModel::Row row = model->children()[i];
2376            if (row[m_Columns.m_col_instr] == pInstrument) {
2377                // select and show the respective instrument in the list view
2378                show_intruments_tab();
2379                m_TreeView.get_selection()->unselect_all();
2380                m_TreeView.get_selection()->select(model->children()[i]);
2381                std::vector<Gtk::TreeModel::Path> rows =
2382                    m_TreeView.get_selection()->get_selected_rows();
2383                if (!rows.empty())
2384                    m_TreeView.scroll_to_row(rows[0]);
2385                on_sel_change(); // the regular instrument selection change callback
2386    
2387                // select respective region in the region selector
2388                m_RegionChooser.set_region(pRegion);
2389    
2390                // select and show the respective dimension region in the editor
2391                //update_dimregs();
2392                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2393                //dimreg_edit.set_dim_region(dimRgn);
2394    
2395                return true;
2396            }
2397        }
2398    
2399        return false;
2400    }
2401    
2402  void MainWindow::select_sample(gig::Sample* sample) {  void MainWindow::select_sample(gig::Sample* sample) {
2403      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2404      for (int g = 0; g < model->children().size(); ++g) {      for (int g = 0; g < model->children().size(); ++g) {
# Line 1901  void MainWindow::select_sample(gig::Samp Line 2407  void MainWindow::select_sample(gig::Samp
2407              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2408              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2409                  show_samples_tab();                  show_samples_tab();
2410                    m_TreeViewSamples.get_selection()->unselect_all();
2411                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2412                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2413                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2414                  );                  if (rows.empty()) return;
2415                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2416                  return;                  return;
2417              }              }
2418          }          }
# Line 1914  void MainWindow::select_sample(gig::Samp Line 2421  void MainWindow::select_sample(gig::Samp
2421    
2422  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2423      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2424            // by default if Ctrl keys is pressed down, then a mouse right-click
2425            // does not select the respective row, so we must assure this
2426            // programmatically ...
2427            /*{
2428                Gtk::TreeModel::Path path;
2429                Gtk::TreeViewColumn* pColumn = NULL;
2430                int cellX, cellY;
2431                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2432                    (int)button->x, (int)button->y,
2433                    path, pColumn, cellX, cellY
2434                );
2435                if (bSuccess) {
2436                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2437                        printf("not selected !!!\n");
2438                        m_TreeViewSamples.get_selection()->select(path);
2439                    }
2440                }
2441            }*/
2442    
2443          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2444              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2445          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2446          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2447          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2448          bool group_selected  = false;          const int n = rows.size();
2449          bool sample_selected = false;          int nGroups  = 0;
2450          if (it) {          int nSamples = 0;
2451            for (int r = 0; r < n; ++r) {
2452                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2453                if (!it) continue;
2454              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2455              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2456              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2457          }          }
2458            
               
2459          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2460              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2461          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2462              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2463          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2464              set_sensitive(file);              set_sensitive(file);
2465          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2466              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2467          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2468              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2469          // show sample popup          // show sample popup
2470          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2471    
2472          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2473              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2474          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2475              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2476          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2477              set_sensitive(file);              set_sensitive(file);
2478          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2479              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2480          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2481              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2482      }      }
2483  }  }
2484    
# Line 2029  void MainWindow::add_instrument(gig::Ins Line 2557  void MainWindow::add_instrument(gig::Ins
2557      instrument_name_connection.block();      instrument_name_connection.block();
2558      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2559      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2560        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2561      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2562      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2563      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2057  void MainWindow::on_action_duplicate_ins Line 2586  void MainWindow::on_action_duplicate_ins
2586      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2587      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2588      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2589      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2590      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2591      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2592      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2593      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2594                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2595      // duplicate the orginal instrument              if (instrOrig) {
2596      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2597      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2598          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2599          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2600                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2601    
2602      add_instrument(instrNew);                  add_instrument(instrNew);
2603                }
2604            }
2605        }
2606  }  }
2607    
2608  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2086  void MainWindow::on_action_remove_instru Line 2619  void MainWindow::on_action_remove_instru
2619      }      }
2620    
2621      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2622      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2623      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2624            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2625            if (!it) continue;
2626          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2627          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2628          try {          try {
# Line 2102  void MainWindow::on_action_remove_instru Line 2637  void MainWindow::on_action_remove_instru
2637    
2638              // remove row from instruments tree view              // remove row from instruments tree view
2639              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2640                // update "Nr" column of all instrument rows
2641                {
2642                    int index = 0;
2643                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2644                         it != m_refTreeModel->children().end(); ++it, ++index)
2645                    {
2646                        Gtk::TreeModel::Row row = *it;
2647                        row[m_Columns.m_col_nr] = index;
2648                    }
2649                }
2650    
2651  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2652              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2199  void MainWindow::on_action_edit_script() Line 2744  void MainWindow::on_action_edit_script()
2744      if (!script) return;      if (!script) return;
2745    
2746      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2747        editor->signal_script_to_be_changed.connect(
2748            signal_script_to_be_changed.make_slot()
2749        );
2750        editor->signal_script_changed.connect(
2751            signal_script_changed.make_slot()
2752        );
2753      editor->setScript(script);      editor->setScript(script);
2754      //editor->reparent(*this);      //editor->reparent(*this);
2755      editor->show();      editor->show();
# Line 2264  void MainWindow::on_action_add_group() { Line 2815  void MainWindow::on_action_add_group() {
2815      file_changed();      file_changed();
2816  }  }
2817    
2818    void MainWindow::on_action_replace_sample() {
2819        add_or_replace_sample(true);
2820    }
2821    
2822  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2823        add_or_replace_sample(false);
2824    }
2825    
2826    void MainWindow::add_or_replace_sample(bool replace) {
2827      if (!file) return;      if (!file) return;
2828      // get selected group  
2829        // get selected group (and probably selected sample)
2830      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2831      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2832        if (rows.empty()) return;
2833        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2834      if (!it) return;      if (!it) return;
2835      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2836        gig::Sample* sample = NULL;
2837      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2838      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2839          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2840          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2841          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2842          if (!it) return;          if (!it) return;
2843          row = *it;          if (!replace) row = *it;
2844          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2845          if (!group) return;          if (!group) return;
2846      }      }
2847        if (replace && !sample) return;
2848    
2849      // show 'browse for file' dialog      // show 'browse for file' dialog
2850      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2851      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2852      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2853      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2854    
2855      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2856  #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 2356  void MainWindow::on_action_add_sample() Line 2921  void MainWindow::on_action_add_sample()
2921                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2922                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2923                  }                  }
2924                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2925                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2926                  // file name without path                  // file name without path
2927                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2928                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2408  void MainWindow::on_action_add_sample() Line 2973  void MainWindow::on_action_add_sample()
2973                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2974                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2975                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2976                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2977                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2978                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2979                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2980                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2981                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2982                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2983                  // add sample to the tree view                  // add sample to the tree view
2984                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2985                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2986                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2987                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2988                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2989                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2990                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2991                            gig_to_utf8(sample->pInfo->Name);
2992                        rowSample[m_SamplesModel.m_col_sample] = sample;
2993                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2994                    }
2995                  // close sound file                  // close sound file
2996                  sf_close(hFile);                  sf_close(hFile);
2997                  file_changed();                  file_changed();
# Line 2433  void MainWindow::on_action_add_sample() Line 3002  void MainWindow::on_action_add_sample()
3002          }          }
3003          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
3004          if (!error_files.empty()) {          if (!error_files.empty()) {
3005              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
3006                    (replace
3007                        ? _("Failed to replace sample with:\n")
3008                        : _("Could not add the following sample(s):\n"))
3009                    + error_files;
3010              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3011              msg.run();              msg.run();
3012          }          }
# Line 2500  void MainWindow::on_action_replace_all_s Line 3073  void MainWindow::on_action_replace_all_s
3073              try              try
3074              {              {
3075                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
3076                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
3077                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
3078                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
3079                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
3080                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
3081                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
3082                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
3083                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
3084                          break;                          break;
3085                      default:                      default:
3086                          sf_close(hFile);                          sf_close(hFile);
# Line 2520  void MainWindow::on_action_replace_all_s Line 3089  void MainWindow::on_action_replace_all_s
3089                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3090                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3091                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3092                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3093                  sf_close(hFile);                  sf_close(hFile);
3094                  file_changed();                  file_changed();
3095              }              }
# Line 2544  void MainWindow::on_action_replace_all_s Line 3113  void MainWindow::on_action_replace_all_s
3113  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
3114      if (!file) return;      if (!file) return;
3115      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3116      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3117      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3118            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3119            if (!it) continue;
3120          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3121          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
3122          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2570  void MainWindow::on_action_remove_sample Line 3141  void MainWindow::on_action_remove_sample
3141                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3142                  // them from the import queue                  // them from the import queue
3143                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3144                       member != members.end(); ++member) {                       member != members.end(); ++member)
3145                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3146                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3147                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3148                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3149                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3150                      }                      }
3151                  }                  }
3152                  file_changed();                  file_changed();
# Line 2593  void MainWindow::on_action_remove_sample Line 3161  void MainWindow::on_action_remove_sample
3161                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3162                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3163                  // the import queue                  // the import queue
3164                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3165                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3166                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3167                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3168                  }                  }
3169                  dimreg_changed();                  dimreg_changed();
3170                  file_changed();                  file_changed();
# Line 2617  void MainWindow::on_action_remove_sample Line 3181  void MainWindow::on_action_remove_sample
3181      }      }
3182  }  }
3183    
3184    void MainWindow::on_action_remove_unused_samples() {
3185        if (!file) return;
3186    
3187        // collect all samples that are not referenced by any instrument
3188        std::list<gig::Sample*> lsamples;
3189        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
3190            gig::Sample* sample = file->GetSample(iSample);
3191            bool isUsed = false;
3192            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
3193                                  instrument = file->GetNextInstrument())
3194            {
3195                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
3196                                  rgn = instrument->GetNextRegion())
3197                {
3198                    for (int i = 0; i < 256; ++i) {
3199                        if (!rgn->pDimensionRegions[i]) continue;
3200                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
3201                        isUsed = true;
3202                        goto endOfRefSearch;
3203                    }
3204                }
3205            }
3206            endOfRefSearch:
3207            if (!isUsed) lsamples.push_back(sample);
3208        }
3209    
3210        if (lsamples.empty()) return;
3211    
3212        // notify everybody that we're going to remove these samples
3213        samples_to_be_removed_signal.emit(lsamples);
3214    
3215        // remove collected samples
3216        try {
3217            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
3218                 itSample != lsamples.end(); ++itSample)
3219            {
3220                gig::Sample* sample = *itSample;
3221                // remove sample from the .gig file
3222                file->DeleteSample(sample);
3223                // if sample was just previously added, remove it from the import queue
3224                if (m_SampleImportQueue.count(sample)) {
3225                    printf("Removing previously added sample '%s'\n",
3226                           m_SampleImportQueue[sample].sample_path.c_str());
3227                    m_SampleImportQueue.erase(sample);
3228                }
3229            }
3230        } catch (RIFF::Exception e) {
3231            // show error message
3232            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3233            msg.run();
3234        }
3235    
3236        // notify everybody that we're done with removal
3237        samples_removed_signal.emit();
3238    
3239        dimreg_changed();
3240        file_changed();
3241        __refreshEntireGUI();
3242    }
3243    
3244  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
3245  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3246  {  {
# Line 2643  void MainWindow::on_scripts_treeview_dra Line 3267  void MainWindow::on_scripts_treeview_dra
3267                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
3268  }  }
3269    
3270    // see comment on on_sample_treeview_drag_begin()
3271    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
3272    {
3273        first_call_to_drag_data_get = true;
3274    }
3275    
3276    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
3277                                                           Gtk::SelectionData& selection_data, guint, guint)
3278    {
3279        if (!first_call_to_drag_data_get) return;
3280        first_call_to_drag_data_get = false;
3281    
3282        // get selected source instrument
3283        gig::Instrument* src = NULL;
3284        {
3285            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3286            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3287            if (!rows.empty()) {
3288                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3289                if (it) {
3290                    Gtk::TreeModel::Row row = *it;
3291                    src = row[m_Columns.m_col_instr];
3292                }
3293            }
3294        }
3295        if (!src) return;
3296    
3297        // pass the source gig::Instrument as pointer
3298        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
3299                           sizeof(src)/*length of data in bytes*/);
3300    }
3301    
3302    void MainWindow::on_instruments_treeview_drop_drag_data_received(
3303        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
3304        const Gtk::SelectionData& selection_data, guint, guint time)
3305    {
3306        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
3307        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
3308            return;
3309    
3310        gig::Instrument* dst = NULL;
3311        {
3312            Gtk::TreeModel::Path path;
3313            const bool found = m_TreeView.get_path_at_pos(x, y, path);
3314            if (!found) return;
3315    
3316            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
3317            if (!iter) return;
3318            Gtk::TreeModel::Row row = *iter;
3319            dst = row[m_Columns.m_col_instr];
3320        }
3321        if (!dst) return;
3322    
3323        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
3324        src->MoveTo(dst);
3325        __refreshEntireGUI();
3326        select_instrument(src);
3327    }
3328    
3329  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
3330  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
3331  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2661  void MainWindow::on_sample_treeview_drag Line 3344  void MainWindow::on_sample_treeview_drag
3344      // get selected sample      // get selected sample
3345      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3346      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3347      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3348      if (it) {      if (!rows.empty()) {
3349          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3350          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3351                Gtk::TreeModel::Row row = *it;
3352                sample = row[m_SamplesModel.m_col_sample];
3353            }
3354      }      }
3355      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3356      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 2804  void MainWindow::script_double_clicked(c Line 3490  void MainWindow::script_double_clicked(c
3490      if (!script) return;      if (!script) return;
3491    
3492      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3493        editor->signal_script_to_be_changed.connect(
3494            signal_script_to_be_changed.make_slot()
3495        );
3496        editor->signal_script_changed.connect(
3497            signal_script_changed.make_slot()
3498        );
3499      editor->setScript(script);      editor->setScript(script);
3500      //editor->reparent(*this);      //editor->reparent(*this);
3501      editor->show();      editor->show();
# Line 2857  void MainWindow::on_action_combine_instr Line 3549  void MainWindow::on_action_combine_instr
3549    
3550  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3551      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3552      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3553        if (rows.empty()) return;
3554        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3555      if (!it) return;      if (!it) return;
3556      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3557      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2865  void MainWindow::on_action_view_referenc Line 3559  void MainWindow::on_action_view_referenc
3559    
3560      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3561      d->setSample(sample);      d->setSample(sample);
3562        d->dimension_region_selected.connect(
3563            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3564        );
3565      d->show_all();      d->show_all();
3566      d->resize(500, 400);      d->resize(500, 400);
3567      d->run();      d->run();
# Line 2995  void MainWindow::on_action_merge_files() Line 3692  void MainWindow::on_action_merge_files()
3692      // show warning in the file picker dialog      // show warning in the file picker dialog
3693      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3694      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3695      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3696        warningIcon.set_from_icon_name("dialog-warning",
3697                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3698      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3699  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3700      view::WrapLabel description;      view::WrapLabel description;
# Line 3018  void MainWindow::on_action_merge_files() Line 3717  void MainWindow::on_action_merge_files()
3717      descriptionArea.show_all();      descriptionArea.show_all();
3718    
3719      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3720          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3721                   static_cast<void*>(Glib::Threads::Thread::self()));
3722          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3723    
3724          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3030  void MainWindow::on_action_merge_files() Line 3730  void MainWindow::on_action_merge_files()
3730          }          }
3731    
3732          // update GUI          // update GUI
3733          __refreshEntireGUI();                  __refreshEntireGUI();
3734      }      }
3735  }  }
3736    
# Line 3100  void MainWindow::show_scripts_tab() { Line 3800  void MainWindow::show_scripts_tab() {
3800      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3801  }  }
3802    
3803    void MainWindow::select_prev_region() {
3804        m_RegionChooser.select_prev_region();
3805    }
3806    
3807    void MainWindow::select_next_region() {
3808        m_RegionChooser.select_next_region();
3809    }
3810    
3811    void MainWindow::select_next_dim_rgn_zone() {
3812        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3813        m_DimRegionChooser.select_next_dimzone();
3814    }
3815    
3816    void MainWindow::select_prev_dim_rgn_zone() {
3817        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3818        m_DimRegionChooser.select_prev_dimzone();
3819    }
3820    
3821    void MainWindow::select_add_next_dim_rgn_zone() {
3822        m_DimRegionChooser.select_next_dimzone(true);
3823    }
3824    
3825    void MainWindow::select_add_prev_dim_rgn_zone() {
3826        m_DimRegionChooser.select_prev_dimzone(true);
3827    }
3828    
3829    void MainWindow::select_prev_dimension() {
3830        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3831        m_DimRegionChooser.select_prev_dimension();
3832    }
3833    
3834    void MainWindow::select_next_dimension() {
3835        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3836        m_DimRegionChooser.select_next_dimension();
3837    }
3838    
3839    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3840        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3841    
3842    void MainWindow::copy_selected_dimrgn() {
3843        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3844        if (!pDimRgn) {
3845            updateClipboardPasteAvailable();
3846            updateClipboardCopyAvailable();
3847            return;
3848        }
3849    
3850        std::vector<Gtk::TargetEntry> targets;
3851        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3852    
3853        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3854        clipboard->set(
3855            targets,
3856            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3857            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3858        );
3859    
3860        m_serializationArchive.serialize(pDimRgn);
3861    
3862        updateClipboardPasteAvailable();
3863    }
3864    
3865    void MainWindow::paste_copied_dimrgn() {
3866        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3867        clipboard->request_contents(
3868            CLIPBOARD_DIMENSIONREGION_TARGET,
3869            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3870        );
3871        updateClipboardPasteAvailable();
3872    }
3873    
3874    void MainWindow::adjust_clipboard_content() {
3875        MacroEditor* editor = new MacroEditor();
3876        editor->setMacro(&m_serializationArchive, true);
3877        editor->show();
3878    }
3879    
3880    void MainWindow::updateClipboardPasteAvailable() {
3881        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3882        clipboard->request_targets(
3883            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3884        );
3885    }
3886    
3887    void MainWindow::updateClipboardCopyAvailable() {
3888        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3889        static_cast<Gtk::MenuItem*>(
3890            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3891        )->set_sensitive(bDimensionRegionCopyIsPossible);
3892    }
3893    
3894    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3895        updateClipboardPasteAvailable();
3896    }
3897    
3898    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3899        const std::string target = selection_data.get_target();
3900        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3901            selection_data.set(
3902                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3903                &m_serializationArchive.rawData()[0],
3904                m_serializationArchive.rawData().size()
3905            );
3906        } else {
3907            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3908        }
3909    }
3910    
3911    void MainWindow::on_clipboard_clear() {
3912        m_serializationArchive.clear();
3913        updateClipboardPasteAvailable();
3914        updateClipboardCopyAvailable();
3915    }
3916    
3917    //NOTE: Might throw exception !!!
3918    void MainWindow::applyMacro(Serialization::Archive& macro) {
3919        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3920        if (!pDimRgn) return;
3921    
3922        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3923             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3924        {
3925            gig::DimensionRegion* pDimRgn = *itDimReg;
3926            DimRegionChangeGuard(this, pDimRgn);
3927            macro.deserialize(pDimRgn);
3928        }
3929        //region_changed()
3930        file_changed();
3931        dimreg_changed();
3932    }
3933    
3934    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3935        const std::string target = selection_data.get_target();
3936        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3937            Glib::ustring errorText;
3938            try {
3939                m_serializationArchive.decode(
3940                    selection_data.get_data(), selection_data.get_length()
3941                );
3942                applyMacro(m_serializationArchive);
3943            } catch (Serialization::Exception e) {
3944                errorText = e.Message;
3945            } catch (...) {
3946                errorText = _("Unknown exception while pasting DimensionRegion");
3947            }
3948            if (!errorText.empty()) {
3949                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3950                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3951                msg.run();
3952            }
3953        }
3954    }
3955    
3956    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3957        const bool bDimensionRegionPasteIsPossible =
3958            std::find(targets.begin(), targets.end(),
3959                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3960    
3961        static_cast<Gtk::MenuItem*>(
3962            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3963        )->set_sensitive(bDimensionRegionPasteIsPossible);
3964    
3965        static_cast<Gtk::MenuItem*>(
3966            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3967        )->set_sensitive(bDimensionRegionPasteIsPossible);
3968    }
3969    
3970  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3971      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3972  }  }

Legend:
Removed from v.2694  
changed lines
  Added in v.3177

  ViewVC Help
Powered by ViewVC