/[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 3106 by schoenebeck, Sat Feb 11 17:04:48 2017 UTC revision 3225 by schoenebeck, Fri May 26 22:10:16 2017 UTC
# 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 58  Line 60 
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"  #include "gfx/builtinpix.h"
63    #include "MacroEditor.h"
64    #include "MacrosSetup.h"
65    
66  MainWindow::MainWindow() :  MainWindow::MainWindow() :
67      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 65  MainWindow::MainWindow() : Line 69  MainWindow::MainWindow() :
69      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
70      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
71      dimreg_stereo(_("both channels")),      dimreg_stereo(_("both channels")),
72        labelLegend(_("Legend:")),
73      labelNoSample(_(" No Sample")),      labelNoSample(_(" No Sample")),
74      labelMissingSample(_(" Missing some Sample(s)")),      labelMissingSample(_(" Missing some Sample(s)")),
75      labelLooped(_(" Looped")),      labelLooped(_(" Looped")),
# Line 73  MainWindow::MainWindow() : Line 78  MainWindow::MainWindow() :
78      loadBuiltInPix();      loadBuiltInPix();
79    
80  //    set_border_width(5);  //    set_border_width(5);
81  //    set_default_size(400, 200);  
82        if (!Settings::singleton()->autoRestoreWindowDimension) {
83            set_default_size(800, 600);
84            set_position(Gtk::WIN_POS_CENTER);
85        }
86    
87      add(m_VBox);      add(m_VBox);
88    
# Line 109  MainWindow::MainWindow() : Line 118  MainWindow::MainWindow() :
118      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
119      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
120      {      {
121            legend_hbox.add(labelLegend);
122    
123          imageNoSample.set(redDot);          imageNoSample.set(redDot);
124          imageNoSample.set_alignment(Gtk::ALIGN_RIGHT);          imageNoSample.set_alignment(Gtk::ALIGN_END);
125          labelNoSample.set_alignment(Gtk::ALIGN_LEFT);          labelNoSample.set_alignment(Gtk::ALIGN_START);
126          legend_hbox.add(imageNoSample);          legend_hbox.add(imageNoSample);
127          legend_hbox.add(labelNoSample);          legend_hbox.add(labelNoSample);
128    
129          imageMissingSample.set(yellowDot);          imageMissingSample.set(yellowDot);
130          imageMissingSample.set_alignment(Gtk::ALIGN_RIGHT);          imageMissingSample.set_alignment(Gtk::ALIGN_END);
131          labelMissingSample.set_alignment(Gtk::ALIGN_LEFT);          labelMissingSample.set_alignment(Gtk::ALIGN_START);
132          legend_hbox.add(imageMissingSample);          legend_hbox.add(imageMissingSample);
133          legend_hbox.add(labelMissingSample);          legend_hbox.add(labelMissingSample);
134    
135          imageLooped.set(blackLoop);          imageLooped.set(blackLoop);
136          imageLooped.set_alignment(Gtk::ALIGN_RIGHT);          imageLooped.set_alignment(Gtk::ALIGN_END);
137          labelLooped.set_alignment(Gtk::ALIGN_LEFT);          labelLooped.set_alignment(Gtk::ALIGN_START);
138          legend_hbox.add(imageLooped);          legend_hbox.add(imageLooped);
139          legend_hbox.add(labelLooped);          legend_hbox.add(labelLooped);
140    
141          imageSomeLoops.set(grayLoop);          imageSomeLoops.set(grayLoop);
142          imageSomeLoops.set_alignment(Gtk::ALIGN_RIGHT);          imageSomeLoops.set_alignment(Gtk::ALIGN_END);
143          labelSomeLoops.set_alignment(Gtk::ALIGN_LEFT);          labelSomeLoops.set_alignment(Gtk::ALIGN_START);
144          legend_hbox.add(imageSomeLoops);          legend_hbox.add(imageSomeLoops);
145          legend_hbox.add(labelSomeLoops);          legend_hbox.add(labelSomeLoops);
146    
# Line 150  MainWindow::MainWindow() : Line 161  MainWindow::MainWindow() :
161      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
162    
163      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
164      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
165                       sigc::mem_fun(                       sigc::mem_fun(
166                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
167      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
168                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
169        action->property_label() = action->property_label() + "...";
170        actionGroup->add(action,
171                       sigc::mem_fun(                       sigc::mem_fun(
172                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
173      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
174                       sigc::mem_fun(                       sigc::mem_fun(
175                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
176      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
177        action->property_label() = action->property_label() + "...";
178        actionGroup->add(action,
179                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
180                       sigc::mem_fun(                       sigc::mem_fun(
181                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
182      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
183                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
184                       sigc::mem_fun(                       sigc::mem_fun(
185                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
186      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
187                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
188                       sigc::mem_fun(                       sigc::mem_fun(
189                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
190      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 182  MainWindow::MainWindow() : Line 195  MainWindow::MainWindow() :
195                                           _("_Script Slots...")),                                           _("_Script Slots...")),
196                       sigc::mem_fun(                       sigc::mem_fun(
197                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
198      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
199                       sigc::mem_fun(                       sigc::mem_fun(
200                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
201      actionGroup->add(      actionGroup->add(
# Line 195  MainWindow::MainWindow() : Line 207  MainWindow::MainWindow() :
207          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
208      );      );
209      actionGroup->add(      actionGroup->add(
210          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
211          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
212      );      );
213      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
214    
215      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
216    
217        const Gdk::ModifierType primaryModifierKey =
218    #if defined(__APPLE__)
219        Gdk::META_MASK; // Cmd key on Mac
220    #else
221        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
222    #endif
223    
224        actionGroup->add(Gtk::Action::create("CopyDimRgn",
225                                             _("Copy selected dimension region")),
226                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
227                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
228    
229        actionGroup->add(Gtk::Action::create("PasteDimRgn",
230                                             _("Paste dimension region")),
231                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
232                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
233    
234        actionGroup->add(Gtk::Action::create("AdjustClipboard",
235                                             _("Adjust Clipboard Content")),
236                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
237                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
238    
239        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
240                                             _("Select Previous Region")),
241                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
242                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
243    
244        actionGroup->add(Gtk::Action::create("SelectNextRegion",
245                                             _("Select Next Region")),
246                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
247                         sigc::mem_fun(*this, &MainWindow::select_next_region));
248    
249        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
250                                             _("Select Previous Dimension Region Zone")),
251                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
252                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
253    
254        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
255                                             _("Select Next Dimension Region Zone")),
256                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
257                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
258    
259        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
260                                             _("Select Previous Dimension")),
261                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
262                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
263    
264        actionGroup->add(Gtk::Action::create("SelectNextDimension",
265                                             _("Select Next Dimension")),
266                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
267                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
268    
269        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
270                                             _("Add Previous Dimension Region Zone to Selection")),
271                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
272                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
273    
274        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
275                                             _("Add Next Dimension Region Zone to Selection")),
276                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
277                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
278    
279      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
280          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
281      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 218  MainWindow::MainWindow() : Line 292  MainWindow::MainWindow() :
292      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
293    
294    
295      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
296    
297    
298        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
299      toggle_action =      toggle_action =
300          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
301      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 245  MainWindow::MainWindow() : Line 322  MainWindow::MainWindow() :
322          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
323      );                      );                
324    
325      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
326      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
327                                             action->property_label()));
328        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
329                       sigc::mem_fun(                       sigc::mem_fun(
330                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
331      actionGroup->add(      actionGroup->add(
# Line 258  MainWindow::MainWindow() : Line 337  MainWindow::MainWindow() :
337          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
338      );      );
339      actionGroup->add(      actionGroup->add(
340          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
341          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
342      );      );
343    
# Line 305  MainWindow::MainWindow() : Line 384  MainWindow::MainWindow() :
384    
385      // sample right-click popup actions      // sample right-click popup actions
386      actionGroup->add(      actionGroup->add(
387          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
388          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
389      );      );
390      actionGroup->add(      actionGroup->add(
# Line 317  MainWindow::MainWindow() : Line 396  MainWindow::MainWindow() :
396          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
397      );      );
398      actionGroup->add(      actionGroup->add(
399          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
400          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
401      );      );
402      actionGroup->add(      actionGroup->add(
# Line 353  MainWindow::MainWindow() : Line 432  MainWindow::MainWindow() :
432          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
433      );      );
434      actionGroup->add(      actionGroup->add(
435          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
436          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
437      );      );
438    
# Line 376  MainWindow::MainWindow() : Line 455  MainWindow::MainWindow() :
455          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
456          "    </menu>"          "    </menu>"
457          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
458            "      <menuitem action='CopyDimRgn'/>"
459            "      <menuitem action='AdjustClipboard'/>"
460            "      <menuitem action='PasteDimRgn'/>"
461            "      <separator/>"
462            "      <menuitem action='SelectPrevRegion'/>"
463            "      <menuitem action='SelectNextRegion'/>"
464            "      <separator/>"
465            "      <menuitem action='SelectPrevDimension'/>"
466            "      <menuitem action='SelectNextDimension'/>"
467            "      <menuitem action='SelectPrevDimRgnZone'/>"
468            "      <menuitem action='SelectNextDimRgnZone'/>"
469            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
470            "      <menuitem action='SelectAddNextDimRgnZone'/>"
471            "      <separator/>"
472          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
473          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
474          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
475          "    </menu>"          "    </menu>"
476            "    <menu action='MenuMacro'>"
477            "    </menu>"
478          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
479          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
480          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 563  MainWindow::MainWindow() : Line 658  MainWindow::MainWindow() :
658      // Add the TreeView's view columns:      // Add the TreeView's view columns:
659      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
660      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
661        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
662      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
663            
664      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 738  MainWindow::MainWindow() : Line 834  MainWindow::MainWindow() :
834    
835      // select 'Instruments' tab by default      // select 'Instruments' tab by default
836      // (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)
837      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
838    
839        Gtk::Clipboard::get()->signal_owner_change().connect(
840            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
841        );
842        updateClipboardPasteAvailable();
843        updateClipboardCopyAvailable();
844    
845        // setup macros and their keyboard accelerators
846        {
847            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
848                uiManager->get_widget("/MenuBar/MenuMacro")
849            )->get_submenu();
850    
851            const Gdk::ModifierType primaryModifierKey =
852    #if defined(__APPLE__)
853                Gdk::META_MASK; // Cmd key on Mac
854    #else
855                Gdk::CONTROL_MASK; // Ctrl key on all other OSs
856    #endif
857    
858            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
859            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
860            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
861            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
862            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
863            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
864            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
865            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
866            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
867            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
868            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
869            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
870            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
871            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
872    
873            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
874            menuMacro->set_accel_group(accelGroup);
875    
876            updateMacroMenu();
877        }
878  }  }
879    
880  MainWindow::~MainWindow()  MainWindow::~MainWindow()
881  {  {
882  }  }
883    
884    void MainWindow::updateMacroMenu() {
885        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
886            uiManager->get_widget("/MenuBar/MenuMacro")
887        )->get_submenu();
888    
889        // remove all entries from "Macro" menu
890        {
891            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
892            for (int i = 0; i < children.size(); ++i) {
893                Gtk::Widget* child = children[i];
894                menuMacro->remove(*child);
895                delete child;
896            }
897        }
898    
899        // (re)load all macros from config file
900        try {
901            Settings::singleton()->loadMacros(m_macros);
902        } catch (Serialization::Exception e) {
903            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
904        } catch (...) {
905            std::cerr << "Unknown exception while loading macros!" << std::endl;
906        }
907    
908        // add all configured macros as menu items to the "Macro" menu
909        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
910            const Serialization::Archive& macro = m_macros[iMacro];
911            std::string name =
912                macro.name().empty() ?
913                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
914            Gtk::MenuItem* item = new Gtk::MenuItem(name);
915            item->signal_activate().connect(
916                sigc::bind(
917                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
918                )
919            );
920            menuMacro->append(*item);
921            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
922            Glib::ustring comment = macro.comment();
923            if (!comment.empty())
924                item->set_tooltip_text(comment);
925        }
926        // if there are no macros configured at all, then show a dummy entry instead
927        if (m_macros.empty()) {
928            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
929            item->set_sensitive(false);
930            menuMacro->append(*item);
931        }
932    
933        // add separator line to menu
934        menuMacro->append(*new Gtk::SeparatorMenuItem);
935    
936        {
937            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
938            item->signal_activate().connect(
939                sigc::mem_fun(*this, &MainWindow::setupMacros)
940            );
941            menuMacro->append(*item);
942            item->set_accel_path("<Macros>/SetupMacros");
943        }
944    
945        menuMacro->show_all_children();
946    }
947    
948    void MainWindow::onMacroSelected(int iMacro) {
949        printf("onMacroSelected(%d)\n", iMacro);
950        if (iMacro < 0 || iMacro >= m_macros.size()) return;
951        Glib::ustring errorText;
952        try {
953            applyMacro(m_macros[iMacro]);
954        } catch (Serialization::Exception e) {
955            errorText = e.Message;
956        } catch (...) {
957            errorText = _("Unknown exception while applying macro");
958        }
959        if (!errorText.empty()) {
960            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
961            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
962            msg.run();
963        }
964    }
965    
966    void MainWindow::setupMacros() {
967        MacrosSetup* setup = new MacrosSetup();
968        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
969        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
970        setup->signal_macros_changed().connect(
971            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
972        );
973        setup->show();
974    }
975    
976    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
977        m_macros = macros;
978        Settings::singleton()->saveMacros(m_macros);
979        updateMacroMenu();
980    }
981    
982  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
983  {  {
984      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 810  void MainWindow::update_dimregs() Line 1044  void MainWindow::update_dimregs()
1044          }          }
1045      }      }
1046    
1047        m_RegionChooser.setModifyAllRegions(all_regions);
1048      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1049      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1050      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
1051    
1052        updateClipboardCopyAvailable();
1053  }  }
1054    
1055  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 972  void Saver::thread_function() Line 1209  void Saver::thread_function()
1209                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1210                  // then move the saved file over the old file                  // then move the saved file over the old file
1211                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1212                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1213                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1214                  #if defined(WIN32)                  #if defined(WIN32)
1215                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 980  void Saver::thread_function() Line 1217  void Saver::thread_function()
1217                  }                  }
1218                  #else // POSIX ...                  #else // POSIX ...
1219                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1220                      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)));
1221                  }                  }
1222                  #endif                  #endif
1223                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1224                      #if defined(WIN32)                      #if defined(WIN32)
1225                      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).");
1226                      #else                      #else
1227                      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)));
1228                      #endif                      #endif
1229                  }                  }
1230              }              }
# Line 1115  bool MainWindow::close_confirmation_dial Line 1352  bool MainWindow::close_confirmation_dial
1352      g_free(msg);      g_free(msg);
1353      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."));
1354      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1355      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1356      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);
1357      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1358      int response = dialog.run();      int response = dialog.run();
1359      dialog.hide();      dialog.hide();
# Line 1147  bool MainWindow::leaving_shared_mode_dia Line 1384  bool MainWindow::leaving_shared_mode_dia
1384            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1385            "load it."));            "load it."));
1386      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1387      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1388      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1389      int response = dialog.run();      int response = dialog.run();
1390      dialog.hide();      dialog.hide();
# Line 1161  void MainWindow::on_action_file_open() Line 1398  void MainWindow::on_action_file_open()
1398      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1399    
1400      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1401      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1402      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1403      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1404  #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
1405      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1357  void MainWindow::on_action_file_save_as( Line 1594  void MainWindow::on_action_file_save_as(
1594    
1595  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1596  {  {
1597      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1598      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1599      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1600      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1601      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1602    
# Line 1445  void MainWindow::__import_queued_samples Line 1682  void MainWindow::__import_queued_samples
1682      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1683      Glib::ustring error_files;      Glib::ustring error_files;
1684      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1685      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1686           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1687          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1688          SF_INFO info;          SF_INFO info;
1689          info.format = 0;          info.format = 0;
1690          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);
1691          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1692          try {          try {
1693              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1473  void MainWindow::__import_queued_samples Line 1710  void MainWindow::__import_queued_samples
1710                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1711              }              }
1712    
1713                // reset write position for sample
1714                iter->first->SetPos(0);
1715    
1716              const int bufsize = 10000;              const int bufsize = 10000;
1717              switch (bitdepth) {              switch (bitdepth) {
1718                  case 16: {                  case 16: {
# Line 1482  void MainWindow::__import_queued_samples Line 1722  void MainWindow::__import_queued_samples
1722                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1723                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1724                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1725                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1726                          cnt -= n;                          cnt -= n;
1727                      }                      }
1728                      delete[] buffer;                      delete[] buffer;
# Line 1502  void MainWindow::__import_queued_samples Line 1742  void MainWindow::__import_queued_samples
1742                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1743                          }                          }
1744                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1745                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1746                          cnt -= n;                          cnt -= n;
1747                      }                      }
1748                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1513  void MainWindow::__import_queued_samples Line 1753  void MainWindow::__import_queued_samples
1753              // cleanup              // cleanup
1754              sf_close(hFile);              sf_close(hFile);
1755              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1756              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1757              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1758              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1759              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1760              ++iter;              ++iter;
1761              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1762          } catch (std::string what) {          } catch (std::string what) {
1763              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1764              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1765              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1766              ++iter;              ++iter;
1767          }          }
1768      }      }
# Line 1580  void MainWindow::on_action_help_about() Line 1820  void MainWindow::on_action_help_about()
1820      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1821      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1822      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1823        dialog.set_position(Gtk::WIN_POS_CENTER);
1824      dialog.run();      dialog.run();
1825  }  }
1826    
# Line 1601  PropDialog::PropDialog() Line 1842  PropDialog::PropDialog()
1842        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1843        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1844        eSubject(_("Subject")),        eSubject(_("Subject")),
1845        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1846        table(2, 1),        table(2, 1),
1847        m_file(NULL)        m_file(NULL)
1848  {  {
1849        if (!Settings::singleton()->autoRestoreWindowDimension) {
1850            set_default_size(470, 390);
1851            set_position(Gtk::WIN_POS_MOUSE);
1852        }
1853    
1854      set_title(_("File Properties"));      set_title(_("File Properties"));
1855      eName.set_width_chars(50);      eName.set_width_chars(50);
1856    
# Line 1724  void InstrumentProps::set_MIDIProgram(ui Line 1970  void InstrumentProps::set_MIDIProgram(ui
1970  }  }
1971    
1972  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1973      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1974      table(2,1),      table(2,1),
1975      eName(_("Name")),      eName(_("Name")),
1976      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1739  InstrumentProps::InstrumentProps() : Line 1985  InstrumentProps::InstrumentProps() :
1985      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1986      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
1987  {  {
1988        if (!Settings::singleton()->autoRestoreWindowDimension) {
1989            //set_default_size(470, 390);
1990            set_position(Gtk::WIN_POS_MOUSE);
1991        }
1992    
1993      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1994    
1995      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1863  void MainWindow::load_gig(gig::File* gig Line 2114  void MainWindow::load_gig(gig::File* gig
2114      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2115           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2116          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2117            const int iScriptSlots = instrument->ScriptSlotCount();
2118    
2119          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2120          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2121          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2122          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2123          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2124            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2125    
2126          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2127      }      }
# Line 2007  void MainWindow::show_script_slots() { Line 2260  void MainWindow::show_script_slots() {
2260    
2261      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2262      window->setInstrument(instrument);      window->setInstrument(instrument);
2263        window->signal_script_slots_changed().connect(
2264            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2265        );
2266      //window->reparent(*this);      //window->reparent(*this);
2267      window->show();      window->show();
2268  }  }
2269    
2270    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2271        if (!pInstrument) return;
2272        const int iScriptSlots = pInstrument->ScriptSlotCount();
2273    
2274        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2275        for (int i = 0; i < model->children().size(); ++i) {
2276            Gtk::TreeModel::Row row = model->children()[i];
2277            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2278            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2279            break;
2280        }
2281    }
2282    
2283  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2284      __refreshEntireGUI();      __refreshEntireGUI();
2285  }  }
# Line 2325  void MainWindow::add_instrument(gig::Ins Line 2594  void MainWindow::add_instrument(gig::Ins
2594      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2595      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2596      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2597        rowInstr[m_Columns.m_col_scripts] = "";
2598      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2599    
2600      add_instrument_to_menu(name);      add_instrument_to_menu(name);
# Line 2613  void MainWindow::add_or_replace_sample(b Line 2883  void MainWindow::add_or_replace_sample(b
2883    
2884      // show 'browse for file' dialog      // show 'browse for file' dialog
2885      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2886      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2887      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2888      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
2889    
2890      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2744  void MainWindow::add_or_replace_sample(b Line 3014  void MainWindow::add_or_replace_sample(b
3014                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3015                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3016                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3017                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3018                  // add sample to the tree view                  // add sample to the tree view
3019                  if (replace) {                  if (replace) {
3020                      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 2814  void MainWindow::on_action_replace_all_s Line 3084  void MainWindow::on_action_replace_all_s
3084      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3085      description.show();      description.show();
3086      entryArea.show_all();      entryArea.show_all();
3087      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3088      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3089      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3090      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2854  void MainWindow::on_action_replace_all_s Line 3124  void MainWindow::on_action_replace_all_s
3124                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3125                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3126                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3127                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3128                  sf_close(hFile);                  sf_close(hFile);
3129                  file_changed();                  file_changed();
3130              }              }
# Line 2906  void MainWindow::on_action_remove_sample Line 3176  void MainWindow::on_action_remove_sample
3176                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3177                  // them from the import queue                  // them from the import queue
3178                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3179                       member != members.end(); ++member) {                       member != members.end(); ++member)
3180                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3181                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3182                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3183                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3184                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3185                      }                      }
3186                  }                  }
3187                  file_changed();                  file_changed();
# Line 2929  void MainWindow::on_action_remove_sample Line 3196  void MainWindow::on_action_remove_sample
3196                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3197                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3198                  // the import queue                  // the import queue
3199                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3200                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3201                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3202                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3203                  }                  }
3204                  dimreg_changed();                  dimreg_changed();
3205                  file_changed();                  file_changed();
# Line 2992  void MainWindow::on_action_remove_unused Line 3255  void MainWindow::on_action_remove_unused
3255              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3256              // remove sample from the .gig file              // remove sample from the .gig file
3257              file->DeleteSample(sample);              file->DeleteSample(sample);
3258              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3259              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3260                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3261              {                         m_SampleImportQueue[sample].sample_path.c_str());
3262                  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;  
                 }  
3263              }              }
3264          }          }
3265      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3315  void MainWindow::instrument_name_changed Line 3573  void MainWindow::instrument_name_changed
3573  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3574      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3575      d->show_all();      d->show_all();
     d->resize(500, 400);  
3576      d->run();      d->run();
3577      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3578          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3450  void MainWindow::on_action_merge_files() Line 3707  void MainWindow::on_action_merge_files()
3707      }      }
3708    
3709      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3710      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3711      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3712      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3713  #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 3577  void MainWindow::show_scripts_tab() { Line 3834  void MainWindow::show_scripts_tab() {
3834      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3835  }  }
3836    
3837    void MainWindow::select_prev_region() {
3838        m_RegionChooser.select_prev_region();
3839    }
3840    
3841    void MainWindow::select_next_region() {
3842        m_RegionChooser.select_next_region();
3843    }
3844    
3845    void MainWindow::select_next_dim_rgn_zone() {
3846        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3847        m_DimRegionChooser.select_next_dimzone();
3848    }
3849    
3850    void MainWindow::select_prev_dim_rgn_zone() {
3851        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3852        m_DimRegionChooser.select_prev_dimzone();
3853    }
3854    
3855    void MainWindow::select_add_next_dim_rgn_zone() {
3856        m_DimRegionChooser.select_next_dimzone(true);
3857    }
3858    
3859    void MainWindow::select_add_prev_dim_rgn_zone() {
3860        m_DimRegionChooser.select_prev_dimzone(true);
3861    }
3862    
3863    void MainWindow::select_prev_dimension() {
3864        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3865        m_DimRegionChooser.select_prev_dimension();
3866    }
3867    
3868    void MainWindow::select_next_dimension() {
3869        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3870        m_DimRegionChooser.select_next_dimension();
3871    }
3872    
3873    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3874        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3875    
3876    void MainWindow::copy_selected_dimrgn() {
3877        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3878        if (!pDimRgn) {
3879            updateClipboardPasteAvailable();
3880            updateClipboardCopyAvailable();
3881            return;
3882        }
3883    
3884        std::vector<Gtk::TargetEntry> targets;
3885        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3886    
3887        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3888        clipboard->set(
3889            targets,
3890            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3891            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3892        );
3893    
3894        m_serializationArchive.serialize(pDimRgn);
3895    
3896        updateClipboardPasteAvailable();
3897    }
3898    
3899    void MainWindow::paste_copied_dimrgn() {
3900        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3901        clipboard->request_contents(
3902            CLIPBOARD_DIMENSIONREGION_TARGET,
3903            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3904        );
3905        updateClipboardPasteAvailable();
3906    }
3907    
3908    void MainWindow::adjust_clipboard_content() {
3909        MacroEditor* editor = new MacroEditor();
3910        editor->setMacro(&m_serializationArchive, true);
3911        editor->show();
3912    }
3913    
3914    void MainWindow::updateClipboardPasteAvailable() {
3915        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3916        clipboard->request_targets(
3917            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3918        );
3919    }
3920    
3921    void MainWindow::updateClipboardCopyAvailable() {
3922        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3923        static_cast<Gtk::MenuItem*>(
3924            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3925        )->set_sensitive(bDimensionRegionCopyIsPossible);
3926    }
3927    
3928    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3929        updateClipboardPasteAvailable();
3930    }
3931    
3932    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3933        const std::string target = selection_data.get_target();
3934        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3935            selection_data.set(
3936                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3937                &m_serializationArchive.rawData()[0],
3938                m_serializationArchive.rawData().size()
3939            );
3940        } else {
3941            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3942        }
3943    }
3944    
3945    void MainWindow::on_clipboard_clear() {
3946        m_serializationArchive.clear();
3947        updateClipboardPasteAvailable();
3948        updateClipboardCopyAvailable();
3949    }
3950    
3951    //NOTE: Might throw exception !!!
3952    void MainWindow::applyMacro(Serialization::Archive& macro) {
3953        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3954        if (!pDimRgn) return;
3955    
3956        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3957             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3958        {
3959            gig::DimensionRegion* pDimRgn = *itDimReg;
3960            DimRegionChangeGuard(this, pDimRgn);
3961            macro.deserialize(pDimRgn);
3962        }
3963        //region_changed()
3964        file_changed();
3965        dimreg_changed();
3966    }
3967    
3968    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3969        const std::string target = selection_data.get_target();
3970        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3971            Glib::ustring errorText;
3972            try {
3973                m_serializationArchive.decode(
3974                    selection_data.get_data(), selection_data.get_length()
3975                );
3976                applyMacro(m_serializationArchive);
3977            } catch (Serialization::Exception e) {
3978                errorText = e.Message;
3979            } catch (...) {
3980                errorText = _("Unknown exception while pasting DimensionRegion");
3981            }
3982            if (!errorText.empty()) {
3983                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3984                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3985                msg.run();
3986            }
3987        }
3988    }
3989    
3990    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3991        const bool bDimensionRegionPasteIsPossible =
3992            std::find(targets.begin(), targets.end(),
3993                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3994    
3995        static_cast<Gtk::MenuItem*>(
3996            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3997        )->set_sensitive(bDimensionRegionPasteIsPossible);
3998    
3999        static_cast<Gtk::MenuItem*>(
4000            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4001        )->set_sensitive(bDimensionRegionPasteIsPossible);
4002    }
4003    
4004  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4005      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4006  }  }

Legend:
Removed from v.3106  
changed lines
  Added in v.3225

  ViewVC Help
Powered by ViewVC