/[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 3344 by schoenebeck, Wed Aug 2 10:39:46 2017 UTC
# Line 32  Line 32 
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
39    #include <gtkmm/stock.h>
40  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
41  #include <gtkmm/main.h>  #include <gtkmm/main.h>
42  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
43    #include <gtkmm/accelmap.h>
44  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
45  #include "wrapLabel.hh"  #include "wrapLabel.hh"
46  #endif  #endif
# Line 58  Line 61 
61  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
62  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
63  #include "gfx/builtinpix.h"  #include "gfx/builtinpix.h"
64    #include "MacroEditor.h"
65    #include "MacrosSetup.h"
66    #if defined(__APPLE__)
67    # include "MacHelper.h"
68    #endif
69    
70    static const Gdk::ModifierType primaryModifierKey =
71        #if defined(__APPLE__)
72        Gdk::META_MASK; // Cmd key on Mac
73        #else
74        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
75        #endif
76    
77  MainWindow::MainWindow() :  MainWindow::MainWindow() :
78      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 65  MainWindow::MainWindow() : Line 80  MainWindow::MainWindow() :
80      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
81      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
82      dimreg_stereo(_("both channels")),      dimreg_stereo(_("both channels")),
83        labelLegend(_("Legend:")),
84      labelNoSample(_(" No Sample")),      labelNoSample(_(" No Sample")),
85      labelMissingSample(_(" Missing some Sample(s)")),      labelMissingSample(_(" Missing some Sample(s)")),
86      labelLooped(_(" Looped")),      labelLooped(_(" Looped")),
# Line 72  MainWindow::MainWindow() : Line 88  MainWindow::MainWindow() :
88  {  {
89      loadBuiltInPix();      loadBuiltInPix();
90    
91        this->file = NULL;
92    
93  //    set_border_width(5);  //    set_border_width(5);
94  //    set_default_size(400, 200);  
95        if (!Settings::singleton()->autoRestoreWindowDimension) {
96            set_default_size(800, 600);
97            set_position(Gtk::WIN_POS_CENTER);
98        }
99    
100      add(m_VBox);      add(m_VBox);
101    
# Line 100  MainWindow::MainWindow() : Line 122  MainWindow::MainWindow() :
122    
123      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
124    
125      m_HPaned.add1(m_TreeViewNotebook);      m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
126        m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
127        m_searchField.pack_start(m_searchText);
128        m_searchField.set_spacing(5);
129    
130        m_left_vbox.pack_start(m_TreeViewNotebook);
131        m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
132    
133        m_HPaned.add1(m_left_vbox);
134    
135      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
136      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
137      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 109  MainWindow::MainWindow() : Line 140  MainWindow::MainWindow() :
140      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
141      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
142      {      {
143            legend_hbox.add(labelLegend);
144    
145          imageNoSample.set(redDot);          imageNoSample.set(redDot);
146          imageNoSample.set_alignment(Gtk::ALIGN_RIGHT);          imageNoSample.set_alignment(Gtk::ALIGN_END);
147          labelNoSample.set_alignment(Gtk::ALIGN_LEFT);          labelNoSample.set_alignment(Gtk::ALIGN_START);
148          legend_hbox.add(imageNoSample);          legend_hbox.add(imageNoSample);
149          legend_hbox.add(labelNoSample);          legend_hbox.add(labelNoSample);
150    
151          imageMissingSample.set(yellowDot);          imageMissingSample.set(yellowDot);
152          imageMissingSample.set_alignment(Gtk::ALIGN_RIGHT);          imageMissingSample.set_alignment(Gtk::ALIGN_END);
153          labelMissingSample.set_alignment(Gtk::ALIGN_LEFT);          labelMissingSample.set_alignment(Gtk::ALIGN_START);
154          legend_hbox.add(imageMissingSample);          legend_hbox.add(imageMissingSample);
155          legend_hbox.add(labelMissingSample);          legend_hbox.add(labelMissingSample);
156    
157          imageLooped.set(blackLoop);          imageLooped.set(blackLoop);
158          imageLooped.set_alignment(Gtk::ALIGN_RIGHT);          imageLooped.set_alignment(Gtk::ALIGN_END);
159          labelLooped.set_alignment(Gtk::ALIGN_LEFT);          labelLooped.set_alignment(Gtk::ALIGN_START);
160          legend_hbox.add(imageLooped);          legend_hbox.add(imageLooped);
161          legend_hbox.add(labelLooped);          legend_hbox.add(labelLooped);
162    
163          imageSomeLoops.set(grayLoop);          imageSomeLoops.set(grayLoop);
164          imageSomeLoops.set_alignment(Gtk::ALIGN_RIGHT);          imageSomeLoops.set_alignment(Gtk::ALIGN_END);
165          labelSomeLoops.set_alignment(Gtk::ALIGN_LEFT);          labelSomeLoops.set_alignment(Gtk::ALIGN_START);
166          legend_hbox.add(imageSomeLoops);          legend_hbox.add(imageSomeLoops);
167          legend_hbox.add(labelSomeLoops);          legend_hbox.add(labelSomeLoops);
168    
# Line 150  MainWindow::MainWindow() : Line 183  MainWindow::MainWindow() :
183      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
184    
185      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
186      actionGroup->add(Gtk::Action::create("New", _("_New")),      actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
                      Gtk::AccelKey("<control>n"),  
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_file_new));                           *this, &MainWindow::on_action_file_new));
189      actionGroup->add(Gtk::Action::create("Open", _("_Open...")),      Glib::RefPtr<Gtk::Action> action =
190                       Gtk::AccelKey("<control>o"),          Gtk::Action::create("Open", Gtk::Stock::OPEN);
191        action->property_label() = action->property_label() + "...";
192        actionGroup->add(action,
193                       sigc::mem_fun(                       sigc::mem_fun(
194                           *this, &MainWindow::on_action_file_open));                           *this, &MainWindow::on_action_file_open));
195      actionGroup->add(Gtk::Action::create("Save", _("_Save")),      actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
                      Gtk::AccelKey("<control>s"),  
196                       sigc::mem_fun(                       sigc::mem_fun(
197                           *this, &MainWindow::on_action_file_save));                           *this, &MainWindow::on_action_file_save));
198      actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")),      action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
199        action->property_label() = action->property_label() + "...";
200        actionGroup->add(action,
201                       Gtk::AccelKey("<shift><control>s"),                       Gtk::AccelKey("<shift><control>s"),
202                       sigc::mem_fun(                       sigc::mem_fun(
203                           *this, &MainWindow::on_action_file_save_as));                           *this, &MainWindow::on_action_file_save_as));
204      actionGroup->add(Gtk::Action::create("Properties",      actionGroup->add(Gtk::Action::create("Properties",
205                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
206                       sigc::mem_fun(                       sigc::mem_fun(
207                           *this, &MainWindow::on_action_file_properties));                           *this, &MainWindow::on_action_file_properties));
208      actionGroup->add(Gtk::Action::create("InstrProperties",      actionGroup->add(Gtk::Action::create("InstrProperties",
209                                           _("_Properties")),                                           Gtk::Stock::PROPERTIES),
210                       sigc::mem_fun(                       sigc::mem_fun(
211                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
212      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
# Line 182  MainWindow::MainWindow() : Line 217  MainWindow::MainWindow() :
217                                           _("_Script Slots...")),                                           _("_Script Slots...")),
218                       sigc::mem_fun(                       sigc::mem_fun(
219                           *this, &MainWindow::show_script_slots));                           *this, &MainWindow::show_script_slots));
220      actionGroup->add(Gtk::Action::create("Quit", _("_Quit")),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
                      Gtk::AccelKey("<control>q"),  
221                       sigc::mem_fun(                       sigc::mem_fun(
222                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
223      actionGroup->add(      actionGroup->add(
# Line 195  MainWindow::MainWindow() : Line 229  MainWindow::MainWindow() :
229          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
230      );      );
231      actionGroup->add(      actionGroup->add(
232          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
233          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
234      );      );
235      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
236        actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
237    
238      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
239    
240        const Gdk::ModifierType primaryModifierKey =
241    #if defined(__APPLE__)
242        Gdk::META_MASK; // Cmd key on Mac
243    #else
244        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
245    #endif
246    
247        actionGroup->add(Gtk::Action::create("CopyDimRgn",
248                                             _("Copy selected dimension region")),
249                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
250                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
251    
252        actionGroup->add(Gtk::Action::create("PasteDimRgn",
253                                             _("Paste dimension region")),
254                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
255                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
256    
257        actionGroup->add(Gtk::Action::create("AdjustClipboard",
258                                             _("Adjust Clipboard Content")),
259                         Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
260                         sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
261    
262        actionGroup->add(Gtk::Action::create("SelectPrevInstr",
263                                             _("Select Previous Instrument")),
264                         Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
265                         sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
266    
267        actionGroup->add(Gtk::Action::create("SelectNextInstr",
268                                             _("Select Next Instrument")),
269                         Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
270                         sigc::mem_fun(*this, &MainWindow::select_next_instrument));
271    
272        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
273                                             _("Select Previous Region")),
274                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
275                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
276    
277        actionGroup->add(Gtk::Action::create("SelectNextRegion",
278                                             _("Select Next Region")),
279                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
280                         sigc::mem_fun(*this, &MainWindow::select_next_region));
281    
282        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
283                                             _("Select Previous Dimension Region Zone")),
284                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
285                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
286    
287        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
288                                             _("Select Next Dimension Region Zone")),
289                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
290                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
291    
292        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
293                                             _("Select Previous Dimension")),
294                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
295                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
296    
297        actionGroup->add(Gtk::Action::create("SelectNextDimension",
298                                             _("Select Next Dimension")),
299                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
300                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
301    
302        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
303                                             _("Add Previous Dimension Region Zone to Selection")),
304                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
305                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
306    
307        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
308                                             _("Add Next Dimension Region Zone to Selection")),
309                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
310                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
311    
312      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
313          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
314      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 218  MainWindow::MainWindow() : Line 325  MainWindow::MainWindow() :
325      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
326    
327    
328      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
329    
330    
331        actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
332      toggle_action =      toggle_action =
333          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
334      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 245  MainWindow::MainWindow() : Line 355  MainWindow::MainWindow() :
355          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
356      );                      );                
357    
358      actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
359      actionGroup->add(Gtk::Action::create("About", _("_About")),      actionGroup->add(Gtk::Action::create("MenuHelp",
360                                             action->property_label()));
361        actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
362                       sigc::mem_fun(                       sigc::mem_fun(
363                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
364      actionGroup->add(      actionGroup->add(
# Line 258  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
371      );      );
372      actionGroup->add(      actionGroup->add(
373          Gtk::Action::create("RemoveInstrument", _("_Remove")),          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
374            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
375            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
376        );
377        actionGroup->add(
378            Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
379          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
380      );      );
381    
# Line 305  MainWindow::MainWindow() : Line 422  MainWindow::MainWindow() :
422    
423      // sample right-click popup actions      // sample right-click popup actions
424      actionGroup->add(      actionGroup->add(
425          Gtk::Action::create("SampleProperties", _("_Properties")),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
426          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)          sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
427      );      );
428      actionGroup->add(      actionGroup->add(
# Line 317  MainWindow::MainWindow() : Line 434  MainWindow::MainWindow() :
434          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
435      );      );
436      actionGroup->add(      actionGroup->add(
437          Gtk::Action::create("RemoveSample", _("_Remove")),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
438          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
439      );      );
440      actionGroup->add(      actionGroup->add(
# Line 353  MainWindow::MainWindow() : Line 470  MainWindow::MainWindow() :
470          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)          sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
471      );      );
472      actionGroup->add(      actionGroup->add(
473          Gtk::Action::create("RemoveScript", _("_Remove")),          Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
474          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)          sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
475      );      );
476    
# Line 376  MainWindow::MainWindow() : Line 493  MainWindow::MainWindow() :
493          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
494          "    </menu>"          "    </menu>"
495          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
496            "      <menuitem action='CopyDimRgn'/>"
497            "      <menuitem action='AdjustClipboard'/>"
498            "      <menuitem action='PasteDimRgn'/>"
499            "      <separator/>"
500            "      <menuitem action='SelectPrevInstr'/>"
501            "      <menuitem action='SelectNextInstr'/>"
502            "      <separator/>"
503            "      <menuitem action='SelectPrevRegion'/>"
504            "      <menuitem action='SelectNextRegion'/>"
505            "      <separator/>"
506            "      <menuitem action='SelectPrevDimension'/>"
507            "      <menuitem action='SelectNextDimension'/>"
508            "      <menuitem action='SelectPrevDimRgnZone'/>"
509            "      <menuitem action='SelectNextDimRgnZone'/>"
510            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
511            "      <menuitem action='SelectAddNextDimRgnZone'/>"
512            "      <separator/>"
513          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
514          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
515          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
516          "    </menu>"          "    </menu>"
517            "    <menu action='MenuMacro'>"
518            "    </menu>"
519          "    <menu action='MenuSample'>"          "    <menu action='MenuSample'>"
520          "      <menuitem action='SampleProperties'/>"          "      <menuitem action='SampleProperties'/>"
521          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
# Line 398  MainWindow::MainWindow() : Line 534  MainWindow::MainWindow() :
534          "      <menuitem action='InstrProperties'/>"          "      <menuitem action='InstrProperties'/>"
535          "      <menuitem action='MidiRules'/>"          "      <menuitem action='MidiRules'/>"
536          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
537            "      <menu action='AssignScripts'/>"
538          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
539          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
540            "      <menuitem action='CombInstruments'/>"
541          "      <separator/>"          "      <separator/>"
542          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
543          "    </menu>"          "    </menu>"
# Line 436  MainWindow::MainWindow() : Line 574  MainWindow::MainWindow() :
574          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
575          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
576          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
577            "    <menuitem action='CombInstruments'/>"
578          "    <separator/>"          "    <separator/>"
579          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
580          "  </popup>"          "  </popup>"
# Line 530  MainWindow::MainWindow() : Line 669  MainWindow::MainWindow() :
669      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
670          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
671    
672        assign_scripts_menu = static_cast<Gtk::MenuItem*>(
673            uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
674    
675      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
676      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
677      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 553  MainWindow::MainWindow() : Line 695  MainWindow::MainWindow() :
695    
696      // Create the Tree model:      // Create the Tree model:
697      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
698      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
699        m_refTreeModelFilter->set_visible_func(
700            sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
701        );
702        m_TreeView.set_model(m_refTreeModelFilter);
703    
704      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
705      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
706      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
# Line 563  MainWindow::MainWindow() : Line 710  MainWindow::MainWindow() :
710      // Add the TreeView's view columns:      // Add the TreeView's view columns:
711      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
712      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
713        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
714      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
715            
716      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 728  MainWindow::MainWindow() : Line 876  MainWindow::MainWindow() :
876      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
877          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
878    
879        m_searchText.signal_changed().connect(
880            sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
881        );
882    
883      file = 0;      file = 0;
884      file_is_changed = false;      file_is_changed = false;
885    
# Line 736  MainWindow::MainWindow() : Line 888  MainWindow::MainWindow() :
888      // start with a new gig file by default      // start with a new gig file by default
889      on_action_file_new();      on_action_file_new();
890    
891        m_TreeViewNotebook.signal_switch_page().connect(
892            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
893        );
894    
895      // select 'Instruments' tab by default      // select 'Instruments' tab by default
896      // (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)
897      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
898    
899        Gtk::Clipboard::get()->signal_owner_change().connect(
900            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
901        );
902        updateClipboardPasteAvailable();
903        updateClipboardCopyAvailable();
904    
905        // setup macros and their keyboard accelerators
906        {
907            Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
908                uiManager->get_widget("/MenuBar/MenuMacro")
909            )->get_submenu();
910    
911            const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
912            Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
913            Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
914            Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
915            Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
916            Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
917            Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
918            Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
919            Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
920            Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
921            Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
922            Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
923            Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
924            Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
925    
926            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
927            menuMacro->set_accel_group(accelGroup);
928    
929            updateMacroMenu();
930        }
931    
932        // setup "Assign Scripts" keyboard accelerators
933        {
934            Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
935            Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
936            Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
937            Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
938            Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
939            Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
940            Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
941            Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
942            Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
943            Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
944            Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
945            Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
946    
947            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
948            assign_scripts_menu->set_accel_group(accelGroup);
949        }
950    
951        Glib::signal_idle().connect_once(
952            sigc::mem_fun(*this, &MainWindow::bringToFront),
953            200
954        );
955  }  }
956    
957  MainWindow::~MainWindow()  MainWindow::~MainWindow()
958  {  {
959  }  }
960    
961    void MainWindow::bringToFront() {
962        #if defined(__APPLE__)
963        macRaiseAppWindow();
964        #endif
965        raise();
966        present();
967    }
968    
969    void MainWindow::updateMacroMenu() {
970        Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
971            uiManager->get_widget("/MenuBar/MenuMacro")
972        )->get_submenu();
973    
974        // remove all entries from "Macro" menu
975        {
976            const std::vector<Gtk::Widget*> children = menuMacro->get_children();
977            for (int i = 0; i < children.size(); ++i) {
978                Gtk::Widget* child = children[i];
979                menuMacro->remove(*child);
980                delete child;
981            }
982        }
983    
984        // (re)load all macros from config file
985        try {
986            Settings::singleton()->loadMacros(m_macros);
987        } catch (Serialization::Exception e) {
988            std::cerr << "Exception while loading macros: " << e.Message << std::endl;
989        } catch (...) {
990            std::cerr << "Unknown exception while loading macros!" << std::endl;
991        }
992    
993        // add all configured macros as menu items to the "Macro" menu
994        for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
995            const Serialization::Archive& macro = m_macros[iMacro];
996            std::string name =
997                macro.name().empty() ?
998                    (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
999            Gtk::MenuItem* item = new Gtk::MenuItem(name);
1000            item->signal_activate().connect(
1001                sigc::bind(
1002                    sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1003                )
1004            );
1005            menuMacro->append(*item);
1006            item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1007            Glib::ustring comment = macro.comment();
1008            if (!comment.empty())
1009                item->set_tooltip_text(comment);
1010        }
1011        // if there are no macros configured at all, then show a dummy entry instead
1012        if (m_macros.empty()) {
1013            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1014            item->set_sensitive(false);
1015            menuMacro->append(*item);
1016        }
1017    
1018        // add separator line to menu
1019        menuMacro->append(*new Gtk::SeparatorMenuItem);
1020    
1021        {
1022            Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1023            item->signal_activate().connect(
1024                sigc::mem_fun(*this, &MainWindow::setupMacros)
1025            );
1026            menuMacro->append(*item);
1027            item->set_accel_path("<Macros>/SetupMacros");
1028        }
1029    
1030        menuMacro->show_all_children();
1031    }
1032    
1033    void MainWindow::onMacroSelected(int iMacro) {
1034        printf("onMacroSelected(%d)\n", iMacro);
1035        if (iMacro < 0 || iMacro >= m_macros.size()) return;
1036        Glib::ustring errorText;
1037        try {
1038            applyMacro(m_macros[iMacro]);
1039        } catch (Serialization::Exception e) {
1040            errorText = e.Message;
1041        } catch (...) {
1042            errorText = _("Unknown exception while applying macro");
1043        }
1044        if (!errorText.empty()) {
1045            Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1046            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1047            msg.run();
1048        }
1049    }
1050    
1051    void MainWindow::setupMacros() {
1052        MacrosSetup* setup = new MacrosSetup();
1053        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1054        setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1055        setup->signal_macros_changed().connect(
1056            sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1057        );
1058        setup->show();
1059    }
1060    
1061    void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1062        m_macros = macros;
1063        Settings::singleton()->saveMacros(m_macros);
1064        updateMacroMenu();
1065    }
1066    
1067    //NOTE: the actual signal's first argument for argument 'page' is on some gtkmm version GtkNotebookPage* and on some Gtk::Widget*. Since we don't need that argument, it is simply void* here for now.
1068    void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1069        bool isInstrumentsPage = (page_num == 1);
1070        // so far we only support filtering for the instruments list, so hide the
1071        // filter text entry field if another tab is selected
1072        m_searchField.set_visible(isInstrumentsPage);
1073    }
1074    
1075  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1076  {  {
1077      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 1137  void MainWindow::update_dimregs()
1137          }          }
1138      }      }
1139    
1140        m_RegionChooser.setModifyAllRegions(all_regions);
1141      m_DimRegionChooser.setModifyAllRegions(all_regions);      m_DimRegionChooser.setModifyAllRegions(all_regions);
1142      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);      m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1143      m_DimRegionChooser.setModifyBothChannels(stereo);      m_DimRegionChooser.setModifyBothChannels(stereo);
1144    
1145        updateClipboardCopyAvailable();
1146  }  }
1147    
1148  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 842  void MainWindow::on_sel_change() Line 1172  void MainWindow::on_sel_change()
1172          }          }
1173      }      }
1174    
1175        updateScriptListOfMenu();
1176    
1177      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
1178    
1179      if (Settings::singleton()->syncSamplerInstrumentSelection) {      if (Settings::singleton()->syncSamplerInstrumentSelection) {
# Line 972  void Saver::thread_function() Line 1304  void Saver::thread_function()
1304                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1305                  // then move the saved file over the old file                  // then move the saved file over the old file
1306                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1307                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1308                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1309                  #if defined(WIN32)                  #if defined(WIN32)
1310                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 980  void Saver::thread_function() Line 1312  void Saver::thread_function()
1312                  }                  }
1313                  #else // POSIX ...                  #else // POSIX ...
1314                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1315                      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)));
1316                  }                  }
1317                  #endif                  #endif
1318                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1319                      #if defined(WIN32)                      #if defined(WIN32)
1320                      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).");
1321                      #else                      #else
1322                      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)));
1323                      #endif                      #endif
1324                  }                  }
1325              }              }
# Line 1115  bool MainWindow::close_confirmation_dial Line 1447  bool MainWindow::close_confirmation_dial
1447      g_free(msg);      g_free(msg);
1448      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."));
1449      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
1450      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1451      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);
1452      dialog.set_default_response(Gtk::RESPONSE_YES);      dialog.set_default_response(Gtk::RESPONSE_YES);
1453      int response = dialog.run();      int response = dialog.run();
1454      dialog.hide();      dialog.hide();
# Line 1147  bool MainWindow::leaving_shared_mode_dia Line 1479  bool MainWindow::leaving_shared_mode_dia
1479            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
1480            "load it."));            "load it."));
1481      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
1482      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1483      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
1484      int response = dialog.run();      int response = dialog.run();
1485      dialog.hide();      dialog.hide();
# Line 1161  void MainWindow::on_action_file_open() Line 1493  void MainWindow::on_action_file_open()
1493      if (file_is_shared && !leaving_shared_mode_dialog()) return;      if (file_is_shared && !leaving_shared_mode_dialog()) return;
1494    
1495      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
1496      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1497      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1498      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1499  #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
1500      Gtk::FileFilter filter;      Gtk::FileFilter filter;
# Line 1357  void MainWindow::on_action_file_save_as( Line 1689  void MainWindow::on_action_file_save_as(
1689    
1690  bool MainWindow::file_save_as()  bool MainWindow::file_save_as()
1691  {  {
1692      Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE);      Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
1693      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1694      dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
1695      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
1696      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
1697    
# Line 1445  void MainWindow::__import_queued_samples Line 1777  void MainWindow::__import_queued_samples
1777      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1778      Glib::ustring error_files;      Glib::ustring error_files;
1779      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1780      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1781           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1782          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1783          SF_INFO info;          SF_INFO info;
1784          info.format = 0;          info.format = 0;
1785          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);
1786          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1787          try {          try {
1788              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 1805  void MainWindow::__import_queued_samples
1805                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1806              }              }
1807    
1808                // reset write position for sample
1809                iter->first->SetPos(0);
1810    
1811              const int bufsize = 10000;              const int bufsize = 10000;
1812              switch (bitdepth) {              switch (bitdepth) {
1813                  case 16: {                  case 16: {
# Line 1482  void MainWindow::__import_queued_samples Line 1817  void MainWindow::__import_queued_samples
1817                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1818                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1819                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1820                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1821                          cnt -= n;                          cnt -= n;
1822                      }                      }
1823                      delete[] buffer;                      delete[] buffer;
# Line 1502  void MainWindow::__import_queued_samples Line 1837  void MainWindow::__import_queued_samples
1837                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1838                          }                          }
1839                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1840                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1841                          cnt -= n;                          cnt -= n;
1842                      }                      }
1843                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1513  void MainWindow::__import_queued_samples Line 1848  void MainWindow::__import_queued_samples
1848              // cleanup              // cleanup
1849              sf_close(hFile);              sf_close(hFile);
1850              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1851              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1852              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1853              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1854              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1855              ++iter;              ++iter;
1856              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1857          } catch (std::string what) {          } catch (std::string what) {
1858              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1859              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1860              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1861              ++iter;              ++iter;
1862          }          }
1863      }      }
# Line 1580  void MainWindow::on_action_help_about() Line 1915  void MainWindow::on_action_help_about()
1915      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1916      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1917      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1918        dialog.set_position(Gtk::WIN_POS_CENTER);
1919      dialog.run();      dialog.run();
1920  }  }
1921    
# Line 1601  PropDialog::PropDialog() Line 1937  PropDialog::PropDialog()
1937        eSourceForm(_("Source form")),        eSourceForm(_("Source form")),
1938        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1939        eSubject(_("Subject")),        eSubject(_("Subject")),
1940        quitButton(_("_Close"), true),        quitButton(Gtk::Stock::CLOSE),
1941        table(2, 1),        table(2, 1),
1942        m_file(NULL)        m_file(NULL)
1943  {  {
1944        if (!Settings::singleton()->autoRestoreWindowDimension) {
1945            set_default_size(470, 390);
1946            set_position(Gtk::WIN_POS_MOUSE);
1947        }
1948    
1949      set_title(_("File Properties"));      set_title(_("File Properties"));
1950      eName.set_width_chars(50);      eName.set_width_chars(50);
1951    
# Line 1724  void InstrumentProps::set_MIDIProgram(ui Line 2065  void InstrumentProps::set_MIDIProgram(ui
2065  }  }
2066    
2067  InstrumentProps::InstrumentProps() :  InstrumentProps::InstrumentProps() :
2068      quitButton(_("_Close"), true),      quitButton(Gtk::Stock::CLOSE),
2069      table(2,1),      table(2,1),
2070      eName(_("Name")),      eName(_("Name")),
2071      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
# Line 1739  InstrumentProps::InstrumentProps() : Line 2080  InstrumentProps::InstrumentProps() :
2080      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2081      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2082  {  {
2083        if (!Settings::singleton()->autoRestoreWindowDimension) {
2084            //set_default_size(470, 390);
2085            set_position(Gtk::WIN_POS_MOUSE);
2086        }
2087    
2088      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2089    
2090      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 1863  void MainWindow::load_gig(gig::File* gig Line 2209  void MainWindow::load_gig(gig::File* gig
2209      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2210           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2211          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2212            const int iScriptSlots = instrument->ScriptSlotCount();
2213    
2214          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2215          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2216          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2217          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2218          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2219            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2220    
2221          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2222      }      }
# Line 2007  void MainWindow::show_script_slots() { Line 2355  void MainWindow::show_script_slots() {
2355    
2356      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2357      window->setInstrument(instrument);      window->setInstrument(instrument);
2358        window->signal_script_slots_changed().connect(
2359            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2360        );
2361      //window->reparent(*this);      //window->reparent(*this);
2362      window->show();      window->show();
2363  }  }
2364    
2365    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2366        if (!pInstrument) return;
2367        const int iScriptSlots = pInstrument->ScriptSlotCount();
2368    
2369        //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
2370        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2371        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2372    
2373        for (int i = 0; i < model->children().size(); ++i) {
2374            Gtk::TreeModel::Row row = model->children()[i];
2375            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2376            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2377            break;
2378        }
2379    
2380        // causes the sampler to reload the instrument with the new script
2381        on_sel_change();
2382    }
2383    
2384    void MainWindow::assignScript(gig::Script* pScript) {
2385        if (!pScript) {
2386            printf("assignScript() : !script\n");
2387            return;
2388        }
2389        printf("assignScript('%s')\n", pScript->Name.c_str());
2390    
2391        gig::Instrument* pInstrument = get_instrument();
2392        if (!pInstrument) {
2393            printf("!instrument\n");
2394            return;
2395        }
2396    
2397        pInstrument->AddScriptSlot(pScript);
2398    
2399        onScriptSlotsModified(pInstrument);
2400    }
2401    
2402  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2403      __refreshEntireGUI();      __refreshEntireGUI();
2404  }  }
# Line 2113  void MainWindow::on_instrument_selection Line 2501  void MainWindow::on_instrument_selection
2501  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
2502      if (!instrument) return;      if (!instrument) return;
2503    
2504        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2505      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2506        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2507    
2508      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2509          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2510          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
# Line 2135  bool MainWindow::select_dimension_region Line 2526  bool MainWindow::select_dimension_region
2526      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2527      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2528    
2529        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2530      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2531        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2532    
2533      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2534          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2535          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
# Line 2283  void MainWindow::on_script_treeview_butt Line 2677  void MainWindow::on_script_treeview_butt
2677      }      }
2678  }  }
2679    
2680    void MainWindow::updateScriptListOfMenu() {
2681        // remove all entries from "Assign Script" menu
2682        {
2683            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
2684            for (int i = 0; i < children.size(); ++i) {
2685                Gtk::Widget* child = children[i];
2686                assign_scripts_menu->remove(*child);
2687                delete child;
2688            }
2689        }
2690    
2691        int iTotalScripts = 0;
2692    
2693        if (!file) goto noScripts;
2694    
2695        // add all configured macros as menu items to the "Macro" menu
2696        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
2697            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
2698            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
2699                gig::Script* pScript = pGroup->GetScript(iScript);
2700                std::string name = pScript->Name;
2701    
2702                Gtk::MenuItem* item = new Gtk::MenuItem(name);
2703                item->signal_activate().connect(
2704                    sigc::bind(
2705                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
2706                    )
2707                );
2708                assign_scripts_menu->append(*item);
2709                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
2710                //item->set_tooltip_text(comment);
2711            }
2712        }
2713    
2714        noScripts:
2715    
2716        // if there are no macros configured at all, then show a dummy entry instead
2717        if (!iTotalScripts) {
2718            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
2719            item->set_sensitive(false);
2720            assign_scripts_menu->append(*item);
2721        }
2722    
2723        assign_scripts_menu->show_all_children();
2724    }
2725    
2726  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2727      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
2728    
# Line 2325  void MainWindow::add_instrument(gig::Ins Line 2765  void MainWindow::add_instrument(gig::Ins
2765      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2766      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2767      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2768        rowInstr[m_Columns.m_col_scripts] = "";
2769      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2770    
2771      add_instrument_to_menu(name);      add_instrument_to_menu(name);
2772        select_instrument(instrument);
     m_TreeView.get_selection()->select(iterInstr);  
   
2773      file_changed();      file_changed();
2774  }  }
2775    
# Line 2613  void MainWindow::add_or_replace_sample(b Line 3052  void MainWindow::add_or_replace_sample(b
3052    
3053      // show 'browse for file' dialog      // show 'browse for file' dialog
3054      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
3055      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3056      dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
3057      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
3058    
3059      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
# Line 2744  void MainWindow::add_or_replace_sample(b Line 3183  void MainWindow::add_or_replace_sample(b
3183                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3184                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3185                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
3186                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3187                  // add sample to the tree view                  // add sample to the tree view
3188                  if (replace) {                  if (replace) {
3189                      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 3253  void MainWindow::on_action_replace_all_s
3253      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);      dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
3254      description.show();      description.show();
3255      entryArea.show_all();      entryArea.show_all();
3256      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3257      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);      dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
3258      dialog.set_select_multiple(false);      dialog.set_select_multiple(false);
3259      if (current_sample_dir != "") {      if (current_sample_dir != "") {
# Line 2854  void MainWindow::on_action_replace_all_s Line 3293  void MainWindow::on_action_replace_all_s
3293                  SampleImportItem sched_item;                  SampleImportItem sched_item;
3294                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
3295                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
3296                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
3297                  sf_close(hFile);                  sf_close(hFile);
3298                  file_changed();                  file_changed();
3299              }              }
# Line 2906  void MainWindow::on_action_remove_sample Line 3345  void MainWindow::on_action_remove_sample
3345                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
3346                  // them from the import queue                  // them from the import queue
3347                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
3348                       member != members.end(); ++member) {                       member != members.end(); ++member)
3349                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
3350                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
3351                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
3352                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
3353                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
3354                      }                      }
3355                  }                  }
3356                  file_changed();                  file_changed();
# Line 2929  void MainWindow::on_action_remove_sample Line 3365  void MainWindow::on_action_remove_sample
3365                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3366                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3367                  // the import queue                  // the import queue
3368                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3369                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3370                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3371                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3372                  }                  }
3373                  dimreg_changed();                  dimreg_changed();
3374                  file_changed();                  file_changed();
# Line 2992  void MainWindow::on_action_remove_unused Line 3424  void MainWindow::on_action_remove_unused
3424              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3425              // remove sample from the .gig file              // remove sample from the .gig file
3426              file->DeleteSample(sample);              file->DeleteSample(sample);
3427              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3428              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3429                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3430              {                         m_SampleImportQueue[sample].sample_path.c_str());
3431                  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;  
                 }  
3432              }              }
3433          }          }
3434      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3312  void MainWindow::instrument_name_changed Line 3739  void MainWindow::instrument_name_changed
3739      }      }
3740  }  }
3741    
3742    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
3743        if (!iter)
3744            return true;
3745    
3746        Glib::ustring pattern = m_searchText.get_text().lowercase();
3747        trim(pattern);
3748        if (pattern.empty()) return true;
3749    
3750        Gtk::TreeModel::Row row = *iter;
3751        Glib::ustring name = row[m_Columns.m_col_name];
3752        name = name.lowercase();
3753    
3754        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
3755        for (int t = 0; t < tokens.size(); ++t)
3756            if (name.find(tokens[t]) == Glib::ustring::npos)
3757                return false;
3758    
3759        return true;
3760    }
3761    
3762  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3763      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3764    
3765        // take over selection from instruments list view for the combine dialog's
3766        // list view as pre-selection
3767        std::set<int> indeces;
3768        {
3769            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3770            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3771            for (int r = 0; r < rows.size(); ++r) {
3772                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3773                if (it) {
3774                    Gtk::TreeModel::Row row = *it;
3775                    int index = row[m_Columns.m_col_nr];
3776                    indeces.insert(index);
3777                }
3778            }
3779        }
3780        d->setSelectedInstruments(indeces);
3781    
3782      d->show_all();      d->show_all();
     d->resize(500, 400);  
3783      d->run();      d->run();
3784      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3785          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3450  void MainWindow::on_action_merge_files() Line 3914  void MainWindow::on_action_merge_files()
3914      }      }
3915    
3916      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));      Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
3917      dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3918      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);      dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
3919      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
3920  #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 4041  void MainWindow::show_scripts_tab() {
4041      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
4042  }  }
4043    
4044    void MainWindow::select_instrument_by_dir(int dir) {
4045        if (!file) return;
4046        gig::Instrument* pInstrument = get_instrument();
4047        if (!pInstrument) {
4048            select_instrument( file->GetInstrument(0) );
4049            return;
4050        }
4051        for (int i = 0; file->GetInstrument(i); ++i) {
4052            if (file->GetInstrument(i) == pInstrument) {
4053                select_instrument( file->GetInstrument(i + dir) );
4054                return;
4055            }
4056        }
4057    }
4058    
4059    void MainWindow::select_prev_instrument() {
4060        select_instrument_by_dir(-1);
4061    }
4062    
4063    void MainWindow::select_next_instrument() {
4064        select_instrument_by_dir(1);
4065    }
4066    
4067    void MainWindow::select_prev_region() {
4068        m_RegionChooser.select_prev_region();
4069    }
4070    
4071    void MainWindow::select_next_region() {
4072        m_RegionChooser.select_next_region();
4073    }
4074    
4075    void MainWindow::select_next_dim_rgn_zone() {
4076        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4077        m_DimRegionChooser.select_next_dimzone();
4078    }
4079    
4080    void MainWindow::select_prev_dim_rgn_zone() {
4081        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4082        m_DimRegionChooser.select_prev_dimzone();
4083    }
4084    
4085    void MainWindow::select_add_next_dim_rgn_zone() {
4086        m_DimRegionChooser.select_next_dimzone(true);
4087    }
4088    
4089    void MainWindow::select_add_prev_dim_rgn_zone() {
4090        m_DimRegionChooser.select_prev_dimzone(true);
4091    }
4092    
4093    void MainWindow::select_prev_dimension() {
4094        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4095        m_DimRegionChooser.select_prev_dimension();
4096    }
4097    
4098    void MainWindow::select_next_dimension() {
4099        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
4100        m_DimRegionChooser.select_next_dimension();
4101    }
4102    
4103    #define CLIPBOARD_DIMENSIONREGION_TARGET \
4104        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
4105    
4106    void MainWindow::copy_selected_dimrgn() {
4107        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
4108        if (!pDimRgn) {
4109            updateClipboardPasteAvailable();
4110            updateClipboardCopyAvailable();
4111            return;
4112        }
4113    
4114        std::vector<Gtk::TargetEntry> targets;
4115        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
4116    
4117        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4118        clipboard->set(
4119            targets,
4120            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
4121            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
4122        );
4123    
4124        m_serializationArchive.serialize(pDimRgn);
4125    
4126        updateClipboardPasteAvailable();
4127    }
4128    
4129    void MainWindow::paste_copied_dimrgn() {
4130        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4131        clipboard->request_contents(
4132            CLIPBOARD_DIMENSIONREGION_TARGET,
4133            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
4134        );
4135        updateClipboardPasteAvailable();
4136    }
4137    
4138    void MainWindow::adjust_clipboard_content() {
4139        MacroEditor* editor = new MacroEditor();
4140        editor->setMacro(&m_serializationArchive, true);
4141        editor->show();
4142    }
4143    
4144    void MainWindow::updateClipboardPasteAvailable() {
4145        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
4146        clipboard->request_targets(
4147            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
4148        );
4149    }
4150    
4151    void MainWindow::updateClipboardCopyAvailable() {
4152        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
4153        static_cast<Gtk::MenuItem*>(
4154            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
4155        )->set_sensitive(bDimensionRegionCopyIsPossible);
4156    }
4157    
4158    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
4159        updateClipboardPasteAvailable();
4160    }
4161    
4162    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
4163        const std::string target = selection_data.get_target();
4164        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4165            selection_data.set(
4166                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
4167                &m_serializationArchive.rawData()[0],
4168                m_serializationArchive.rawData().size()
4169            );
4170        } else {
4171            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
4172        }
4173    }
4174    
4175    void MainWindow::on_clipboard_clear() {
4176        m_serializationArchive.clear();
4177        updateClipboardPasteAvailable();
4178        updateClipboardCopyAvailable();
4179    }
4180    
4181    //NOTE: Might throw exception !!!
4182    void MainWindow::applyMacro(Serialization::Archive& macro) {
4183        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
4184        if (!pDimRgn) return;
4185    
4186        for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
4187             itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
4188        {
4189            gig::DimensionRegion* pDimRgn = *itDimReg;
4190            DimRegionChangeGuard(this, pDimRgn);
4191            macro.deserialize(pDimRgn);
4192        }
4193        //region_changed()
4194        file_changed();
4195        dimreg_changed();
4196    }
4197    
4198    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
4199        const std::string target = selection_data.get_target();
4200        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
4201            Glib::ustring errorText;
4202            try {
4203                m_serializationArchive.decode(
4204                    selection_data.get_data(), selection_data.get_length()
4205                );
4206                applyMacro(m_serializationArchive);
4207            } catch (Serialization::Exception e) {
4208                errorText = e.Message;
4209            } catch (...) {
4210                errorText = _("Unknown exception while pasting DimensionRegion");
4211            }
4212            if (!errorText.empty()) {
4213                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
4214                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4215                msg.run();
4216            }
4217        }
4218    }
4219    
4220    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
4221        const bool bDimensionRegionPasteIsPossible =
4222            std::find(targets.begin(), targets.end(),
4223                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
4224    
4225        static_cast<Gtk::MenuItem*>(
4226            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
4227        )->set_sensitive(bDimensionRegionPasteIsPossible);
4228    
4229        static_cast<Gtk::MenuItem*>(
4230            uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
4231        )->set_sensitive(bDimensionRegionPasteIsPossible);
4232    }
4233    
4234  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
4235      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
4236  }  }

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

  ViewVC Help
Powered by ViewVC