/[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 2918 by schoenebeck, Wed May 18 10:10:25 2016 UTC revision 3157 by schoenebeck, Mon May 8 17:30:10 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2016 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 38  Line 38 
38  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
39  #include <gtkmm/main.h>  #include <gtkmm/main.h>
40  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
41    #include <gtkmm/accelmap.h>
42  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
43  #include "wrapLabel.hh"  #include "wrapLabel.hh"
44  #endif  #endif
# Line 57  Line 58 
58  #include "ReferencesView.h"  #include "ReferencesView.h"
59  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
60  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
61    #include "gfx/builtinpix.h"
62    #include "MacroEditor.h"
63    #include "MacrosSetup.h"
64    
65  MainWindow::MainWindow() :  MainWindow::MainWindow() :
66      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
67      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
68      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
69      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
70      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
71        labelLegend(_("Legend:")),
72        labelNoSample(_(" No Sample")),
73        labelMissingSample(_(" Missing some Sample(s)")),
74        labelLooped(_(" Looped")),
75        labelSomeLoops(_(" Some Loop(s)"))
76  {  {
77        loadBuiltInPix();
78    
79  //    set_border_width(5);  //    set_border_width(5);
80  //    set_default_size(400, 200);  //    set_default_size(400, 200);
81    
   
82      add(m_VBox);      add(m_VBox);
83    
84      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 112  MainWindow::MainWindow() :
112      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
113      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
114      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
115        {
116            legend_hbox.add(labelLegend);
117    
118            imageNoSample.set(redDot);
119            imageNoSample.set_alignment(Gtk::ALIGN_END);
120            labelNoSample.set_alignment(Gtk::ALIGN_START);
121            legend_hbox.add(imageNoSample);
122            legend_hbox.add(labelNoSample);
123    
124            imageMissingSample.set(yellowDot);
125            imageMissingSample.set_alignment(Gtk::ALIGN_END);
126            labelMissingSample.set_alignment(Gtk::ALIGN_START);
127            legend_hbox.add(imageMissingSample);
128            legend_hbox.add(labelMissingSample);
129    
130            imageLooped.set(blackLoop);
131            imageLooped.set_alignment(Gtk::ALIGN_END);
132            labelLooped.set_alignment(Gtk::ALIGN_START);
133            legend_hbox.add(imageLooped);
134            legend_hbox.add(labelLooped);
135    
136            imageSomeLoops.set(grayLoop);
137            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
138            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
139            legend_hbox.add(imageSomeLoops);
140            legend_hbox.add(labelSomeLoops);
141    
142            legend_hbox.show_all_children();
143        }
144        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
145      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
146    
147      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 162  MainWindow::MainWindow() : Line 201  MainWindow::MainWindow() :
201          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
202      );      );
203      actionGroup->add(      actionGroup->add(
204          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
205          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
206      );      );
207      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
208    
209      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
210    
211        const Gdk::ModifierType primaryModifierKey =
212    #if defined(__APPLE__)
213        Gdk::META_MASK; // Cmd key on Mac
214    #else
215        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
216    #endif
217    
218        actionGroup->add(Gtk::Action::create("CopyDimRgn",
219                                             _("Copy selected dimension region")),
220                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
221                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
222    
223        actionGroup->add(Gtk::Action::create("PasteDimRgn",
224                                             _("Paste dimension region")),
225                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
226                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
227    
228        actionGroup->add(Gtk::Action::create("AdjustClipboard",
229                                             _("Adjust Clipboard Content")),
230                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
231                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
232    
233        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
234                                             _("Select Previous Region")),
235                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
236                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
237    
238        actionGroup->add(Gtk::Action::create("SelectNextRegion",
239                                             _("Select Next Region")),
240                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
241                         sigc::mem_fun(*this, &MainWindow::select_next_region));
242    
243        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
244                                             _("Select Previous Dimension Region Zone")),
245                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
246                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
247    
248        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
249                                             _("Select Next Dimension Region Zone")),
250                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
251                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
252    
253        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
254                                             _("Select Previous Dimension")),
255                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
256                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
257    
258        actionGroup->add(Gtk::Action::create("SelectNextDimension",
259                                             _("Select Next Dimension")),
260                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
261                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
262    
263        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
264                                             _("Add Previous Dimension Region Zone to Selection")),
265                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
266                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
267    
268        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
269                                             _("Add Next Dimension Region Zone to Selection")),
270                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
271                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
272    
273      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
274          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
275      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 185  MainWindow::MainWindow() : Line 286  MainWindow::MainWindow() :
286      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
287    
288    
289      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
290    
291    
292        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
293      toggle_action =      toggle_action =
294          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
295      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 200  MainWindow::MainWindow() : Line 304  MainWindow::MainWindow() :
304                       sigc::mem_fun(                       sigc::mem_fun(
305                           *this, &MainWindow::on_auto_restore_win_dim));                           *this, &MainWindow::on_auto_restore_win_dim));
306    
307        toggle_action =
308            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
309        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
310        actionGroup->add(toggle_action,
311                         sigc::mem_fun(
312                             *this, &MainWindow::on_save_with_temporary_file));
313    
314      actionGroup->add(      actionGroup->add(
315          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
316          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
# Line 336  MainWindow::MainWindow() : Line 447  MainWindow::MainWindow() :
447          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
448          "    </menu>"          "    </menu>"
449          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
450            "      <menuitem action='CopyDimRgn'/>"
451            "      <menuitem action='AdjustClipboard'/>"
452            "      <menuitem action='PasteDimRgn'/>"
453            "      <separator/>"
454            "      <menuitem action='SelectPrevRegion'/>"
455            "      <menuitem action='SelectNextRegion'/>"
456            "      <separator/>"
457            "      <menuitem action='SelectPrevDimension'/>"
458            "      <menuitem action='SelectNextDimension'/>"
459            "      <menuitem action='SelectPrevDimRgnZone'/>"
460            "      <menuitem action='SelectNextDimRgnZone'/>"
461            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
462            "      <menuitem action='SelectAddNextDimRgnZone'/>"
463            "      <separator/>"
464          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
465          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
466          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
467          "    </menu>"          "    </menu>"
468            "    <menu action='MenuMacro'>"
469            "    </menu>"
470          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
471          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
472          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 384  MainWindow::MainWindow() : Line 511  MainWindow::MainWindow() :
511          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
512          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
513          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
514            "      <menuitem action='SaveWithTemporaryFile'/>"
515          "    </menu>"          "    </menu>"
516          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
517          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 513  MainWindow::MainWindow() : Line 641  MainWindow::MainWindow() :
641      // Create the Tree model:      // Create the Tree model:
642      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
643      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
644        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
645      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."));
646      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
647          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
648      );      );
649    
650      // Add the TreeView's view columns:      // Add the TreeView's view columns:
651      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
652      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
653        m_TreeView.set_headers_visible(true);
654            
655      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
656      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 543  MainWindow::MainWindow() : Line 673  MainWindow::MainWindow() :
673      // create samples treeview (including its data model)      // create samples treeview (including its data model)
674      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
675      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
676        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
677      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."));
678      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
679      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 694  MainWindow::MainWindow() : Line 825  MainWindow::MainWindow() :
825    
826      // select 'Instruments' tab by default      // select 'Instruments' tab by default
827      // (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)
828      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
829    
830        Gtk::Clipboard::get()->signal_owner_change().connect(
831            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
832        );
833        updateClipboardPasteAvailable();
834        updateClipboardCopyAvailable();
835    
836        // setup macros and their keyboard accelerators
837        {
838            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
839                uiManager->get_widget("/MenuBar/MenuMacro")
840            )->get_submenu();
841    
842            const Gdk::ModifierType primaryModifierKey =
843    #if defined(__APPLE__)
844                Gdk::META_MASK; // Cmd key on Mac
845    #else
846                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
847    #endif
848    
849            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
850            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
851            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
852            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
853            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
854            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
855            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
856            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
857            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
858            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
859            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
863    
864            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
865            menuMacro->set_accel_group(accelGroup);
866    
867            updateMacroMenu();
868        }
869  }  }
870    
871  MainWindow::~MainWindow()  MainWindow::~MainWindow()
872  {  {
873  }  }
874    
875    void MainWindow::updateMacroMenu() {
876        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
877            uiManager->get_widget("/MenuBar/MenuMacro")
878        )->get_submenu();
879    
880        // remove all entries from "Macro" menu
881        {
882            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
883            for (int i = 0; i < children.size(); ++i) {
884                Gtk::Widget* child = children[i];
885                menuMacro->remove(*child);
886                delete child;
887            }
888        }
889    
890        // (re)load all macros from config file
891        try {
892            Settings::singleton()->loadMacros(m_macros);
893        } catch (Serialization::Exception e) {
894            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
895        } catch (...) {
896            std::cerr << "Unknown exception while loading macros!" << std::endl;
897        }
898    
899        // add all configured macros as menu items to the "Macro" menu
900        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
901            const Serialization::Archive& macro = m_macros[iMacro];
902            std::string name =
903                macro.name().empty() ?
904                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
905            Gtk::MenuItem* item = new Gtk::MenuItem(name);
906            item->signal_activate().connect(
907                sigc::bind(
908                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
909                )
910            );
911            menuMacro->append(*item);
912            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
913        }
914        // if there are no macros configured at all, then show a dummy entry instead
915        if (m_macros.empty()) {
916            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
917            item->set_sensitive(false);
918            menuMacro->append(*item);
919        }
920    
921        // add separator line to menu
922        menuMacro->append(*new Gtk::SeparatorMenuItem);
923    
924        {
925            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
926            item->signal_activate().connect(
927                sigc::mem_fun(*this, &MainWindow::setupMacros)
928            );
929            menuMacro->append(*item);
930            item->set_accel_path("<Macros>/SetupMacros");
931        }
932    
933        menuMacro->show_all_children();
934    }
935    
936    void MainWindow::onMacroSelected(int iMacro) {
937        printf("onMacroSelected(%d)\n", iMacro);
938        if (iMacro < 0 || iMacro >= m_macros.size()) return;
939        Glib::ustring errorText;
940        try {
941            applyMacro(m_macros[iMacro]);
942        } catch (Serialization::Exception e) {
943            errorText = e.Message;
944        } catch (...) {
945            errorText = _("Unknown exception while applying macro");
946        }
947        if (!errorText.empty()) {
948            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
949            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
950            msg.run();
951        }
952    }
953    
954    void MainWindow::setupMacros() {
955        MacrosSetup* setup = new MacrosSetup();
956        setup->setMacros(m_macros);
957        setup->signal_macros_changed().connect(
958            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
959        );
960        setup->show();
961    }
962    
963    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
964        m_macros = macros;
965        Settings::singleton()->saveMacros(m_macros);
966        updateMacroMenu();
967    }
968    
969  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
970  {  {
971      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 720  void MainWindow::region_changed() Line 985  void MainWindow::region_changed()
985  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
986  {  {
987      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
988      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
989          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
990        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
991      if (it) {      if (it) {
992          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
993          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 764  void MainWindow::update_dimregs() Line 1030  void MainWindow::update_dimregs()
1030              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1031          }          }
1032      }      }
1033    
1034        m_RegionChooser.setModifyAllRegions(all_regions);
1035        m_DimRegionChooser.setModifyAllRegions(all_regions);
1036        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1037        m_DimRegionChooser.setModifyBothChannels(stereo);
1038    
1039        updateClipboardCopyAvailable();
1040  }  }
1041    
1042  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 781  void MainWindow::dimreg_changed() Line 1054  void MainWindow::dimreg_changed()
1054  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
1055  {  {
1056      // select item in instrument menu      // select item in instrument menu
1057      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1058      if (it) {      if (!rows.empty()) {
1059          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1060          int index = path[0];          if (it) {
1061          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
1062              instrument_menu->get_children();              int index = path[0];
1063          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
1064                    instrument_menu->get_children();
1065                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1066            }
1067      }      }
1068    
1069      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 812  void Loader::progress_callback(float fra Line 1088  void Loader::progress_callback(float fra
1088      progress_dispatcher();      progress_dispatcher();
1089  }  }
1090    
1091    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1092    // make sure stack is 16-byte aligned for SSE instructions
1093    __attribute__((force_align_arg_pointer))
1094    #endif
1095  void Loader::thread_function()  void Loader::thread_function()
1096  {  {
1097      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 891  void Saver::progress_callback(float frac Line 1171  void Saver::progress_callback(float frac
1171      progress_dispatcher.emit();      progress_dispatcher.emit();
1172  }  }
1173    
1174    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1175    // make sure stack is 16-byte aligned for SSE instructions
1176    __attribute__((force_align_arg_pointer))
1177    #endif
1178  void Saver::thread_function()  void Saver::thread_function()
1179  {  {
1180      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 903  void Saver::thread_function() Line 1187  void Saver::thread_function()
1187    
1188          // 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"
1189          if (filename.empty()) {          if (filename.empty()) {
1190              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
1191                    // save directly over the existing .gig file
1192                    // (requires less disk space than solution below
1193                    // but may be slower)
1194                    gig->Save(&progress);
1195                } else {
1196                    // save the file as separate temporary file first,
1197                    // then move the saved file over the old file
1198                    // (may result in performance speedup during save)
1199                    String tmpname = filename + ".TMP";
1200                    gig->Save(tmpname, &progress);
1201                    #if defined(WIN32)
1202                    if (!DeleteFile(filename.c_str())) {
1203                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
1204                    }
1205                    #else // POSIX ...
1206                    if (unlink(filename.c_str())) {
1207                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
1208                    }
1209                    #endif
1210                    if (rename(tmpname.c_str(), filename.c_str())) {
1211                        #if defined(WIN32)
1212                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1213                        #else
1214                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
1215                        #endif
1216                    }
1217                }
1218          } else {          } else {
1219              gig->Save(filename, &progress);              gig->Save(filename, &progress);
1220          }          }
# Line 1358  void MainWindow::__import_queued_samples Line 1669  void MainWindow::__import_queued_samples
1669      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1670      Glib::ustring error_files;      Glib::ustring error_files;
1671      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1672      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1673           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1674          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1675          SF_INFO info;          SF_INFO info;
1676          info.format = 0;          info.format = 0;
1677          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);
1678          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1679          try {          try {
1680              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1386  void MainWindow::__import_queued_samples Line 1697  void MainWindow::__import_queued_samples
1697                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1698              }              }
1699    
1700                // reset write position for sample
1701                iter->first->SetPos(0);
1702    
1703              const int bufsize = 10000;              const int bufsize = 10000;
1704              switch (bitdepth) {              switch (bitdepth) {
1705                  case 16: {                  case 16: {
# Line 1395  void MainWindow::__import_queued_samples Line 1709  void MainWindow::__import_queued_samples
1709                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1710                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1711                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1712                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1713                          cnt -= n;                          cnt -= n;
1714                      }                      }
1715                      delete[] buffer;                      delete[] buffer;
# Line 1415  void MainWindow::__import_queued_samples Line 1729  void MainWindow::__import_queued_samples
1729                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1730                          }                          }
1731                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1732                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1733                          cnt -= n;                          cnt -= n;
1734                      }                      }
1735                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1426  void MainWindow::__import_queued_samples Line 1740  void MainWindow::__import_queued_samples
1740              // cleanup              // cleanup
1741              sf_close(hFile);              sf_close(hFile);
1742              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1743              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1744              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1745              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1746              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1747              ++iter;              ++iter;
1748              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1749          } catch (std::string what) {          } catch (std::string what) {
1750              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1751              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1752              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1753              ++iter;              ++iter;
1754          }          }
1755      }      }
# Line 1477  void MainWindow::on_action_help_about() Line 1791  void MainWindow::on_action_help_about()
1791      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1792  #endif  #endif
1793      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1794      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1795      const std::string sComment =      const std::string sComment =
1796          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1797          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1772  void MainWindow::load_gig(gig::File* gig Line 2086  void MainWindow::load_gig(gig::File* gig
2086      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
2087    
2088      instrument_name_connection.block();      instrument_name_connection.block();
2089        int index = 0;
2090      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2091           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
2092          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2093    
2094          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2095          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2096            row[m_Columns.m_col_nr] = index;
2097          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2098          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2099    
# Line 1850  bool MainWindow::instr_props_set_instrum Line 2166  bool MainWindow::instr_props_set_instrum
2166  {  {
2167      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
2168    
2169      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2170          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
2171            instrumentProps.hide();
2172            return false;
2173        }
2174        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
2175      if (it) {      if (it) {
2176          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2177          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1904  void MainWindow::show_midi_rules() Line 2224  void MainWindow::show_midi_rules()
2224  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2225      if (!file) return;      if (!file) return;
2226      // get selected instrument      // get selected instrument
2227      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2228      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2229        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2230      if (!it) return;      if (!it) return;
2231      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2232      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1942  void MainWindow::on_auto_restore_win_dim Line 2263  void MainWindow::on_auto_restore_win_dim
2263      Settings::singleton()->autoRestoreWindowDimension = item->get_active();      Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2264  }  }
2265    
2266    void MainWindow::on_save_with_temporary_file() {
2267        Gtk::CheckMenuItem* item =
2268            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2269        if (!item) {
2270            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2271            return;
2272        }
2273        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2274    }
2275    
2276  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2277      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2278          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 2015  void MainWindow::select_instrument(gig:: Line 2346  void MainWindow::select_instrument(gig::
2346          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2347              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2348              show_intruments_tab();              show_intruments_tab();
2349                m_TreeView.get_selection()->unselect_all();
2350              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2351              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2352                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2353              );              if (!rows.empty())
2354              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2355              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2356          }          }
2357      }      }
# Line 2036  bool MainWindow::select_dimension_region Line 2368  bool MainWindow::select_dimension_region
2368          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2369              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2370              show_intruments_tab();              show_intruments_tab();
2371                m_TreeView.get_selection()->unselect_all();
2372              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2373              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2374                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2375              );              if (!rows.empty())
2376              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2377              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2378    
2379              // select respective region in the region selector              // select respective region in the region selector
# Line 2066  void MainWindow::select_sample(gig::Samp Line 2399  void MainWindow::select_sample(gig::Samp
2399              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2400              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2401                  show_samples_tab();                  show_samples_tab();
2402                    m_TreeViewSamples.get_selection()->unselect_all();
2403                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2404                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2405                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2406                  );                  if (rows.empty()) return;
2407                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2408                  return;                  return;
2409              }              }
2410          }          }
# Line 2079  void MainWindow::select_sample(gig::Samp Line 2413  void MainWindow::select_sample(gig::Samp
2413    
2414  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2415      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2416            // by default if Ctrl keys is pressed down, then a mouse right-click
2417            // does not select the respective row, so we must assure this
2418            // programmatically ...
2419            /*{
2420                Gtk::TreeModel::Path path;
2421                Gtk::TreeViewColumn* pColumn = NULL;
2422                int cellX, cellY;
2423                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2424                    (int)button->x, (int)button->y,
2425                    path, pColumn, cellX, cellY
2426                );
2427                if (bSuccess) {
2428                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2429                        printf("not selected !!!\n");
2430                        m_TreeViewSamples.get_selection()->select(path);
2431                    }
2432                }
2433            }*/
2434    
2435          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2436              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2437          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2438          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2439          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2440          bool group_selected  = false;          const int n = rows.size();
2441          bool sample_selected = false;          int nGroups  = 0;
2442          if (it) {          int nSamples = 0;
2443            for (int r = 0; r < n; ++r) {
2444                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2445                if (!it) continue;
2446              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2447              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2448              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2449          }          }
2450            
               
2451          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2452              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2453          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2454              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2455          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2456              set_sensitive(file);              set_sensitive(file);
2457          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2458              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2459          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2460              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2461          // show sample popup          // show sample popup
2462          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2463    
2464          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2465              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2466          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2467              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2468          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2469              set_sensitive(file);              set_sensitive(file);
2470          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2471              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2472          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2473              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2474      }      }
2475  }  }
2476    
# Line 2194  void MainWindow::add_instrument(gig::Ins Line 2549  void MainWindow::add_instrument(gig::Ins
2549      instrument_name_connection.block();      instrument_name_connection.block();
2550      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2551      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2552        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2553      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2554      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2555      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2222  void MainWindow::on_action_duplicate_ins Line 2578  void MainWindow::on_action_duplicate_ins
2578      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2579      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2580      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2581      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2582      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2583      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2584      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2585      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2586                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2587      // duplicate the orginal instrument              if (instrOrig) {
2588      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2589      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2590          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2591          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2592                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2593    
2594      add_instrument(instrNew);                  add_instrument(instrNew);
2595                }
2596            }
2597        }
2598  }  }
2599    
2600  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2251  void MainWindow::on_action_remove_instru Line 2611  void MainWindow::on_action_remove_instru
2611      }      }
2612    
2613      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2614      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2615      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2616            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2617            if (!it) continue;
2618          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2619          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2620          try {          try {
# Line 2267  void MainWindow::on_action_remove_instru Line 2629  void MainWindow::on_action_remove_instru
2629    
2630              // remove row from instruments tree view              // remove row from instruments tree view
2631              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2632                // update "Nr" column of all instrument rows
2633                {
2634                    int index = 0;
2635                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2636                         it != m_refTreeModel->children().end(); ++it, ++index)
2637                    {
2638                        Gtk::TreeModel::Row row = *it;
2639                        row[m_Columns.m_col_nr] = index;
2640                    }
2641                }
2642    
2643  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2644              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2448  void MainWindow::add_or_replace_sample(b Line 2820  void MainWindow::add_or_replace_sample(b
2820    
2821      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2822      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2823      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2824        if (rows.empty()) return;
2825        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2826      if (!it) return;      if (!it) return;
2827      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2828      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2597  void MainWindow::add_or_replace_sample(b Line 2971  void MainWindow::add_or_replace_sample(b
2971                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2972                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2973                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2974                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2975                  // add sample to the tree view                  // add sample to the tree view
2976                  if (replace) {                  if (replace) {
2977                      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 2707  void MainWindow::on_action_replace_all_s Line 3081  void MainWindow::on_action_replace_all_s
3081                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3082                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3083                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3084                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3085                  sf_close(hFile);                  sf_close(hFile);
3086                  file_changed();                  file_changed();
3087              }              }
# Line 2731  void MainWindow::on_action_replace_all_s Line 3105  void MainWindow::on_action_replace_all_s
3105  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
3106      if (!file) return;      if (!file) return;
3107      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3108      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3109      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
3110            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3111            if (!it) continue;
3112          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3113          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
3114          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2757  void MainWindow::on_action_remove_sample Line 3133  void MainWindow::on_action_remove_sample
3133                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3134                  // them from the import queue                  // them from the import queue
3135                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3136                       member != members.end(); ++member) {                       member != members.end(); ++member)
3137                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3138                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3139                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3140                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3141                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3142                      }                      }
3143                  }                  }
3144                  file_changed();                  file_changed();
# Line 2780  void MainWindow::on_action_remove_sample Line 3153  void MainWindow::on_action_remove_sample
3153                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3154                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3155                  // the import queue                  // the import queue
3156                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3157                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3158                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3159                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3160                  }                  }
3161                  dimreg_changed();                  dimreg_changed();
3162                  file_changed();                  file_changed();
# Line 2843  void MainWindow::on_action_remove_unused Line 3212  void MainWindow::on_action_remove_unused
3212              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3213              // remove sample from the .gig file              // remove sample from the .gig file
3214              file->DeleteSample(sample);              file->DeleteSample(sample);
3215              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3216              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3217                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3218              {                         m_SampleImportQueue[sample].sample_path.c_str());
3219                  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;  
                 }  
3220              }              }
3221          }          }
3222      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 2911  void MainWindow::on_instruments_treeview Line 3275  void MainWindow::on_instruments_treeview
3275      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3276      {      {
3277          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3278          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3279          if (it) {          if (!rows.empty()) {
3280              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3281              src = row[m_Columns.m_col_instr];              if (it) {
3282                    Gtk::TreeModel::Row row = *it;
3283                    src = row[m_Columns.m_col_instr];
3284                }
3285          }          }
3286      }      }
3287      if (!src) return;      if (!src) return;
# Line 2969  void MainWindow::on_sample_treeview_drag Line 3336  void MainWindow::on_sample_treeview_drag
3336      // get selected sample      // get selected sample
3337      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3338      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3339      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3340      if (it) {      if (!rows.empty()) {
3341          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3342          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3343                Gtk::TreeModel::Row row = *it;
3344                sample = row[m_SamplesModel.m_col_sample];
3345            }
3346      }      }
3347      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3348      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 3171  void MainWindow::on_action_combine_instr Line 3541  void MainWindow::on_action_combine_instr
3541    
3542  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3543      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3544      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3545        if (rows.empty()) return;
3546        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3547      if (!it) return;      if (!it) return;
3548      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3549      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 3420  void MainWindow::show_scripts_tab() { Line 3792  void MainWindow::show_scripts_tab() {
3792      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3793  }  }
3794    
3795    void MainWindow::select_prev_region() {
3796        m_RegionChooser.select_prev_region();
3797    }
3798    
3799    void MainWindow::select_next_region() {
3800        m_RegionChooser.select_next_region();
3801    }
3802    
3803    void MainWindow::select_next_dim_rgn_zone() {
3804        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3805        m_DimRegionChooser.select_next_dimzone();
3806    }
3807    
3808    void MainWindow::select_prev_dim_rgn_zone() {
3809        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3810        m_DimRegionChooser.select_prev_dimzone();
3811    }
3812    
3813    void MainWindow::select_add_next_dim_rgn_zone() {
3814        m_DimRegionChooser.select_next_dimzone(true);
3815    }
3816    
3817    void MainWindow::select_add_prev_dim_rgn_zone() {
3818        m_DimRegionChooser.select_prev_dimzone(true);
3819    }
3820    
3821    void MainWindow::select_prev_dimension() {
3822        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3823        m_DimRegionChooser.select_prev_dimension();
3824    }
3825    
3826    void MainWindow::select_next_dimension() {
3827        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3828        m_DimRegionChooser.select_next_dimension();
3829    }
3830    
3831    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3832        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3833    
3834    void MainWindow::copy_selected_dimrgn() {
3835        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3836        if (!pDimRgn) {
3837            updateClipboardPasteAvailable();
3838            updateClipboardCopyAvailable();
3839            return;
3840        }
3841    
3842        std::vector<Gtk::TargetEntry> targets;
3843        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3844    
3845        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3846        clipboard->set(
3847            targets,
3848            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3849            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3850        );
3851    
3852        m_serializationArchive.serialize(pDimRgn);
3853    
3854        updateClipboardPasteAvailable();
3855    }
3856    
3857    void MainWindow::paste_copied_dimrgn() {
3858        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3859        clipboard->request_contents(
3860            CLIPBOARD_DIMENSIONREGION_TARGET,
3861            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3862        );
3863        updateClipboardPasteAvailable();
3864    }
3865    
3866    void MainWindow::adjust_clipboard_content() {
3867        MacroEditor* editor = new MacroEditor();
3868        editor->setMacro(&m_serializationArchive);
3869        editor->show();
3870    }
3871    
3872    void MainWindow::updateClipboardPasteAvailable() {
3873        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3874        clipboard->request_targets(
3875            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3876        );
3877    }
3878    
3879    void MainWindow::updateClipboardCopyAvailable() {
3880        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3881        static_cast<Gtk::MenuItem*>(
3882            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3883        )->set_sensitive(bDimensionRegionCopyIsPossible);
3884    }
3885    
3886    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3887        updateClipboardPasteAvailable();
3888    }
3889    
3890    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3891        const std::string target = selection_data.get_target();
3892        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3893            selection_data.set(
3894                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3895                &m_serializationArchive.rawData()[0],
3896                m_serializationArchive.rawData().size()
3897            );
3898        } else {
3899            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3900        }
3901    }
3902    
3903    void MainWindow::on_clipboard_clear() {
3904        m_serializationArchive.clear();
3905        updateClipboardPasteAvailable();
3906        updateClipboardCopyAvailable();
3907    }
3908    
3909    //NOTE: Might throw exception !!!
3910    void MainWindow::applyMacro(Serialization::Archive& macro) {
3911        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3912        if (!pDimRgn) return;
3913    
3914        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3915             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3916        {
3917            gig::DimensionRegion* pDimRgn = *itDimReg;
3918            dimreg_to_be_changed_signal.emit(pDimRgn);
3919            m_serializationArchive.deserialize(pDimRgn);
3920            dimreg_changed_signal.emit(pDimRgn);
3921        }
3922        //region_changed()
3923        file_changed();
3924        dimreg_changed();
3925    }
3926    
3927    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3928        const std::string target = selection_data.get_target();
3929        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3930            Glib::ustring errorText;
3931            try {
3932                m_serializationArchive.decode(
3933                    selection_data.get_data(), selection_data.get_length()
3934                );
3935                applyMacro(m_serializationArchive);
3936            } catch (Serialization::Exception e) {
3937                errorText = e.Message;
3938            } catch (...) {
3939                errorText = _("Unknown exception while pasting DimensionRegion");
3940            }
3941            if (!errorText.empty()) {
3942                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3943                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3944                msg.run();
3945            }
3946        }
3947    }
3948    
3949    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3950        const bool bDimensionRegionPasteIsPossible =
3951            std::find(targets.begin(), targets.end(),
3952                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3953    
3954        static_cast<Gtk::MenuItem*>(
3955            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3956        )->set_sensitive(bDimensionRegionPasteIsPossible);
3957    
3958        static_cast<Gtk::MenuItem*>(
3959            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
3960        )->set_sensitive(bDimensionRegionPasteIsPossible);
3961    }
3962    
3963  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3964      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3965  }  }

Legend:
Removed from v.2918  
changed lines
  Added in v.3157

  ViewVC Help
Powered by ViewVC