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

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

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

revision 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC revision 3340 by schoenebeck, Mon Jul 31 11:20:18 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>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
# Line 31  Line 40 
40  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
41  #include <gtkmm/main.h>  #include <gtkmm/main.h>
42  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
43    #include <gtkmm/accelmap.h>
44  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
45  #include "wrapLabel.hh"  #include "wrapLabel.hh"
46  #endif  #endif
# Line 50  Line 60 
60  #include "ReferencesView.h"  #include "ReferencesView.h"
61  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
62  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
63    #include "gfx/builtinpix.h"
64    #include "MacroEditor.h"
65    #include "MacrosSetup.h"
66    #if defined(__APPLE__)
67    # include "MacHelper.h"
68    #endif
69    
70    static const Gdk::ModifierType primaryModifierKey =
71        #if defined(__APPLE__)
72        Gdk::META_MASK; // Cmd key on Mac
73        #else
74        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
75        #endif
76    
77  MainWindow::MainWindow() :  MainWindow::MainWindow() :
78      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
79      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
80      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
81      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
82      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
83        labelLegend(_("Legend:")),
84        labelNoSample(_(" No Sample")),
85        labelMissingSample(_(" Missing some Sample(s)")),
86        labelLooped(_(" Looped")),
87        labelSomeLoops(_(" Some Loop(s)"))
88  {  {
89        loadBuiltInPix();
90    
91        this->file = NULL;
92    
93  //    set_border_width(5);  //    set_border_width(5);
 //    set_default_size(400, 200);  
94    
95        if (!Settings::singleton()->autoRestoreWindowDimension) {
96            set_default_size(800, 600);
97            set_position(Gtk::WIN_POS_CENTER);
98        }
99    
100      add(m_VBox);      add(m_VBox);
101    
# Line 88  MainWindow::MainWindow() : Line 122  MainWindow::MainWindow() :
122    
123      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
124    
125      m_HPaned.add1(m_TreeViewNotebook);      m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
126        m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
127        m_searchField.pack_start(m_searchText);
128        m_searchField.set_spacing(5);
129    
130        m_left_vbox.pack_start(m_TreeViewNotebook);
131        m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
132    
133        m_HPaned.add1(m_left_vbox);
134    
135      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
136      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
137      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 96  MainWindow::MainWindow() : Line 139  MainWindow::MainWindow() :
139      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
140      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
141      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
142        {
143            legend_hbox.add(labelLegend);
144    
145            imageNoSample.set(redDot);
146            imageNoSample.set_alignment(Gtk::ALIGN_END);
147            labelNoSample.set_alignment(Gtk::ALIGN_START);
148            legend_hbox.add(imageNoSample);
149            legend_hbox.add(labelNoSample);
150    
151            imageMissingSample.set(yellowDot);
152            imageMissingSample.set_alignment(Gtk::ALIGN_END);
153            labelMissingSample.set_alignment(Gtk::ALIGN_START);
154            legend_hbox.add(imageMissingSample);
155            legend_hbox.add(labelMissingSample);
156    
157            imageLooped.set(blackLoop);
158            imageLooped.set_alignment(Gtk::ALIGN_END);
159            labelLooped.set_alignment(Gtk::ALIGN_START);
160            legend_hbox.add(imageLooped);
161            legend_hbox.add(labelLooped);
162    
163            imageSomeLoops.set(grayLoop);
164            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
165            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
166            legend_hbox.add(imageSomeLoops);
167            legend_hbox.add(labelSomeLoops);
168    
169            legend_hbox.show_all_children();
170        }
171        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
172      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
173    
174      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 229  MainWindow::MainWindow() :
229          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
230      );      );
231      actionGroup->add(      actionGroup->add(
232          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
233          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
234      );      );
235      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
236        actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
237    
238      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
239    
240        const Gdk::ModifierType primaryModifierKey =
241    #if defined(__APPLE__)
242        Gdk::META_MASK; // Cmd key on Mac
243    #else
244        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
245    #endif
246    
247        actionGroup->add(Gtk::Action::create("CopyDimRgn",
248                                             _("Copy selected dimension region")),
249                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
250                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
251    
252        actionGroup->add(Gtk::Action::create("PasteDimRgn",
253                                             _("Paste dimension region")),
254                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
255                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
256    
257        actionGroup->add(Gtk::Action::create("AdjustClipboard",
258                                             _("Adjust Clipboard Content")),
259                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
260                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
261    
262        actionGroup->add(Gtk::Action::create("SelectPrevInstr",
263                                             _("Select Previous Instrument")),
264                         Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
265                         sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
266    
267        actionGroup->add(Gtk::Action::create("SelectNextInstr",
268                                             _("Select Next Instrument")),
269                         Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
270                         sigc::mem_fun(*this, &MainWindow::select_next_instrument));
271    
272        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
273                                             _("Select Previous Region")),
274                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
275                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
276    
277        actionGroup->add(Gtk::Action::create("SelectNextRegion",
278                                             _("Select Next Region")),
279                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
280                         sigc::mem_fun(*this, &MainWindow::select_next_region));
281    
282        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
283                                             _("Select Previous Dimension Region Zone")),
284                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
285                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
286    
287        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
288                                             _("Select Next Dimension Region Zone")),
289                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
290                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
291    
292        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
293                                             _("Select Previous Dimension")),
294                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
295                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
296    
297        actionGroup->add(Gtk::Action::create("SelectNextDimension",
298                                             _("Select Next Dimension")),
299                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
300                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
301    
302        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
303                                             _("Add Previous Dimension Region Zone to Selection")),
304                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
305                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
306    
307        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
308                                             _("Add Next Dimension Region Zone to Selection")),
309                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
310                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
311    
312      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
313          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
314      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 179  MainWindow::MainWindow() : Line 325  MainWindow::MainWindow() :
325      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
326    
327    
328      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
329    
330    
331        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
332      toggle_action =      toggle_action =
333          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
334      toggle_action->set_active(true);      toggle_action->set_active(true);
335      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
336                       sigc::mem_fun(                       sigc::mem_fun(
337                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
338    
339        toggle_action =
340            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
341        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
342        actionGroup->add(toggle_action,
343                         sigc::mem_fun(
344                             *this, &MainWindow::on_auto_restore_win_dim));
345    
346        toggle_action =
347            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
348        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
349        actionGroup->add(toggle_action,
350                         sigc::mem_fun(
351                             *this, &MainWindow::on_save_with_temporary_file));
352    
353      actionGroup->add(      actionGroup->add(
354          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
355          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
# Line 206  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
371      );      );
372      actionGroup->add(      actionGroup->add(
373            Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
374            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
375            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
376        );
377        actionGroup->add(
378          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
379          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
380      );      );
# Line 324  MainWindow::MainWindow() : Line 493  MainWindow::MainWindow() :
493          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
494          "    </menu>"          "    </menu>"
495          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
496            "      <menuitem action='CopyDimRgn'/>"
497            "      <menuitem action='AdjustClipboard'/>"
498            "      <menuitem action='PasteDimRgn'/>"
499            "      <separator/>"
500            "      <menuitem action='SelectPrevInstr'/>"
501            "      <menuitem action='SelectNextInstr'/>"
502            "      <separator/>"
503            "      <menuitem action='SelectPrevRegion'/>"
504            "      <menuitem action='SelectNextRegion'/>"
505            "      <separator/>"
506            "      <menuitem action='SelectPrevDimension'/>"
507            "      <menuitem action='SelectNextDimension'/>"
508            "      <menuitem action='SelectPrevDimRgnZone'/>"
509            "      <menuitem action='SelectNextDimRgnZone'/>"
510            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
511            "      <menuitem action='SelectAddNextDimRgnZone'/>"
512            "      <separator/>"
513          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
514          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
515          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
516          "    </menu>"          "    </menu>"
517            "    <menu action='MenuMacro'>"
518            "    </menu>"
519          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
520          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
521          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 346  MainWindow::MainWindow() : Line 534  MainWindow::MainWindow() :
534          "      <menuitem action='InstrProperties'/>"          "      <menuitem action='InstrProperties'/>"
535          "      <menuitem action='MidiRules'/>"          "      <menuitem action='MidiRules'/>"
536          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
537            "      <menu action='AssignScripts'/>"
538          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
539          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
540            "      <menuitem action='CombInstruments'/>"
541          "      <separator/>"          "      <separator/>"
542          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
543          "    </menu>"          "    </menu>"
# Line 360  MainWindow::MainWindow() : Line 550  MainWindow::MainWindow() :
550          "    </menu>"          "    </menu>"
551          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
552          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
553            "      <menuitem action='AutoRestoreWinDim'/>"
554          "      <separator/>"          "      <separator/>"
555          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
556          "    </menu>"          "    </menu>"
# Line 371  MainWindow::MainWindow() : Line 562  MainWindow::MainWindow() :
562          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
563          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
564          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
565            "      <menuitem action='SaveWithTemporaryFile'/>"
566          "    </menu>"          "    </menu>"
567          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
568          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 382  MainWindow::MainWindow() : Line 574  MainWindow::MainWindow() :
574          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
575          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
576          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
577            "    <menuitem action='CombInstruments'/>"
578          "    <separator/>"          "    <separator/>"
579          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
580          "  </popup>"          "  </popup>"
# Line 458  MainWindow::MainWindow() : Line 651  MainWindow::MainWindow() :
651      }      }
652      {      {
653          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
654                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
655            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
656        }
657        {
658            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
659              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
660          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."));
661      }      }
# Line 471  MainWindow::MainWindow() : Line 669  MainWindow::MainWindow() :
669      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
670          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
671    
672        assign_scripts_menu = static_cast<Gtk::MenuItem*>(
673            uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
674    
675      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
676      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
677      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 494  MainWindow::MainWindow() : Line 695  MainWindow::MainWindow() :
695    
696      // Create the Tree model:      // Create the Tree model:
697      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
698      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
699        m_refTreeModelFilter->set_visible_func(
700            sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
701        );
702        m_TreeView.set_model(m_refTreeModelFilter);
703    
704        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
705      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
706      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
707          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
708      );      );
709    
710      // Add the TreeView's view columns:      // Add the TreeView's view columns:
711      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
712      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
713        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
714        m_TreeView.set_headers_visible(true);
715            
716      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
717      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 525  MainWindow::MainWindow() : Line 734  MainWindow::MainWindow() :
734      // create samples treeview (including its data model)      // create samples treeview (including its data model)
735      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
736      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
737        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
738      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."));
739      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
740      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 666  MainWindow::MainWindow() : Line 876  MainWindow::MainWindow() :
876      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
877          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
878    
879        m_searchText.signal_changed().connect(
880            sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
881        );
882    
883      file = 0;      file = 0;
884      file_is_changed = false;      file_is_changed = false;
885    
# Line 674  MainWindow::MainWindow() : Line 888  MainWindow::MainWindow() :
888      // start with a new gig file by default      // start with a new gig file by default
889      on_action_file_new();      on_action_file_new();
890    
891        m_TreeViewNotebook.signal_switch_page().connect(
892            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
893        );
894    
895      // select 'Instruments' tab by default      // select 'Instruments' tab by default
896      // (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)
897      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
898    
899        Gtk::Clipboard::get()->signal_owner_change().connect(
900            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
901        );
902        updateClipboardPasteAvailable();
903        updateClipboardCopyAvailable();
904    
905        // setup macros and their keyboard accelerators
906        {
907            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
908                uiManager->get_widget("/MenuBar/MenuMacro")
909            )->get_submenu();
910    
911            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
912            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
913            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
914            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
915            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
916            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
917            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
918            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
919            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
920            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
921            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
922            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
923            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
924            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
925    
926            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
927            menuMacro->set_accel_group(accelGroup);
928    
929            updateMacroMenu();
930        }
931    
932        // setup "Assign Scripts" keyboard accelerators
933        {
934            Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
935            Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
936            Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
937            Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
938            Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
939            Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
940            Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
941            Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
942            Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
943            Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
944            Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
945            Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
946    
947            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
948            assign_scripts_menu->set_accel_group(accelGroup);
949        }
950    
951        Glib::signal_idle().connect_once(
952            sigc::mem_fun(*this, &MainWindow::bringToFront),
953            200
954        );
955  }  }
956    
957  MainWindow::~MainWindow()  MainWindow::~MainWindow()
958  {  {
959  }  }
960    
961    void MainWindow::bringToFront() {
962        #if defined(__APPLE__)
963        macRaiseAppWindow();
964        #endif
965        raise();
966        present();
967    }
968    
969    void MainWindow::updateMacroMenu() {
970        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
971            uiManager->get_widget("/MenuBar/MenuMacro")
972        )->get_submenu();
973    
974        // remove all entries from "Macro" menu
975        {
976            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
977            for (int i = 0; i < children.size(); ++i) {
978                Gtk::Widget* child = children[i];
979                menuMacro->remove(*child);
980                delete child;
981            }
982        }
983    
984        // (re)load all macros from config file
985        try {
986            Settings::singleton()->loadMacros(m_macros);
987        } catch (Serialization::Exception e) {
988            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
989        } catch (...) {
990            std::cerr << "Unknown exception while loading macros!" << std::endl;
991        }
992    
993        // add all configured macros as menu items to the "Macro" menu
994        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
995            const Serialization::Archive& macro = m_macros[iMacro];
996            std::string name =
997                macro.name().empty() ?
998                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
999            Gtk::MenuItem* item = new Gtk::MenuItem(name);
1000            item->signal_activate().connect(
1001                sigc::bind(
1002                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1003                )
1004            );
1005            menuMacro->append(*item);
1006            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1007            Glib::ustring comment = macro.comment();
1008            if (!comment.empty())
1009                item->set_tooltip_text(comment);
1010        }
1011        // if there are no macros configured at all, then show a dummy entry instead
1012        if (m_macros.empty()) {
1013            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1014            item->set_sensitive(false);
1015            menuMacro->append(*item);
1016        }
1017    
1018        // add separator line to menu
1019        menuMacro->append(*new Gtk::SeparatorMenuItem);
1020    
1021        {
1022            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1023            item->signal_activate().connect(
1024                sigc::mem_fun(*this, &MainWindow::setupMacros)
1025            );
1026            menuMacro->append(*item);
1027            item->set_accel_path("<Macros>/SetupMacros");
1028        }
1029    
1030        menuMacro->show_all_children();
1031    }
1032    
1033    void MainWindow::onMacroSelected(int iMacro) {
1034        printf("onMacroSelected(%d)\n", iMacro);
1035        if (iMacro < 0 || iMacro >= m_macros.size()) return;
1036        Glib::ustring errorText;
1037        try {
1038            applyMacro(m_macros[iMacro]);
1039        } catch (Serialization::Exception e) {
1040            errorText = e.Message;
1041        } catch (...) {
1042            errorText = _("Unknown exception while applying macro");
1043        }
1044        if (!errorText.empty()) {
1045            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1046            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1047            msg.run();
1048        }
1049    }
1050    
1051    void MainWindow::setupMacros() {
1052        MacrosSetup* setup = new MacrosSetup();
1053        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1054        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1055        setup->signal_macros_changed().connect(
1056            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1057        );
1058        setup->show();
1059    }
1060    
1061    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1062        m_macros = macros;
1063        Settings::singleton()->saveMacros(m_macros);
1064        updateMacroMenu();
1065    }
1066    
1067    void MainWindow::on_notebook_tab_switched(GtkNotebookPage* page, guint page_num) {
1068        bool isInstrumentsPage = (page_num == 1);
1069        // so far we only support filtering for the instruments list, so hide the
1070        // filter text entry field if another tab is selected
1071        m_searchField.set_visible(isInstrumentsPage);
1072    }
1073    
1074  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1075  {  {
1076      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 702  void MainWindow::region_changed() Line 1090  void MainWindow::region_changed()
1090  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
1091  {  {
1092      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
1093      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1094          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
1095        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1096      if (it) {      if (it) {
1097          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1098          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 746  void MainWindow::update_dimregs() Line 1135  void MainWindow::update_dimregs()
1135              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1136          }          }
1137      }      }
1138    
1139        m_RegionChooser.setModifyAllRegions(all_regions);
1140        m_DimRegionChooser.setModifyAllRegions(all_regions);
1141        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1142        m_DimRegionChooser.setModifyBothChannels(stereo);
1143    
1144        updateClipboardCopyAvailable();
1145  }  }
1146    
1147  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 763  void MainWindow::dimreg_changed() Line 1159  void MainWindow::dimreg_changed()
1159  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1160  {  {
1161      // select item in instrument menu      // select item in instrument menu
1162      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1163      if (it) {      if (!rows.empty()) {
1164          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1165          int index = path[0];          if (it) {
1166          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1167              instrument_menu->get_children();              int index = path[0];
1168          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1169                    instrument_menu->get_children();
1170                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1171            }
1172      }      }
1173    
1174        updateScriptListOfMenu();
1175    
1176      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
1177    
1178      if (Settings::singleton()->syncSamplerInstrumentSelection) {      if (Settings::singleton()->syncSamplerInstrumentSelection) {
# Line 794  void Loader::progress_callback(float fra Line 1195  void Loader::progress_callback(float fra
1195      progress_dispatcher();      progress_dispatcher();
1196  }  }
1197    
1198    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1199    // make sure stack is 16-byte aligned for SSE instructions
1200    __attribute__((force_align_arg_pointer))
1201    #endif
1202  void Loader::thread_function()  void Loader::thread_function()
1203  {  {
1204      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1205               static_cast<void*>(Glib::Threads::Thread::self()));
1206      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1207      try {      try {
1208          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 818  void Loader::thread_function() Line 1224  void Loader::thread_function()
1224  }  }
1225    
1226  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1227      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
1228  {  {
1229  }  }
1230    
# Line 829  void Loader::launch() Line 1235  void Loader::launch()
1235  #else  #else
1236      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1237  #endif  #endif
1238      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1239  }  }
1240    
1241  float Loader::get_progress()  float Loader::get_progress()
# Line 872  void Saver::progress_callback(float frac Line 1278  void Saver::progress_callback(float frac
1278      progress_dispatcher.emit();      progress_dispatcher.emit();
1279  }  }
1280    
1281    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1282    // make sure stack is 16-byte aligned for SSE instructions
1283    __attribute__((force_align_arg_pointer))
1284    #endif
1285  void Saver::thread_function()  void Saver::thread_function()
1286  {  {
1287      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1288               static_cast<void*>(Glib::Threads::Thread::self()));
1289      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1290      try {      try {
1291          gig::progress_t progress;          gig::progress_t progress;
# Line 883  void Saver::thread_function() Line 1294  void Saver::thread_function()
1294    
1295          // 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"
1296          if (filename.empty()) {          if (filename.empty()) {
1297              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1298                    // save directly over the existing .gig file
1299                    // (requires less disk space than solution below
1300                    // but may be slower)
1301                    gig->Save(&progress);
1302                } else {
1303                    // save the file as separate temporary file first,
1304                    // then move the saved file over the old file
1305                    // (may result in performance speedup during save)
1306                    gig::String tmpname = filename + ".TMP";
1307                    gig->Save(tmpname, &progress);
1308                    #if defined(WIN32)
1309                    if (!DeleteFile(filename.c_str())) {
1310                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1311                    }
1312                    #else // POSIX ...
1313                    if (unlink(filename.c_str())) {
1314                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1315                    }
1316                    #endif
1317                    if (rename(tmpname.c_str(), filename.c_str())) {
1318                        #if defined(WIN32)
1319                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1320                        #else
1321                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1322                        #endif
1323                    }
1324                }
1325          } else {          } else {
1326              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1327          }          }
# Line 911  void Saver::launch() Line 1349  void Saver::launch()
1349  #else  #else
1350      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1351  #endif  #endif
1352      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1353  }  }
1354    
1355  float Saver::get_progress()  float Saver::get_progress()
# Line 1071  void MainWindow::on_action_file_open() Line 1509  void MainWindow::on_action_file_open()
1509      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1510          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1511          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1512          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1513                   static_cast<void*>(Glib::Threads::Thread::self()));
1514          load_file(filename.c_str());          load_file(filename.c_str());
1515          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1516      }      }
# Line 1141  void MainWindow::on_loader_progress() Line 1580  void MainWindow::on_loader_progress()
1580  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1581  {  {
1582      printf("Loader finished!\n");      printf("Loader finished!\n");
1583      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1584               static_cast<void*>(Glib::Threads::Thread::self()));
1585      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1586      progress_dialog->hide();      progress_dialog->hide();
1587  }  }
# Line 1281  bool MainWindow::file_save_as() Line 1721  bool MainWindow::file_save_as()
1721      // show warning in the dialog      // show warning in the dialog
1722      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1723      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1724      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1725        warningIcon.set_from_icon_name("dialog-warning",
1726                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1727      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1728  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1729      view::WrapLabel description;      view::WrapLabel description;
# Line 1333  bool MainWindow::file_save_as() Line 1775  bool MainWindow::file_save_as()
1775  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1776      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1777      Glib::ustring error_files;      Glib::ustring error_files;
1778      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1779      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1780           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1781          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1782          SF_INFO info;          SF_INFO info;
1783          info.format = 0;          info.format = 0;
1784          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);
1785          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1786          try {          try {
1787              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1362  void MainWindow::__import_queued_samples Line 1804  void MainWindow::__import_queued_samples
1804                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1805              }              }
1806    
1807                // reset write position for sample
1808                iter->first->SetPos(0);
1809    
1810              const int bufsize = 10000;              const int bufsize = 10000;
1811              switch (bitdepth) {              switch (bitdepth) {
1812                  case 16: {                  case 16: {
# Line 1371  void MainWindow::__import_queued_samples Line 1816  void MainWindow::__import_queued_samples
1816                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1817                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1818                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1819                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1820                          cnt -= n;                          cnt -= n;
1821                      }                      }
1822                      delete[] buffer;                      delete[] buffer;
# Line 1391  void MainWindow::__import_queued_samples Line 1836  void MainWindow::__import_queued_samples
1836                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1837                          }                          }
1838                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1839                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1840                          cnt -= n;                          cnt -= n;
1841                      }                      }
1842                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1402  void MainWindow::__import_queued_samples Line 1847  void MainWindow::__import_queued_samples
1847              // cleanup              // cleanup
1848              sf_close(hFile);              sf_close(hFile);
1849              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1850              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1851              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1852              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1853              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1854              ++iter;              ++iter;
1855              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1856          } catch (std::string what) {          } catch (std::string what) {
1857              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1858              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1859              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1860              ++iter;              ++iter;
1861          }          }
1862      }      }
# Line 1453  void MainWindow::on_action_help_about() Line 1898  void MainWindow::on_action_help_about()
1898      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1899  #endif  #endif
1900      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1901      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1902      const std::string sComment =      const std::string sComment =
1903          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1904          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1469  void MainWindow::on_action_help_about() Line 1914  void MainWindow::on_action_help_about()
1914      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1915      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1916      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1917        dialog.set_position(Gtk::WIN_POS_CENTER);
1918      dialog.run();      dialog.run();
1919  }  }
1920    
# Line 1494  PropDialog::PropDialog() Line 1940  PropDialog::PropDialog()
1940        table(2, 1),        table(2, 1),
1941        m_file(NULL)        m_file(NULL)
1942  {  {
1943        if (!Settings::singleton()->autoRestoreWindowDimension) {
1944            set_default_size(470, 390);
1945            set_position(Gtk::WIN_POS_MOUSE);
1946        }
1947    
1948      set_title(_("File Properties"));      set_title(_("File Properties"));
1949      eName.set_width_chars(50);      eName.set_width_chars(50);
1950    
# Line 1628  InstrumentProps::InstrumentProps() : Line 2079  InstrumentProps::InstrumentProps() :
2079      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2080      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2081  {  {
2082        if (!Settings::singleton()->autoRestoreWindowDimension) {
2083            //set_default_size(470, 390);
2084            set_position(Gtk::WIN_POS_MOUSE);
2085        }
2086    
2087      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2088    
2089      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1748  void MainWindow::load_gig(gig::File* gig Line 2204  void MainWindow::load_gig(gig::File* gig
2204      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2205    
2206      instrument_name_connection.block();      instrument_name_connection.block();
2207        int index = 0;
2208      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2209           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2210          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2211            const int iScriptSlots = instrument->ScriptSlotCount();
2212    
2213          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2214          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2215            row[m_Columns.m_col_nr] = index;
2216          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2217          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2218            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2219    
2220          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2221      }      }
# Line 1826  bool MainWindow::instr_props_set_instrum Line 2286  bool MainWindow::instr_props_set_instrum
2286  {  {
2287      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2288    
2289      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2290          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2291            instrumentProps.hide();
2292            return false;
2293        }
2294        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2295      if (it) {      if (it) {
2296          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2297          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1880  void MainWindow::show_midi_rules() Line 2344  void MainWindow::show_midi_rules()
2344  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2345      if (!file) return;      if (!file) return;
2346      // get selected instrument      // get selected instrument
2347      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2348      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2349        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2350      if (!it) return;      if (!it) return;
2351      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2352      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1889  void MainWindow::show_script_slots() { Line 2354  void MainWindow::show_script_slots() {
2354    
2355      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2356      window->setInstrument(instrument);      window->setInstrument(instrument);
2357        window->signal_script_slots_changed().connect(
2358            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2359        );
2360      //window->reparent(*this);      //window->reparent(*this);
2361      window->show();      window->show();
2362  }  }
2363    
2364    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2365        if (!pInstrument) return;
2366        const int iScriptSlots = pInstrument->ScriptSlotCount();
2367    
2368        //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
2369        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2370        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2371    
2372        for (int i = 0; i < model->children().size(); ++i) {
2373            Gtk::TreeModel::Row row = model->children()[i];
2374            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2375            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2376            break;
2377        }
2378    
2379        // causes the sampler to reload the instrument with the new script
2380        on_sel_change();
2381    }
2382    
2383    void MainWindow::assignScript(gig::Script* pScript) {
2384        if (!pScript) {
2385            printf("assignScript() : !script\n");
2386            return;
2387        }
2388        printf("assignScript('%s')\n", pScript->Name.c_str());
2389    
2390        gig::Instrument* pInstrument = get_instrument();
2391        if (!pInstrument) {
2392            printf("!instrument\n");
2393            return;
2394        }
2395    
2396        pInstrument->AddScriptSlot(pScript);
2397    
2398        onScriptSlotsModified(pInstrument);
2399    }
2400    
2401  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2402      __refreshEntireGUI();      __refreshEntireGUI();
2403  }  }
# Line 1908  void MainWindow::on_action_view_status_b Line 2413  void MainWindow::on_action_view_status_b
2413      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2414  }  }
2415    
2416    void MainWindow::on_auto_restore_win_dim() {
2417        Gtk::CheckMenuItem* item =
2418            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2419        if (!item) {
2420            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2421            return;
2422        }
2423        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2424    }
2425    
2426    void MainWindow::on_save_with_temporary_file() {
2427        Gtk::CheckMenuItem* item =
2428            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2429        if (!item) {
2430            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2431            return;
2432        }
2433        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2434    }
2435    
2436  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2437      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2438          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1975  void MainWindow::on_instrument_selection Line 2500  void MainWindow::on_instrument_selection
2500  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
2501      if (!instrument) return;      if (!instrument) return;
2502    
2503        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2504      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2505        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2506    
2507      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2508          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2509          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2510              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2511              show_intruments_tab();              show_intruments_tab();
2512                m_TreeView.get_selection()->unselect_all();
2513              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2514              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2515                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2516              );              if (!rows.empty())
2517              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2518              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2519          }          }
2520      }      }
# Line 1996  bool MainWindow::select_dimension_region Line 2525  bool MainWindow::select_dimension_region
2525      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2526      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2527    
2528        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2529      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2530        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2531    
2532      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2533          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2534          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2535              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2536              show_intruments_tab();              show_intruments_tab();
2537                m_TreeView.get_selection()->unselect_all();
2538              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2539              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2540                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2541              );              if (!rows.empty())
2542              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2543              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2544    
2545              // select respective region in the region selector              // select respective region in the region selector
# Line 2032  void MainWindow::select_sample(gig::Samp Line 2565  void MainWindow::select_sample(gig::Samp
2565              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2566              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2567                  show_samples_tab();                  show_samples_tab();
2568                    m_TreeViewSamples.get_selection()->unselect_all();
2569                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2570                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2571                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2572                  );                  if (rows.empty()) return;
2573                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2574                  return;                  return;
2575              }              }
2576          }          }
# Line 2045  void MainWindow::select_sample(gig::Samp Line 2579  void MainWindow::select_sample(gig::Samp
2579    
2580  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2581      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2582            // by default if Ctrl keys is pressed down, then a mouse right-click
2583            // does not select the respective row, so we must assure this
2584            // programmatically ...
2585            /*{
2586                Gtk::TreeModel::Path path;
2587                Gtk::TreeViewColumn* pColumn = NULL;
2588                int cellX, cellY;
2589                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2590                    (int)button->x, (int)button->y,
2591                    path, pColumn, cellX, cellY
2592                );
2593                if (bSuccess) {
2594                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2595                        printf("not selected !!!\n");
2596                        m_TreeViewSamples.get_selection()->select(path);
2597                    }
2598                }
2599            }*/
2600    
2601          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2602              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2603          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2604          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2605          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2606          bool group_selected  = false;          const int n = rows.size();
2607          bool sample_selected = false;          int nGroups  = 0;
2608          if (it) {          int nSamples = 0;
2609            for (int r = 0; r < n; ++r) {
2610                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2611                if (!it) continue;
2612              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2613              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2614              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2615          }          }
2616            
               
2617          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2618              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2619          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2620              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2621          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2622              set_sensitive(file);              set_sensitive(file);
2623          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2624              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2625          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2626              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2627          // show sample popup          // show sample popup
2628          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2629    
2630          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2631              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2632          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2633              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2634          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2635              set_sensitive(file);              set_sensitive(file);
2636          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2637              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2638          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2639              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2640      }      }
2641  }  }
2642    
# Line 2121  void MainWindow::on_script_treeview_butt Line 2676  void MainWindow::on_script_treeview_butt
2676      }      }
2677  }  }
2678    
2679    void MainWindow::updateScriptListOfMenu() {
2680        // remove all entries from "Assign Script" menu
2681        {
2682            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
2683            for (int i = 0; i < children.size(); ++i) {
2684                Gtk::Widget* child = children[i];
2685                assign_scripts_menu->remove(*child);
2686                delete child;
2687            }
2688        }
2689    
2690        int iTotalScripts = 0;
2691    
2692        if (!file) goto noScripts;
2693    
2694        // add all configured macros as menu items to the "Macro" menu
2695        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
2696            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
2697            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
2698                gig::Script* pScript = pGroup->GetScript(iScript);
2699                std::string name = pScript->Name;
2700    
2701                Gtk::MenuItem* item = new Gtk::MenuItem(name);
2702                item->signal_activate().connect(
2703                    sigc::bind(
2704                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
2705                    )
2706                );
2707                assign_scripts_menu->append(*item);
2708                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
2709                //item->set_tooltip_text(comment);
2710            }
2711        }
2712    
2713        noScripts:
2714    
2715        // if there are no macros configured at all, then show a dummy entry instead
2716        if (!iTotalScripts) {
2717            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
2718            item->set_sensitive(false);
2719            assign_scripts_menu->append(*item);
2720        }
2721    
2722        assign_scripts_menu->show_all_children();
2723    }
2724    
2725  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2726      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
2727    
# Line 2160  void MainWindow::add_instrument(gig::Ins Line 2761  void MainWindow::add_instrument(gig::Ins
2761      instrument_name_connection.block();      instrument_name_connection.block();
2762      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2763      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2764        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2765      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2766      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2767        rowInstr[m_Columns.m_col_scripts] = "";
2768      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2769    
2770      add_instrument_to_menu(name);      add_instrument_to_menu(name);
2771        select_instrument(instrument);
     m_TreeView.get_selection()->select(iterInstr);  
   
2772      file_changed();      file_changed();
2773  }  }
2774    
# Line 2188  void MainWindow::on_action_duplicate_ins Line 2789  void MainWindow::on_action_duplicate_ins
2789      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2790      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2791      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2792      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2793      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2794      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2795      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2796      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2797                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2798      // duplicate the orginal instrument              if (instrOrig) {
2799      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2800      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2801          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2802          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2803                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2804    
2805      add_instrument(instrNew);                  add_instrument(instrNew);
2806                }
2807            }
2808        }
2809  }  }
2810    
2811  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2217  void MainWindow::on_action_remove_instru Line 2822  void MainWindow::on_action_remove_instru
2822      }      }
2823    
2824      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2825      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2826      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2827            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2828            if (!it) continue;
2829          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2830          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2831          try {          try {
# Line 2233  void MainWindow::on_action_remove_instru Line 2840  void MainWindow::on_action_remove_instru
2840    
2841              // remove row from instruments tree view              // remove row from instruments tree view
2842              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2843                // update "Nr" column of all instrument rows
2844                {
2845                    int index = 0;
2846                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2847                         it != m_refTreeModel->children().end(); ++it, ++index)
2848                    {
2849                        Gtk::TreeModel::Row row = *it;
2850                        row[m_Columns.m_col_nr] = index;
2851                    }
2852                }
2853    
2854  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2855              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2330  void MainWindow::on_action_edit_script() Line 2947  void MainWindow::on_action_edit_script()
2947      if (!script) return;      if (!script) return;
2948    
2949      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2950        editor->signal_script_to_be_changed.connect(
2951            signal_script_to_be_changed.make_slot()
2952        );
2953        editor->signal_script_changed.connect(
2954            signal_script_changed.make_slot()
2955        );
2956      editor->setScript(script);      editor->setScript(script);
2957      //editor->reparent(*this);      //editor->reparent(*this);
2958      editor->show();      editor->show();
# Line 2408  void MainWindow::add_or_replace_sample(b Line 3031  void MainWindow::add_or_replace_sample(b
3031    
3032      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
3033      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3034      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3035        if (rows.empty()) return;
3036        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3037      if (!it) return;      if (!it) return;
3038      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3039      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2557  void MainWindow::add_or_replace_sample(b Line 3182  void MainWindow::add_or_replace_sample(b
3182                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3183                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3184                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3185                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3186                  // add sample to the tree view                  // add sample to the tree view
3187                  if (replace) {                  if (replace) {
3188                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2651  void MainWindow::on_action_replace_all_s Line 3276  void MainWindow::on_action_replace_all_s
3276              try              try
3277              {              {
3278                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
3279                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
3280                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
3281                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
3282                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
3283                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
3284                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
3285                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
3286                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
3287                          break;                          break;
3288                      default:                      default:
3289                          sf_close(hFile);                          sf_close(hFile);
# Line 2671  void MainWindow::on_action_replace_all_s Line 3292  void MainWindow::on_action_replace_all_s
3292                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3293                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3294                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3295                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3296                  sf_close(hFile);                  sf_close(hFile);
3297                  file_changed();                  file_changed();
3298              }              }
# Line 2695  void MainWindow::on_action_replace_all_s Line 3316  void MainWindow::on_action_replace_all_s
3316  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
3317      if (!file) return;      if (!file) return;
3318      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3319      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3320      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3321            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3322            if (!it) continue;
3323          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3324          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
3325          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2721  void MainWindow::on_action_remove_sample Line 3344  void MainWindow::on_action_remove_sample
3344                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3345                  // them from the import queue                  // them from the import queue
3346                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3347                       member != members.end(); ++member) {                       member != members.end(); ++member)
3348                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3349                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3350                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3351                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3352                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3353                      }                      }
3354                  }                  }
3355                  file_changed();                  file_changed();
# Line 2744  void MainWindow::on_action_remove_sample Line 3364  void MainWindow::on_action_remove_sample
3364                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3365                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3366                  // the import queue                  // the import queue
3367                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3368                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3369                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3370                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3371                  }                  }
3372                  dimreg_changed();                  dimreg_changed();
3373                  file_changed();                  file_changed();
# Line 2807  void MainWindow::on_action_remove_unused Line 3423  void MainWindow::on_action_remove_unused
3423              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3424              // remove sample from the .gig file              // remove sample from the .gig file
3425              file->DeleteSample(sample);              file->DeleteSample(sample);
3426              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3427              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3428                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3429              {                         m_SampleImportQueue[sample].sample_path.c_str());
3430                  if ((*iter).gig_sample == sample) {                  m_SampleImportQueue.erase(sample);
                     printf("Removing previously added sample '%s'\n",  
                            (*iter).sample_path.c_str());  
                     m_SampleImportQueue.erase(iter);  
                     break;  
                 }  
3431              }              }
3432          }          }
3433      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2875  void MainWindow::on_instruments_treeview Line 3486  void MainWindow::on_instruments_treeview
3486      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3487      {      {
3488          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3489          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3490          if (it) {          if (!rows.empty()) {
3491              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3492              src = row[m_Columns.m_col_instr];              if (it) {
3493                    Gtk::TreeModel::Row row = *it;
3494                    src = row[m_Columns.m_col_instr];
3495                }
3496          }          }
3497      }      }
3498      if (!src) return;      if (!src) return;
# Line 2933  void MainWindow::on_sample_treeview_drag Line 3547  void MainWindow::on_sample_treeview_drag
3547      // get selected sample      // get selected sample
3548      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3549      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3550      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3551      if (it) {      if (!rows.empty()) {
3552          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3553          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3554                Gtk::TreeModel::Row row = *it;
3555                sample = row[m_SamplesModel.m_col_sample];
3556            }
3557      }      }
3558      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3559      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 3076  void MainWindow::script_double_clicked(c Line 3693  void MainWindow::script_double_clicked(c
3693      if (!script) return;      if (!script) return;
3694    
3695      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3696        editor->signal_script_to_be_changed.connect(
3697            signal_script_to_be_changed.make_slot()
3698        );
3699        editor->signal_script_changed.connect(
3700            signal_script_changed.make_slot()
3701        );
3702      editor->setScript(script);      editor->setScript(script);
3703      //editor->reparent(*this);      //editor->reparent(*this);
3704      editor->show();      editor->show();
# Line 3115  void MainWindow::instrument_name_changed Line 3738  void MainWindow::instrument_name_changed
3738      }      }
3739  }  }
3740    
3741    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
3742        if (!iter)
3743            return true;
3744    
3745        Glib::ustring pattern = m_searchText.get_text().lowercase();
3746        trim(pattern);
3747        if (pattern.empty()) return true;
3748    
3749        Gtk::TreeModel::Row row = *iter;
3750        Glib::ustring name = row[m_Columns.m_col_name];
3751        name = name.lowercase();
3752    
3753        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
3754        for (int t = 0; t < tokens.size(); ++t)
3755            if (name.find(tokens[t]) == Glib::ustring::npos)
3756                return false;
3757    
3758        return true;
3759    }
3760    
3761  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3762      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3763    
3764        // take over selection from instruments list view for the combine dialog's
3765        // list view as pre-selection
3766        std::set<int> indeces;
3767        {
3768            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3769            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3770            for (int r = 0; r < rows.size(); ++r) {
3771                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3772                if (it) {
3773                    Gtk::TreeModel::Row row = *it;
3774                    int index = row[m_Columns.m_col_nr];
3775                    indeces.insert(index);
3776                }
3777            }
3778        }
3779        d->setSelectedInstruments(indeces);
3780    
3781      d->show_all();      d->show_all();
     d->resize(500, 400);  
3782      d->run();      d->run();
3783      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3784          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3129  void MainWindow::on_action_combine_instr Line 3789  void MainWindow::on_action_combine_instr
3789    
3790  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3791      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3792      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3793        if (rows.empty()) return;
3794        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3795      if (!it) return;      if (!it) return;
3796      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3797      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3270  void MainWindow::on_action_merge_files() Line 3932  void MainWindow::on_action_merge_files()
3932      // show warning in the file picker dialog      // show warning in the file picker dialog
3933      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3934      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3935      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3936        warningIcon.set_from_icon_name("dialog-warning",
3937                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3938      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3939  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3940      view::WrapLabel description;      view::WrapLabel description;
# Line 3293  void MainWindow::on_action_merge_files() Line 3957  void MainWindow::on_action_merge_files()
3957      descriptionArea.show_all();      descriptionArea.show_all();
3958    
3959      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3960          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3961                   static_cast<void*>(Glib::Threads::Thread::self()));
3962          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3963    
3964          // merge the selected files to the currently open .gig file          // merge the selected files to the currently open .gig file
# Line 3375  void MainWindow::show_scripts_tab() { Line 4040  void MainWindow::show_scripts_tab() {
4040      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
4041  }  }
4042    
4043    void MainWindow::select_instrument_by_dir(int dir) {
4044        if (!file) return;
4045        gig::Instrument* pInstrument = get_instrument();
4046        if (!pInstrument) {
4047            select_instrument( file->GetInstrument(0) );
4048            return;
4049        }
4050        for (int i = 0; file->GetInstrument(i); ++i) {
4051            if (file->GetInstrument(i) == pInstrument) {
4052                select_instrument( file->GetInstrument(i + dir) );
4053                return;
4054            }
4055        }
4056    }
4057    
4058    void MainWindow::select_prev_instrument() {
4059        select_instrument_by_dir(-1);
4060    }
4061    
4062    void MainWindow::select_next_instrument() {
4063        select_instrument_by_dir(1);
4064    }
4065    
4066    void MainWindow::select_prev_region() {
4067        m_RegionChooser.select_prev_region();
4068    }
4069    
4070    void MainWindow::select_next_region() {
4071        m_RegionChooser.select_next_region();
4072    }
4073    
4074    void MainWindow::select_next_dim_rgn_zone() {
4075        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4076        m_DimRegionChooser.select_next_dimzone();
4077    }
4078    
4079    void MainWindow::select_prev_dim_rgn_zone() {
4080        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4081        m_DimRegionChooser.select_prev_dimzone();
4082    }
4083    
4084    void MainWindow::select_add_next_dim_rgn_zone() {
4085        m_DimRegionChooser.select_next_dimzone(true);
4086    }
4087    
4088    void MainWindow::select_add_prev_dim_rgn_zone() {
4089        m_DimRegionChooser.select_prev_dimzone(true);
4090    }
4091    
4092    void MainWindow::select_prev_dimension() {
4093        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4094        m_DimRegionChooser.select_prev_dimension();
4095    }
4096    
4097    void MainWindow::select_next_dimension() {
4098        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4099        m_DimRegionChooser.select_next_dimension();
4100    }
4101    
4102    #define CLIPBOARD_DIMENSIONREGION_TARGET \
4103        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
4104    
4105    void MainWindow::copy_selected_dimrgn() {
4106        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
4107        if (!pDimRgn) {
4108            updateClipboardPasteAvailable();
4109            updateClipboardCopyAvailable();
4110            return;
4111        }
4112    
4113        std::vector<Gtk::TargetEntry> targets;
4114        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
4115    
4116        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4117        clipboard->set(
4118            targets,
4119            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
4120            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
4121        );
4122    
4123        m_serializationArchive.serialize(pDimRgn);
4124    
4125        updateClipboardPasteAvailable();
4126    }
4127    
4128    void MainWindow::paste_copied_dimrgn() {
4129        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4130        clipboard->request_contents(
4131            CLIPBOARD_DIMENSIONREGION_TARGET,
4132            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
4133        );
4134        updateClipboardPasteAvailable();
4135    }
4136    
4137    void MainWindow::adjust_clipboard_content() {
4138        MacroEditor* editor = new MacroEditor();
4139        editor->setMacro(&m_serializationArchive, true);
4140        editor->show();
4141    }
4142    
4143    void MainWindow::updateClipboardPasteAvailable() {
4144        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4145        clipboard->request_targets(
4146            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
4147        );
4148    }
4149    
4150    void MainWindow::updateClipboardCopyAvailable() {
4151        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
4152        static_cast<Gtk::MenuItem*>(
4153            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
4154        )->set_sensitive(bDimensionRegionCopyIsPossible);
4155    }
4156    
4157    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
4158        updateClipboardPasteAvailable();
4159    }
4160    
4161    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
4162        const std::string target = selection_data.get_target();
4163        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4164            selection_data.set(
4165                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
4166                &m_serializationArchive.rawData()[0],
4167                m_serializationArchive.rawData().size()
4168            );
4169        } else {
4170            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
4171        }
4172    }
4173    
4174    void MainWindow::on_clipboard_clear() {
4175        m_serializationArchive.clear();
4176        updateClipboardPasteAvailable();
4177        updateClipboardCopyAvailable();
4178    }
4179    
4180    //NOTE: Might throw exception !!!
4181    void MainWindow::applyMacro(Serialization::Archive& macro) {
4182        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
4183        if (!pDimRgn) return;
4184    
4185        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
4186             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
4187        {
4188            gig::DimensionRegion* pDimRgn = *itDimReg;
4189            DimRegionChangeGuard(this, pDimRgn);
4190            macro.deserialize(pDimRgn);
4191        }
4192        //region_changed()
4193        file_changed();
4194        dimreg_changed();
4195    }
4196    
4197    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
4198        const std::string target = selection_data.get_target();
4199        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4200            Glib::ustring errorText;
4201            try {
4202                m_serializationArchive.decode(
4203                    selection_data.get_data(), selection_data.get_length()
4204                );
4205                applyMacro(m_serializationArchive);
4206            } catch (Serialization::Exception e) {
4207                errorText = e.Message;
4208            } catch (...) {
4209                errorText = _("Unknown exception while pasting DimensionRegion");
4210            }
4211            if (!errorText.empty()) {
4212                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
4213                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4214                msg.run();
4215            }
4216        }
4217    }
4218    
4219    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
4220        const bool bDimensionRegionPasteIsPossible =
4221            std::find(targets.begin(), targets.end(),
4222                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
4223    
4224        static_cast<Gtk::MenuItem*>(
4225            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4226        )->set_sensitive(bDimensionRegionPasteIsPossible);
4227    
4228        static_cast<Gtk::MenuItem*>(
4229            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4230        )->set_sensitive(bDimensionRegionPasteIsPossible);
4231    }
4232    
4233  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4234      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4235  }  }

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

  ViewVC Help
Powered by ViewVC