/[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 3300 by schoenebeck, Sun Jul 9 18:15:02 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2015 Andreas Persson   * Copyright (C) 2006-2017 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmmconfig.h>
24    // threads.h must be included first to be able to build with
25    // G_DISABLE_DEPRECATED
26    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28    #include <glibmm/threads.h>
29    #endif
30    
31  #include <glibmm/convert.h>  #include <glibmm/convert.h>
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
# Line 31  Line 39 
39  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
40  #include <gtkmm/main.h>  #include <gtkmm/main.h>
41  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
42    #include <gtkmm/accelmap.h>
43  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
44  #include "wrapLabel.hh"  #include "wrapLabel.hh"
45  #endif  #endif
# Line 50  Line 59 
59  #include "ReferencesView.h"  #include "ReferencesView.h"
60  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
61  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
62    #include "gfx/builtinpix.h"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    #if defined(__APPLE__)
66    # include "MacHelper.h"
67    #endif
68    
69    static const Gdk::ModifierType primaryModifierKey =
70        #if defined(__APPLE__)
71        Gdk::META_MASK; // Cmd key on Mac
72        #else
73        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
74        #endif
75    
76  MainWindow::MainWindow() :  MainWindow::MainWindow() :
77      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
78      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
79      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
80      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
81      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
82        labelLegend(_("Legend:")),
83        labelNoSample(_(" No Sample")),
84        labelMissingSample(_(" Missing some Sample(s)")),
85        labelLooped(_(" Looped")),
86        labelSomeLoops(_(" Some Loop(s)"))
87  {  {
88        loadBuiltInPix();
89    
90  //    set_border_width(5);  //    set_border_width(5);
 //    set_default_size(400, 200);  
91    
92        if (!Settings::singleton()->autoRestoreWindowDimension) {
93            set_default_size(800, 600);
94            set_position(Gtk::WIN_POS_CENTER);
95        }
96    
97      add(m_VBox);      add(m_VBox);
98    
# Line 96  MainWindow::MainWindow() : Line 127  MainWindow::MainWindow() :
127      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
128      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
129      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
130        {
131            legend_hbox.add(labelLegend);
132    
133            imageNoSample.set(redDot);
134            imageNoSample.set_alignment(Gtk::ALIGN_END);
135            labelNoSample.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageNoSample);
137            legend_hbox.add(labelNoSample);
138    
139            imageMissingSample.set(yellowDot);
140            imageMissingSample.set_alignment(Gtk::ALIGN_END);
141            labelMissingSample.set_alignment(Gtk::ALIGN_START);
142            legend_hbox.add(imageMissingSample);
143            legend_hbox.add(labelMissingSample);
144    
145            imageLooped.set(blackLoop);
146            imageLooped.set_alignment(Gtk::ALIGN_END);
147            labelLooped.set_alignment(Gtk::ALIGN_START);
148            legend_hbox.add(imageLooped);
149            legend_hbox.add(labelLooped);
150    
151            imageSomeLoops.set(grayLoop);
152            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
153            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
154            legend_hbox.add(imageSomeLoops);
155            legend_hbox.add(labelSomeLoops);
156    
157            legend_hbox.show_all_children();
158        }
159        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
160      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
161    
162      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 217  MainWindow::MainWindow() :
217          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
218      );      );
219      actionGroup->add(      actionGroup->add(
220          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
221          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
222      );      );
223      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
224    
225      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
226    
227        const Gdk::ModifierType primaryModifierKey =
228    #if defined(__APPLE__)
229        Gdk::META_MASK; // Cmd key on Mac
230    #else
231        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
232    #endif
233    
234        actionGroup->add(Gtk::Action::create("CopyDimRgn",
235                                             _("Copy selected dimension region")),
236                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
237                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
238    
239        actionGroup->add(Gtk::Action::create("PasteDimRgn",
240                                             _("Paste dimension region")),
241                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
242                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
243    
244        actionGroup->add(Gtk::Action::create("AdjustClipboard",
245                                             _("Adjust Clipboard Content")),
246                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
247                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
248    
249        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
250                                             _("Select Previous Region")),
251                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
252                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
253    
254        actionGroup->add(Gtk::Action::create("SelectNextRegion",
255                                             _("Select Next Region")),
256                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
257                         sigc::mem_fun(*this, &MainWindow::select_next_region));
258    
259        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
260                                             _("Select Previous Dimension Region Zone")),
261                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
262                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
263    
264        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
265                                             _("Select Next Dimension Region Zone")),
266                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
267                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
268    
269        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
270                                             _("Select Previous Dimension")),
271                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
272                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
273    
274        actionGroup->add(Gtk::Action::create("SelectNextDimension",
275                                             _("Select Next Dimension")),
276                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
277                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
278    
279        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
280                                             _("Add Previous Dimension Region Zone to Selection")),
281                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
282                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
283    
284        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
285                                             _("Add Next Dimension Region Zone to Selection")),
286                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
287                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
288    
289      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
290          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
291      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 179  MainWindow::MainWindow() : Line 302  MainWindow::MainWindow() :
302      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
303    
304    
305      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
306    
307    
308        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
309      toggle_action =      toggle_action =
310          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
311      toggle_action->set_active(true);      toggle_action->set_active(true);
312      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
313                       sigc::mem_fun(                       sigc::mem_fun(
314                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
315    
316        toggle_action =
317            Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
318        toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
319        actionGroup->add(toggle_action,
320                         sigc::mem_fun(
321                             *this, &MainWindow::on_auto_restore_win_dim));
322    
323        toggle_action =
324            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
325        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
326        actionGroup->add(toggle_action,
327                         sigc::mem_fun(
328                             *this, &MainWindow::on_save_with_temporary_file));
329    
330      actionGroup->add(      actionGroup->add(
331          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
332          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
# Line 206  MainWindow::MainWindow() : Line 347  MainWindow::MainWindow() :
347          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
348      );      );
349      actionGroup->add(      actionGroup->add(
350            Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
351            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
352            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
353        );
354        actionGroup->add(
355          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
356          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
357      );      );
# Line 324  MainWindow::MainWindow() : Line 470  MainWindow::MainWindow() :
470          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
471          "    </menu>"          "    </menu>"
472          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
473            "      <menuitem action='CopyDimRgn'/>"
474            "      <menuitem action='AdjustClipboard'/>"
475            "      <menuitem action='PasteDimRgn'/>"
476            "      <separator/>"
477            "      <menuitem action='SelectPrevRegion'/>"
478            "      <menuitem action='SelectNextRegion'/>"
479            "      <separator/>"
480            "      <menuitem action='SelectPrevDimension'/>"
481            "      <menuitem action='SelectNextDimension'/>"
482            "      <menuitem action='SelectPrevDimRgnZone'/>"
483            "      <menuitem action='SelectNextDimRgnZone'/>"
484            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
485            "      <menuitem action='SelectAddNextDimRgnZone'/>"
486            "      <separator/>"
487          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
488          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
489          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
490          "    </menu>"          "    </menu>"
491            "    <menu action='MenuMacro'>"
492            "    </menu>"
493          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
494          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
495          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 348  MainWindow::MainWindow() : Line 510  MainWindow::MainWindow() :
510          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
511          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
512          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
513            "      <menuitem action='CombInstruments'/>"
514          "      <separator/>"          "      <separator/>"
515          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
516          "    </menu>"          "    </menu>"
# Line 360  MainWindow::MainWindow() : Line 523  MainWindow::MainWindow() :
523          "    </menu>"          "    </menu>"
524          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
525          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
526            "      <menuitem action='AutoRestoreWinDim'/>"
527          "      <separator/>"          "      <separator/>"
528          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
529          "    </menu>"          "    </menu>"
# Line 371  MainWindow::MainWindow() : Line 535  MainWindow::MainWindow() :
535          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
536          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
537          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
538            "      <menuitem action='SaveWithTemporaryFile'/>"
539          "    </menu>"          "    </menu>"
540          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
541          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 382  MainWindow::MainWindow() : Line 547  MainWindow::MainWindow() :
547          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
548          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
549          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
550            "    <menuitem action='CombInstruments'/>"
551          "    <separator/>"          "    <separator/>"
552          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
553          "  </popup>"          "  </popup>"
# Line 458  MainWindow::MainWindow() : Line 624  MainWindow::MainWindow() :
624      }      }
625      {      {
626          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
627                uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
628            item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
629        }
630        {
631            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
632              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
633          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."));
634      }      }
# Line 495  MainWindow::MainWindow() : Line 666  MainWindow::MainWindow() :
666      // Create the Tree model:      // Create the Tree model:
667      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
668      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
669        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
670      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."));
671      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
672          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
673      );      );
674    
675      // Add the TreeView's view columns:      // Add the TreeView's view columns:
676      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
677      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
678        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
679        m_TreeView.set_headers_visible(true);
680            
681      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
682      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 525  MainWindow::MainWindow() : Line 699  MainWindow::MainWindow() :
699      // create samples treeview (including its data model)      // create samples treeview (including its data model)
700      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
701      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
702        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
703      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."));
704      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
705      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 676  MainWindow::MainWindow() : Line 851  MainWindow::MainWindow() :
851    
852      // select 'Instruments' tab by default      // select 'Instruments' tab by default
853      // (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)
854      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
855    
856        Gtk::Clipboard::get()->signal_owner_change().connect(
857            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
858        );
859        updateClipboardPasteAvailable();
860        updateClipboardCopyAvailable();
861    
862        // setup macros and their keyboard accelerators
863        {
864            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
865                uiManager->get_widget("/MenuBar/MenuMacro")
866            )->get_submenu();
867    
868            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
869            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
870            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
871            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
872            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
873            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
874            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
875            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
876            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
877            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
878            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
879            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
880            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
881            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
882    
883            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
884            menuMacro->set_accel_group(accelGroup);
885    
886            updateMacroMenu();
887        }
888    
889        Glib::signal_idle().connect_once(
890            sigc::mem_fun(*this, &MainWindow::bringToFront),
891            200
892        );
893  }  }
894    
895  MainWindow::~MainWindow()  MainWindow::~MainWindow()
896  {  {
897  }  }
898    
899    void MainWindow::bringToFront() {
900        #if defined(__APPLE__)
901        macRaiseAppWindow();
902        #endif
903        raise();
904        present();
905    }
906    
907    void MainWindow::updateMacroMenu() {
908        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
909            uiManager->get_widget("/MenuBar/MenuMacro")
910        )->get_submenu();
911    
912        // remove all entries from "Macro" menu
913        {
914            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
915            for (int i = 0; i < children.size(); ++i) {
916                Gtk::Widget* child = children[i];
917                menuMacro->remove(*child);
918                delete child;
919            }
920        }
921    
922        // (re)load all macros from config file
923        try {
924            Settings::singleton()->loadMacros(m_macros);
925        } catch (Serialization::Exception e) {
926            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
927        } catch (...) {
928            std::cerr << "Unknown exception while loading macros!" << std::endl;
929        }
930    
931        // add all configured macros as menu items to the "Macro" menu
932        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
933            const Serialization::Archive& macro = m_macros[iMacro];
934            std::string name =
935                macro.name().empty() ?
936                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
937            Gtk::MenuItem* item = new Gtk::MenuItem(name);
938            item->signal_activate().connect(
939                sigc::bind(
940                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
941                )
942            );
943            menuMacro->append(*item);
944            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
945            Glib::ustring comment = macro.comment();
946            if (!comment.empty())
947                item->set_tooltip_text(comment);
948        }
949        // if there are no macros configured at all, then show a dummy entry instead
950        if (m_macros.empty()) {
951            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
952            item->set_sensitive(false);
953            menuMacro->append(*item);
954        }
955    
956        // add separator line to menu
957        menuMacro->append(*new Gtk::SeparatorMenuItem);
958    
959        {
960            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
961            item->signal_activate().connect(
962                sigc::mem_fun(*this, &MainWindow::setupMacros)
963            );
964            menuMacro->append(*item);
965            item->set_accel_path("<Macros>/SetupMacros");
966        }
967    
968        menuMacro->show_all_children();
969    }
970    
971    void MainWindow::onMacroSelected(int iMacro) {
972        printf("onMacroSelected(%d)\n", iMacro);
973        if (iMacro < 0 || iMacro >= m_macros.size()) return;
974        Glib::ustring errorText;
975        try {
976            applyMacro(m_macros[iMacro]);
977        } catch (Serialization::Exception e) {
978            errorText = e.Message;
979        } catch (...) {
980            errorText = _("Unknown exception while applying macro");
981        }
982        if (!errorText.empty()) {
983            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
984            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
985            msg.run();
986        }
987    }
988    
989    void MainWindow::setupMacros() {
990        MacrosSetup* setup = new MacrosSetup();
991        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
992        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
993        setup->signal_macros_changed().connect(
994            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
995        );
996        setup->show();
997    }
998    
999    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1000        m_macros = macros;
1001        Settings::singleton()->saveMacros(m_macros);
1002        updateMacroMenu();
1003    }
1004    
1005  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1006  {  {
1007      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 1021  void MainWindow::region_changed()
1021  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
1022  {  {
1023      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
1024      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1025          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
1026        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1027      if (it) {      if (it) {
1028          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1029          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 746  void MainWindow::update_dimregs() Line 1066  void MainWindow::update_dimregs()
1066              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1067          }          }
1068      }      }
1069    
1070        m_RegionChooser.setModifyAllRegions(all_regions);
1071        m_DimRegionChooser.setModifyAllRegions(all_regions);
1072        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1073        m_DimRegionChooser.setModifyBothChannels(stereo);
1074    
1075        updateClipboardCopyAvailable();
1076  }  }
1077    
1078  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 763  void MainWindow::dimreg_changed() Line 1090  void MainWindow::dimreg_changed()
1090  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1091  {  {
1092      // select item in instrument menu      // select item in instrument menu
1093      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1094      if (it) {      if (!rows.empty()) {
1095          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1096          int index = path[0];          if (it) {
1097          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1098              instrument_menu->get_children();              int index = path[0];
1099          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1100                    instrument_menu->get_children();
1101                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1102            }
1103      }      }
1104    
1105      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 794  void Loader::progress_callback(float fra Line 1124  void Loader::progress_callback(float fra
1124      progress_dispatcher();      progress_dispatcher();
1125  }  }
1126    
1127    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1128    // make sure stack is 16-byte aligned for SSE instructions
1129    __attribute__((force_align_arg_pointer))
1130    #endif
1131  void Loader::thread_function()  void Loader::thread_function()
1132  {  {
1133      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1134               static_cast<void*>(Glib::Threads::Thread::self()));
1135      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1136      try {      try {
1137          RIFF::File* riff = new RIFF::File(filename);          RIFF::File* riff = new RIFF::File(filename);
# Line 818  void Loader::thread_function() Line 1153  void Loader::thread_function()
1153  }  }
1154    
1155  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
1156      : filename(filename), thread(0), progress(0.f)      : filename(filename), gig(0), thread(0), progress(0.f)
1157  {  {
1158  }  }
1159    
# Line 829  void Loader::launch() Line 1164  void Loader::launch()
1164  #else  #else
1165      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1166  #endif  #endif
1167      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1168  }  }
1169    
1170  float Loader::get_progress()  float Loader::get_progress()
# Line 872  void Saver::progress_callback(float frac Line 1207  void Saver::progress_callback(float frac
1207      progress_dispatcher.emit();      progress_dispatcher.emit();
1208  }  }
1209    
1210    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1211    // make sure stack is 16-byte aligned for SSE instructions
1212    __attribute__((force_align_arg_pointer))
1213    #endif
1214  void Saver::thread_function()  void Saver::thread_function()
1215  {  {
1216      printf("thread_function self=%x\n", Glib::Threads::Thread::self());      printf("thread_function self=%p\n",
1217               static_cast<void*>(Glib::Threads::Thread::self()));
1218      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1219      try {      try {
1220          gig::progress_t progress;          gig::progress_t progress;
# Line 883  void Saver::thread_function() Line 1223  void Saver::thread_function()
1223    
1224          // 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"
1225          if (filename.empty()) {          if (filename.empty()) {
1226              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1227                    // save directly over the existing .gig file
1228                    // (requires less disk space than solution below
1229                    // but may be slower)
1230                    gig->Save(&progress);
1231                } else {
1232                    // save the file as separate temporary file first,
1233                    // then move the saved file over the old file
1234                    // (may result in performance speedup during save)
1235                    gig::String tmpname = filename + ".TMP";
1236                    gig->Save(tmpname, &progress);
1237                    #if defined(WIN32)
1238                    if (!DeleteFile(filename.c_str())) {
1239                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1240                    }
1241                    #else // POSIX ...
1242                    if (unlink(filename.c_str())) {
1243                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1244                    }
1245                    #endif
1246                    if (rename(tmpname.c_str(), filename.c_str())) {
1247                        #if defined(WIN32)
1248                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1249                        #else
1250                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1251                        #endif
1252                    }
1253                }
1254          } else {          } else {
1255              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1256          }          }
# Line 911  void Saver::launch() Line 1278  void Saver::launch()
1278  #else  #else
1279      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
1280  #endif  #endif
1281      printf("launch thread=%x\n", thread);      printf("launch thread=%p\n", static_cast<void*>(thread));
1282  }  }
1283    
1284  float Saver::get_progress()  float Saver::get_progress()
# Line 1071  void MainWindow::on_action_file_open() Line 1438  void MainWindow::on_action_file_open()
1438      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1439          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
1440          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
1441          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());          printf("on_action_file_open self=%p\n",
1442                   static_cast<void*>(Glib::Threads::Thread::self()));
1443          load_file(filename.c_str());          load_file(filename.c_str());
1444          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
1445      }      }
# Line 1141  void MainWindow::on_loader_progress() Line 1509  void MainWindow::on_loader_progress()
1509  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
1510  {  {
1511      printf("Loader finished!\n");      printf("Loader finished!\n");
1512      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());      printf("on_loader_finished self=%p\n",
1513               static_cast<void*>(Glib::Threads::Thread::self()));
1514      load_gig(loader->gig, loader->filename.c_str());      load_gig(loader->gig, loader->filename.c_str());
1515      progress_dialog->hide();      progress_dialog->hide();
1516  }  }
# Line 1281  bool MainWindow::file_save_as() Line 1650  bool MainWindow::file_save_as()
1650      // show warning in the dialog      // show warning in the dialog
1651      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
1652      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
1653      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
1654        warningIcon.set_from_icon_name("dialog-warning",
1655                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
1656      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
1657  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
1658      view::WrapLabel description;      view::WrapLabel description;
# Line 1333  bool MainWindow::file_save_as() Line 1704  bool MainWindow::file_save_as()
1704  void MainWindow::__import_queued_samples() {  void MainWindow::__import_queued_samples() {
1705      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1706      Glib::ustring error_files;      Glib::ustring error_files;
1707      printf("Samples to import: %d\n", m_SampleImportQueue.size());      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1708      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1709           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1710          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1711          SF_INFO info;          SF_INFO info;
1712          info.format = 0;          info.format = 0;
1713          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);
1714          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1715          try {          try {
1716              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 1733  void MainWindow::__import_queued_samples
1733                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1734              }              }
1735    
1736                // reset write position for sample
1737                iter->first->SetPos(0);
1738    
1739              const int bufsize = 10000;              const int bufsize = 10000;
1740              switch (bitdepth) {              switch (bitdepth) {
1741                  case 16: {                  case 16: {
# Line 1371  void MainWindow::__import_queued_samples Line 1745  void MainWindow::__import_queued_samples
1745                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1746                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1747                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1748                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1749                          cnt -= n;                          cnt -= n;
1750                      }                      }
1751                      delete[] buffer;                      delete[] buffer;
# Line 1391  void MainWindow::__import_queued_samples Line 1765  void MainWindow::__import_queued_samples
1765                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1766                          }                          }
1767                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1768                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1769                          cnt -= n;                          cnt -= n;
1770                      }                      }
1771                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1402  void MainWindow::__import_queued_samples Line 1776  void MainWindow::__import_queued_samples
1776              // cleanup              // cleanup
1777              sf_close(hFile);              sf_close(hFile);
1778              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1779              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1780              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1781              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1782              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1783              ++iter;              ++iter;
1784              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1785          } catch (std::string what) {          } catch (std::string what) {
1786              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1787              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1788              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1789              ++iter;              ++iter;
1790          }          }
1791      }      }
# Line 1453  void MainWindow::on_action_help_about() Line 1827  void MainWindow::on_action_help_about()
1827      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1828  #endif  #endif
1829      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1830      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1831      const std::string sComment =      const std::string sComment =
1832          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1833          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1469  void MainWindow::on_action_help_about() Line 1843  void MainWindow::on_action_help_about()
1843      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1844      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1845      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1846        dialog.set_position(Gtk::WIN_POS_CENTER);
1847      dialog.run();      dialog.run();
1848  }  }
1849    
# Line 1494  PropDialog::PropDialog() Line 1869  PropDialog::PropDialog()
1869        table(2, 1),        table(2, 1),
1870        m_file(NULL)        m_file(NULL)
1871  {  {
1872        if (!Settings::singleton()->autoRestoreWindowDimension) {
1873            set_default_size(470, 390);
1874            set_position(Gtk::WIN_POS_MOUSE);
1875        }
1876    
1877      set_title(_("File Properties"));      set_title(_("File Properties"));
1878      eName.set_width_chars(50);      eName.set_width_chars(50);
1879    
# Line 1628  InstrumentProps::InstrumentProps() : Line 2008  InstrumentProps::InstrumentProps() :
2008      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2009      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2010  {  {
2011        if (!Settings::singleton()->autoRestoreWindowDimension) {
2012            //set_default_size(470, 390);
2013            set_position(Gtk::WIN_POS_MOUSE);
2014        }
2015    
2016      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2017    
2018      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1748  void MainWindow::load_gig(gig::File* gig Line 2133  void MainWindow::load_gig(gig::File* gig
2133      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2134    
2135      instrument_name_connection.block();      instrument_name_connection.block();
2136        int index = 0;
2137      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2138           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2139          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2140            const int iScriptSlots = instrument->ScriptSlotCount();
2141    
2142          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2143          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2144            row[m_Columns.m_col_nr] = index;
2145          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2146          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2147            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2148    
2149          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2150      }      }
# Line 1826  bool MainWindow::instr_props_set_instrum Line 2215  bool MainWindow::instr_props_set_instrum
2215  {  {
2216      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2217    
2218      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2219          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2220            instrumentProps.hide();
2221            return false;
2222        }
2223        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2224      if (it) {      if (it) {
2225          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2226          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 2273  void MainWindow::show_midi_rules()
2273  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2274      if (!file) return;      if (!file) return;
2275      // get selected instrument      // get selected instrument
2276      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2277      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2278        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2279      if (!it) return;      if (!it) return;
2280      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2281      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 2283  void MainWindow::show_script_slots() {
2283    
2284      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2285      window->setInstrument(instrument);      window->setInstrument(instrument);
2286        window->signal_script_slots_changed().connect(
2287            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2288        );
2289      //window->reparent(*this);      //window->reparent(*this);
2290      window->show();      window->show();
2291  }  }
2292    
2293    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2294        if (!pInstrument) return;
2295        const int iScriptSlots = pInstrument->ScriptSlotCount();
2296    
2297        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2298        for (int i = 0; i < model->children().size(); ++i) {
2299            Gtk::TreeModel::Row row = model->children()[i];
2300            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2301            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2302            break;
2303        }
2304    }
2305    
2306  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2307      __refreshEntireGUI();      __refreshEntireGUI();
2308  }  }
# Line 1908  void MainWindow::on_action_view_status_b Line 2318  void MainWindow::on_action_view_status_b
2318      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
2319  }  }
2320    
2321    void MainWindow::on_auto_restore_win_dim() {
2322        Gtk::CheckMenuItem* item =
2323            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
2324        if (!item) {
2325            std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
2326            return;
2327        }
2328        Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2329    }
2330    
2331    void MainWindow::on_save_with_temporary_file() {
2332        Gtk::CheckMenuItem* item =
2333            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2334        if (!item) {
2335            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2336            return;
2337        }
2338        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2339    }
2340    
2341  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2342      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2343          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 1981  void MainWindow::select_instrument(gig:: Line 2411  void MainWindow::select_instrument(gig::
2411          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2412              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2413              show_intruments_tab();              show_intruments_tab();
2414                m_TreeView.get_selection()->unselect_all();
2415              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2416              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2417                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2418              );              if (!rows.empty())
2419              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2420              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2421          }          }
2422      }      }
# Line 2002  bool MainWindow::select_dimension_region Line 2433  bool MainWindow::select_dimension_region
2433          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2434              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2435              show_intruments_tab();              show_intruments_tab();
2436                m_TreeView.get_selection()->unselect_all();
2437              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2438              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2439                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2440              );              if (!rows.empty())
2441              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2442              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2443    
2444              // select respective region in the region selector              // select respective region in the region selector
# Line 2032  void MainWindow::select_sample(gig::Samp Line 2464  void MainWindow::select_sample(gig::Samp
2464              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2465              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2466                  show_samples_tab();                  show_samples_tab();
2467                    m_TreeViewSamples.get_selection()->unselect_all();
2468                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2469                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2470                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2471                  );                  if (rows.empty()) return;
2472                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2473                  return;                  return;
2474              }              }
2475          }          }
# Line 2045  void MainWindow::select_sample(gig::Samp Line 2478  void MainWindow::select_sample(gig::Samp
2478    
2479  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2480      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2481            // by default if Ctrl keys is pressed down, then a mouse right-click
2482            // does not select the respective row, so we must assure this
2483            // programmatically ...
2484            /*{
2485                Gtk::TreeModel::Path path;
2486                Gtk::TreeViewColumn* pColumn = NULL;
2487                int cellX, cellY;
2488                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2489                    (int)button->x, (int)button->y,
2490                    path, pColumn, cellX, cellY
2491                );
2492                if (bSuccess) {
2493                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2494                        printf("not selected !!!\n");
2495                        m_TreeViewSamples.get_selection()->select(path);
2496                    }
2497                }
2498            }*/
2499    
2500          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2501              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2502          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2503          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2504          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2505          bool group_selected  = false;          const int n = rows.size();
2506          bool sample_selected = false;          int nGroups  = 0;
2507          if (it) {          int nSamples = 0;
2508            for (int r = 0; r < n; ++r) {
2509                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2510                if (!it) continue;
2511              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2512              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2513              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2514          }          }
2515            
               
2516          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2517              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2518          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2519              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2520          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2521              set_sensitive(file);              set_sensitive(file);
2522          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2523              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2524          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2525              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2526          // show sample popup          // show sample popup
2527          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2528    
2529          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2530              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2531          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2532              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2533          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2534              set_sensitive(file);              set_sensitive(file);
2535          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2536              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2537          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2538              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2539      }      }
2540  }  }
2541    
# Line 2160  void MainWindow::add_instrument(gig::Ins Line 2614  void MainWindow::add_instrument(gig::Ins
2614      instrument_name_connection.block();      instrument_name_connection.block();
2615      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2616      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2617        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2618      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2619      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2620        rowInstr[m_Columns.m_col_scripts] = "";
2621      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2622    
2623      add_instrument_to_menu(name);      add_instrument_to_menu(name);
2624    
2625      m_TreeView.get_selection()->select(iterInstr);      m_TreeView.get_selection()->select(iterInstr);
2626        m_TreeView.scroll_to_row(Gtk::TreePath(iterInstr));
2627    
2628      file_changed();      file_changed();
2629  }  }
# Line 2188  void MainWindow::on_action_duplicate_ins Line 2645  void MainWindow::on_action_duplicate_ins
2645      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2646      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2647      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2648      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2649      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2650      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2651      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2652      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2653                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2654      // duplicate the orginal instrument              if (instrOrig) {
2655      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2656      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2657          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2658          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2659                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2660    
2661      add_instrument(instrNew);                  add_instrument(instrNew);
2662                }
2663            }
2664        }
2665  }  }
2666    
2667  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2217  void MainWindow::on_action_remove_instru Line 2678  void MainWindow::on_action_remove_instru
2678      }      }
2679    
2680      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2681      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2682      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2683            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2684            if (!it) continue;
2685          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2686          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2687          try {          try {
# Line 2233  void MainWindow::on_action_remove_instru Line 2696  void MainWindow::on_action_remove_instru
2696    
2697              // remove row from instruments tree view              // remove row from instruments tree view
2698              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2699                // update "Nr" column of all instrument rows
2700                {
2701                    int index = 0;
2702                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2703                         it != m_refTreeModel->children().end(); ++it, ++index)
2704                    {
2705                        Gtk::TreeModel::Row row = *it;
2706                        row[m_Columns.m_col_nr] = index;
2707                    }
2708                }
2709    
2710  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2711              // 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 2803  void MainWindow::on_action_edit_script()
2803      if (!script) return;      if (!script) return;
2804    
2805      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
2806        editor->signal_script_to_be_changed.connect(
2807            signal_script_to_be_changed.make_slot()
2808        );
2809        editor->signal_script_changed.connect(
2810            signal_script_changed.make_slot()
2811        );
2812      editor->setScript(script);      editor->setScript(script);
2813      //editor->reparent(*this);      //editor->reparent(*this);
2814      editor->show();      editor->show();
# Line 2408  void MainWindow::add_or_replace_sample(b Line 2887  void MainWindow::add_or_replace_sample(b
2887    
2888      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2889      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2890      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2891        if (rows.empty()) return;
2892        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2893      if (!it) return;      if (!it) return;
2894      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2895      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2557  void MainWindow::add_or_replace_sample(b Line 3038  void MainWindow::add_or_replace_sample(b
3038                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3039                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3040                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3041                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3042                  // add sample to the tree view                  // add sample to the tree view
3043                  if (replace) {                  if (replace) {
3044                      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 3132  void MainWindow::on_action_replace_all_s
3132              try              try
3133              {              {
3134                  if (!hFile) throw std::string(_("could not open file"));                  if (!hFile) throw std::string(_("could not open file"));
                 int bitdepth;  
3135                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
3136                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
3137                      case SF_FORMAT_PCM_16:                      case SF_FORMAT_PCM_16:
3138                      case SF_FORMAT_PCM_U8:                      case SF_FORMAT_PCM_U8:
                         bitdepth = 16;  
                         break;  
3139                      case SF_FORMAT_PCM_24:                      case SF_FORMAT_PCM_24:
3140                      case SF_FORMAT_PCM_32:                      case SF_FORMAT_PCM_32:
3141                      case SF_FORMAT_FLOAT:                      case SF_FORMAT_FLOAT:
3142                      case SF_FORMAT_DOUBLE:                      case SF_FORMAT_DOUBLE:
                         bitdepth = 24;  
3143                          break;                          break;
3144                      default:                      default:
3145                          sf_close(hFile);                          sf_close(hFile);
# Line 2671  void MainWindow::on_action_replace_all_s Line 3148  void MainWindow::on_action_replace_all_s
3148                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3149                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3150                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3151                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3152                  sf_close(hFile);                  sf_close(hFile);
3153                  file_changed();                  file_changed();
3154              }              }
# Line 2695  void MainWindow::on_action_replace_all_s Line 3172  void MainWindow::on_action_replace_all_s
3172  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
3173      if (!file) return;      if (!file) return;
3174      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3175      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3176      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3177            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3178            if (!it) continue;
3179          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3180          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
3181          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 3200  void MainWindow::on_action_remove_sample
3200                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3201                  // them from the import queue                  // them from the import queue
3202                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3203                       member != members.end(); ++member) {                       member != members.end(); ++member)
3204                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3205                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3206                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3207                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3208                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3209                      }                      }
3210                  }                  }
3211                  file_changed();                  file_changed();
# Line 2744  void MainWindow::on_action_remove_sample Line 3220  void MainWindow::on_action_remove_sample
3220                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3221                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3222                  // the import queue                  // the import queue
3223                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3224                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3225                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3226                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3227                  }                  }
3228                  dimreg_changed();                  dimreg_changed();
3229                  file_changed();                  file_changed();
# Line 2807  void MainWindow::on_action_remove_unused Line 3279  void MainWindow::on_action_remove_unused
3279              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3280              // remove sample from the .gig file              // remove sample from the .gig file
3281              file->DeleteSample(sample);              file->DeleteSample(sample);
3282              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3283              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3284                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3285              {                         m_SampleImportQueue[sample].sample_path.c_str());
3286                  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;  
                 }  
3287              }              }
3288          }          }
3289      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2875  void MainWindow::on_instruments_treeview Line 3342  void MainWindow::on_instruments_treeview
3342      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3343      {      {
3344          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3345          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3346          if (it) {          if (!rows.empty()) {
3347              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3348              src = row[m_Columns.m_col_instr];              if (it) {
3349                    Gtk::TreeModel::Row row = *it;
3350                    src = row[m_Columns.m_col_instr];
3351                }
3352          }          }
3353      }      }
3354      if (!src) return;      if (!src) return;
# Line 2933  void MainWindow::on_sample_treeview_drag Line 3403  void MainWindow::on_sample_treeview_drag
3403      // get selected sample      // get selected sample
3404      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3405      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3406      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3407      if (it) {      if (!rows.empty()) {
3408          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3409          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3410                Gtk::TreeModel::Row row = *it;
3411                sample = row[m_SamplesModel.m_col_sample];
3412            }
3413      }      }
3414      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3415      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 3549  void MainWindow::script_double_clicked(c
3549      if (!script) return;      if (!script) return;
3550    
3551      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
3552        editor->signal_script_to_be_changed.connect(
3553            signal_script_to_be_changed.make_slot()
3554        );
3555        editor->signal_script_changed.connect(
3556            signal_script_changed.make_slot()
3557        );
3558      editor->setScript(script);      editor->setScript(script);
3559      //editor->reparent(*this);      //editor->reparent(*this);
3560      editor->show();      editor->show();
# Line 3117  void MainWindow::instrument_name_changed Line 3596  void MainWindow::instrument_name_changed
3596    
3597  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3598      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3599    
3600        // take over selection from instruments list view for the combine dialog's
3601        // list view as pre-selection
3602        std::set<int> indeces;
3603        {
3604            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3605            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3606            for (int r = 0; r < rows.size(); ++r) {
3607                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3608                if (it) {
3609                    Gtk::TreeModel::Row row = *it;
3610                    int index = row[m_Columns.m_col_nr];
3611                    indeces.insert(index);
3612                }
3613            }
3614        }
3615        d->setSelectedInstruments(indeces);
3616    
3617      d->show_all();      d->show_all();
     d->resize(500, 400);  
3618      d->run();      d->run();
3619      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3620          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3129  void MainWindow::on_action_combine_instr Line 3625  void MainWindow::on_action_combine_instr
3625    
3626  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3627      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3628      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3629        if (rows.empty()) return;
3630        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3631      if (!it) return;      if (!it) return;
3632      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3633      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 3768  void MainWindow::on_action_merge_files()
3768      // show warning in the file picker dialog      // show warning in the file picker dialog
3769      Gtk::HBox descriptionArea;      Gtk::HBox descriptionArea;
3770      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
3771      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon;
3772        warningIcon.set_from_icon_name("dialog-warning",
3773                                       Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
3774      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
3775  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
3776      view::WrapLabel description;      view::WrapLabel description;
# Line 3293  void MainWindow::on_action_merge_files() Line 3793  void MainWindow::on_action_merge_files()
3793      descriptionArea.show_all();      descriptionArea.show_all();
3794    
3795      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
3796          printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());          printf("on_action_merge_files self=%p\n",
3797                   static_cast<void*>(Glib::Threads::Thread::self()));
3798          std::vector<std::string> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
3799    
3800          // 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 3876  void MainWindow::show_scripts_tab() {
3876      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3877  }  }
3878    
3879    void MainWindow::select_prev_region() {
3880        m_RegionChooser.select_prev_region();
3881    }
3882    
3883    void MainWindow::select_next_region() {
3884        m_RegionChooser.select_next_region();
3885    }
3886    
3887    void MainWindow::select_next_dim_rgn_zone() {
3888        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3889        m_DimRegionChooser.select_next_dimzone();
3890    }
3891    
3892    void MainWindow::select_prev_dim_rgn_zone() {
3893        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3894        m_DimRegionChooser.select_prev_dimzone();
3895    }
3896    
3897    void MainWindow::select_add_next_dim_rgn_zone() {
3898        m_DimRegionChooser.select_next_dimzone(true);
3899    }
3900    
3901    void MainWindow::select_add_prev_dim_rgn_zone() {
3902        m_DimRegionChooser.select_prev_dimzone(true);
3903    }
3904    
3905    void MainWindow::select_prev_dimension() {
3906        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3907        m_DimRegionChooser.select_prev_dimension();
3908    }
3909    
3910    void MainWindow::select_next_dimension() {
3911        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3912        m_DimRegionChooser.select_next_dimension();
3913    }
3914    
3915    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3916        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3917    
3918    void MainWindow::copy_selected_dimrgn() {
3919        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3920        if (!pDimRgn) {
3921            updateClipboardPasteAvailable();
3922            updateClipboardCopyAvailable();
3923            return;
3924        }
3925    
3926        std::vector<Gtk::TargetEntry> targets;
3927        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3928    
3929        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3930        clipboard->set(
3931            targets,
3932            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3933            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3934        );
3935    
3936        m_serializationArchive.serialize(pDimRgn);
3937    
3938        updateClipboardPasteAvailable();
3939    }
3940    
3941    void MainWindow::paste_copied_dimrgn() {
3942        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3943        clipboard->request_contents(
3944            CLIPBOARD_DIMENSIONREGION_TARGET,
3945            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3946        );
3947        updateClipboardPasteAvailable();
3948    }
3949    
3950    void MainWindow::adjust_clipboard_content() {
3951        MacroEditor* editor = new MacroEditor();
3952        editor->setMacro(&m_serializationArchive, true);
3953        editor->show();
3954    }
3955    
3956    void MainWindow::updateClipboardPasteAvailable() {
3957        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3958        clipboard->request_targets(
3959            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3960        );
3961    }
3962    
3963    void MainWindow::updateClipboardCopyAvailable() {
3964        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3965        static_cast<Gtk::MenuItem*>(
3966            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3967        )->set_sensitive(bDimensionRegionCopyIsPossible);
3968    }
3969    
3970    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3971        updateClipboardPasteAvailable();
3972    }
3973    
3974    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3975        const std::string target = selection_data.get_target();
3976        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3977            selection_data.set(
3978                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3979                &m_serializationArchive.rawData()[0],
3980                m_serializationArchive.rawData().size()
3981            );
3982        } else {
3983            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3984        }
3985    }
3986    
3987    void MainWindow::on_clipboard_clear() {
3988        m_serializationArchive.clear();
3989        updateClipboardPasteAvailable();
3990        updateClipboardCopyAvailable();
3991    }
3992    
3993    //NOTE: Might throw exception !!!
3994    void MainWindow::applyMacro(Serialization::Archive& macro) {
3995        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3996        if (!pDimRgn) return;
3997    
3998        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3999             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
4000        {
4001            gig::DimensionRegion* pDimRgn = *itDimReg;
4002            DimRegionChangeGuard(this, pDimRgn);
4003            macro.deserialize(pDimRgn);
4004        }
4005        //region_changed()
4006        file_changed();
4007        dimreg_changed();
4008    }
4009    
4010    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
4011        const std::string target = selection_data.get_target();
4012        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4013            Glib::ustring errorText;
4014            try {
4015                m_serializationArchive.decode(
4016                    selection_data.get_data(), selection_data.get_length()
4017                );
4018                applyMacro(m_serializationArchive);
4019            } catch (Serialization::Exception e) {
4020                errorText = e.Message;
4021            } catch (...) {
4022                errorText = _("Unknown exception while pasting DimensionRegion");
4023            }
4024            if (!errorText.empty()) {
4025                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
4026                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4027                msg.run();
4028            }
4029        }
4030    }
4031    
4032    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
4033        const bool bDimensionRegionPasteIsPossible =
4034            std::find(targets.begin(), targets.end(),
4035                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
4036    
4037        static_cast<Gtk::MenuItem*>(
4038            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4039        )->set_sensitive(bDimensionRegionPasteIsPossible);
4040    
4041        static_cast<Gtk::MenuItem*>(
4042            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4043        )->set_sensitive(bDimensionRegionPasteIsPossible);
4044    }
4045    
4046  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4047      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4048  }  }

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

  ViewVC Help
Powered by ViewVC