/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Annotation of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3460 - (hide annotations) (download)
Sat Feb 2 07:48:50 2019 UTC (21 months, 3 weeks ago) by persson
File size: 211765 byte(s)
* Use GDK Seat API if available to grab pointer
* Improve version checks for pangomm
* Fix the instrument list tooltip handling so it doesn't generate GTK
  assertion error messages
* Use English quotation marks in tooltips instead of German
* Use multiple columns in controller value popups, as tall popup menus
  work really badly in some GTK environments

1 schoenebeck 1225 /*
2 persson 3456 * Copyright (C) 2006-2019 Andreas Persson
3 schoenebeck 1225 *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #include <iostream>
21 persson 1714 #include <cstring>
22 schoenebeck 1225
23 schoenebeck 3364 #include "compat.h"
24 persson 2841 // threads.h must be included first to be able to build with
25     // G_DISABLE_DEPRECATED
26     #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27     (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28     #include <glibmm/threads.h>
29     #endif
30    
31 persson 2325 #include <glibmm/convert.h>
32     #include <glibmm/dispatcher.h>
33     #include <glibmm/miscutils.h>
34     #include <glibmm/stringutils.h>
35 schoenebeck 3340 #include <glibmm/regex.h>
36 persson 2151 #include <gtkmm/aboutdialog.h>
37 schoenebeck 1225 #include <gtkmm/filechooserdialog.h>
38     #include <gtkmm/messagedialog.h>
39 schoenebeck 3364 #if HAS_GTKMM_STOCK
40     # include <gtkmm/stock.h>
41     #endif
42 schoenebeck 1225 #include <gtkmm/targetentry.h>
43     #include <gtkmm/main.h>
44 schoenebeck 3364 #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89)
45     # include <gtkmm/toggleaction.h>
46     #endif
47 schoenebeck 3157 #include <gtkmm/accelmap.h>
48 persson 2344 #if GTKMM_MAJOR_VERSION < 3
49 persson 1799 #include "wrapLabel.hh"
50 persson 2344 #endif
51 schoenebeck 1225
52 schoenebeck 1396 #include "global.h"
53 persson 2169 #include "compat.h"
54 schoenebeck 1396
55 schoenebeck 1225 #include <stdio.h>
56 schoenebeck 3364 #ifdef LIBSNDFILE_HEADER_FILE
57     # include LIBSNDFILE_HEADER_FILE(sndfile.h)
58     #else
59     # include <sndfile.h>
60     #endif
61 schoenebeck 2553 #include <assert.h>
62 schoenebeck 1225
63     #include "mainwindow.h"
64 schoenebeck 2541 #include "Settings.h"
65 schoenebeck 2548 #include "CombineInstrumentsDialog.h"
66 schoenebeck 2604 #include "scripteditor.h"
67 schoenebeck 2610 #include "scriptslots.h"
68 schoenebeck 2624 #include "ReferencesView.h"
69 schoenebeck 1411 #include "../../gfx/status_attached.xpm"
70     #include "../../gfx/status_detached.xpm"
71 schoenebeck 3106 #include "gfx/builtinpix.h"
72 schoenebeck 3151 #include "MacroEditor.h"
73 schoenebeck 3157 #include "MacrosSetup.h"
74 schoenebeck 3258 #if defined(__APPLE__)
75     # include "MacHelper.h"
76     #endif
77 schoenebeck 1411
78 schoenebeck 3299 static const Gdk::ModifierType primaryModifierKey =
79     #if defined(__APPLE__)
80     Gdk::META_MASK; // Cmd key on Mac
81     #else
82     Gdk::CONTROL_MASK; // Ctrl key on all other OSs
83     #endif
84    
85 persson 1533 MainWindow::MainWindow() :
86 schoenebeck 2626 m_DimRegionChooser(*this),
87 persson 1533 dimreg_label(_("Changes apply to:")),
88     dimreg_all_regions(_("all regions")),
89     dimreg_all_dimregs(_("all dimension splits")),
90 schoenebeck 3106 dimreg_stereo(_("both channels")),
91 schoenebeck 3109 labelLegend(_("Legend:")),
92 schoenebeck 3106 labelNoSample(_(" No Sample")),
93     labelMissingSample(_(" Missing some Sample(s)")),
94     labelLooped(_(" Looped")),
95     labelSomeLoops(_(" Some Loop(s)"))
96 schoenebeck 1225 {
97 schoenebeck 3106 loadBuiltInPix();
98    
99 schoenebeck 3339 this->file = NULL;
100    
101 schoenebeck 1225 // set_border_width(5);
102    
103 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
104 schoenebeck 3368 #if GTKMM_MAJOR_VERSION >= 3
105     set_default_size(895, 600);
106     #else
107 schoenebeck 3225 set_default_size(800, 600);
108 schoenebeck 3368 #endif
109 schoenebeck 3225 set_position(Gtk::WIN_POS_CENTER);
110     }
111    
112 schoenebeck 1225 add(m_VBox);
113    
114     // Handle selection
115 persson 2442 m_TreeView.get_selection()->signal_changed().connect(
116 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_sel_change));
117    
118     // m_TreeView.set_reorderable();
119    
120 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
121     m_TreeView.signal_button_press_event().connect(
122     sigc::mem_fun(*this, &MainWindow::on_button_release));
123     #else
124 schoenebeck 1225 m_TreeView.signal_button_press_event().connect_notify(
125     sigc::mem_fun(*this, &MainWindow::on_button_release));
126 schoenebeck 3364 #endif
127 schoenebeck 1225
128     // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
129     m_ScrolledWindow.add(m_TreeView);
130     // m_ScrolledWindow.set_size_request(200, 600);
131     m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132    
133     m_ScrolledWindowSamples.add(m_TreeViewSamples);
134     m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
135    
136 schoenebeck 2604 m_ScrolledWindowScripts.add(m_TreeViewScripts);
137     m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138 schoenebeck 1225
139 schoenebeck 3368 #if GTKMM_MAJOR_VERSION < 3
140 schoenebeck 1225 m_TreeViewNotebook.set_size_request(300);
141 schoenebeck 3368 #endif
142 schoenebeck 1225
143 schoenebeck 3340 m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
144     m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
145     m_searchField.pack_start(m_searchText);
146     m_searchField.set_spacing(5);
147    
148     m_left_vbox.pack_start(m_TreeViewNotebook);
149     m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
150    
151     m_HPaned.add1(m_left_vbox);
152    
153 persson 1533 dimreg_hbox.add(dimreg_label);
154     dimreg_hbox.add(dimreg_all_regions);
155     dimreg_hbox.add(dimreg_all_dimregs);
156     dimreg_stereo.set_active();
157     dimreg_hbox.add(dimreg_stereo);
158     dimreg_vbox.add(dimreg_edit);
159 persson 1582 dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
160 schoenebeck 3106 {
161 schoenebeck 3109 legend_hbox.add(labelLegend);
162    
163 schoenebeck 3106 imageNoSample.set(redDot);
164 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
165 schoenebeck 3108 imageNoSample.set_alignment(Gtk::ALIGN_END);
166     labelNoSample.set_alignment(Gtk::ALIGN_START);
167 schoenebeck 3364 #else
168     imageNoSample.set_halign(Gtk::ALIGN_END);
169     labelNoSample.set_halign(Gtk::ALIGN_START);
170     #endif
171 schoenebeck 3106 legend_hbox.add(imageNoSample);
172     legend_hbox.add(labelNoSample);
173    
174     imageMissingSample.set(yellowDot);
175 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
176 schoenebeck 3108 imageMissingSample.set_alignment(Gtk::ALIGN_END);
177     labelMissingSample.set_alignment(Gtk::ALIGN_START);
178 schoenebeck 3364 #else
179     imageMissingSample.set_halign(Gtk::ALIGN_END);
180     labelMissingSample.set_halign(Gtk::ALIGN_START);
181     #endif
182 schoenebeck 3106 legend_hbox.add(imageMissingSample);
183     legend_hbox.add(labelMissingSample);
184    
185     imageLooped.set(blackLoop);
186 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
187 schoenebeck 3108 imageLooped.set_alignment(Gtk::ALIGN_END);
188     labelLooped.set_alignment(Gtk::ALIGN_START);
189 schoenebeck 3364 #else
190     imageLooped.set_halign(Gtk::ALIGN_END);
191     labelLooped.set_halign(Gtk::ALIGN_START);
192     #endif
193 schoenebeck 3106 legend_hbox.add(imageLooped);
194     legend_hbox.add(labelLooped);
195    
196     imageSomeLoops.set(grayLoop);
197 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
198 schoenebeck 3108 imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199     labelSomeLoops.set_alignment(Gtk::ALIGN_START);
200 schoenebeck 3364 #else
201     imageSomeLoops.set_halign(Gtk::ALIGN_END);
202     labelSomeLoops.set_halign(Gtk::ALIGN_START);
203     #endif
204 schoenebeck 3106 legend_hbox.add(imageSomeLoops);
205     legend_hbox.add(labelSomeLoops);
206    
207 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
208 schoenebeck 3106 legend_hbox.show_all_children();
209 schoenebeck 3364 #endif
210 schoenebeck 3106 }
211     dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212 persson 1533 m_HPaned.add2(dimreg_vbox);
213 schoenebeck 1225
214 schoenebeck 2536 dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
215     dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
216     dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
217     dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
218 schoenebeck 1225
219 persson 1831 m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
220     m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221 schoenebeck 2604 m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
222 schoenebeck 1225
223 schoenebeck 3364 #if USE_GLIB_ACTION
224     m_actionGroup = Gio::SimpleActionGroup::create();
225     m_actionGroup->add_action(
226     "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
227     );
228     m_actionGroup->add_action(
229     "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
230     );
231     m_actionGroup->add_action(
232     "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
233     );
234     m_actionGroup->add_action(
235     "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
236     );
237     m_actionGroup->add_action(
238     "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
239     );
240     m_actionGroup->add_action(
241     "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
242     );
243     m_actionMIDIRules = m_actionGroup->add_action(
244     "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
245     );
246     m_actionGroup->add_action(
247     "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
248     );
249     m_actionGroup->add_action(
250     "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
251     );
252     m_actionGroup->add_action(
253     "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
254     );
255     m_actionGroup->add_action(
256     "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
257     );
258     m_actionGroup->add_action(
259     "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
260     );
261     #else
262 schoenebeck 1225 actionGroup = Gtk::ActionGroup::create();
263    
264     actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
265 schoenebeck 3158 actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
266 schoenebeck 1225 sigc::mem_fun(
267     *this, &MainWindow::on_action_file_new));
268 schoenebeck 3158 Glib::RefPtr<Gtk::Action> action =
269     Gtk::Action::create("Open", Gtk::Stock::OPEN);
270     action->property_label() = action->property_label() + "...";
271     actionGroup->add(action,
272 schoenebeck 1225 sigc::mem_fun(
273     *this, &MainWindow::on_action_file_open));
274 schoenebeck 3158 actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
275 schoenebeck 1225 sigc::mem_fun(
276     *this, &MainWindow::on_action_file_save));
277 schoenebeck 3158 action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
278     action->property_label() = action->property_label() + "...";
279     actionGroup->add(action,
280 persson 1261 Gtk::AccelKey("<shift><control>s"),
281 schoenebeck 1225 sigc::mem_fun(
282 persson 1261 *this, &MainWindow::on_action_file_save_as));
283 schoenebeck 1225 actionGroup->add(Gtk::Action::create("Properties",
284 schoenebeck 3158 Gtk::Stock::PROPERTIES),
285 schoenebeck 1225 sigc::mem_fun(
286     *this, &MainWindow::on_action_file_properties));
287     actionGroup->add(Gtk::Action::create("InstrProperties",
288 schoenebeck 3158 Gtk::Stock::PROPERTIES),
289 schoenebeck 1225 sigc::mem_fun(
290     *this, &MainWindow::show_instr_props));
291 persson 2507 actionGroup->add(Gtk::Action::create("MidiRules",
292 schoenebeck 2610 _("_Midi Rules...")),
293 persson 2507 sigc::mem_fun(
294     *this, &MainWindow::show_midi_rules));
295 schoenebeck 2610 actionGroup->add(Gtk::Action::create("ScriptSlots",
296     _("_Script Slots...")),
297     sigc::mem_fun(
298     *this, &MainWindow::show_script_slots));
299 schoenebeck 3158 actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
300 schoenebeck 1225 sigc::mem_fun(
301 persson 1261 *this, &MainWindow::on_action_quit));
302 schoenebeck 2625 actionGroup->add(
303     Gtk::Action::create("MenuSample", _("_Sample")),
304     sigc::mem_fun(*this, &MainWindow::show_samples_tab)
305     );
306     actionGroup->add(
307     Gtk::Action::create("MenuInstrument", _("_Instrument")),
308     sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309     );
310     actionGroup->add(
311 schoenebeck 3144 Gtk::Action::create("MenuScript", _("Scr_ipt")),
312 schoenebeck 2625 sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313     );
314     actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
315 schoenebeck 3339 actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
316 schoenebeck 1225
317 schoenebeck 2464 actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
318 schoenebeck 3364 #endif
319 schoenebeck 2464
320 schoenebeck 3123 const Gdk::ModifierType primaryModifierKey =
321     #if defined(__APPLE__)
322     Gdk::META_MASK; // Cmd key on Mac
323     #else
324     Gdk::CONTROL_MASK; // Ctrl key on all other OSs
325     #endif
326    
327 schoenebeck 3364 #if USE_GLIB_ACTION
328     m_actionCopyDimRgn = m_actionGroup->add_action(
329     "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)
330     );
331     m_actionPasteDimRgn = m_actionGroup->add_action(
332     "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)
333     );
334     m_actionAdjustClipboard = m_actionGroup->add_action(
335     "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)
336     );
337     m_actionGroup->add_action(
338     "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument)
339     );
340     m_actionGroup->add_action(
341     "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument)
342     );
343     m_actionGroup->add_action(
344     "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region)
345     );
346     m_actionGroup->add_action(
347     "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region)
348     );
349     m_actionGroup->add_action(
350     "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)
351     );
352     m_actionGroup->add_action(
353     "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)
354     );
355     m_actionGroup->add_action(
356     "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension)
357     );
358     m_actionGroup->add_action(
359     "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension)
360     );
361     m_actionGroup->add_action(
362     "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)
363     );
364     m_actionGroup->add_action(
365     "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)
366     );
367     #else
368 schoenebeck 3144 actionGroup->add(Gtk::Action::create("CopyDimRgn",
369     _("Copy selected dimension region")),
370     Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
371     sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
372    
373     actionGroup->add(Gtk::Action::create("PasteDimRgn",
374     _("Paste dimension region")),
375     Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
376     sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
377    
378 schoenebeck 3151 actionGroup->add(Gtk::Action::create("AdjustClipboard",
379     _("Adjust Clipboard Content")),
380     Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
381     sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
382    
383 schoenebeck 3339 actionGroup->add(Gtk::Action::create("SelectPrevInstr",
384     _("Select Previous Instrument")),
385     Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
386     sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
387    
388     actionGroup->add(Gtk::Action::create("SelectNextInstr",
389     _("Select Next Instrument")),
390     Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
391     sigc::mem_fun(*this, &MainWindow::select_next_instrument));
392    
393 schoenebeck 3123 actionGroup->add(Gtk::Action::create("SelectPrevRegion",
394     _("Select Previous Region")),
395     Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
396     sigc::mem_fun(*this, &MainWindow::select_prev_region));
397    
398     actionGroup->add(Gtk::Action::create("SelectNextRegion",
399     _("Select Next Region")),
400     Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
401     sigc::mem_fun(*this, &MainWindow::select_next_region));
402    
403     actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
404     _("Select Previous Dimension Region Zone")),
405     Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
406     sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
407    
408     actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
409     _("Select Next Dimension Region Zone")),
410     Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
411     sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
412    
413     actionGroup->add(Gtk::Action::create("SelectPrevDimension",
414     _("Select Previous Dimension")),
415     Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
416     sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
417    
418     actionGroup->add(Gtk::Action::create("SelectNextDimension",
419     _("Select Next Dimension")),
420     Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
421     sigc::mem_fun(*this, &MainWindow::select_next_dimension));
422    
423 schoenebeck 3134 actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
424     _("Add Previous Dimension Region Zone to Selection")),
425     Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
426     sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
427 schoenebeck 3123
428 schoenebeck 3134 actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
429     _("Add Next Dimension Region Zone to Selection")),
430     Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
431     sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
432 schoenebeck 3364 #endif
433 schoenebeck 3134
434 schoenebeck 3364 #if USE_GLIB_ACTION
435     m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true);
436     m_actionToggleCopySampleTune = m_actionGroup->add_action_bool("CopySampleTune", true);
437     m_actionToggleCopySampleLoop = m_actionGroup->add_action_bool("CopySampleLoop", true);
438     #else
439 schoenebeck 2464 Glib::RefPtr<Gtk::ToggleAction> toggle_action =
440 schoenebeck 2536 Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
441 schoenebeck 2464 toggle_action->set_active(true);
442     actionGroup->add(toggle_action);
443    
444     toggle_action =
445     Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
446     toggle_action->set_active(true);
447     actionGroup->add(toggle_action);
448    
449     toggle_action =
450     Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451     toggle_action->set_active(true);
452     actionGroup->add(toggle_action);
453 schoenebeck 3364 #endif
454 schoenebeck 2464
455 schoenebeck 3364 #if USE_GLIB_ACTION
456     m_actionToggleStatusBar =
457     m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458     m_actionToggleRestoreWinDim =
459     m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460 schoenebeck 3409 m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
461     "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
462     Settings::singleton()->showTooltips
463     );
464 schoenebeck 3364 m_actionToggleSaveWithTempFile =
465     m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
466     m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
467     #else
468 schoenebeck 3157 actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
469    
470    
471 schoenebeck 3144 actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
472 schoenebeck 2464 toggle_action =
473 schoenebeck 1415 Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
474     toggle_action->set_active(true);
475     actionGroup->add(toggle_action,
476     sigc::mem_fun(
477     *this, &MainWindow::on_action_view_status_bar));
478 schoenebeck 2918
479     toggle_action =
480     Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
481     toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
482     actionGroup->add(toggle_action,
483     sigc::mem_fun(
484     *this, &MainWindow::on_auto_restore_win_dim));
485    
486 schoenebeck 2967 toggle_action =
487 schoenebeck 3409 Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
488     toggle_action->set_active(Settings::singleton()->showTooltips);
489     actionGroup->add(
490     toggle_action,
491     sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips)
492     );
493    
494     toggle_action =
495 schoenebeck 2967 Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
496     toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
497     actionGroup->add(toggle_action,
498     sigc::mem_fun(
499     *this, &MainWindow::on_save_with_temporary_file));
500    
501 schoenebeck 2772 actionGroup->add(
502     Gtk::Action::create("RefreshAll", _("_Refresh All")),
503     sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
504     );
505 schoenebeck 3364 #endif
506 schoenebeck 1415
507 schoenebeck 3364 #if USE_GLIB_ACTION
508     m_actionGroup->add_action(
509     "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
510     );
511     m_actionGroup->add_action(
512     "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
513     );
514     m_actionGroup->add_action(
515     "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
516     );
517     m_actionGroup->add_action(
518     "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
519     );
520     m_actionGroup->add_action(
521     "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
522     );
523     #else
524 schoenebeck 3158 action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
525     actionGroup->add(Gtk::Action::create("MenuHelp",
526     action->property_label()));
527     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
528 schoenebeck 1225 sigc::mem_fun(
529     *this, &MainWindow::on_action_help_about));
530     actionGroup->add(
531     Gtk::Action::create("AddInstrument", _("Add _Instrument")),
532     sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
533     );
534     actionGroup->add(
535 schoenebeck 2395 Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
536     sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
537     );
538     actionGroup->add(
539 schoenebeck 3299 Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
540     Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
541     sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
542     );
543     actionGroup->add(
544 schoenebeck 3158 Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
545 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
546     );
547 schoenebeck 3364 #endif
548 schoenebeck 1225
549 schoenebeck 3364 #if USE_GLIB_ACTION
550     m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool(
551     "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions),
552     Settings::singleton()->warnUserOnExtensions
553     );
554     m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool(
555     "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection),
556     Settings::singleton()->syncSamplerInstrumentSelection
557     );
558     m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool(
559     "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved),
560     Settings::singleton()->moveRootNoteWithRegionMoved
561     );
562     #else
563 schoenebeck 2541 actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
564    
565     toggle_action =
566     Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
567     toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
568     actionGroup->add(
569     toggle_action,
570     sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
571     );
572    
573 schoenebeck 2689 toggle_action =
574     Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
575     toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
576     actionGroup->add(
577     toggle_action,
578     sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
579     );
580 schoenebeck 2541
581 schoenebeck 2773 toggle_action =
582     Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
583     toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
584     actionGroup->add(
585     toggle_action,
586     sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
587     );
588 schoenebeck 3364 #endif
589 schoenebeck 2689
590 schoenebeck 3364 #if USE_GLIB_ACTION
591     m_actionGroup->add_action(
592     "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
593     );
594     m_actionGroup->add_action(
595     "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
596     );
597     #else
598 schoenebeck 2548 actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
599    
600     actionGroup->add(
601     Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
602     sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
603     );
604    
605 schoenebeck 2553 actionGroup->add(
606     Gtk::Action::create("MergeFiles", _("_Merge Files...")),
607     sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
608     );
609 schoenebeck 3364 #endif
610 schoenebeck 2548
611 schoenebeck 1225 // sample right-click popup actions
612 schoenebeck 3364 #if USE_GLIB_ACTION
613     m_actionSampleProperties = m_actionGroup->add_action(
614     "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
615     );
616     m_actionAddSampleGroup = m_actionGroup->add_action(
617     "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group)
618     );
619     m_actionAddSample = m_actionGroup->add_action(
620     "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
621     );
622     m_actionRemoveSample = m_actionGroup->add_action(
623     "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
624     );
625     m_actionGroup->add_action(
626     "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
627     );
628     m_actionViewSampleRefs = m_actionGroup->add_action(
629     "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references)
630     );
631     m_actionReplaceSample = m_actionGroup->add_action(
632     "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
633     );
634     m_actionGroup->add_action(
635     "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
636     );
637     #else
638 schoenebeck 1225 actionGroup->add(
639 schoenebeck 3158 Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
640 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
641     );
642     actionGroup->add(
643     Gtk::Action::create("AddGroup", _("Add _Group")),
644     sigc::mem_fun(*this, &MainWindow::on_action_add_group)
645     );
646     actionGroup->add(
647 persson 1799 Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
648 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
649     );
650     actionGroup->add(
651 schoenebeck 3158 Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
652 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
653     );
654 schoenebeck 1673 actionGroup->add(
655 schoenebeck 2772 Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
656     sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
657     );
658     actionGroup->add(
659 schoenebeck 2624 Gtk::Action::create("ShowSampleRefs", _("Show References...")),
660     sigc::mem_fun(*this, &MainWindow::on_action_view_references)
661     );
662     actionGroup->add(
663 schoenebeck 2715 Gtk::Action::create("ReplaceSample",
664     _("Replace Sample...")),
665     sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
666     );
667     actionGroup->add(
668 persson 1799 Gtk::Action::create("ReplaceAllSamplesInAllGroups",
669     _("Replace All Samples in All Groups...")),
670 schoenebeck 1673 sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
671     );
672 schoenebeck 3364 #endif
673 schoenebeck 2604
674     // script right-click popup actions
675 schoenebeck 3364 #if USE_GLIB_ACTION
676     m_actionAddScriptGroup = m_actionGroup->add_action(
677     "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
678     );
679     m_actionAddScript = m_actionGroup->add_action(
680     "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script)
681     );
682     m_actionEditScript = m_actionGroup->add_action(
683     "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
684     );
685     m_actionRemoveScript = m_actionGroup->add_action(
686     "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
687     );
688     #else
689 schoenebeck 2604 actionGroup->add(
690     Gtk::Action::create("AddScriptGroup", _("Add _Group")),
691     sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
692     );
693     actionGroup->add(
694     Gtk::Action::create("AddScript", _("Add _Script")),
695     sigc::mem_fun(*this, &MainWindow::on_action_add_script)
696     );
697     actionGroup->add(
698     Gtk::Action::create("EditScript", _("_Edit Script...")),
699     sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
700     );
701     actionGroup->add(
702 schoenebeck 3158 Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
703 schoenebeck 2604 sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
704     );
705 schoenebeck 3364 #endif
706 schoenebeck 1225
707 schoenebeck 3364 #if USE_GTKMM_BUILDER
708     insert_action_group("AppMenu", m_actionGroup);
709    
710     m_uiManager = Gtk::Builder::create();
711     Glib::ustring ui_info =
712     "<interface>"
713     " <menubar id='MenuBar'>"
714     " <menu id='MenuFile'>"
715     " <attribute name='label' translatable='yes'>_File</attribute>"
716     " <section>"
717     " <item id='New'>"
718     " <attribute name='label' translatable='yes'>New</attribute>"
719     " <attribute name='action'>AppMenu.New</attribute>"
720     " </item>"
721     " <item id='Open'>"
722     " <attribute name='label' translatable='yes'>Open</attribute>"
723     " <attribute name='action'>AppMenu.Open</attribute>"
724     " </item>"
725     " </section>"
726     " <section>"
727     " <item id='Save'>"
728     " <attribute name='label' translatable='yes'>Save</attribute>"
729     " <attribute name='action'>AppMenu.Save</attribute>"
730     " </item>"
731     " <item id='SaveAs'>"
732     " <attribute name='label' translatable='yes'>Save As</attribute>"
733     " <attribute name='action'>AppMenu.SaveAs</attribute>"
734     " </item>"
735     " </section>"
736     " <section>"
737     " <item id='Properties'>"
738     " <attribute name='label' translatable='yes'>Properties</attribute>"
739     " <attribute name='action'>AppMenu.Properties</attribute>"
740     " </item>"
741     " </section>"
742     " <section>"
743     " <item id='Quit'>"
744     " <attribute name='label' translatable='yes'>Quit</attribute>"
745     " <attribute name='action'>AppMenu.Quit</attribute>"
746     " </item>"
747     " </section>"
748     " </menu>"
749     " <menu id='MenuEdit'>"
750     " <attribute name='label' translatable='yes'>Edit</attribute>"
751     " <section>"
752     " <item id='CopyDimRgn'>"
753     " <attribute name='label' translatable='yes'>Copy Dimension Region</attribute>"
754     " <attribute name='action'>AppMenu.CopyDimRgn</attribute>"
755     " </item>"
756     " <item id='AdjustClipboard'>"
757     " <attribute name='label' translatable='yes'>Adjust Clipboard</attribute>"
758     " <attribute name='action'>AppMenu.AdjustClipboard</attribute>"
759     " </item>"
760     " <item id='PasteDimRgn'>"
761     " <attribute name='label' translatable='yes'>Paste Dimension Region</attribute>"
762     " <attribute name='action'>AppMenu.PasteDimRgn</attribute>"
763     " </item>"
764     " </section>"
765     " <item id='SelectPrevInstr'>"
766     " <attribute name='label' translatable='yes'>Previous Instrument</attribute>"
767     " <attribute name='action'>AppMenu.SelectPrevInstr</attribute>"
768     " </item>"
769     " <item id='SelectNextInstr'>"
770     " <attribute name='label' translatable='yes'>Next Instrument</attribute>"
771     " <attribute name='action'>AppMenu.SelectNextInstr</attribute>"
772     " </item>"
773     " <section>"
774     " <item id='SelectPrevRegion'>"
775     " <attribute name='label' translatable='yes'>Previous Region</attribute>"
776     " <attribute name='action'>AppMenu.SelectPrevRegion</attribute>"
777     " </item>"
778     " <item id='SelectNextRegion'>"
779     " <attribute name='label' translatable='yes'>Next Region</attribute>"
780     " <attribute name='action'>AppMenu.SelectNextRegion</attribute>"
781     " </item>"
782     " </section>"
783     " <item id='SelectPrevDimension'>"
784     " <attribute name='label' translatable='yes'>Previous Dimension</attribute>"
785     " <attribute name='action'>AppMenu.SelectPrevDimension</attribute>"
786     " </item>"
787     " <item id='SelectNextDimension'>"
788     " <attribute name='label' translatable='yes'>Next Dimension</attribute>"
789     " <attribute name='action'>AppMenu.SelectNextDimension</attribute>"
790     " </item>"
791     " <item id='SelectPrevDimRgnZone'>"
792     " <attribute name='label' translatable='yes'>Previous Dimension Region Zone</attribute>"
793     " <attribute name='action'>AppMenu.SelectPrevDimRgnZone</attribute>"
794     " </item>"
795     " <item id='SelectNextDimRgnZone'>"
796     " <attribute name='label' translatable='yes'>Next Dimension Region Zone</attribute>"
797     " <attribute name='action'>AppMenu.SelectNextDimRgnZone</attribute>"
798     " </item>"
799     " <item id='SelectAddPrevDimRgnZone'>"
800     " <attribute name='label' translatable='yes'>Add Previous Dimension Region Zone</attribute>"
801     " <attribute name='action'>AppMenu.SelectAddPrevDimRgnZone</attribute>"
802     " </item>"
803     " <item id='SelectAddNextDimRgnZone'>"
804     " <attribute name='label' translatable='yes'>Add Next Dimension Region Zone</attribute>"
805     " <attribute name='action'>AppMenu.SelectAddNextDimRgnZone</attribute>"
806     " </item>"
807     " <section>"
808     " <item id='CopySampleUnity'>"
809     " <attribute name='label' translatable='yes'>Copy Sample Unity</attribute>"
810     " <attribute name='action'>AppMenu.CopySampleUnity</attribute>"
811     " </item>"
812     " <item id='CopySampleTune'>"
813     " <attribute name='label' translatable='yes'>Copy Sample Tune</attribute>"
814     " <attribute name='action'>AppMenu.CopySampleTune</attribute>"
815     " </item>"
816     " <item id='CopySampleLoop'>"
817     " <attribute name='label' translatable='yes'>Copy Sample Loop</attribute>"
818     " <attribute name='action'>AppMenu.CopySampleLoop</attribute>"
819     " </item>"
820     " </section>"
821     " </menu>"
822     " <menu id='MenuMacro'>"
823     " <attribute name='label' translatable='yes'>Macro</attribute>"
824     " <section>"
825     " </section>"
826     " </menu>"
827     " <menu id='MenuSample'>"
828     " <attribute name='label' translatable='yes'>Sample</attribute>"
829     " <section>"
830     " <item id='SampleProperties'>"
831     " <attribute name='label' translatable='yes'>Properties</attribute>"
832     " <attribute name='action'>AppMenu.SampleProperties</attribute>"
833     " </item>"
834     " <item id='AddGroup'>"
835     " <attribute name='label' translatable='yes'>Add Group</attribute>"
836     " <attribute name='action'>AppMenu.AddGroup</attribute>"
837     " </item>"
838     " <item id='AddSample'>"
839     " <attribute name='label' translatable='yes'>Add Sample</attribute>"
840     " <attribute name='action'>AppMenu.AddSample</attribute>"
841     " </item>"
842     " <item id='ShowSampleRefs'>"
843     " <attribute name='label' translatable='yes'>Show Sample References</attribute>"
844     " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
845     " </item>"
846     " <item id='ReplaceSample'>"
847     " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
848     " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
849     " </item>"
850     " <item id='ReplaceAllSamplesInAllGroups'>"
851     " <attribute name='label' translatable='yes'>Replace all Samples in all Groups</attribute>"
852     " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
853     " </item>"
854     " </section>"
855     " <section>"
856     " <item id='RemoveSample'>"
857     " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
858     " <attribute name='action'>AppMenu.RemoveSample</attribute>"
859     " </item>"
860     " <item id='RemoveUnusedSamples'>"
861     " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
862     " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
863     " </item>"
864     " </section>"
865     " </menu>"
866     " <menu id='MenuInstrument'>"
867     " <attribute name='label' translatable='yes'>Instrument</attribute>"
868     " <section>"
869     " <item id='InstrProperties'>"
870     " <attribute name='label' translatable='yes'>Properties</attribute>"
871     " <attribute name='action'>AppMenu.InstrProperties</attribute>"
872     " </item>"
873     " <item id='MidiRules'>"
874     " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
875     " <attribute name='action'>AppMenu.MidiRules</attribute>"
876     " </item>"
877     " <item id='ScriptSlots'>"
878     " <attribute name='label' translatable='yes'>Script Slots</attribute>"
879     " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
880     " </item>"
881     " </section>"
882     " <submenu id='AssignScripts'>"
883     " <attribute name='label' translatable='yes'>Assign Scripts</attribute>"
884     " </submenu>"
885     " <section>"
886     " <item id='AddInstrument'>"
887     " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
888     " <attribute name='action'>AppMenu.AddInstrument</attribute>"
889     " </item>"
890     " <item id='DupInstrument'>"
891     " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
892     " <attribute name='action'>AppMenu.DupInstrument</attribute>"
893     " </item>"
894     " <item id='CombInstruments'>"
895     " <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
896     " <attribute name='action'>AppMenu.CombInstruments</attribute>"
897     " </item>"
898     " </section>"
899     " <section>"
900     " <item id='RemoveInstrument'>"
901     " <attribute name='label' translatable='yes'>Remove Instrument</attribute>"
902     " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
903     " </item>"
904     " </section>"
905     " </menu>"
906     " <menu id='MenuScript'>"
907     " <attribute name='label' translatable='yes'>Script</attribute>"
908     " <section>"
909     " <item id='AddScriptGroup'>"
910     " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
911     " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
912     " </item>"
913     " <item id='AddScript'>"
914     " <attribute name='label' translatable='yes'>Add Script</attribute>"
915     " <attribute name='action'>AppMenu.AddScript</attribute>"
916     " </item>"
917     " <item id='EditScript'>"
918     " <attribute name='label' translatable='yes'>Edit Script</attribute>"
919     " <attribute name='action'>AppMenu.EditScript</attribute>"
920     " </item>"
921     " </section>"
922     " <section>"
923     " <item id='RemoveScript'>"
924     " <attribute name='label' translatable='yes'>Remove Script</attribute>"
925     " <attribute name='action'>AppMenu.RemoveScript</attribute>"
926     " </item>"
927     " </section>"
928     " </menu>"
929     " <menu id='MenuView'>"
930     " <attribute name='label' translatable='yes'>View</attribute>"
931     " <section>"
932     " <item id='Statusbar'>"
933     " <attribute name='label' translatable='yes'>Statusbar</attribute>"
934     " <attribute name='action'>AppMenu.Statusbar</attribute>"
935     " </item>"
936 schoenebeck 3409 " <item id='ShowTooltips'>"
937     " <attribute name='label' translatable='yes'>Tooltips for Beginners</attribute>"
938     " <attribute name='action'>AppMenu.ShowTooltips</attribute>"
939     " </item>"
940 schoenebeck 3364 " <item id='AutoRestoreWinDim'>"
941     " <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
942     " <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
943     " </item>"
944     " </section>"
945     " <section>"
946     " <item id='RefreshAll'>"
947     " <attribute name='label' translatable='yes'>Refresh All</attribute>"
948     " <attribute name='action'>AppMenu.RefreshAll</attribute>"
949     " </item>"
950     " </section>"
951     " </menu>"
952     " <menu id='MenuTools'>"
953     " <attribute name='label' translatable='yes'>Tools</attribute>"
954     " <section>"
955     " <item id='CombineInstruments'>"
956     " <attribute name='label' translatable='yes'>Combine Instruments ...</attribute>"
957     " <attribute name='action'>AppMenu.CombineInstruments</attribute>"
958     " </item>"
959     " <item id='MergeFiles'>"
960     " <attribute name='label' translatable='yes'>Merge Files ...</attribute>"
961     " <attribute name='action'>AppMenu.MergeFiles</attribute>"
962     " </item>"
963     " </section>"
964     " </menu>"
965     " <menu id='MenuSettings'>"
966     " <attribute name='label' translatable='yes'>Settings</attribute>"
967     " <section>"
968     " <item id='WarnUserOnExtensions'>"
969     " <attribute name='label' translatable='yes'>Warning on Format Extensions</attribute>"
970     " <attribute name='action'>AppMenu.WarnUserOnExtensions</attribute>"
971     " </item>"
972     " <item id='SyncSamplerInstrumentSelection'>"
973     " <attribute name='label' translatable='yes'>Synchronize Sampler Selection</attribute>"
974     " <attribute name='action'>AppMenu.SyncSamplerInstrumentSelection</attribute>"
975     " </item>"
976     " <item id='MoveRootNoteWithRegionMoved'>"
977     " <attribute name='label' translatable='yes'>Move Root Note with Region moved</attribute>"
978     " <attribute name='action'>AppMenu.MoveRootNoteWithRegionMoved</attribute>"
979     " </item>"
980     " <item id='SaveWithTemporaryFile'>"
981     " <attribute name='label' translatable='yes'>Save with temporary file</attribute>"
982     " <attribute name='action'>AppMenu.SaveWithTemporaryFile</attribute>"
983     " </item>"
984     " </section>"
985     " </menu>"
986     " <menu id='MenuHelp'>"
987     " <attribute name='label' translatable='yes'>Help</attribute>"
988     " <section>"
989     " <item id='About'>"
990     " <attribute name='label' translatable='yes'>About ...</attribute>"
991     " <attribute name='action'>AppMenu.About</attribute>"
992     " </item>"
993     " </section>"
994     " </menu>"
995     " </menubar>"
996     // popups
997     " <menu id='PopupMenu'>"
998     " <section>"
999     " <item id='InstrProperties'>"
1000     " <attribute name='label' translatable='yes'>Instrument Properties</attribute>"
1001     " <attribute name='action'>AppMenu.InstrProperties</attribute>"
1002     " </item>"
1003     " <item id='MidiRules'>"
1004     " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
1005     " <attribute name='action'>AppMenu.MidiRules</attribute>"
1006     " </item>"
1007     " <item id='ScriptSlots'>"
1008     " <attribute name='label' translatable='yes'>Script Slots</attribute>"
1009     " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
1010     " </item>"
1011     " <item id='AddInstrument'>"
1012     " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
1013     " <attribute name='action'>AppMenu.AddInstrument</attribute>"
1014     " </item>"
1015     " <item id='DupInstrument'>"
1016     " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1017     " <attribute name='action'>AppMenu.DupInstrument</attribute>"
1018     " </item>"
1019     " <item id='CombInstruments'>"
1020     " <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1021     " <attribute name='action'>AppMenu.CombInstruments</attribute>"
1022     " </item>"
1023     " </section>"
1024     " <section>"
1025     " <item id='RemoveInstrument'>"
1026     " <attribute name='label' translatable='yes'>Remove Instruments</attribute>"
1027     " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
1028     " </item>"
1029     " </section>"
1030     " </menu>"
1031     " <menu id='SamplePopupMenu'>"
1032     " <section>"
1033     " <item id='SampleProperties'>"
1034     " <attribute name='label' translatable='yes'>Sample Properties</attribute>"
1035     " <attribute name='action'>AppMenu.SampleProperties</attribute>"
1036     " </item>"
1037     " <item id='AddGroup'>"
1038     " <attribute name='label' translatable='yes'>Add Sample Group</attribute>"
1039     " <attribute name='action'>AppMenu.AddGroup</attribute>"
1040     " </item>"
1041     " <item id='AddSample'>"
1042     " <attribute name='label' translatable='yes'>Add Sample</attribute>"
1043     " <attribute name='action'>AppMenu.AddSample</attribute>"
1044     " </item>"
1045     " <item id='ShowSampleRefs'>"
1046     " <attribute name='label' translatable='yes'>Show Sample References ...</attribute>"
1047     " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
1048     " </item>"
1049     " <item id='ReplaceSample'>"
1050     " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
1051     " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
1052     " </item>"
1053     " <item id='ReplaceAllSamplesInAllGroups'>"
1054     " <attribute name='label' translatable='yes'>Replace all Samples ...</attribute>"
1055     " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
1056     " </item>"
1057     " </section>"
1058     " <section>"
1059     " <item id='RemoveSample'>"
1060     " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
1061     " <attribute name='action'>AppMenu.RemoveSample</attribute>"
1062     " </item>"
1063     " <item id='RemoveUnusedSamples'>"
1064     " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
1065     " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
1066     " </item>"
1067     " </section>"
1068     " </menu>"
1069     " <menu id='ScriptPopupMenu'>"
1070     " <section>"
1071     " <item id='AddScriptGroup'>"
1072     " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
1073     " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
1074     " </item>"
1075     " <item id='AddScript'>"
1076     " <attribute name='label' translatable='yes'>Add Script</attribute>"
1077     " <attribute name='action'>AppMenu.AddScript</attribute>"
1078     " </item>"
1079     " <item id='EditScript'>"
1080     " <attribute name='label' translatable='yes'>Edit Script</attribute>"
1081     " <attribute name='action'>AppMenu.EditScript</attribute>"
1082     " </item>"
1083     " </section>"
1084     " <section>"
1085     " <item id='RemoveScript'>"
1086     " <attribute name='label' translatable='yes'>Remove Script</attribute>"
1087     " <attribute name='action'>AppMenu.RemoveScript</attribute>"
1088     " </item>"
1089     " </section>"
1090     " </menu>"
1091     "</interface>";
1092     m_uiManager->add_from_string(ui_info);
1093     #else
1094 schoenebeck 1225 uiManager = Gtk::UIManager::create();
1095     uiManager->insert_action_group(actionGroup);
1096 persson 1261 add_accel_group(uiManager->get_accel_group());
1097 schoenebeck 1225
1098     Glib::ustring ui_info =
1099     "<ui>"
1100     " <menubar name='MenuBar'>"
1101     " <menu action='MenuFile'>"
1102     " <menuitem action='New'/>"
1103     " <menuitem action='Open'/>"
1104     " <separator/>"
1105     " <menuitem action='Save'/>"
1106     " <menuitem action='SaveAs'/>"
1107     " <separator/>"
1108     " <menuitem action='Properties'/>"
1109     " <separator/>"
1110     " <menuitem action='Quit'/>"
1111     " </menu>"
1112 schoenebeck 2464 " <menu action='MenuEdit'>"
1113 schoenebeck 3144 " <menuitem action='CopyDimRgn'/>"
1114 schoenebeck 3151 " <menuitem action='AdjustClipboard'/>"
1115 schoenebeck 3144 " <menuitem action='PasteDimRgn'/>"
1116     " <separator/>"
1117 schoenebeck 3339 " <menuitem action='SelectPrevInstr'/>"
1118     " <menuitem action='SelectNextInstr'/>"
1119     " <separator/>"
1120 schoenebeck 3123 " <menuitem action='SelectPrevRegion'/>"
1121     " <menuitem action='SelectNextRegion'/>"
1122     " <separator/>"
1123 schoenebeck 3134 " <menuitem action='SelectPrevDimension'/>"
1124     " <menuitem action='SelectNextDimension'/>"
1125 schoenebeck 3123 " <menuitem action='SelectPrevDimRgnZone'/>"
1126     " <menuitem action='SelectNextDimRgnZone'/>"
1127 schoenebeck 3134 " <menuitem action='SelectAddPrevDimRgnZone'/>"
1128     " <menuitem action='SelectAddNextDimRgnZone'/>"
1129 schoenebeck 3123 " <separator/>"
1130 schoenebeck 2464 " <menuitem action='CopySampleUnity'/>"
1131     " <menuitem action='CopySampleTune'/>"
1132     " <menuitem action='CopySampleLoop'/>"
1133     " </menu>"
1134 schoenebeck 3157 " <menu action='MenuMacro'>"
1135     " </menu>"
1136 schoenebeck 2625 " <menu action='MenuSample'>"
1137     " <menuitem action='SampleProperties'/>"
1138     " <menuitem action='AddGroup'/>"
1139     " <menuitem action='AddSample'/>"
1140     " <menuitem action='ShowSampleRefs'/>"
1141 schoenebeck 2715 " <menuitem action='ReplaceSample' />"
1142 schoenebeck 2625 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1143     " <separator/>"
1144     " <menuitem action='RemoveSample'/>"
1145 schoenebeck 2772 " <menuitem action='RemoveUnusedSamples'/>"
1146 schoenebeck 2625 " </menu>"
1147 schoenebeck 1225 " <menu action='MenuInstrument'>"
1148 schoenebeck 2625 " <menu action='AllInstruments'>"
1149     " </menu>"
1150     " <separator/>"
1151     " <menuitem action='InstrProperties'/>"
1152     " <menuitem action='MidiRules'/>"
1153     " <menuitem action='ScriptSlots'/>"
1154 schoenebeck 3339 " <menu action='AssignScripts'/>"
1155 schoenebeck 2625 " <menuitem action='AddInstrument'/>"
1156     " <menuitem action='DupInstrument'/>"
1157 schoenebeck 3299 " <menuitem action='CombInstruments'/>"
1158 schoenebeck 2625 " <separator/>"
1159     " <menuitem action='RemoveInstrument'/>"
1160 schoenebeck 1225 " </menu>"
1161 schoenebeck 2625 " <menu action='MenuScript'>"
1162     " <menuitem action='AddScriptGroup'/>"
1163     " <menuitem action='AddScript'/>"
1164     " <menuitem action='EditScript'/>"
1165     " <separator/>"
1166     " <menuitem action='RemoveScript'/>"
1167     " </menu>"
1168 schoenebeck 1415 " <menu action='MenuView'>"
1169     " <menuitem action='Statusbar'/>"
1170 schoenebeck 3409 " <menuitem action='ShowTooltips'/>"
1171 schoenebeck 2918 " <menuitem action='AutoRestoreWinDim'/>"
1172 schoenebeck 2772 " <separator/>"
1173     " <menuitem action='RefreshAll'/>"
1174 schoenebeck 1415 " </menu>"
1175 schoenebeck 2548 " <menu action='MenuTools'>"
1176     " <menuitem action='CombineInstruments'/>"
1177 schoenebeck 2553 " <menuitem action='MergeFiles'/>"
1178 schoenebeck 2548 " </menu>"
1179 schoenebeck 2541 " <menu action='MenuSettings'>"
1180     " <menuitem action='WarnUserOnExtensions'/>"
1181 schoenebeck 2689 " <menuitem action='SyncSamplerInstrumentSelection'/>"
1182 schoenebeck 2773 " <menuitem action='MoveRootNoteWithRegionMoved'/>"
1183 schoenebeck 2967 " <menuitem action='SaveWithTemporaryFile'/>"
1184 schoenebeck 2541 " </menu>"
1185 schoenebeck 1225 " <menu action='MenuHelp'>"
1186     " <menuitem action='About'/>"
1187     " </menu>"
1188     " </menubar>"
1189     " <popup name='PopupMenu'>"
1190     " <menuitem action='InstrProperties'/>"
1191 persson 2507 " <menuitem action='MidiRules'/>"
1192 schoenebeck 2610 " <menuitem action='ScriptSlots'/>"
1193 schoenebeck 1225 " <menuitem action='AddInstrument'/>"
1194 schoenebeck 2395 " <menuitem action='DupInstrument'/>"
1195 schoenebeck 3299 " <menuitem action='CombInstruments'/>"
1196 schoenebeck 1225 " <separator/>"
1197     " <menuitem action='RemoveInstrument'/>"
1198     " </popup>"
1199     " <popup name='SamplePopupMenu'>"
1200     " <menuitem action='SampleProperties'/>"
1201     " <menuitem action='AddGroup'/>"
1202     " <menuitem action='AddSample'/>"
1203 schoenebeck 2624 " <menuitem action='ShowSampleRefs'/>"
1204 schoenebeck 2715 " <menuitem action='ReplaceSample' />"
1205 persson 2442 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1206 schoenebeck 1225 " <separator/>"
1207     " <menuitem action='RemoveSample'/>"
1208 schoenebeck 2772 " <menuitem action='RemoveUnusedSamples'/>"
1209 schoenebeck 1225 " </popup>"
1210 schoenebeck 2604 " <popup name='ScriptPopupMenu'>"
1211     " <menuitem action='AddScriptGroup'/>"
1212     " <menuitem action='AddScript'/>"
1213     " <menuitem action='EditScript'/>"
1214     " <separator/>"
1215     " <menuitem action='RemoveScript'/>"
1216     " </popup>"
1217 schoenebeck 1225 "</ui>";
1218     uiManager->add_ui_from_string(ui_info);
1219 schoenebeck 3364 #endif
1220 schoenebeck 1225
1221 schoenebeck 3364 #if USE_GTKMM_BUILDER
1222     popup_menu = new Gtk::Menu(
1223     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1224     m_uiManager->get_object("PopupMenu")
1225     )
1226     );
1227     sample_popup = new Gtk::Menu(
1228     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1229     m_uiManager->get_object("SamplePopupMenu")
1230     )
1231     );
1232     script_popup = new Gtk::Menu(
1233     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1234     m_uiManager->get_object("ScriptPopupMenu")
1235     )
1236     );
1237     #else
1238 schoenebeck 1225 popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
1239 schoenebeck 2536
1240     // Set tooltips for menu items (for some reason, setting a tooltip on the
1241     // respective Gtk::Action objects above will simply be ignored, no matter
1242     // if using Gtk::Action::set_tooltip() or passing the tooltip string on
1243     // Gtk::Action::create()).
1244     {
1245     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1246     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1247     item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
1248     }
1249     {
1250     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1251     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1252     item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
1253     }
1254     {
1255     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1256     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1257 schoenebeck 3408 item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop information to be altered by this action."));
1258 schoenebeck 2536 }
1259 schoenebeck 2541 {
1260     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1261     uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
1262     item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
1263     }
1264 schoenebeck 2553 {
1265     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1266 schoenebeck 2689 uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
1267     item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
1268     }
1269     {
1270     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1271 schoenebeck 2773 uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
1272 schoenebeck 3408 item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keyboard position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
1273 schoenebeck 2773 }
1274     {
1275     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1276 schoenebeck 2772 uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
1277     item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
1278     // copy tooltip to popup menu
1279     Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
1280     uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
1281     item2->set_tooltip_text(item->get_tooltip_text());
1282     }
1283     {
1284     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1285     uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
1286     item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
1287     }
1288     {
1289     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1290 schoenebeck 2918 uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1291     item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
1292     }
1293     {
1294     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1295 schoenebeck 2553 uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1296     item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1297     }
1298     {
1299     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1300     uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1301     item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
1302     }
1303 schoenebeck 3364 #endif
1304 schoenebeck 1225
1305 schoenebeck 3364 #if USE_GTKMM_BUILDER
1306     assign_scripts_menu = new Gtk::Menu(
1307     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1308     m_uiManager->get_object("AssignScripts")
1309     )
1310     );
1311     #else
1312 persson 2442 instrument_menu = static_cast<Gtk::MenuItem*>(
1313 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
1314 persson 2442
1315 schoenebeck 3339 assign_scripts_menu = static_cast<Gtk::MenuItem*>(
1316     uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
1317 schoenebeck 3364 #endif
1318 schoenebeck 3339
1319 schoenebeck 3364 #if USE_GTKMM_BUILDER
1320     Gtk::Widget* menuBar = NULL;
1321     m_uiManager->get_widget("MenuBar", menuBar);
1322     #else
1323 schoenebeck 1225 Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1324 schoenebeck 3364 #endif
1325    
1326 schoenebeck 1225 m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1327     m_VBox.pack_start(m_HPaned);
1328     m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
1329 schoenebeck 1661 m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
1330 schoenebeck 1225 m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
1331 schoenebeck 1411 m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
1332 schoenebeck 1225
1333 persson 2246 set_file_is_shared(false);
1334    
1335 schoenebeck 1411 // Status Bar:
1336 schoenebeck 3364 #if USE_GTKMM_BOX
1337     # warning No status bar layout for GTKMM 4 yet
1338     #else
1339 schoenebeck 1411 m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1340     m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1341 schoenebeck 3364 #endif
1342 schoenebeck 1411 m_StatusBar.show();
1343    
1344 persson 1261 m_RegionChooser.signal_region_selected().connect(
1345 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::region_changed) );
1346 persson 1261 m_DimRegionChooser.signal_dimregion_selected().connect(
1347 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::dimreg_changed) );
1348    
1349    
1350     // Create the Tree model:
1351     m_refTreeModel = Gtk::ListStore::create(m_Columns);
1352 schoenebeck 3340 m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1353     m_refTreeModelFilter->set_visible_func(
1354     sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1355     );
1356     m_TreeView.set_model(m_refTreeModelFilter);
1357    
1358 schoenebeck 2994 m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1359 schoenebeck 3418 m_TreeView.set_has_tooltip(true);
1360     m_TreeView.signal_query_tooltip().connect(
1361     sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1362     );
1363 persson 2442 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1364 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1365     );
1366    
1367     // Add the TreeView's view columns:
1368 schoenebeck 2994 m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1369     m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1370 schoenebeck 3197 m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1371 schoenebeck 2994 m_TreeView.set_headers_visible(true);
1372 schoenebeck 2701
1373     // establish drag&drop within the instrument tree view, allowing to reorder
1374     // the sequence of instruments within the gig file
1375     {
1376     std::vector<Gtk::TargetEntry> drag_target_instrument;
1377     drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1378     m_TreeView.drag_source_set(drag_target_instrument);
1379     m_TreeView.drag_dest_set(drag_target_instrument);
1380     m_TreeView.signal_drag_begin().connect(
1381     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1382     );
1383     m_TreeView.signal_drag_data_get().connect(
1384     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1385     );
1386     m_TreeView.signal_drag_data_received().connect(
1387     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1388     );
1389     }
1390 schoenebeck 1225
1391     // create samples treeview (including its data model)
1392     m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1393     m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1394 schoenebeck 2994 m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1395 schoenebeck 2536 m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
1396 schoenebeck 1225 // m_TreeViewSamples.set_reorderable();
1397 schoenebeck 2621 m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1398     m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1399     {
1400     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1401     Gtk::CellRendererText* cellrenderer =
1402 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1403 schoenebeck 2621 column->add_attribute(
1404     cellrenderer->property_foreground(), m_SamplesModel.m_color
1405     );
1406     }
1407     {
1408     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1409     Gtk::CellRendererText* cellrenderer =
1410 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1411 schoenebeck 2621 column->add_attribute(
1412     cellrenderer->property_foreground(), m_SamplesModel.m_color
1413     );
1414     }
1415     m_TreeViewSamples.set_headers_visible(true);
1416 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1417     m_TreeViewSamples.signal_button_press_event().connect(
1418     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1419     );
1420     #else
1421 schoenebeck 1225 m_TreeViewSamples.signal_button_press_event().connect_notify(
1422     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1423     );
1424 schoenebeck 3364 #endif
1425 schoenebeck 1225 m_refSamplesTreeModel->signal_row_changed().connect(
1426     sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1427     );
1428    
1429 schoenebeck 2604 // create scripts treeview (including its data model)
1430     m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1431     m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1432     m_TreeViewScripts.set_tooltip_text(_(
1433 schoenebeck 2644 "Use CTRL + double click for editing a script."
1434     "\n\n"
1435 schoenebeck 2604 "Note: instrument scripts are a LinuxSampler extension of the gig "
1436     "format. This feature will not work with the GigaStudio software!"
1437     ));
1438     // m_TreeViewScripts.set_reorderable();
1439     m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1440     m_TreeViewScripts.set_headers_visible(false);
1441 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1442     m_TreeViewScripts.signal_button_press_event().connect(
1443     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1444     );
1445     #else
1446 schoenebeck 2604 m_TreeViewScripts.signal_button_press_event().connect_notify(
1447     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1448     );
1449 schoenebeck 3364 #endif
1450 schoenebeck 2695 //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1451 schoenebeck 2644 m_TreeViewScripts.signal_row_activated().connect(
1452     sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1453     );
1454 schoenebeck 2604 m_refScriptsTreeModel->signal_row_changed().connect(
1455     sigc::mem_fun(*this, &MainWindow::script_name_changed)
1456     );
1457    
1458 schoenebeck 2610 // establish drag&drop between scripts tree view and ScriptSlots window
1459     std::vector<Gtk::TargetEntry> drag_target_gig_script;
1460     drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1461     m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1462     m_TreeViewScripts.signal_drag_begin().connect(
1463     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1464     );
1465     m_TreeViewScripts.signal_drag_data_get().connect(
1466     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1467     );
1468    
1469 schoenebeck 1225 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1470 persson 2169 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1471     drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1472 schoenebeck 1225 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1473 persson 1303 m_TreeViewSamples.signal_drag_begin().connect(
1474     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
1475     );
1476 schoenebeck 1225 m_TreeViewSamples.signal_drag_data_get().connect(
1477     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
1478     );
1479     dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
1480     dimreg_edit.wSample->signal_drag_data_received().connect(
1481     sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
1482     );
1483 persson 1261 dimreg_edit.signal_dimreg_changed().connect(
1484 schoenebeck 1322 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1485 persson 1261 m_RegionChooser.signal_instrument_changed().connect(
1486     sigc::mem_fun(*this, &MainWindow::file_changed));
1487 schoenebeck 2773 m_RegionChooser.signal_instrument_changed().connect(
1488     sigc::mem_fun(*this, &MainWindow::region_changed));
1489 persson 1261 m_DimRegionChooser.signal_region_changed().connect(
1490     sigc::mem_fun(*this, &MainWindow::file_changed));
1491 persson 2423 instrumentProps.signal_changed().connect(
1492 persson 1261 sigc::mem_fun(*this, &MainWindow::file_changed));
1493 persson 2423 propDialog.signal_changed().connect(
1494 persson 1582 sigc::mem_fun(*this, &MainWindow::file_changed));
1495 persson 2507 midiRules.signal_changed().connect(
1496     sigc::mem_fun(*this, &MainWindow::file_changed));
1497 schoenebeck 1322
1498     dimreg_edit.signal_dimreg_to_be_changed().connect(
1499     dimreg_to_be_changed_signal.make_slot());
1500     dimreg_edit.signal_dimreg_changed().connect(
1501     dimreg_changed_signal.make_slot());
1502     dimreg_edit.signal_sample_ref_changed().connect(
1503     sample_ref_changed_signal.make_slot());
1504 schoenebeck 2621 sample_ref_changed_signal.connect(
1505     sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1506     );
1507     samples_to_be_removed_signal.connect(
1508     sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1509     );
1510 schoenebeck 1322
1511 schoenebeck 2691 dimreg_edit.signal_select_sample().connect(
1512     sigc::mem_fun(*this, &MainWindow::select_sample)
1513     );
1514    
1515 schoenebeck 1322 m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1516     sigc::hide(
1517     sigc::bind(
1518     file_structure_to_be_changed_signal.make_slot(),
1519     sigc::ref(this->file)
1520     )
1521     )
1522     );
1523     m_RegionChooser.signal_instrument_struct_changed().connect(
1524     sigc::hide(
1525     sigc::bind(
1526     file_structure_changed_signal.make_slot(),
1527     sigc::ref(this->file)
1528     )
1529     )
1530     );
1531     m_RegionChooser.signal_region_to_be_changed().connect(
1532     region_to_be_changed_signal.make_slot());
1533     m_RegionChooser.signal_region_changed_signal().connect(
1534     region_changed_signal.make_slot());
1535    
1536 schoenebeck 1654 note_on_signal.connect(
1537     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
1538     note_off_signal.connect(
1539     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
1540    
1541 persson 1533 dimreg_all_regions.signal_toggled().connect(
1542     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1543     dimreg_all_dimregs.signal_toggled().connect(
1544     sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
1545     dimreg_stereo.signal_toggled().connect(
1546     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1547    
1548 schoenebeck 3340 m_searchText.signal_changed().connect(
1549     sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1550     );
1551    
1552 schoenebeck 1225 file = 0;
1553 persson 1261 file_is_changed = false;
1554 schoenebeck 1225
1555 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1556 schoenebeck 1225 show_all_children();
1557 schoenebeck 3364 #endif
1558 schoenebeck 1300
1559     // start with a new gig file by default
1560     on_action_file_new();
1561 schoenebeck 2550
1562 schoenebeck 3340 m_TreeViewNotebook.signal_switch_page().connect(
1563     sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1564     );
1565    
1566 schoenebeck 2550 // select 'Instruments' tab by default
1567     // (gtk allows this only if the tab childs are visible, thats why it's here)
1568 schoenebeck 3144 m_TreeViewNotebook.set_current_page(1);
1569    
1570     Gtk::Clipboard::get()->signal_owner_change().connect(
1571     sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1572     );
1573     updateClipboardPasteAvailable();
1574     updateClipboardCopyAvailable();
1575 schoenebeck 3157
1576     // setup macros and their keyboard accelerators
1577     {
1578 schoenebeck 3364 #if USE_GTKMM_BUILDER
1579     menuMacro = new Gtk::Menu(
1580     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1581     m_uiManager->get_object("MenuMacro")
1582     )
1583     );
1584     #else
1585 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1586     uiManager->get_widget("/MenuBar/MenuMacro")
1587     )->get_submenu();
1588 schoenebeck 3364 #endif
1589 schoenebeck 3157
1590     const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1591     Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1592     Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1593     Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1594     Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1595     Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1596     Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1597     Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1598     Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1599     Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1600     Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1601     Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1602     Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1603 schoenebeck 3417 Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1604     Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1605     Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1606     Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1607     Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1608     Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1609     Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1610 schoenebeck 3157 Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1611    
1612     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1613     menuMacro->set_accel_group(accelGroup);
1614    
1615     updateMacroMenu();
1616     }
1617 schoenebeck 3258
1618 schoenebeck 3339 // setup "Assign Scripts" keyboard accelerators
1619     {
1620     Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1621     Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1622     Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1623     Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1624     Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1625     Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1626     Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1627     Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1628     Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1629     Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1630     Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1631     Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1632 schoenebeck 3417 Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1633     Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1634     Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1635     Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1636     Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1637     Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1638     Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1639 schoenebeck 3419 Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1640 schoenebeck 3339
1641     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1642     assign_scripts_menu->set_accel_group(accelGroup);
1643     }
1644    
1645 schoenebeck 3409 on_show_tooltips_changed();
1646    
1647 schoenebeck 3258 Glib::signal_idle().connect_once(
1648     sigc::mem_fun(*this, &MainWindow::bringToFront),
1649     200
1650     );
1651 schoenebeck 1225 }
1652    
1653     MainWindow::~MainWindow()
1654     {
1655     }
1656    
1657 schoenebeck 3258 void MainWindow::bringToFront() {
1658     #if defined(__APPLE__)
1659     macRaiseAppWindow();
1660     #endif
1661     raise();
1662     present();
1663     }
1664    
1665 schoenebeck 3157 void MainWindow::updateMacroMenu() {
1666 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1667 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1668     uiManager->get_widget("/MenuBar/MenuMacro")
1669     )->get_submenu();
1670 schoenebeck 3364 #endif
1671 schoenebeck 3157
1672     // remove all entries from "Macro" menu
1673     {
1674     const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1675     for (int i = 0; i < children.size(); ++i) {
1676     Gtk::Widget* child = children[i];
1677     menuMacro->remove(*child);
1678     delete child;
1679     }
1680     }
1681    
1682     // (re)load all macros from config file
1683     try {
1684     Settings::singleton()->loadMacros(m_macros);
1685     } catch (Serialization::Exception e) {
1686     std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1687     } catch (...) {
1688     std::cerr << "Unknown exception while loading macros!" << std::endl;
1689     }
1690    
1691     // add all configured macros as menu items to the "Macro" menu
1692     for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1693     const Serialization::Archive& macro = m_macros[iMacro];
1694     std::string name =
1695     macro.name().empty() ?
1696     (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1697     Gtk::MenuItem* item = new Gtk::MenuItem(name);
1698     item->signal_activate().connect(
1699     sigc::bind(
1700     sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1701     )
1702     );
1703     menuMacro->append(*item);
1704     item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1705 schoenebeck 3174 Glib::ustring comment = macro.comment();
1706     if (!comment.empty())
1707     item->set_tooltip_text(comment);
1708 schoenebeck 3157 }
1709     // if there are no macros configured at all, then show a dummy entry instead
1710     if (m_macros.empty()) {
1711     Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1712     item->set_sensitive(false);
1713     menuMacro->append(*item);
1714     }
1715    
1716     // add separator line to menu
1717     menuMacro->append(*new Gtk::SeparatorMenuItem);
1718    
1719     {
1720     Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1721     item->signal_activate().connect(
1722     sigc::mem_fun(*this, &MainWindow::setupMacros)
1723     );
1724     menuMacro->append(*item);
1725     item->set_accel_path("<Macros>/SetupMacros");
1726     }
1727    
1728 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1729 schoenebeck 3157 menuMacro->show_all_children();
1730 schoenebeck 3364 #endif
1731 schoenebeck 3157 }
1732    
1733     void MainWindow::onMacroSelected(int iMacro) {
1734     printf("onMacroSelected(%d)\n", iMacro);
1735     if (iMacro < 0 || iMacro >= m_macros.size()) return;
1736     Glib::ustring errorText;
1737     try {
1738     applyMacro(m_macros[iMacro]);
1739     } catch (Serialization::Exception e) {
1740     errorText = e.Message;
1741     } catch (...) {
1742     errorText = _("Unknown exception while applying macro");
1743     }
1744     if (!errorText.empty()) {
1745     Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1746     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1747     msg.run();
1748     }
1749     }
1750    
1751     void MainWindow::setupMacros() {
1752     MacrosSetup* setup = new MacrosSetup();
1753 schoenebeck 3160 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1754     setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1755 schoenebeck 3157 setup->signal_macros_changed().connect(
1756     sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1757     );
1758     setup->show();
1759     }
1760    
1761     void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1762     m_macros = macros;
1763     Settings::singleton()->saveMacros(m_macros);
1764     updateMacroMenu();
1765     }
1766    
1767 schoenebeck 3344 //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.
1768     void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1769 schoenebeck 3340 bool isInstrumentsPage = (page_num == 1);
1770     // so far we only support filtering for the instruments list, so hide the
1771     // filter text entry field if another tab is selected
1772     m_searchField.set_visible(isInstrumentsPage);
1773     }
1774    
1775 persson 1261 bool MainWindow::on_delete_event(GdkEventAny* event)
1776     {
1777 schoenebeck 1382 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
1778 persson 1261 }
1779    
1780     void MainWindow::on_action_quit()
1781     {
1782 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
1783 persson 1261 hide();
1784     }
1785    
1786 schoenebeck 1225 void MainWindow::region_changed()
1787     {
1788     m_DimRegionChooser.set_region(m_RegionChooser.get_region());
1789     }
1790    
1791 persson 1533 gig::Instrument* MainWindow::get_instrument()
1792 schoenebeck 1225 {
1793 persson 1533 gig::Instrument* instrument = 0;
1794 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1795     if (rows.empty()) return NULL;
1796 schoenebeck 3364 //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1797     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1798 schoenebeck 1225 if (it) {
1799     Gtk::TreeModel::Row row = *it;
1800 persson 1533 instrument = row[m_Columns.m_col_instr];
1801     }
1802     return instrument;
1803     }
1804 schoenebeck 1225
1805 persson 1533 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
1806     {
1807     if (all_dimregs) {
1808     for (int i = 0 ; i < region->DimensionRegions ; i++) {
1809     if (region->pDimensionRegions[i]) {
1810     dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
1811     }
1812     }
1813 schoenebeck 1225 } else {
1814 persson 1533 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
1815 schoenebeck 1225 }
1816     }
1817    
1818 persson 1533 void MainWindow::update_dimregs()
1819     {
1820     dimreg_edit.dimregs.clear();
1821     bool all_regions = dimreg_all_regions.get_active();
1822     bool stereo = dimreg_stereo.get_active();
1823     bool all_dimregs = dimreg_all_dimregs.get_active();
1824    
1825     if (all_regions) {
1826     gig::Instrument* instrument = get_instrument();
1827     if (instrument) {
1828     for (gig::Region* region = instrument->GetFirstRegion() ;
1829     region ;
1830     region = instrument->GetNextRegion()) {
1831     add_region_to_dimregs(region, stereo, all_dimregs);
1832     }
1833     }
1834     } else {
1835     gig::Region* region = m_RegionChooser.get_region();
1836     if (region) {
1837     add_region_to_dimregs(region, stereo, all_dimregs);
1838     }
1839     }
1840 schoenebeck 3089
1841 schoenebeck 3148 m_RegionChooser.setModifyAllRegions(all_regions);
1842 schoenebeck 3089 m_DimRegionChooser.setModifyAllRegions(all_regions);
1843     m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1844     m_DimRegionChooser.setModifyBothChannels(stereo);
1845 schoenebeck 3144
1846     updateClipboardCopyAvailable();
1847 persson 1533 }
1848    
1849     void MainWindow::dimreg_all_dimregs_toggled()
1850     {
1851     dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
1852     update_dimregs();
1853     }
1854    
1855     void MainWindow::dimreg_changed()
1856     {
1857     update_dimregs();
1858 schoenebeck 2626 dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1859 persson 1533 }
1860    
1861     void MainWindow::on_sel_change()
1862     {
1863 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1864 persson 2442 // select item in instrument menu
1865 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1866     if (!rows.empty()) {
1867     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1868     if (it) {
1869     Gtk::TreePath path(it);
1870     int index = path[0];
1871     const std::vector<Gtk::Widget*> children =
1872     instrument_menu->get_children();
1873     static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1874     }
1875 persson 2442 }
1876 schoenebeck 3364 #endif
1877 persson 2442
1878 schoenebeck 3339 updateScriptListOfMenu();
1879    
1880 persson 1533 m_RegionChooser.set_instrument(get_instrument());
1881 schoenebeck 2689
1882     if (Settings::singleton()->syncSamplerInstrumentSelection) {
1883     switch_sampler_instrument_signal.emit(get_instrument());
1884     }
1885 persson 1533 }
1886    
1887 schoenebeck 1225 void loader_progress_callback(gig::progress_t* progress)
1888     {
1889     Loader* loader = static_cast<Loader*>(progress->custom);
1890     loader->progress_callback(progress->factor);
1891     }
1892    
1893     void Loader::progress_callback(float fraction)
1894     {
1895     {
1896 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
1897 schoenebeck 1225 progress = fraction;
1898     }
1899     progress_dispatcher();
1900     }
1901    
1902 persson 3021 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1903     // make sure stack is 16-byte aligned for SSE instructions
1904     __attribute__((force_align_arg_pointer))
1905     #endif
1906 schoenebeck 1225 void Loader::thread_function()
1907     {
1908 persson 2841 printf("thread_function self=%p\n",
1909     static_cast<void*>(Glib::Threads::Thread::self()));
1910 schoenebeck 2683 printf("Start %s\n", filename.c_str());
1911     try {
1912     RIFF::File* riff = new RIFF::File(filename);
1913     gig = new gig::File(riff);
1914     gig::progress_t progress;
1915     progress.callback = loader_progress_callback;
1916     progress.custom = this;
1917 schoenebeck 1225
1918 schoenebeck 2683 gig->GetInstrument(0, &progress);
1919     printf("End\n");
1920     finished_dispatcher();
1921     } catch (RIFF::Exception e) {
1922     error_message = e.Message;
1923     error_dispatcher.emit();
1924     } catch (...) {
1925     error_message = _("Unknown exception occurred");
1926     error_dispatcher.emit();
1927     }
1928 schoenebeck 1225 }
1929    
1930     Loader::Loader(const char* filename)
1931 persson 2841 : filename(filename), gig(0), thread(0), progress(0.f)
1932 schoenebeck 1225 {
1933     }
1934    
1935     void Loader::launch()
1936     {
1937 persson 2332 #ifdef OLD_THREADS
1938     thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
1939     #else
1940     thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1941     #endif
1942 persson 2841 printf("launch thread=%p\n", static_cast<void*>(thread));
1943 schoenebeck 1225 }
1944    
1945     float Loader::get_progress()
1946     {
1947     float res;
1948     {
1949 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
1950 schoenebeck 1225 res = progress;
1951     }
1952     return res;
1953     }
1954    
1955     Glib::Dispatcher& Loader::signal_progress()
1956     {
1957     return progress_dispatcher;
1958     }
1959    
1960     Glib::Dispatcher& Loader::signal_finished()
1961     {
1962     return finished_dispatcher;
1963     }
1964    
1965 schoenebeck 2683 Glib::Dispatcher& Loader::signal_error()
1966     {
1967     return error_dispatcher;
1968     }
1969    
1970     void saver_progress_callback(gig::progress_t* progress)
1971     {
1972     Saver* saver = static_cast<Saver*>(progress->custom);
1973     saver->progress_callback(progress->factor);
1974     }
1975    
1976     void Saver::progress_callback(float fraction)
1977     {
1978     {
1979     Glib::Threads::Mutex::Lock lock(progressMutex);
1980     progress = fraction;
1981     }
1982     progress_dispatcher.emit();
1983     }
1984    
1985 persson 3021 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1986     // make sure stack is 16-byte aligned for SSE instructions
1987     __attribute__((force_align_arg_pointer))
1988     #endif
1989 schoenebeck 2683 void Saver::thread_function()
1990     {
1991 persson 2841 printf("thread_function self=%p\n",
1992     static_cast<void*>(Glib::Threads::Thread::self()));
1993 schoenebeck 2683 printf("Start %s\n", filename.c_str());
1994     try {
1995     gig::progress_t progress;
1996     progress.callback = saver_progress_callback;
1997     progress.custom = this;
1998    
1999     // if no filename was provided, that means "save", if filename was provided means "save as"
2000     if (filename.empty()) {
2001 schoenebeck 2967 if (!Settings::singleton()->saveWithTemporaryFile) {
2002     // save directly over the existing .gig file
2003     // (requires less disk space than solution below
2004     // but may be slower)
2005     gig->Save(&progress);
2006     } else {
2007     // save the file as separate temporary file first,
2008     // then move the saved file over the old file
2009     // (may result in performance speedup during save)
2010 schoenebeck 3179 gig::String tmpname = filename + ".TMP";
2011 schoenebeck 2967 gig->Save(tmpname, &progress);
2012     #if defined(WIN32)
2013 schoenebeck 2968 if (!DeleteFile(filename.c_str())) {
2014 schoenebeck 2967 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
2015     }
2016     #else // POSIX ...
2017     if (unlink(filename.c_str())) {
2018 schoenebeck 3180 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2019 schoenebeck 2967 }
2020     #endif
2021     if (rename(tmpname.c_str(), filename.c_str())) {
2022     #if defined(WIN32)
2023     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
2024     #else
2025 schoenebeck 3180 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2026 schoenebeck 2967 #endif
2027     }
2028     }
2029 schoenebeck 2683 } else {
2030     gig->Save(filename, &progress);
2031     }
2032    
2033     printf("End\n");
2034     finished_dispatcher.emit();
2035     } catch (RIFF::Exception e) {
2036     error_message = e.Message;
2037     error_dispatcher.emit();
2038     } catch (...) {
2039     error_message = _("Unknown exception occurred");
2040     error_dispatcher.emit();
2041     }
2042     }
2043    
2044     Saver::Saver(gig::File* file, Glib::ustring filename)
2045     : gig(file), filename(filename), thread(0), progress(0.f)
2046     {
2047     }
2048    
2049     void Saver::launch()
2050     {
2051     #ifdef OLD_THREADS
2052     thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
2053     #else
2054     thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2055     #endif
2056 persson 2841 printf("launch thread=%p\n", static_cast<void*>(thread));
2057 schoenebeck 2683 }
2058    
2059     float Saver::get_progress()
2060     {
2061     float res;
2062     {
2063     Glib::Threads::Mutex::Lock lock(progressMutex);
2064     res = progress;
2065     }
2066     return res;
2067     }
2068    
2069     Glib::Dispatcher& Saver::signal_progress()
2070     {
2071     return progress_dispatcher;
2072     }
2073    
2074     Glib::Dispatcher& Saver::signal_finished()
2075     {
2076     return finished_dispatcher;
2077     }
2078    
2079     Glib::Dispatcher& Saver::signal_error()
2080     {
2081     return error_dispatcher;
2082     }
2083    
2084     ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2085 schoenebeck 1225 : Gtk::Dialog(title, parent, true)
2086     {
2087 schoenebeck 3364 #if USE_GTKMM_BOX
2088     get_content_area()->pack_start(progressBar);
2089     #else
2090 schoenebeck 1225 get_vbox()->pack_start(progressBar);
2091 schoenebeck 3364 #endif
2092     #if HAS_GTKMM_SHOW_ALL_CHILDREN
2093 schoenebeck 1225 show_all_children();
2094 schoenebeck 3364 #endif
2095 schoenebeck 2683 resize(600,50);
2096 schoenebeck 1225 }
2097    
2098     // Clear all GUI elements / controls. This method is typically called
2099     // before a new .gig file is to be created or to be loaded.
2100     void MainWindow::__clear() {
2101     // forget all samples that ought to be imported
2102     m_SampleImportQueue.clear();
2103     // clear the samples and instruments tree views
2104     m_refTreeModel->clear();
2105     m_refSamplesTreeModel->clear();
2106 schoenebeck 2615 m_refScriptsTreeModel->clear();
2107 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2108 persson 2442 // remove all entries from "Instrument" menu
2109     while (!instrument_menu->get_children().empty()) {
2110     remove_instrument_from_menu(0);
2111     }
2112 schoenebeck 3364 #endif
2113 schoenebeck 1225 // free libgig's gig::File instance
2114 schoenebeck 1382 if (file && !file_is_shared) delete file;
2115     file = NULL;
2116 schoenebeck 1411 set_file_is_shared(false);
2117 schoenebeck 1225 }
2118    
2119 schoenebeck 2553 void MainWindow::__refreshEntireGUI() {
2120     // clear the samples and instruments tree views
2121     m_refTreeModel->clear();
2122     m_refSamplesTreeModel->clear();
2123 schoenebeck 2615 m_refScriptsTreeModel->clear();
2124 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2125 schoenebeck 2553 // remove all entries from "Instrument" menu
2126     while (!instrument_menu->get_children().empty()) {
2127     remove_instrument_from_menu(0);
2128     }
2129 schoenebeck 3364 #endif
2130 schoenebeck 2553
2131     if (!this->file) return;
2132    
2133     load_gig(
2134     this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2135     );
2136     }
2137    
2138 schoenebeck 1225 void MainWindow::on_action_file_new()
2139     {
2140 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2141 persson 1261
2142 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2143    
2144 schoenebeck 1225 // clear all GUI elements
2145     __clear();
2146     // create a new .gig file (virtually yet)
2147     gig::File* pFile = new gig::File;
2148     // already add one new instrument by default
2149     gig::Instrument* pInstrument = pFile->AddInstrument();
2150 persson 2446 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2151 schoenebeck 1225 // update GUI with that new gig::File
2152 persson 1261 load_gig(pFile, 0 /*no file name yet*/);
2153 schoenebeck 1225 }
2154    
2155 persson 1261 bool MainWindow::close_confirmation_dialog()
2156     {
2157     gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
2158     Glib::filename_display_basename(filename).c_str());
2159     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2160     g_free(msg);
2161     dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2162     dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2163 schoenebeck 3364 #if HAS_GTKMM_STOCK
2164 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2165     dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2166 schoenebeck 3364 #else
2167     dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2168     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2169     #endif
2170 persson 1261 dialog.set_default_response(Gtk::RESPONSE_YES);
2171     int response = dialog.run();
2172 persson 1303 dialog.hide();
2173 schoenebeck 2683
2174 schoenebeck 2694 // user decided to exit app without saving
2175     if (response == Gtk::RESPONSE_NO) return true;
2176    
2177     // user cancelled dialog, thus don't close app
2178     if (response == Gtk::RESPONSE_CANCEL) return false;
2179    
2180 schoenebeck 2683 // TODO: the following return valid is disabled and hard coded instead for
2181     // now, due to the fact that saving with progress bar is now implemented
2182     // asynchronously, as a result the app does not close automatically anymore
2183     // after saving the file has completed
2184     //
2185     // if (response == Gtk::RESPONSE_YES) return file_save();
2186     // return response != Gtk::RESPONSE_CANCEL;
2187     //
2188     if (response == Gtk::RESPONSE_YES) file_save();
2189     return false; // always prevent closing the app for now (see comment above)
2190 persson 1261 }
2191    
2192 schoenebeck 1382 bool MainWindow::leaving_shared_mode_dialog() {
2193     Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2194     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2195     dialog.set_secondary_text(
2196     _("If you proceed to work on another instrument file, it won't be "
2197     "used by the sampler until you tell the sampler explicitly to "
2198 persson 2151 "load it."));
2199 schoenebeck 1382 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2200 schoenebeck 3364 #if HAS_GTKMM_STOCK
2201 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2202 schoenebeck 3364 #else
2203     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2204     #endif
2205 schoenebeck 1382 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2206     int response = dialog.run();
2207     dialog.hide();
2208     return response == Gtk::RESPONSE_YES;
2209     }
2210    
2211 schoenebeck 1225 void MainWindow::on_action_file_open()
2212     {
2213 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2214 persson 1261
2215 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2216    
2217 schoenebeck 1225 Gtk::FileChooserDialog dialog(*this, _("Open file"));
2218 schoenebeck 3364 #if HAS_GTKMM_STOCK
2219 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2220     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2221 schoenebeck 3364 #else
2222     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2223     dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2224     #endif
2225 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
2226 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2227 schoenebeck 1225 Gtk::FileFilter filter;
2228     filter.add_pattern("*.gig");
2229 persson 2169 #else
2230     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2231     filter->add_pattern("*.gig");
2232     #endif
2233 schoenebeck 1225 dialog.set_filter(filter);
2234 persson 1725 if (current_gig_dir != "") {
2235     dialog.set_current_folder(current_gig_dir);
2236 persson 1261 }
2237 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
2238 persson 1261 std::string filename = dialog.get_filename();
2239     printf("filename=%s\n", filename.c_str());
2240 persson 2841 printf("on_action_file_open self=%p\n",
2241     static_cast<void*>(Glib::Threads::Thread::self()));
2242 persson 1261 load_file(filename.c_str());
2243 persson 1725 current_gig_dir = Glib::path_get_dirname(filename);
2244 schoenebeck 1225 }
2245     }
2246    
2247     void MainWindow::load_file(const char* name)
2248     {
2249 persson 1303 __clear();
2250 schoenebeck 2683
2251     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2252     _("Loading") + Glib::ustring(" '") +
2253     Glib::filename_display_basename(name) + "' ...",
2254     *this
2255     );
2256 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2257 schoenebeck 2683 progress_dialog->show_all();
2258 schoenebeck 3364 #endif
2259 schoenebeck 2683 loader = new Loader(name); //FIXME: memory leak!
2260 schoenebeck 1225 loader->signal_progress().connect(
2261     sigc::mem_fun(*this, &MainWindow::on_loader_progress));
2262     loader->signal_finished().connect(
2263     sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2264 schoenebeck 2683 loader->signal_error().connect(
2265     sigc::mem_fun(*this, &MainWindow::on_loader_error));
2266 schoenebeck 1225 loader->launch();
2267     }
2268    
2269     void MainWindow::load_instrument(gig::Instrument* instr) {
2270     if (!instr) {
2271     Glib::ustring txt = "Provided instrument is NULL!\n";
2272     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2273     msg.run();
2274     Gtk::Main::quit();
2275     }
2276 schoenebeck 1328 // clear all GUI elements
2277     __clear();
2278     // load the instrument
2279 schoenebeck 1225 gig::File* pFile = (gig::File*) instr->GetParent();
2280 schoenebeck 1382 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2281 schoenebeck 2664 // automatically select the given instrument
2282     int i = 0;
2283     for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2284     instrument = pFile->GetNextInstrument(), ++i)
2285     {
2286     if (instrument == instr) {
2287     // select item in "instruments" tree view
2288     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2289     // make sure the selected item in the "instruments" tree view is
2290     // visible (scroll to it)
2291     m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2292 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2293 schoenebeck 2664 // select item in instrument menu
2294     {
2295     const std::vector<Gtk::Widget*> children =
2296     instrument_menu->get_children();
2297     static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2298     }
2299 schoenebeck 3364 #endif
2300 schoenebeck 2664 // update region chooser and dimension region chooser
2301     m_RegionChooser.set_instrument(instr);
2302     break;
2303     }
2304     }
2305 schoenebeck 1225 }
2306    
2307     void MainWindow::on_loader_progress()
2308     {
2309 schoenebeck 2683 progress_dialog->set_fraction(loader->get_progress());
2310 schoenebeck 1225 }
2311    
2312     void MainWindow::on_loader_finished()
2313     {
2314     printf("Loader finished!\n");
2315 persson 2841 printf("on_loader_finished self=%p\n",
2316     static_cast<void*>(Glib::Threads::Thread::self()));
2317 schoenebeck 2683 load_gig(loader->gig, loader->filename.c_str());
2318     progress_dialog->hide();
2319 schoenebeck 1225 }
2320    
2321 schoenebeck 2683 void MainWindow::on_loader_error()
2322     {
2323     Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2324     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2325     msg.run();
2326     progress_dialog->hide();
2327     }
2328    
2329 schoenebeck 1225 void MainWindow::on_action_file_save()
2330     {
2331 persson 1261 file_save();
2332     }
2333    
2334 persson 1303 bool MainWindow::check_if_savable()
2335     {
2336     if (!file) return false;
2337    
2338     if (!file->GetFirstSample()) {
2339     Gtk::MessageDialog(*this, _("The file could not be saved "
2340     "because it contains no samples"),
2341     false, Gtk::MESSAGE_ERROR).run();
2342     return false;
2343     }
2344    
2345     for (gig::Instrument* instrument