/[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 3300 by schoenebeck, Sun Jul 9 18:15:02 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    #if defined(__APPLE__)
66    # include "MacHelper.h"
67    #endif
68    
69    static const Gdk::ModifierType primaryModifierKey =
70        #if defined(__APPLE__)
71        Gdk::META_MASK; // Cmd key on Mac
72        #else
73        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
74        #endif
75    
76  MainWindow::MainWindow() :  MainWindow::MainWindow() :
77      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 65  MainWindow::MainWindow() : Line 79  MainWindow::MainWindow() :
79      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
80      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
81      dimreg_stereo(_("both channels")),      dimreg_stereo(_("both channels")),
82        labelLegend(_("Legend:")),
83      labelNoSample(_(" No Sample")),      labelNoSample(_(" No Sample")),
84      labelMissingSample(_(" Missing some Sample(s)")),      labelMissingSample(_(" Missing some Sample(s)")),
85      labelLooped(_(" Looped")),      labelLooped(_(" Looped")),
# Line 73  MainWindow::MainWindow() : Line 88  MainWindow::MainWindow() :
88      loadBuiltInPix();      loadBuiltInPix();
89    
90  //    set_border_width(5);  //    set_border_width(5);
91  //    set_default_size(400, 200);  
92        if (!Settings::singleton()->autoRestoreWindowDimension) {
93            set_default_size(800, 600);
94            set_position(Gtk::WIN_POS_CENTER);
95        }
96    
97      add(m_VBox);      add(m_VBox);
98    
# Line 109  MainWindow::MainWindow() : Line 128  MainWindow::MainWindow() :
128      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
129      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
130      {      {
131            legend_hbox.add(labelLegend);
132    
133          imageNoSample.set(redDot);          imageNoSample.set(redDot);
134          imageNoSample.set_alignment(Gtk::ALIGN_RIGHT);          imageNoSample.set_alignment(Gtk::ALIGN_END);
135          labelNoSample.set_alignment(Gtk::ALIGN_LEFT);          labelNoSample.set_alignment(Gtk::ALIGN_START);
136          legend_hbox.add(imageNoSample);          legend_hbox.add(imageNoSample);
137          legend_hbox.add(labelNoSample);          legend_hbox.add(labelNoSample);
138    
139          imageMissingSample.set(yellowDot);          imageMissingSample.set(yellowDot);
140          imageMissingSample.set_alignment(Gtk::ALIGN_RIGHT);          imageMissingSample.set_alignment(Gtk::ALIGN_END);
141          labelMissingSample.set_alignment(Gtk::ALIGN_LEFT);          labelMissingSample.set_alignment(Gtk::ALIGN_START);
142          legend_hbox.add(imageMissingSample);          legend_hbox.add(imageMissingSample);
143          legend_hbox.add(labelMissingSample);          legend_hbox.add(labelMissingSample);
144    
145          imageLooped.set(blackLoop);          imageLooped.set(blackLoop);
146          imageLooped.set_alignment(Gtk::ALIGN_RIGHT);          imageLooped.set_alignment(Gtk::ALIGN_END);
147          labelLooped.set_alignment(Gtk::ALIGN_LEFT);          labelLooped.set_alignment(Gtk::ALIGN_START);
148          legend_hbox.add(imageLooped);          legend_hbox.add(imageLooped);
149          legend_hbox.add(labelLooped);          legend_hbox.add(labelLooped);
150    
151          imageSomeLoops.set(grayLoop);          imageSomeLoops.set(grayLoop);
152          imageSomeLoops.set_alignment(Gtk::ALIGN_RIGHT);          imageSomeLoops.set_alignment(Gtk::ALIGN_END);
153          labelSomeLoops.set_alignment(Gtk::ALIGN_LEFT);          labelSomeLoops.set_alignment(Gtk::ALIGN_START);
154          legend_hbox.add(imageSomeLoops);          legend_hbox.add(imageSomeLoops);
155          legend_hbox.add(labelSomeLoops);          legend_hbox.add(labelSomeLoops);
156    
# Line 150  MainWindow::MainWindow() : Line 171  MainWindow::MainWindow() :
171      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
172    
173      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
174      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
175                       sigc::mem_fun(                       sigc::mem_fun(
176                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
177      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
178                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
179        action->property_label() = action->property_label() + "...";
180        actionGroup->add(action,
181                       sigc::mem_fun(                       sigc::mem_fun(
182                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
183      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
184                       sigc::mem_fun(                       sigc::mem_fun(
185                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
186      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
187        action->property_label() = action->property_label() + "...";
188        actionGroup->add(action,
189                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
190                       sigc::mem_fun(                       sigc::mem_fun(
191                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
192      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
193                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
194                       sigc::mem_fun(                       sigc::mem_fun(
195                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
196      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
197                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
198                       sigc::mem_fun(                       sigc::mem_fun(
199                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
200      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 182  MainWindow::MainWindow() : Line 205  MainWindow::MainWindow() :
205                                           _("_Script Slots...")),                                           _("_Script Slots...")),
206                       sigc::mem_fun(                       sigc::mem_fun(
207                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
208      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
209                       sigc::mem_fun(                       sigc::mem_fun(
210                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
211      actionGroup->add(      actionGroup->add(
# Line 195  MainWindow::MainWindow() : Line 217  MainWindow::MainWindow() :
217          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
218      );      );
219      actionGroup->add(      actionGroup->add(
220          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
221          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
222      );      );
223      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
224    
225      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
226    
227        const Gdk::ModifierType primaryModifierKey =
228    #if defined(__APPLE__)
229        Gdk::META_MASK; // Cmd key on Mac
230    #else
231        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
232    #endif
233    
234        actionGroup->add(Gtk::Action::create("CopyDimRgn",
235                                             _("Copy selected dimension region")),
236                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
237                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
238    
239        actionGroup->add(Gtk::Action::create("PasteDimRgn",
240                                             _("Paste dimension region")),
241                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
242                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
243    
244        actionGroup->add(Gtk::Action::create("AdjustClipboard",
245                                             _("Adjust Clipboard Content")),
246                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
247                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
248    
249        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
250                                             _("Select Previous Region")),
251                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
252                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
253    
254        actionGroup->add(Gtk::Action::create("SelectNextRegion",
255                                             _("Select Next Region")),
256                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
257                         sigc::mem_fun(*this, &MainWindow::select_next_region));
258    
259        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
260                                             _("Select Previous Dimension Region Zone")),
261                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
262                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
263    
264        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
265                                             _("Select Next Dimension Region Zone")),
266                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
267                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
268    
269        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
270                                             _("Select Previous Dimension")),
271                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
272                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
273    
274        actionGroup->add(Gtk::Action::create("SelectNextDimension",
275                                             _("Select Next Dimension")),
276                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
277                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
278    
279        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
280                                             _("Add Previous Dimension Region Zone to Selection")),
281                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
282                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
283    
284        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
285                                             _("Add Next Dimension Region Zone to Selection")),
286                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
287                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
288    
289      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
290          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
291      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 218  MainWindow::MainWindow() : Line 302  MainWindow::MainWindow() :
302      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
303    
304    
305      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
306    
307    
308        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
309      toggle_action =      toggle_action =
310          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
311      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 245  MainWindow::MainWindow() : Line 332  MainWindow::MainWindow() :
332          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
333      );                      );                
334    
335      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
336      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
337                                             action->property_label()));
338        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
339                       sigc::mem_fun(                       sigc::mem_fun(
340                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
341      actionGroup->add(      actionGroup->add(
# Line 258  MainWindow::MainWindow() : Line 347  MainWindow::MainWindow() :
347          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
348      );      );
349      actionGroup->add(      actionGroup->add(
350          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
351            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
352            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
353        );
354        actionGroup->add(
355            Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
356          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
357      );      );
358    
# Line 305  MainWindow::MainWindow() : Line 399  MainWindow::MainWindow() :
399    
400      // sample right-click popup actions      // sample right-click popup actions
401      actionGroup->add(      actionGroup->add(
402          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
403          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
404      );      );
405      actionGroup->add(      actionGroup->add(
# Line 317  MainWindow::MainWindow() : Line 411  MainWindow::MainWindow() :
411          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
412      );      );
413      actionGroup->add(      actionGroup->add(
414          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
415          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
416      );      );
417      actionGroup->add(      actionGroup->add(
# Line 353  MainWindow::MainWindow() : Line 447  MainWindow::MainWindow() :
447          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
448      );      );
449      actionGroup->add(      actionGroup->add(
450          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
451          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
452      );      );
453    
# Line 376  MainWindow::MainWindow() : Line 470  MainWindow::MainWindow() :
470          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
471          "    </menu>"          "    </menu>"
472          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
473            "      <menuitem action='CopyDimRgn'/>"
474            "      <menuitem action='AdjustClipboard'/>"
475            "      <menuitem action='PasteDimRgn'/>"
476            "      <separator/>"
477            "      <menuitem action='SelectPrevRegion'/>"
478            "      <menuitem action='SelectNextRegion'/>"
479            "      <separator/>"
480            "      <menuitem action='SelectPrevDimension'/>"
481            "      <menuitem action='SelectNextDimension'/>"
482            "      <menuitem action='SelectPrevDimRgnZone'/>"
483            "      <menuitem action='SelectNextDimRgnZone'/>"
484            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
485            "      <menuitem action='SelectAddNextDimRgnZone'/>"
486            "      <separator/>"
487          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
488          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
489          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
490          "    </menu>"          "    </menu>"
491            "    <menu action='MenuMacro'>"
492            "    </menu>"
493          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
494          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
495          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 400  MainWindow::MainWindow() : Line 510  MainWindow::MainWindow() :
510          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
511          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
512          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
513            "      <menuitem action='CombInstruments'/>"
514          "      <separator/>"          "      <separator/>"
515          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
516          "    </menu>"          "    </menu>"
# Line 436  MainWindow::MainWindow() : Line 547  MainWindow::MainWindow() :
547          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
548          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
549          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
550            "    <menuitem action='CombInstruments'/>"
551          "    <separator/>"          "    <separator/>"
552          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
553          "  </popup>"          "  </popup>"
# Line 563  MainWindow::MainWindow() : Line 675  MainWindow::MainWindow() :
675      // Add the TreeView's view columns:      // Add the TreeView's view columns:
676      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
677      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
678        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
679      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
680            
681      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 738  MainWindow::MainWindow() : Line 851  MainWindow::MainWindow() :
851    
852      // select 'Instruments' tab by default      // select 'Instruments' tab by default
853      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
854      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
855    
856        Gtk::Clipboard::get()->signal_owner_change().connect(
857            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
858        );
859        updateClipboardPasteAvailable();
860        updateClipboardCopyAvailable();
861    
862        // setup macros and their keyboard accelerators
863        {
864            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
865                uiManager->get_widget("/MenuBar/MenuMacro")
866            )->get_submenu();
867    
868            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
869            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
870            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
871            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
872            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
873            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
874            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
875            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
876            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
877            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
878            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
879            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
880            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
881            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
882    
883            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
884            menuMacro->set_accel_group(accelGroup);
885    
886            updateMacroMenu();
887        }
888    
889        Glib::signal_idle().connect_once(
890            sigc::mem_fun(*this, &MainWindow::bringToFront),
891            200
892        );
893  }  }
894    
895  MainWindow::~MainWindow()  MainWindow::~MainWindow()
896  {  {
897  }  }
898    
899    void MainWindow::bringToFront() {
900        #if defined(__APPLE__)
901        macRaiseAppWindow();
902        #endif
903        raise();
904        present();
905    }
906    
907    void MainWindow::updateMacroMenu() {
908        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
909            uiManager->get_widget("/MenuBar/MenuMacro")
910        )->get_submenu();
911    
912        // remove all entries from "Macro" menu
913        {
914            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
915            for (int i = 0; i < children.size(); ++i) {
916                Gtk::Widget* child = children[i];
917                menuMacro->remove(*child);
918                delete child;
919            }
920        }
921    
922        // (re)load all macros from config file
923        try {
924            Settings::singleton()->loadMacros(m_macros);
925        } catch (Serialization::Exception e) {
926            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
927        } catch (...) {
928            std::cerr << "Unknown exception while loading macros!" << std::endl;
929        }
930    
931        // add all configured macros as menu items to the "Macro" menu
932        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
933            const Serialization::Archive& macro = m_macros[iMacro];
934            std::string name =
935                macro.name().empty() ?
936                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
937            Gtk::MenuItem* item = new Gtk::MenuItem(name);
938            item->signal_activate().connect(
939                sigc::bind(
940                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
941                )
942            );
943            menuMacro->append(*item);
944            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
945            Glib::ustring comment = macro.comment();
946            if (!comment.empty())
947                item->set_tooltip_text(comment);
948        }
949        // if there are no macros configured at all, then show a dummy entry instead
950        if (m_macros.empty()) {
951            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
952            item->set_sensitive(false);
953            menuMacro->append(*item);
954        }
955    
956        // add separator line to menu
957        menuMacro->append(*new Gtk::SeparatorMenuItem);
958    
959        {
960            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
961            item->signal_activate().connect(
962                sigc::mem_fun(*this, &MainWindow::setupMacros)
963            );
964            menuMacro->append(*item);
965            item->set_accel_path("<Macros>/SetupMacros");
966        }
967    
968        menuMacro->show_all_children();
969    }
970    
971    void MainWindow::onMacroSelected(int iMacro) {
972        printf("onMacroSelected(%d)\n", iMacro);
973        if (iMacro < 0 || iMacro >= m_macros.size()) return;
974        Glib::ustring errorText;
975        try {
976            applyMacro(m_macros[iMacro]);
977        } catch (Serialization::Exception e) {
978            errorText = e.Message;
979        } catch (...) {
980            errorText = _("Unknown exception while applying macro");
981        }
982        if (!errorText.empty()) {
983            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
984            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
985            msg.run();
986        }
987    }
988    
989    void MainWindow::setupMacros() {
990        MacrosSetup* setup = new MacrosSetup();
991        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
992        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
993        setup->signal_macros_changed().connect(
994            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
995        );
996        setup->show();
997    }
998    
999    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1000        m_macros = macros;
1001        Settings::singleton()->saveMacros(m_macros);
1002        updateMacroMenu();
1003    }
1004    
1005  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1006  {  {
1007      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 810  void MainWindow::update_dimregs() Line 1067  void MainWindow::update_dimregs()
1067          }          }
1068      }      }
1069    
1070        m_RegionChooser.setModifyAllRegions(all_regions);
1071      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1072      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1073      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
1074    
1075        updateClipboardCopyAvailable();
1076  }  }
1077    
1078  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 972  void Saver::thread_function() Line 1232  void Saver::thread_function()
1232                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1233                  // then move the saved file over the old file                  // then move the saved file over the old file
1234                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1235                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1236                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1237                  #if defined(WIN32)                  #if defined(WIN32)
1238                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 980  void Saver::thread_function() Line 1240  void Saver::thread_function()
1240                  }                  }
1241                  #else // POSIX ...                  #else // POSIX ...
1242                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1243                      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)));
1244                  }                  }
1245                  #endif                  #endif
1246                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1247                      #if defined(WIN32)                      #if defined(WIN32)
1248                      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).");
1249                      #else                      #else
1250                      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)));
1251                      #endif                      #endif
1252                  }                  }
1253              }              }
# Line 1115  bool MainWindow::close_confirmation_dial Line 1375  bool MainWindow::close_confirmation_dial
1375      g_free(msg);      g_free(msg);
1376      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."));
1377      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1378      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1379      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);
1380      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1381      int response = dialog.run();      int response = dialog.run();
1382      dialog.hide();      dialog.hide();
# Line 1147  bool MainWindow::leaving_shared_mode_dia Line 1407  bool MainWindow::leaving_shared_mode_dia
1407            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1408            "load it."));            "load it."));
1409      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1410      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1411      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1412      int response = dialog.run();      int response = dialog.run();
1413      dialog.hide();      dialog.hide();
# Line 1161  void MainWindow::on_action_file_open() Line 1421  void MainWindow::on_action_file_open()
1421      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1422    
1423      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1424      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1425      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1426      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1427  #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
1428      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1357  void MainWindow::on_action_file_save_as( Line 1617  void MainWindow::on_action_file_save_as(
1617    
1618  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1619  {  {
1620      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1621      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1622      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1623      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1624      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1625    
# Line 1445  void MainWindow::__import_queued_samples Line 1705  void MainWindow::__import_queued_samples
1705      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1706      Glib::ustring error_files;      Glib::ustring error_files;
1707      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1708      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1709           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1710          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1711          SF_INFO info;          SF_INFO info;
1712          info.format = 0;          info.format = 0;
1713          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
1714          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1715          try {          try {
1716              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1473  void MainWindow::__import_queued_samples Line 1733  void MainWindow::__import_queued_samples
1733                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1734              }              }
1735    
1736                // reset write position for sample
1737                iter->first->SetPos(0);
1738    
1739              const int bufsize = 10000;              const int bufsize = 10000;
1740              switch (bitdepth) {              switch (bitdepth) {
1741                  case 16: {                  case 16: {
# Line 1482  void MainWindow::__import_queued_samples Line 1745  void MainWindow::__import_queued_samples
1745                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1746                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1747                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1748                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1749                          cnt -= n;                          cnt -= n;
1750                      }                      }
1751                      delete[] buffer;                      delete[] buffer;
# Line 1502  void MainWindow::__import_queued_samples Line 1765  void MainWindow::__import_queued_samples
1765                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1766                          }                          }
1767                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1768                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1769                          cnt -= n;                          cnt -= n;
1770                      }                      }
1771                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1513  void MainWindow::__import_queued_samples Line 1776  void MainWindow::__import_queued_samples
1776              // cleanup              // cleanup
1777              sf_close(hFile);              sf_close(hFile);
1778              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1779              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1780              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1781              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1782              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1783              ++iter;              ++iter;
1784              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1785          } catch (std::string what) {          } catch (std::string what) {
1786              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1787              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1788              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1789              ++iter;              ++iter;
1790          }          }
1791      }      }
# Line 1580  void MainWindow::on_action_help_about() Line 1843  void MainWindow::on_action_help_about()
1843      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1844      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1845      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1846        dialog.set_position(Gtk::WIN_POS_CENTER);
1847      dialog.run();      dialog.run();
1848  }  }
1849    
# Line 1601  PropDialog::PropDialog() Line 1865  PropDialog::PropDialog()
1865        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1866        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1867        eSubject(_("Subject")),        eSubject(_("Subject")),
1868        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1869        table(2, 1),        table(2, 1),
1870        m_file(NULL)        m_file(NULL)
1871  {  {
1872        if (!Settings::singleton()->autoRestoreWindowDimension) {
1873            set_default_size(470, 390);
1874            set_position(Gtk::WIN_POS_MOUSE);
1875        }
1876    
1877      set_title(_("File Properties"));      set_title(_("File Properties"));
1878      eName.set_width_chars(50);      eName.set_width_chars(50);
1879    
# Line 1724  void InstrumentProps::set_MIDIProgram(ui Line 1993  void InstrumentProps::set_MIDIProgram(ui
1993  }  }
1994    
1995  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
1996      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
1997      table(2,1),      table(2,1),
1998      eName(_("Name")),      eName(_("Name")),
1999      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1739  InstrumentProps::InstrumentProps() : Line 2008  InstrumentProps::InstrumentProps() :
2008      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2009      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2010  {  {
2011        if (!Settings::singleton()->autoRestoreWindowDimension) {
2012            //set_default_size(470, 390);
2013            set_position(Gtk::WIN_POS_MOUSE);
2014        }
2015    
2016      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2017    
2018      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1863  void MainWindow::load_gig(gig::File* gig Line 2137  void MainWindow::load_gig(gig::File* gig
2137      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2138           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2139          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2140            const int iScriptSlots = instrument->ScriptSlotCount();
2141    
2142          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2143          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2144          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2145          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2146          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2147            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2148    
2149          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2150      }      }
# Line 2007  void MainWindow::show_script_slots() { Line 2283  void MainWindow::show_script_slots() {
2283    
2284      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2285      window->setInstrument(instrument);      window->setInstrument(instrument);
2286        window->signal_script_slots_changed().connect(
2287            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2288        );
2289      //window->reparent(*this);      //window->reparent(*this);
2290      window->show();      window->show();
2291  }  }
2292    
2293    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2294        if (!pInstrument) return;
2295        const int iScriptSlots = pInstrument->ScriptSlotCount();
2296    
2297        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2298        for (int i = 0; i < model->children().size(); ++i) {
2299            Gtk::TreeModel::Row row = model->children()[i];
2300            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2301            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2302            break;
2303        }
2304    }
2305    
2306  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2307      __refreshEntireGUI();      __refreshEntireGUI();
2308  }  }
# Line 2325  void MainWindow::add_instrument(gig::Ins Line 2617  void MainWindow::add_instrument(gig::Ins
2617      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2618      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2619      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2620        rowInstr[m_Columns.m_col_scripts] = "";
2621      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2622    
2623      add_instrument_to_menu(name);      add_instrument_to_menu(name);
2624    
2625      m_TreeView.get_selection()->select(iterInstr);      m_TreeView.get_selection()->select(iterInstr);
2626        m_TreeView.scroll_to_row(Gtk::TreePath(iterInstr));
2627    
2628      file_changed();      file_changed();
2629  }  }
# Line 2613  void MainWindow::add_or_replace_sample(b Line 2907  void MainWindow::add_or_replace_sample(b
2907    
2908      // show 'browse for file' dialog      // show 'browse for file' dialog
2909      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2910      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2911      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2912      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
2913    
2914      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2744  void MainWindow::add_or_replace_sample(b Line 3038  void MainWindow::add_or_replace_sample(b
3038                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3039                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3040                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3041                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3042                  // add sample to the tree view                  // add sample to the tree view
3043                  if (replace) {                  if (replace) {
3044                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2814  void MainWindow::on_action_replace_all_s Line 3108  void MainWindow::on_action_replace_all_s
3108      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3109      description.show();      description.show();
3110      entryArea.show_all();      entryArea.show_all();
3111      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3112      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3113      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3114      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2854  void MainWindow::on_action_replace_all_s Line 3148  void MainWindow::on_action_replace_all_s
3148                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3149                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3150                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3151                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3152                  sf_close(hFile);                  sf_close(hFile);
3153                  file_changed();                  file_changed();
3154              }              }
# Line 2906  void MainWindow::on_action_remove_sample Line 3200  void MainWindow::on_action_remove_sample
3200                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3201                  // them from the import queue                  // them from the import queue
3202                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3203                       member != members.end(); ++member) {                       member != members.end(); ++member)
3204                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3205                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3206                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3207                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3208                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3209                      }                      }
3210                  }                  }
3211                  file_changed();                  file_changed();
# Line 2929  void MainWindow::on_action_remove_sample Line 3220  void MainWindow::on_action_remove_sample
3220                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3221                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3222                  // the import queue                  // the import queue
3223                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3224                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3225                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3226                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3227                  }                  }
3228                  dimreg_changed();                  dimreg_changed();
3229                  file_changed();                  file_changed();
# Line 2992  void MainWindow::on_action_remove_unused Line 3279  void MainWindow::on_action_remove_unused
3279              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3280              // remove sample from the .gig file              // remove sample from the .gig file
3281              file->DeleteSample(sample);              file->DeleteSample(sample);
3282              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3283              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3284                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3285              {                         m_SampleImportQueue[sample].sample_path.c_str());
3286                  if ((*iter).gig_sample == sample) {                  m_SampleImportQueue.erase(sample);
                     printf("Removing previously added sample '%s'\n",  
                            (*iter).sample_path.c_str());  
                     m_SampleImportQueue.erase(iter);  
                     break;  
                 }  
3287              }              }
3288          }          }
3289      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3314  void MainWindow::instrument_name_changed Line 3596  void MainWindow::instrument_name_changed
3596    
3597  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3598      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3599    
3600        // take over selection from instruments list view for the combine dialog's
3601        // list view as pre-selection
3602        std::set<int> indeces;
3603        {
3604            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3605            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3606            for (int r = 0; r < rows.size(); ++r) {
3607                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3608                if (it) {
3609                    Gtk::TreeModel::Row row = *it;
3610                    int index = row[m_Columns.m_col_nr];
3611                    indeces.insert(index);
3612                }
3613            }
3614        }
3615        d->setSelectedInstruments(indeces);
3616    
3617      d->show_all();      d->show_all();
     d->resize(500, 400);  
3618      d->run();      d->run();
3619      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3620          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3450  void MainWindow::on_action_merge_files() Line 3749  void MainWindow::on_action_merge_files()
3749      }      }
3750    
3751      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3752      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3753      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3754      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3755  #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 3876  void MainWindow::show_scripts_tab() {
3876      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3877  }  }
3878    
3879    void MainWindow::select_prev_region() {
3880        m_RegionChooser.select_prev_region();
3881    }
3882    
3883    void MainWindow::select_next_region() {
3884        m_RegionChooser.select_next_region();
3885    }
3886    
3887    void MainWindow::select_next_dim_rgn_zone() {
3888        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3889        m_DimRegionChooser.select_next_dimzone();
3890    }
3891    
3892    void MainWindow::select_prev_dim_rgn_zone() {
3893        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3894        m_DimRegionChooser.select_prev_dimzone();
3895    }
3896    
3897    void MainWindow::select_add_next_dim_rgn_zone() {
3898        m_DimRegionChooser.select_next_dimzone(true);
3899    }
3900    
3901    void MainWindow::select_add_prev_dim_rgn_zone() {
3902        m_DimRegionChooser.select_prev_dimzone(true);
3903    }
3904    
3905    void MainWindow::select_prev_dimension() {
3906        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3907        m_DimRegionChooser.select_prev_dimension();
3908    }
3909    
3910    void MainWindow::select_next_dimension() {
3911        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3912        m_DimRegionChooser.select_next_dimension();
3913    }
3914    
3915    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3916        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3917    
3918    void MainWindow::copy_selected_dimrgn() {
3919        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3920        if (!pDimRgn) {
3921            updateClipboardPasteAvailable();
3922            updateClipboardCopyAvailable();
3923            return;
3924        }
3925    
3926        std::vector<Gtk::TargetEntry> targets;
3927        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3928    
3929        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3930        clipboard->set(
3931            targets,
3932            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3933            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3934        );
3935    
3936        m_serializationArchive.serialize(pDimRgn);
3937    
3938        updateClipboardPasteAvailable();
3939    }
3940    
3941    void MainWindow::paste_copied_dimrgn() {
3942        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3943        clipboard->request_contents(
3944            CLIPBOARD_DIMENSIONREGION_TARGET,
3945            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3946        );
3947        updateClipboardPasteAvailable();
3948    }
3949    
3950    void MainWindow::adjust_clipboard_content() {
3951        MacroEditor* editor = new MacroEditor();
3952        editor->setMacro(&m_serializationArchive, true);
3953        editor->show();
3954    }
3955    
3956    void MainWindow::updateClipboardPasteAvailable() {
3957        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3958        clipboard->request_targets(
3959            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3960        );
3961    }
3962    
3963    void MainWindow::updateClipboardCopyAvailable() {
3964        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3965        static_cast<Gtk::MenuItem*>(
3966            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3967        )->set_sensitive(bDimensionRegionCopyIsPossible);
3968    }
3969    
3970    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3971        updateClipboardPasteAvailable();
3972    }
3973    
3974    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3975        const std::string target = selection_data.get_target();
3976        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3977            selection_data.set(
3978                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3979                &m_serializationArchive.rawData()[0],
3980                m_serializationArchive.rawData().size()
3981            );
3982        } else {
3983            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3984        }
3985    }
3986    
3987    void MainWindow::on_clipboard_clear() {
3988        m_serializationArchive.clear();
3989        updateClipboardPasteAvailable();
3990        updateClipboardCopyAvailable();
3991    }
3992    
3993    //NOTE: Might throw exception !!!
3994    void MainWindow::applyMacro(Serialization::Archive& macro) {
3995        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3996        if (!pDimRgn) return;
3997    
3998        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3999             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
4000        {
4001            gig::DimensionRegion* pDimRgn = *itDimReg;
4002            DimRegionChangeGuard(this, pDimRgn);
4003            macro.deserialize(pDimRgn);
4004        }
4005        //region_changed()
4006        file_changed();
4007        dimreg_changed();
4008    }
4009    
4010    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
4011        const std::string target = selection_data.get_target();
4012        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4013            Glib::ustring errorText;
4014            try {
4015                m_serializationArchive.decode(
4016                    selection_data.get_data(), selection_data.get_length()
4017                );
4018                applyMacro(m_serializationArchive);
4019            } catch (Serialization::Exception e) {
4020                errorText = e.Message;
4021            } catch (...) {
4022                errorText = _("Unknown exception while pasting DimensionRegion");
4023            }
4024            if (!errorText.empty()) {
4025                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
4026                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4027                msg.run();
4028            }
4029        }
4030    }
4031    
4032    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
4033        const bool bDimensionRegionPasteIsPossible =
4034            std::find(targets.begin(), targets.end(),
4035                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
4036    
4037        static_cast<Gtk::MenuItem*>(
4038            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4039        )->set_sensitive(bDimensionRegionPasteIsPossible);
4040    
4041        static_cast<Gtk::MenuItem*>(
4042            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4043        )->set_sensitive(bDimensionRegionPasteIsPossible);
4044    }
4045    
4046  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4047      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4048  }  }

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

  ViewVC Help
Powered by ViewVC