/[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 3021 by persson, Sun Oct 23 07:24:40 2016 UTC revision 3258 by schoenebeck, Tue May 30 20:17:12 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 35  Line 35 
35  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
36  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
37  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
38    #include <gtkmm/stock.h>
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 57  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  MainWindow::MainWindow() :  MainWindow::MainWindow() :
70      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
71      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
72      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
73      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
74      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
75        labelLegend(_("Legend:")),
76        labelNoSample(_(" No Sample")),
77        labelMissingSample(_(" Missing some Sample(s)")),
78        labelLooped(_(" Looped")),
79        labelSomeLoops(_(" Some Loop(s)"))
80  {  {
81        loadBuiltInPix();
82    
83  //    set_border_width(5);  //    set_border_width(5);
 //    set_default_size(400, 200);  
84    
85        if (!Settings::singleton()->autoRestoreWindowDimension) {
86            set_default_size(800, 600);
87            set_position(Gtk::WIN_POS_CENTER);
88        }
89    
90      add(m_VBox);      add(m_VBox);
91    
# Line 103  MainWindow::MainWindow() : Line 120  MainWindow::MainWindow() :
120      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
121      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
122      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
123        {
124            legend_hbox.add(labelLegend);
125    
126            imageNoSample.set(redDot);
127            imageNoSample.set_alignment(Gtk::ALIGN_END);
128            labelNoSample.set_alignment(Gtk::ALIGN_START);
129            legend_hbox.add(imageNoSample);
130            legend_hbox.add(labelNoSample);
131    
132            imageMissingSample.set(yellowDot);
133            imageMissingSample.set_alignment(Gtk::ALIGN_END);
134            labelMissingSample.set_alignment(Gtk::ALIGN_START);
135            legend_hbox.add(imageMissingSample);
136            legend_hbox.add(labelMissingSample);
137    
138            imageLooped.set(blackLoop);
139            imageLooped.set_alignment(Gtk::ALIGN_END);
140            labelLooped.set_alignment(Gtk::ALIGN_START);
141            legend_hbox.add(imageLooped);
142            legend_hbox.add(labelLooped);
143    
144            imageSomeLoops.set(grayLoop);
145            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
146            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
147            legend_hbox.add(imageSomeLoops);
148            legend_hbox.add(labelSomeLoops);
149    
150            legend_hbox.show_all_children();
151        }
152        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
153      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
154    
155      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 117  MainWindow::MainWindow() : Line 164  MainWindow::MainWindow() :
164      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
165    
166      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
167      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
168                       sigc::mem_fun(                       sigc::mem_fun(
169                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
170      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
171                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
172        action->property_label() = action->property_label() + "...";
173        actionGroup->add(action,
174                       sigc::mem_fun(                       sigc::mem_fun(
175                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
176      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
177                       sigc::mem_fun(                       sigc::mem_fun(
178                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
179      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
180        action->property_label() = action->property_label() + "...";
181        actionGroup->add(action,
182                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
183                       sigc::mem_fun(                       sigc::mem_fun(
184                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
185      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
186                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
189      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
190                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
191                       sigc::mem_fun(                       sigc::mem_fun(
192                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
193      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 149  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198                                           _("_Script Slots...")),                                           _("_Script Slots...")),
199                       sigc::mem_fun(                       sigc::mem_fun(
200                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
201      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
202                       sigc::mem_fun(                       sigc::mem_fun(
203                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
204      actionGroup->add(      actionGroup->add(
# Line 162  MainWindow::MainWindow() : Line 210  MainWindow::MainWindow() :
210          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
211      );      );
212      actionGroup->add(      actionGroup->add(
213          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
214          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
215      );      );
216      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
217    
218      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
219    
220        const Gdk::ModifierType primaryModifierKey =
221    #if defined(__APPLE__)
222        Gdk::META_MASK; // Cmd key on Mac
223    #else
224        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
225    #endif
226    
227        actionGroup->add(Gtk::Action::create("CopyDimRgn",
228                                             _("Copy selected dimension region")),
229                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
230                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
231    
232        actionGroup->add(Gtk::Action::create("PasteDimRgn",
233                                             _("Paste dimension region")),
234                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
235                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
236    
237        actionGroup->add(Gtk::Action::create("AdjustClipboard",
238                                             _("Adjust Clipboard Content")),
239                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
240                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
241    
242        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
243                                             _("Select Previous Region")),
244                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
245                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
246    
247        actionGroup->add(Gtk::Action::create("SelectNextRegion",
248                                             _("Select Next Region")),
249                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
250                         sigc::mem_fun(*this, &MainWindow::select_next_region));
251    
252        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
253                                             _("Select Previous Dimension Region Zone")),
254                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
255                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
256    
257        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
258                                             _("Select Next Dimension Region Zone")),
259                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
260                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
261    
262        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
263                                             _("Select Previous Dimension")),
264                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
265                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
266    
267        actionGroup->add(Gtk::Action::create("SelectNextDimension",
268                                             _("Select Next Dimension")),
269                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
270                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
271    
272        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
273                                             _("Add Previous Dimension Region Zone to Selection")),
274                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
275                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
276    
277        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
278                                             _("Add Next Dimension Region Zone to Selection")),
279                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
280                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
281    
282      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
283          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
284      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 185  MainWindow::MainWindow() : Line 295  MainWindow::MainWindow() :
295      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
296    
297    
298      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
299    
300    
301        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
302      toggle_action =      toggle_action =
303          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
304      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 212  MainWindow::MainWindow() : Line 325  MainWindow::MainWindow() :
325          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
326      );                      );                
327    
328      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
329      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
330                                             action->property_label()));
331        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
332                       sigc::mem_fun(                       sigc::mem_fun(
333                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
334      actionGroup->add(      actionGroup->add(
# Line 225  MainWindow::MainWindow() : Line 340  MainWindow::MainWindow() :
340          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
341      );      );
342      actionGroup->add(      actionGroup->add(
343          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
344          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
345      );      );
346    
# Line 272  MainWindow::MainWindow() : Line 387  MainWindow::MainWindow() :
387    
388      // sample right-click popup actions      // sample right-click popup actions
389      actionGroup->add(      actionGroup->add(
390          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
391          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
392      );      );
393      actionGroup->add(      actionGroup->add(
# Line 284  MainWindow::MainWindow() : Line 399  MainWindow::MainWindow() :
399          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
400      );      );
401      actionGroup->add(      actionGroup->add(
402          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
403          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
404      );      );
405      actionGroup->add(      actionGroup->add(
# Line 320  MainWindow::MainWindow() : Line 435  MainWindow::MainWindow() :
435          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
436      );      );
437      actionGroup->add(      actionGroup->add(
438          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
439          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
440      );      );
441    
# Line 343  MainWindow::MainWindow() : Line 458  MainWindow::MainWindow() :
458          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
459          "    </menu>"          "    </menu>"
460          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
461            "      <menuitem action='CopyDimRgn'/>"
462            "      <menuitem action='AdjustClipboard'/>"
463            "      <menuitem action='PasteDimRgn'/>"
464            "      <separator/>"
465            "      <menuitem action='SelectPrevRegion'/>"
466            "      <menuitem action='SelectNextRegion'/>"
467            "      <separator/>"
468            "      <menuitem action='SelectPrevDimension'/>"
469            "      <menuitem action='SelectNextDimension'/>"
470            "      <menuitem action='SelectPrevDimRgnZone'/>"
471            "      <menuitem action='SelectNextDimRgnZone'/>"
472            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
473            "      <menuitem action='SelectAddNextDimRgnZone'/>"
474            "      <separator/>"
475          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
476          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
477          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
478          "    </menu>"          "    </menu>"
479            "    <menu action='MenuMacro'>"
480            "    </menu>"
481          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
482          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
483          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 530  MainWindow::MainWindow() : Line 661  MainWindow::MainWindow() :
661      // Add the TreeView's view columns:      // Add the TreeView's view columns:
662      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
663      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
664        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
665      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
666            
667      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 705  MainWindow::MainWindow() : Line 837  MainWindow::MainWindow() :
837    
838      // select 'Instruments' tab by default      // select 'Instruments' tab by default
839      // (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)
840      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
841    
842        Gtk::Clipboard::get()->signal_owner_change().connect(
843            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
844        );
845        updateClipboardPasteAvailable();
846        updateClipboardCopyAvailable();
847    
848        // setup macros and their keyboard accelerators
849        {
850            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
851                uiManager->get_widget("/MenuBar/MenuMacro")
852            )->get_submenu();
853    
854            const Gdk::ModifierType primaryModifierKey =
855    #if defined(__APPLE__)
856                Gdk::META_MASK; // Cmd key on Mac
857    #else
858                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
859    #endif
860    
861            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
862            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
867            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
868            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
869            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
870            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
871            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
872            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
873            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
874            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
875    
876            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
877            menuMacro->set_accel_group(accelGroup);
878    
879            updateMacroMenu();
880        }
881    
882        Glib::signal_idle().connect_once(
883            sigc::mem_fun(*this, &MainWindow::bringToFront),
884            200
885        );
886  }  }
887    
888  MainWindow::~MainWindow()  MainWindow::~MainWindow()
889  {  {
890  }  }
891    
892    void MainWindow::bringToFront() {
893        #if defined(__APPLE__)
894        macRaiseAppWindow();
895        #endif
896        raise();
897        present();
898    }
899    
900    void MainWindow::updateMacroMenu() {
901        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
902            uiManager->get_widget("/MenuBar/MenuMacro")
903        )->get_submenu();
904    
905        // remove all entries from "Macro" menu
906        {
907            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
908            for (int i = 0; i < children.size(); ++i) {
909                Gtk::Widget* child = children[i];
910                menuMacro->remove(*child);
911                delete child;
912            }
913        }
914    
915        // (re)load all macros from config file
916        try {
917            Settings::singleton()->loadMacros(m_macros);
918        } catch (Serialization::Exception e) {
919            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
920        } catch (...) {
921            std::cerr << "Unknown exception while loading macros!" << std::endl;
922        }
923    
924        // add all configured macros as menu items to the "Macro" menu
925        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
926            const Serialization::Archive& macro = m_macros[iMacro];
927            std::string name =
928                macro.name().empty() ?
929                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
930            Gtk::MenuItem* item = new Gtk::MenuItem(name);
931            item->signal_activate().connect(
932                sigc::bind(
933                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
934                )
935            );
936            menuMacro->append(*item);
937            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
938            Glib::ustring comment = macro.comment();
939            if (!comment.empty())
940                item->set_tooltip_text(comment);
941        }
942        // if there are no macros configured at all, then show a dummy entry instead
943        if (m_macros.empty()) {
944            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
945            item->set_sensitive(false);
946            menuMacro->append(*item);
947        }
948    
949        // add separator line to menu
950        menuMacro->append(*new Gtk::SeparatorMenuItem);
951    
952        {
953            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
954            item->signal_activate().connect(
955                sigc::mem_fun(*this, &MainWindow::setupMacros)
956            );
957            menuMacro->append(*item);
958            item->set_accel_path("<Macros>/SetupMacros");
959        }
960    
961        menuMacro->show_all_children();
962    }
963    
964    void MainWindow::onMacroSelected(int iMacro) {
965        printf("onMacroSelected(%d)\n", iMacro);
966        if (iMacro < 0 || iMacro >= m_macros.size()) return;
967        Glib::ustring errorText;
968        try {
969            applyMacro(m_macros[iMacro]);
970        } catch (Serialization::Exception e) {
971            errorText = e.Message;
972        } catch (...) {
973            errorText = _("Unknown exception while applying macro");
974        }
975        if (!errorText.empty()) {
976            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
977            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
978            msg.run();
979        }
980    }
981    
982    void MainWindow::setupMacros() {
983        MacrosSetup* setup = new MacrosSetup();
984        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
985        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
986        setup->signal_macros_changed().connect(
987            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
988        );
989        setup->show();
990    }
991    
992    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
993        m_macros = macros;
994        Settings::singleton()->saveMacros(m_macros);
995        updateMacroMenu();
996    }
997    
998  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
999  {  {
1000      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 776  void MainWindow::update_dimregs() Line 1059  void MainWindow::update_dimregs()
1059              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
1060          }          }
1061      }      }
1062    
1063        m_RegionChooser.setModifyAllRegions(all_regions);
1064        m_DimRegionChooser.setModifyAllRegions(all_regions);
1065        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1066        m_DimRegionChooser.setModifyBothChannels(stereo);
1067    
1068        updateClipboardCopyAvailable();
1069  }  }
1070    
1071  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 935  void Saver::thread_function() Line 1225  void Saver::thread_function()
1225                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1226                  // then move the saved file over the old file                  // then move the saved file over the old file
1227                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1228                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1229                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1230                  #if defined(WIN32)                  #if defined(WIN32)
1231                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 943  void Saver::thread_function() Line 1233  void Saver::thread_function()
1233                  }                  }
1234                  #else // POSIX ...                  #else // POSIX ...
1235                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1236                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1237                  }                  }
1238                  #endif                  #endif
1239                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1240                      #if defined(WIN32)                      #if defined(WIN32)
1241                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1242                      #else                      #else
1243                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1244                      #endif                      #endif
1245                  }                  }
1246              }              }
# Line 1078  bool MainWindow::close_confirmation_dial Line 1368  bool MainWindow::close_confirmation_dial
1368      g_free(msg);      g_free(msg);
1369      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
1370      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1371      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1372      dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
1373      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1374      int response = dialog.run();      int response = dialog.run();
1375      dialog.hide();      dialog.hide();
# Line 1110  bool MainWindow::leaving_shared_mode_dia Line 1400  bool MainWindow::leaving_shared_mode_dia
1400            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1401            "load it."));            "load it."));
1402      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1403      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1404      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1405      int response = dialog.run();      int response = dialog.run();
1406      dialog.hide();      dialog.hide();
# Line 1124  void MainWindow::on_action_file_open() Line 1414  void MainWindow::on_action_file_open()
1414      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1415    
1416      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1417      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1418      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1419      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1420  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1421      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1320  void MainWindow::on_action_file_save_as( Line 1610  void MainWindow::on_action_file_save_as(
1610    
1611  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1612  {  {
1613      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1614      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1615      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1616      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1617      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1618    
# Line 1408  void MainWindow::__import_queued_samples Line 1698  void MainWindow::__import_queued_samples
1698      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1699      Glib::ustring error_files;      Glib::ustring error_files;
1700      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1701      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1702           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1703          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1704          SF_INFO info;          SF_INFO info;
1705          info.format = 0;          info.format = 0;
1706          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);
1707          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1708          try {          try {
1709              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1436  void MainWindow::__import_queued_samples Line 1726  void MainWindow::__import_queued_samples
1726                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1727              }              }
1728    
1729                // reset write position for sample
1730                iter->first->SetPos(0);
1731    
1732              const int bufsize = 10000;              const int bufsize = 10000;
1733              switch (bitdepth) {              switch (bitdepth) {
1734                  case 16: {                  case 16: {
# Line 1445  void MainWindow::__import_queued_samples Line 1738  void MainWindow::__import_queued_samples
1738                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1739                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1740                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1741                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1742                          cnt -= n;                          cnt -= n;
1743                      }                      }
1744                      delete[] buffer;                      delete[] buffer;
# Line 1465  void MainWindow::__import_queued_samples Line 1758  void MainWindow::__import_queued_samples
1758                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1759                          }                          }
1760                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1761                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1762                          cnt -= n;                          cnt -= n;
1763                      }                      }
1764                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1476  void MainWindow::__import_queued_samples Line 1769  void MainWindow::__import_queued_samples
1769              // cleanup              // cleanup
1770              sf_close(hFile);              sf_close(hFile);
1771              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1772              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1773              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1774              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1775              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1776              ++iter;              ++iter;
1777              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1778          } catch (std::string what) {          } catch (std::string what) {
1779              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1780              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1781              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1782              ++iter;              ++iter;
1783          }          }
1784      }      }
# Line 1527  void MainWindow::on_action_help_about() Line 1820  void MainWindow::on_action_help_about()
1820      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1821  #endif  #endif
1822      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1823      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1824      const std::string sComment =      const std::string sComment =
1825          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1826          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1543  void MainWindow::on_action_help_about() Line 1836  void MainWindow::on_action_help_about()
1836      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1837      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1838      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1839        dialog.set_position(Gtk::WIN_POS_CENTER);
1840      dialog.run();      dialog.run();
1841  }  }
1842    
# Line 1564  PropDialog::PropDialog() Line 1858  PropDialog::PropDialog()
1858        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1859        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1860        eSubject(_("Subject")),        eSubject(_("Subject")),
1861        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1862        table(2, 1),        table(2, 1),
1863        m_file(NULL)        m_file(NULL)
1864  {  {
1865        if (!Settings::singleton()->autoRestoreWindowDimension) {
1866            set_default_size(470, 390);
1867            set_position(Gtk::WIN_POS_MOUSE);
1868        }
1869    
1870      set_title(_("File Properties"));      set_title(_("File Properties"));
1871      eName.set_width_chars(50);      eName.set_width_chars(50);
1872    
# Line 1687  void InstrumentProps::set_MIDIProgram(ui Line 1986  void InstrumentProps::set_MIDIProgram(ui
1986  }  }
1987    
1988  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1989      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1990      table(2,1),      table(2,1),
1991      eName(_("Name")),      eName(_("Name")),
1992      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1702  InstrumentProps::InstrumentProps() : Line 2001  InstrumentProps::InstrumentProps() :
2001      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2002      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2003  {  {
2004        if (!Settings::singleton()->autoRestoreWindowDimension) {
2005            //set_default_size(470, 390);
2006            set_position(Gtk::WIN_POS_MOUSE);
2007        }
2008    
2009      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2010    
2011      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1826  void MainWindow::load_gig(gig::File* gig Line 2130  void MainWindow::load_gig(gig::File* gig
2130      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2131           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2132          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2133            const int iScriptSlots = instrument->ScriptSlotCount();
2134    
2135          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2136          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2137          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2138          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2139          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2140            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2141    
2142          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2143      }      }
# Line 1970  void MainWindow::show_script_slots() { Line 2276  void MainWindow::show_script_slots() {
2276    
2277      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2278      window->setInstrument(instrument);      window->setInstrument(instrument);
2279        window->signal_script_slots_changed().connect(
2280            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2281        );
2282      //window->reparent(*this);      //window->reparent(*this);
2283      window->show();      window->show();
2284  }  }
2285    
2286    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2287        if (!pInstrument) return;
2288        const int iScriptSlots = pInstrument->ScriptSlotCount();
2289    
2290        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2291        for (int i = 0; i < model->children().size(); ++i) {
2292            Gtk::TreeModel::Row row = model->children()[i];
2293            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2294            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2295            break;
2296        }
2297    }
2298    
2299  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2300      __refreshEntireGUI();      __refreshEntireGUI();
2301  }  }
# Line 2288  void MainWindow::add_instrument(gig::Ins Line 2610  void MainWindow::add_instrument(gig::Ins
2610      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2611      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2612      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2613        rowInstr[m_Columns.m_col_scripts] = "";
2614      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2615    
2616      add_instrument_to_menu(name);      add_instrument_to_menu(name);
# Line 2576  void MainWindow::add_or_replace_sample(b Line 2899  void MainWindow::add_or_replace_sample(b
2899    
2900      // show 'browse for file' dialog      // show 'browse for file' dialog
2901      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2902      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2903      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2904      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2905    
2906      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2707  void MainWindow::add_or_replace_sample(b Line 3030  void MainWindow::add_or_replace_sample(b
3030                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3031                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3032                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3033                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3034                  // add sample to the tree view                  // add sample to the tree view
3035                  if (replace) {                  if (replace) {
3036                      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 2777  void MainWindow::on_action_replace_all_s Line 3100  void MainWindow::on_action_replace_all_s
3100      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3101      description.show();      description.show();
3102      entryArea.show_all();      entryArea.show_all();
3103      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3104      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3105      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3106      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2817  void MainWindow::on_action_replace_all_s Line 3140  void MainWindow::on_action_replace_all_s
3140                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3141                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3142                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3143                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3144                  sf_close(hFile);                  sf_close(hFile);
3145                  file_changed();                  file_changed();
3146              }              }
# Line 2869  void MainWindow::on_action_remove_sample Line 3192  void MainWindow::on_action_remove_sample
3192                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3193                  // them from the import queue                  // them from the import queue
3194                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3195                       member != members.end(); ++member) {                       member != members.end(); ++member)
3196                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3197                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3198                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3199                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3200                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3201                      }                      }
3202                  }                  }
3203                  file_changed();                  file_changed();
# Line 2892  void MainWindow::on_action_remove_sample Line 3212  void MainWindow::on_action_remove_sample
3212                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3213                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3214                  // the import queue                  // the import queue
3215                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3216                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3217                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3218                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3219                  }                  }
3220                  dimreg_changed();                  dimreg_changed();
3221                  file_changed();                  file_changed();
# Line 2955  void MainWindow::on_action_remove_unused Line 3271  void MainWindow::on_action_remove_unused
3271              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3272              // remove sample from the .gig file              // remove sample from the .gig file
3273              file->DeleteSample(sample);              file->DeleteSample(sample);
3274              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3275              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3276                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3277              {                         m_SampleImportQueue[sample].sample_path.c_str());
3278                  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;  
                 }  
3279              }              }
3280          }          }
3281      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3278  void MainWindow::instrument_name_changed Line 3589  void MainWindow::instrument_name_changed
3589  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3590      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3591      d->show_all();      d->show_all();
     d->resize(500, 400);  
3592      d->run();      d->run();
3593      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3594          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3413  void MainWindow::on_action_merge_files() Line 3723  void MainWindow::on_action_merge_files()
3723      }      }
3724    
3725      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3726      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3727      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3728      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3729  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 3540  void MainWindow::show_scripts_tab() { Line 3850  void MainWindow::show_scripts_tab() {
3850      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3851  }  }
3852    
3853    void MainWindow::select_prev_region() {
3854        m_RegionChooser.select_prev_region();
3855    }
3856    
3857    void MainWindow::select_next_region() {
3858        m_RegionChooser.select_next_region();
3859    }
3860    
3861    void MainWindow::select_next_dim_rgn_zone() {
3862        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3863        m_DimRegionChooser.select_next_dimzone();
3864    }
3865    
3866    void MainWindow::select_prev_dim_rgn_zone() {
3867        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3868        m_DimRegionChooser.select_prev_dimzone();
3869    }
3870    
3871    void MainWindow::select_add_next_dim_rgn_zone() {
3872        m_DimRegionChooser.select_next_dimzone(true);
3873    }
3874    
3875    void MainWindow::select_add_prev_dim_rgn_zone() {
3876        m_DimRegionChooser.select_prev_dimzone(true);
3877    }
3878    
3879    void MainWindow::select_prev_dimension() {
3880        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3881        m_DimRegionChooser.select_prev_dimension();
3882    }
3883    
3884    void MainWindow::select_next_dimension() {
3885        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3886        m_DimRegionChooser.select_next_dimension();
3887    }
3888    
3889    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3890        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3891    
3892    void MainWindow::copy_selected_dimrgn() {
3893        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3894        if (!pDimRgn) {
3895            updateClipboardPasteAvailable();
3896            updateClipboardCopyAvailable();
3897            return;
3898        }
3899    
3900        std::vector<Gtk::TargetEntry> targets;
3901        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3902    
3903        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3904        clipboard->set(
3905            targets,
3906            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3907            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3908        );
3909    
3910        m_serializationArchive.serialize(pDimRgn);
3911    
3912        updateClipboardPasteAvailable();
3913    }
3914    
3915    void MainWindow::paste_copied_dimrgn() {
3916        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3917        clipboard->request_contents(
3918            CLIPBOARD_DIMENSIONREGION_TARGET,
3919            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3920        );
3921        updateClipboardPasteAvailable();
3922    }
3923    
3924    void MainWindow::adjust_clipboard_content() {
3925        MacroEditor* editor = new MacroEditor();
3926        editor->setMacro(&m_serializationArchive, true);
3927        editor->show();
3928    }
3929    
3930    void MainWindow::updateClipboardPasteAvailable() {
3931        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3932        clipboard->request_targets(
3933            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3934        );
3935    }
3936    
3937    void MainWindow::updateClipboardCopyAvailable() {
3938        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3939        static_cast<Gtk::MenuItem*>(
3940            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3941        )->set_sensitive(bDimensionRegionCopyIsPossible);
3942    }
3943    
3944    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3945        updateClipboardPasteAvailable();
3946    }
3947    
3948    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3949        const std::string target = selection_data.get_target();
3950        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3951            selection_data.set(
3952                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3953                &m_serializationArchive.rawData()[0],
3954                m_serializationArchive.rawData().size()
3955            );
3956        } else {
3957            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3958        }
3959    }
3960    
3961    void MainWindow::on_clipboard_clear() {
3962        m_serializationArchive.clear();
3963        updateClipboardPasteAvailable();
3964        updateClipboardCopyAvailable();
3965    }
3966    
3967    //NOTE: Might throw exception !!!
3968    void MainWindow::applyMacro(Serialization::Archive& macro) {
3969        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3970        if (!pDimRgn) return;
3971    
3972        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3973             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3974        {
3975            gig::DimensionRegion* pDimRgn = *itDimReg;
3976            DimRegionChangeGuard(this, pDimRgn);
3977            macro.deserialize(pDimRgn);
3978        }
3979        //region_changed()
3980        file_changed();
3981        dimreg_changed();
3982    }
3983    
3984    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3985        const std::string target = selection_data.get_target();
3986        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3987            Glib::ustring errorText;
3988            try {
3989                m_serializationArchive.decode(
3990                    selection_data.get_data(), selection_data.get_length()
3991                );
3992                applyMacro(m_serializationArchive);
3993            } catch (Serialization::Exception e) {
3994                errorText = e.Message;
3995            } catch (...) {
3996                errorText = _("Unknown exception while pasting DimensionRegion");
3997            }
3998            if (!errorText.empty()) {
3999                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
4000                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4001                msg.run();
4002            }
4003        }
4004    }
4005    
4006    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
4007        const bool bDimensionRegionPasteIsPossible =
4008            std::find(targets.begin(), targets.end(),
4009                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
4010    
4011        static_cast<Gtk::MenuItem*>(
4012            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4013        )->set_sensitive(bDimensionRegionPasteIsPossible);
4014    
4015        static_cast<Gtk::MenuItem*>(
4016            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4017        )->set_sensitive(bDimensionRegionPasteIsPossible);
4018    }
4019    
4020  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4021      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4022  }  }

Legend:
Removed from v.3021  
changed lines
  Added in v.3258

  ViewVC Help
Powered by ViewVC