/[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 3417 - (hide annotations) (download)
Fri Feb 9 15:29:13 2018 UTC (6 years, 2 months ago) by schoenebeck
File size: 208002 byte(s)
* Extended support for keyboard function keys up to F19.
* Bumped version (1.1.0.svn4).

1 schoenebeck 1225 /*
2 schoenebeck 3089 * Copyright (C) 2006-2017 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 2701 m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
1360 persson 2442 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1361 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1362     );
1363    
1364     // Add the TreeView's view columns:
1365 schoenebeck 2994 m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1366     m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1367 schoenebeck 3197 m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1368 schoenebeck 2994 m_TreeView.set_headers_visible(true);
1369 schoenebeck 2701
1370     // establish drag&drop within the instrument tree view, allowing to reorder
1371     // the sequence of instruments within the gig file
1372     {
1373     std::vector<Gtk::TargetEntry> drag_target_instrument;
1374     drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1375     m_TreeView.drag_source_set(drag_target_instrument);
1376     m_TreeView.drag_dest_set(drag_target_instrument);
1377     m_TreeView.signal_drag_begin().connect(
1378     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1379     );
1380     m_TreeView.signal_drag_data_get().connect(
1381     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1382     );
1383     m_TreeView.signal_drag_data_received().connect(
1384     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1385     );
1386     }
1387 schoenebeck 1225
1388     // create samples treeview (including its data model)
1389     m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1390     m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1391 schoenebeck 2994 m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1392 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."));
1393 schoenebeck 1225 // m_TreeViewSamples.set_reorderable();
1394 schoenebeck 2621 m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1395     m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1396     {
1397     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1398     Gtk::CellRendererText* cellrenderer =
1399 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1400 schoenebeck 2621 column->add_attribute(
1401     cellrenderer->property_foreground(), m_SamplesModel.m_color
1402     );
1403     }
1404     {
1405     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1406     Gtk::CellRendererText* cellrenderer =
1407 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1408 schoenebeck 2621 column->add_attribute(
1409     cellrenderer->property_foreground(), m_SamplesModel.m_color
1410     );
1411     }
1412     m_TreeViewSamples.set_headers_visible(true);
1413 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
1414     m_TreeViewSamples.signal_button_press_event().connect(
1415     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1416     );
1417     #else
1418 schoenebeck 1225 m_TreeViewSamples.signal_button_press_event().connect_notify(
1419     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1420     );
1421 schoenebeck 3364 #endif
1422 schoenebeck 1225 m_refSamplesTreeModel->signal_row_changed().connect(
1423     sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1424     );
1425    
1426 schoenebeck 2604 // create scripts treeview (including its data model)
1427     m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1428     m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1429     m_TreeViewScripts.set_tooltip_text(_(
1430 schoenebeck 2644 "Use CTRL + double click for editing a script."
1431     "\n\n"
1432 schoenebeck 2604 "Note: instrument scripts are a LinuxSampler extension of the gig "
1433     "format. This feature will not work with the GigaStudio software!"
1434     ));
1435     // m_TreeViewScripts.set_reorderable();
1436     m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1437     m_TreeViewScripts.set_headers_visible(false);
1438 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
1439     m_TreeViewScripts.signal_button_press_event().connect(
1440     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1441     );
1442     #else
1443 schoenebeck 2604 m_TreeViewScripts.signal_button_press_event().connect_notify(
1444     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1445     );
1446 schoenebeck 3364 #endif
1447 schoenebeck 2695 //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1448 schoenebeck 2644 m_TreeViewScripts.signal_row_activated().connect(
1449     sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1450     );
1451 schoenebeck 2604 m_refScriptsTreeModel->signal_row_changed().connect(
1452     sigc::mem_fun(*this, &MainWindow::script_name_changed)
1453     );
1454    
1455 schoenebeck 2610 // establish drag&drop between scripts tree view and ScriptSlots window
1456     std::vector<Gtk::TargetEntry> drag_target_gig_script;
1457     drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1458     m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1459     m_TreeViewScripts.signal_drag_begin().connect(
1460     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1461     );
1462     m_TreeViewScripts.signal_drag_data_get().connect(
1463     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1464     );
1465    
1466 schoenebeck 1225 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1467 persson 2169 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1468     drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1469 schoenebeck 1225 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1470 persson 1303 m_TreeViewSamples.signal_drag_begin().connect(
1471     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
1472     );
1473 schoenebeck 1225 m_TreeViewSamples.signal_drag_data_get().connect(
1474     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
1475     );
1476     dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
1477     dimreg_edit.wSample->signal_drag_data_received().connect(
1478     sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
1479     );
1480 persson 1261 dimreg_edit.signal_dimreg_changed().connect(
1481 schoenebeck 1322 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1482 persson 1261 m_RegionChooser.signal_instrument_changed().connect(
1483     sigc::mem_fun(*this, &MainWindow::file_changed));
1484 schoenebeck 2773 m_RegionChooser.signal_instrument_changed().connect(
1485     sigc::mem_fun(*this, &MainWindow::region_changed));
1486 persson 1261 m_DimRegionChooser.signal_region_changed().connect(
1487     sigc::mem_fun(*this, &MainWindow::file_changed));
1488 persson 2423 instrumentProps.signal_changed().connect(
1489 persson 1261 sigc::mem_fun(*this, &MainWindow::file_changed));
1490 persson 2423 propDialog.signal_changed().connect(
1491 persson 1582 sigc::mem_fun(*this, &MainWindow::file_changed));
1492 persson 2507 midiRules.signal_changed().connect(
1493     sigc::mem_fun(*this, &MainWindow::file_changed));
1494 schoenebeck 1322
1495     dimreg_edit.signal_dimreg_to_be_changed().connect(
1496     dimreg_to_be_changed_signal.make_slot());
1497     dimreg_edit.signal_dimreg_changed().connect(
1498     dimreg_changed_signal.make_slot());
1499     dimreg_edit.signal_sample_ref_changed().connect(
1500     sample_ref_changed_signal.make_slot());
1501 schoenebeck 2621 sample_ref_changed_signal.connect(
1502     sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1503     );
1504     samples_to_be_removed_signal.connect(
1505     sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1506     );
1507 schoenebeck 1322
1508 schoenebeck 2691 dimreg_edit.signal_select_sample().connect(
1509     sigc::mem_fun(*this, &MainWindow::select_sample)
1510     );
1511    
1512 schoenebeck 1322 m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1513     sigc::hide(
1514     sigc::bind(
1515     file_structure_to_be_changed_signal.make_slot(),
1516     sigc::ref(this->file)
1517     )
1518     )
1519     );
1520     m_RegionChooser.signal_instrument_struct_changed().connect(
1521     sigc::hide(
1522     sigc::bind(
1523     file_structure_changed_signal.make_slot(),
1524     sigc::ref(this->file)
1525     )
1526     )
1527     );
1528     m_RegionChooser.signal_region_to_be_changed().connect(
1529     region_to_be_changed_signal.make_slot());
1530     m_RegionChooser.signal_region_changed_signal().connect(
1531     region_changed_signal.make_slot());
1532    
1533 schoenebeck 1654 note_on_signal.connect(
1534     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
1535     note_off_signal.connect(
1536     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
1537    
1538 persson 1533 dimreg_all_regions.signal_toggled().connect(
1539     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1540     dimreg_all_dimregs.signal_toggled().connect(
1541     sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
1542     dimreg_stereo.signal_toggled().connect(
1543     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1544    
1545 schoenebeck 3340 m_searchText.signal_changed().connect(
1546     sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1547     );
1548    
1549 schoenebeck 1225 file = 0;
1550 persson 1261 file_is_changed = false;
1551 schoenebeck 1225
1552 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1553 schoenebeck 1225 show_all_children();
1554 schoenebeck 3364 #endif
1555 schoenebeck 1300
1556     // start with a new gig file by default
1557     on_action_file_new();
1558 schoenebeck 2550
1559 schoenebeck 3340 m_TreeViewNotebook.signal_switch_page().connect(
1560     sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1561     );
1562    
1563 schoenebeck 2550 // select 'Instruments' tab by default
1564     // (gtk allows this only if the tab childs are visible, thats why it's here)
1565 schoenebeck 3144 m_TreeViewNotebook.set_current_page(1);
1566    
1567     Gtk::Clipboard::get()->signal_owner_change().connect(
1568     sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1569     );
1570     updateClipboardPasteAvailable();
1571     updateClipboardCopyAvailable();
1572 schoenebeck 3157
1573     // setup macros and their keyboard accelerators
1574     {
1575 schoenebeck 3364 #if USE_GTKMM_BUILDER
1576     menuMacro = new Gtk::Menu(
1577     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1578     m_uiManager->get_object("MenuMacro")
1579     )
1580     );
1581     #else
1582 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1583     uiManager->get_widget("/MenuBar/MenuMacro")
1584     )->get_submenu();
1585 schoenebeck 3364 #endif
1586 schoenebeck 3157
1587     const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1588     Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1589     Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1590     Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1591     Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1592     Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1593     Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1594     Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1595     Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1596     Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1597     Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1598     Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1599     Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1600 schoenebeck 3417 Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1601     Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1602     Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1603     Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1604     Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1605     Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1606     Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1607 schoenebeck 3157 Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1608    
1609     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1610     menuMacro->set_accel_group(accelGroup);
1611    
1612     updateMacroMenu();
1613     }
1614 schoenebeck 3258
1615 schoenebeck 3339 // setup "Assign Scripts" keyboard accelerators
1616     {
1617     Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1618     Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1619     Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1620     Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1621     Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1622     Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1623     Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1624     Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1625     Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1626     Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1627     Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1628     Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1629 schoenebeck 3417 Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1630     Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1631     Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1632     Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1633     Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1634     Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1635     Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1636 schoenebeck 3339
1637     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1638     assign_scripts_menu->set_accel_group(accelGroup);
1639     }
1640    
1641 schoenebeck 3409 on_show_tooltips_changed();
1642    
1643 schoenebeck 3258 Glib::signal_idle().connect_once(
1644     sigc::mem_fun(*this, &MainWindow::bringToFront),
1645     200
1646     );
1647 schoenebeck 1225 }
1648    
1649     MainWindow::~MainWindow()
1650     {
1651     }
1652    
1653 schoenebeck 3258 void MainWindow::bringToFront() {
1654     #if defined(__APPLE__)
1655     macRaiseAppWindow();
1656     #endif
1657     raise();
1658     present();
1659     }
1660    
1661 schoenebeck 3157 void MainWindow::updateMacroMenu() {
1662 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1663 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1664     uiManager->get_widget("/MenuBar/MenuMacro")
1665     )->get_submenu();
1666 schoenebeck 3364 #endif
1667 schoenebeck 3157
1668     // remove all entries from "Macro" menu
1669     {
1670     const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1671     for (int i = 0; i < children.size(); ++i) {
1672     Gtk::Widget* child = children[i];
1673     menuMacro->remove(*child);
1674     delete child;
1675     }
1676     }
1677    
1678     // (re)load all macros from config file
1679     try {
1680     Settings::singleton()->loadMacros(m_macros);
1681     } catch (Serialization::Exception e) {
1682     std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1683     } catch (...) {
1684     std::cerr << "Unknown exception while loading macros!" << std::endl;
1685     }
1686    
1687     // add all configured macros as menu items to the "Macro" menu
1688     for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1689     const Serialization::Archive& macro = m_macros[iMacro];
1690     std::string name =
1691     macro.name().empty() ?
1692     (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1693     Gtk::MenuItem* item = new Gtk::MenuItem(name);
1694     item->signal_activate().connect(
1695     sigc::bind(
1696     sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1697     )
1698     );
1699     menuMacro->append(*item);
1700     item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1701 schoenebeck 3174 Glib::ustring comment = macro.comment();
1702     if (!comment.empty())
1703     item->set_tooltip_text(comment);
1704 schoenebeck 3157 }
1705     // if there are no macros configured at all, then show a dummy entry instead
1706     if (m_macros.empty()) {
1707     Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1708     item->set_sensitive(false);
1709     menuMacro->append(*item);
1710     }
1711    
1712     // add separator line to menu
1713     menuMacro->append(*new Gtk::SeparatorMenuItem);
1714    
1715     {
1716     Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1717     item->signal_activate().connect(
1718     sigc::mem_fun(*this, &MainWindow::setupMacros)
1719     );
1720     menuMacro->append(*item);
1721     item->set_accel_path("<Macros>/SetupMacros");
1722     }
1723    
1724 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1725 schoenebeck 3157 menuMacro->show_all_children();
1726 schoenebeck 3364 #endif
1727 schoenebeck 3157 }
1728    
1729     void MainWindow::onMacroSelected(int iMacro) {
1730     printf("onMacroSelected(%d)\n", iMacro);
1731     if (iMacro < 0 || iMacro >= m_macros.size()) return;
1732     Glib::ustring errorText;
1733     try {
1734     applyMacro(m_macros[iMacro]);
1735     } catch (Serialization::Exception e) {
1736     errorText = e.Message;
1737     } catch (...) {
1738     errorText = _("Unknown exception while applying macro");
1739     }
1740     if (!errorText.empty()) {
1741     Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1742     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1743     msg.run();
1744     }
1745     }
1746    
1747     void MainWindow::setupMacros() {
1748     MacrosSetup* setup = new MacrosSetup();
1749 schoenebeck 3160 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1750     setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1751 schoenebeck 3157 setup->signal_macros_changed().connect(
1752     sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1753     );
1754     setup->show();
1755     }
1756    
1757     void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1758     m_macros = macros;
1759     Settings::singleton()->saveMacros(m_macros);
1760     updateMacroMenu();
1761     }
1762    
1763 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.
1764     void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1765 schoenebeck 3340 bool isInstrumentsPage = (page_num == 1);
1766     // so far we only support filtering for the instruments list, so hide the
1767     // filter text entry field if another tab is selected
1768     m_searchField.set_visible(isInstrumentsPage);
1769     }
1770    
1771 persson 1261 bool MainWindow::on_delete_event(GdkEventAny* event)
1772     {
1773 schoenebeck 1382 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
1774 persson 1261 }
1775    
1776     void MainWindow::on_action_quit()
1777     {
1778 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
1779 persson 1261 hide();
1780     }
1781    
1782 schoenebeck 1225 void MainWindow::region_changed()
1783     {
1784     m_DimRegionChooser.set_region(m_RegionChooser.get_region());
1785     }
1786    
1787 persson 1533 gig::Instrument* MainWindow::get_instrument()
1788 schoenebeck 1225 {
1789 persson 1533 gig::Instrument* instrument = 0;
1790 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1791     if (rows.empty()) return NULL;
1792 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.
1793     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1794 schoenebeck 1225 if (it) {
1795     Gtk::TreeModel::Row row = *it;
1796 persson 1533 instrument = row[m_Columns.m_col_instr];
1797     }
1798     return instrument;
1799     }
1800 schoenebeck 1225
1801 persson 1533 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
1802     {
1803     if (all_dimregs) {
1804     for (int i = 0 ; i < region->DimensionRegions ; i++) {
1805     if (region->pDimensionRegions[i]) {
1806     dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
1807     }
1808     }
1809 schoenebeck 1225 } else {
1810 persson 1533 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
1811 schoenebeck 1225 }
1812     }
1813    
1814 persson 1533 void MainWindow::update_dimregs()
1815     {
1816     dimreg_edit.dimregs.clear();
1817     bool all_regions = dimreg_all_regions.get_active();
1818     bool stereo = dimreg_stereo.get_active();
1819     bool all_dimregs = dimreg_all_dimregs.get_active();
1820    
1821     if (all_regions) {
1822     gig::Instrument* instrument = get_instrument();
1823     if (instrument) {
1824     for (gig::Region* region = instrument->GetFirstRegion() ;
1825     region ;
1826     region = instrument->GetNextRegion()) {
1827     add_region_to_dimregs(region, stereo, all_dimregs);
1828     }
1829     }
1830     } else {
1831     gig::Region* region = m_RegionChooser.get_region();
1832     if (region) {
1833     add_region_to_dimregs(region, stereo, all_dimregs);
1834     }
1835     }
1836 schoenebeck 3089
1837 schoenebeck 3148 m_RegionChooser.setModifyAllRegions(all_regions);
1838 schoenebeck 3089 m_DimRegionChooser.setModifyAllRegions(all_regions);
1839     m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1840     m_DimRegionChooser.setModifyBothChannels(stereo);
1841 schoenebeck 3144
1842     updateClipboardCopyAvailable();
1843 persson 1533 }
1844    
1845     void MainWindow::dimreg_all_dimregs_toggled()
1846     {
1847     dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
1848     update_dimregs();
1849     }
1850    
1851     void MainWindow::dimreg_changed()
1852     {
1853     update_dimregs();
1854 schoenebeck 2626 dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1855 persson 1533 }
1856    
1857     void MainWindow::on_sel_change()
1858     {
1859 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1860 persson 2442 // select item in instrument menu
1861 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1862     if (!rows.empty()) {
1863     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1864     if (it) {
1865     Gtk::TreePath path(it);
1866     int index = path[0];
1867     const std::vector<Gtk::Widget*> children =
1868     instrument_menu->get_children();
1869     static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1870     }
1871 persson 2442 }
1872 schoenebeck 3364 #endif
1873 persson 2442
1874 schoenebeck 3339 updateScriptListOfMenu();
1875    
1876 persson 1533 m_RegionChooser.set_instrument(get_instrument());
1877 schoenebeck 2689
1878     if (Settings::singleton()->syncSamplerInstrumentSelection) {
1879     switch_sampler_instrument_signal.emit(get_instrument());
1880     }
1881 persson 1533 }
1882    
1883 schoenebeck 1225 void loader_progress_callback(gig::progress_t* progress)
1884     {
1885     Loader* loader = static_cast<Loader*>(progress->custom);
1886     loader->progress_callback(progress->factor);
1887     }
1888    
1889     void Loader::progress_callback(float fraction)
1890     {
1891     {
1892 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
1893 schoenebeck 1225 progress = fraction;
1894     }
1895     progress_dispatcher();
1896     }
1897    
1898 persson 3021 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1899     // make sure stack is 16-byte aligned for SSE instructions
1900     __attribute__((force_align_arg_pointer))
1901     #endif
1902 schoenebeck 1225 void Loader::thread_function()
1903     {
1904 persson 2841 printf("thread_function self=%p\n",
1905     static_cast<void*>(Glib::Threads::Thread::self()));
1906 schoenebeck 2683 printf("Start %s\n", filename.c_str());
1907     try {
1908     RIFF::File* riff = new RIFF::File(filename);
1909     gig = new gig::File(riff);
1910     gig::progress_t progress;
1911     progress.callback = loader_progress_callback;
1912     progress.custom = this;
1913 schoenebeck 1225
1914 schoenebeck 2683 gig->GetInstrument(0, &progress);
1915     printf("End\n");
1916     finished_dispatcher();
1917     } catch (RIFF::Exception e) {
1918     error_message = e.Message;
1919     error_dispatcher.emit();
1920     } catch (...) {
1921     error_message = _("Unknown exception occurred");
1922     error_dispatcher.emit();
1923     }
1924 schoenebeck 1225 }
1925    
1926     Loader::Loader(const char* filename)
1927 persson 2841 : filename(filename), gig(0), thread(0), progress(0.f)
1928 schoenebeck 1225 {
1929     }
1930    
1931     void Loader::launch()
1932     {
1933 persson 2332 #ifdef OLD_THREADS
1934     thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
1935     #else
1936     thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
1937     #endif
1938 persson 2841 printf("launch thread=%p\n", static_cast<void*>(thread));
1939 schoenebeck 1225 }
1940    
1941     float Loader::get_progress()
1942     {
1943     float res;
1944     {
1945 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
1946 schoenebeck 1225 res = progress;
1947     }
1948     return res;
1949     }
1950    
1951     Glib::Dispatcher& Loader::signal_progress()
1952     {
1953     return progress_dispatcher;
1954     }
1955    
1956     Glib::Dispatcher& Loader::signal_finished()
1957     {
1958     return finished_dispatcher;
1959     }
1960    
1961 schoenebeck 2683 Glib::Dispatcher& Loader::signal_error()
1962     {
1963     return error_dispatcher;
1964     }
1965    
1966     void saver_progress_callback(gig::progress_t* progress)
1967     {
1968     Saver* saver = static_cast<Saver*>(progress->custom);
1969     saver->progress_callback(progress->factor);
1970     }
1971    
1972     void Saver::progress_callback(float fraction)
1973     {
1974     {
1975     Glib::Threads::Mutex::Lock lock(progressMutex);
1976     progress = fraction;
1977     }
1978     progress_dispatcher.emit();
1979     }
1980    
1981 persson 3021 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1982     // make sure stack is 16-byte aligned for SSE instructions
1983     __attribute__((force_align_arg_pointer))
1984     #endif
1985 schoenebeck 2683 void Saver::thread_function()
1986     {
1987 persson 2841 printf("thread_function self=%p\n",
1988     static_cast<void*>(Glib::Threads::Thread::self()));
1989 schoenebeck 2683 printf("Start %s\n", filename.c_str());
1990     try {
1991     gig::progress_t progress;
1992     progress.callback = saver_progress_callback;
1993     progress.custom = this;
1994    
1995     // if no filename was provided, that means "save", if filename was provided means "save as"
1996     if (filename.empty()) {
1997 schoenebeck 2967 if (!Settings::singleton()->saveWithTemporaryFile) {
1998     // save directly over the existing .gig file
1999     // (requires less disk space than solution below
2000     // but may be slower)
2001     gig->Save(&progress);
2002     } else {
2003     // save the file as separate temporary file first,
2004     // then move the saved file over the old file
2005     // (may result in performance speedup during save)
2006 schoenebeck 3179 gig::String tmpname = filename + ".TMP";
2007 schoenebeck 2967 gig->Save(tmpname, &progress);
2008     #if defined(WIN32)
2009 schoenebeck 2968 if (!DeleteFile(filename.c_str())) {
2010 schoenebeck 2967 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
2011     }
2012     #else // POSIX ...
2013     if (unlink(filename.c_str())) {
2014 schoenebeck 3180 throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2015 schoenebeck 2967 }
2016     #endif
2017     if (rename(tmpname.c_str(), filename.c_str())) {
2018     #if defined(WIN32)
2019     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
2020     #else
2021 schoenebeck 3180 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2022 schoenebeck 2967 #endif
2023     }
2024     }
2025 schoenebeck 2683 } else {
2026     gig->Save(filename, &progress);
2027     }
2028    
2029     printf("End\n");
2030     finished_dispatcher.emit();
2031     } catch (RIFF::Exception e) {
2032     error_message = e.Message;
2033     error_dispatcher.emit();
2034     } catch (...) {
2035     error_message = _("Unknown exception occurred");
2036     error_dispatcher.emit();
2037     }
2038     }
2039    
2040     Saver::Saver(gig::File* file, Glib::ustring filename)
2041     : gig(file), filename(filename), thread(0), progress(0.f)
2042     {
2043     }
2044    
2045     void Saver::launch()
2046     {
2047     #ifdef OLD_THREADS
2048     thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);
2049     #else
2050     thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));
2051     #endif
2052 persson 2841 printf("launch thread=%p\n", static_cast<void*>(thread));
2053 schoenebeck 2683 }
2054    
2055     float Saver::get_progress()
2056     {
2057     float res;
2058     {
2059     Glib::Threads::Mutex::Lock lock(progressMutex);
2060     res = progress;
2061     }
2062     return res;
2063     }
2064    
2065     Glib::Dispatcher& Saver::signal_progress()
2066     {
2067     return progress_dispatcher;
2068     }
2069    
2070     Glib::Dispatcher& Saver::signal_finished()
2071     {
2072     return finished_dispatcher;
2073     }
2074    
2075     Glib::Dispatcher& Saver::signal_error()
2076     {
2077     return error_dispatcher;
2078     }
2079    
2080     ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2081 schoenebeck 1225 : Gtk::Dialog(title, parent, true)
2082     {
2083 schoenebeck 3364 #if USE_GTKMM_BOX
2084     get_content_area()->pack_start(progressBar);
2085     #else
2086 schoenebeck 1225 get_vbox()->pack_start(progressBar);
2087 schoenebeck 3364 #endif
2088     #if HAS_GTKMM_SHOW_ALL_CHILDREN
2089 schoenebeck 1225 show_all_children();
2090 schoenebeck 3364 #endif
2091 schoenebeck 2683 resize(600,50);
2092 schoenebeck 1225 }
2093    
2094     // Clear all GUI elements / controls. This method is typically called
2095     // before a new .gig file is to be created or to be loaded.
2096     void MainWindow::__clear() {
2097     // forget all samples that ought to be imported
2098     m_SampleImportQueue.clear();
2099     // clear the samples and instruments tree views
2100     m_refTreeModel->clear();
2101     m_refSamplesTreeModel->clear();
2102 schoenebeck 2615 m_refScriptsTreeModel->clear();
2103 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2104 persson 2442 // remove all entries from "Instrument" menu
2105     while (!instrument_menu->get_children().empty()) {
2106     remove_instrument_from_menu(0);
2107     }
2108 schoenebeck 3364 #endif
2109 schoenebeck 1225 // free libgig's gig::File instance
2110 schoenebeck 1382 if (file && !file_is_shared) delete file;
2111     file = NULL;
2112 schoenebeck 1411 set_file_is_shared(false);
2113 schoenebeck 1225 }
2114    
2115 schoenebeck 2553 void MainWindow::__refreshEntireGUI() {
2116     // clear the samples and instruments tree views
2117     m_refTreeModel->clear();
2118     m_refSamplesTreeModel->clear();
2119 schoenebeck 2615 m_refScriptsTreeModel->clear();
2120 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2121 schoenebeck 2553 // remove all entries from "Instrument" menu
2122     while (!instrument_menu->get_children().empty()) {
2123     remove_instrument_from_menu(0);
2124     }
2125 schoenebeck 3364 #endif
2126 schoenebeck 2553
2127     if (!this->file) return;
2128    
2129     load_gig(
2130     this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2131     );
2132     }
2133    
2134 schoenebeck 1225 void MainWindow::on_action_file_new()
2135     {
2136 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2137 persson 1261
2138 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2139    
2140 schoenebeck 1225 // clear all GUI elements
2141     __clear();
2142     // create a new .gig file (virtually yet)
2143     gig::File* pFile = new gig::File;
2144     // already add one new instrument by default
2145     gig::Instrument* pInstrument = pFile->AddInstrument();
2146 persson 2446 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2147 schoenebeck 1225 // update GUI with that new gig::File
2148 persson 1261 load_gig(pFile, 0 /*no file name yet*/);
2149 schoenebeck 1225 }
2150    
2151 persson 1261 bool MainWindow::close_confirmation_dialog()
2152     {
2153     gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
2154     Glib::filename_display_basename(filename).c_str());
2155     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2156     g_free(msg);
2157     dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2158     dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2159 schoenebeck 3364 #if HAS_GTKMM_STOCK
2160 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2161     dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2162 schoenebeck 3364 #else
2163     dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2164     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2165     #endif
2166 persson 1261 dialog.set_default_response(Gtk::RESPONSE_YES);
2167     int response = dialog.run();
2168 persson 1303 dialog.hide();
2169 schoenebeck 2683
2170 schoenebeck 2694 // user decided to exit app without saving
2171     if (response == Gtk::RESPONSE_NO) return true;
2172    
2173     // user cancelled dialog, thus don't close app
2174     if (response == Gtk::RESPONSE_CANCEL) return false;
2175    
2176 schoenebeck 2683 // TODO: the following return valid is disabled and hard coded instead for
2177     // now, due to the fact that saving with progress bar is now implemented
2178     // asynchronously, as a result the app does not close automatically anymore
2179     // after saving the file has completed
2180     //
2181     // if (response == Gtk::RESPONSE_YES) return file_save();
2182     // return response != Gtk::RESPONSE_CANCEL;
2183     //
2184     if (response == Gtk::RESPONSE_YES) file_save();
2185     return false; // always prevent closing the app for now (see comment above)
2186 persson 1261 }
2187    
2188 schoenebeck 1382 bool MainWindow::leaving_shared_mode_dialog() {
2189     Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2190     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2191     dialog.set_secondary_text(
2192     _("If you proceed to work on another instrument file, it won't be "
2193     "used by the sampler until you tell the sampler explicitly to "
2194 persson 2151 "load it."));
2195 schoenebeck 1382 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2196 schoenebeck 3364 #if HAS_GTKMM_STOCK
2197 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2198 schoenebeck 3364 #else
2199     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2200     #endif
2201 schoenebeck 1382 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2202     int response = dialog.run();
2203     dialog.hide();
2204     return response == Gtk::RESPONSE_YES;
2205     }
2206    
2207 schoenebeck 1225 void MainWindow::on_action_file_open()
2208     {
2209 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2210 persson 1261
2211 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2212    
2213 schoenebeck 1225 Gtk::FileChooserDialog dialog(*this, _("Open file"));
2214 schoenebeck 3364 #if HAS_GTKMM_STOCK
2215 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2216     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2217 schoenebeck 3364 #else
2218     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2219     dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2220     #endif
2221 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
2222 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2223 schoenebeck 1225 Gtk::FileFilter filter;
2224     filter.add_pattern("*.gig");
2225 persson 2169 #else
2226     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2227     filter->add_pattern("*.gig");
2228     #endif
2229 schoenebeck 1225 dialog.set_filter(filter);
2230 persson 1725 if (current_gig_dir != "") {
2231     dialog.set_current_folder(current_gig_dir);
2232 persson 1261 }
2233 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
2234 persson 1261 std::string filename = dialog.get_filename();
2235     printf("filename=%s\n", filename.c_str());
2236 persson 2841 printf("on_action_file_open self=%p\n",
2237     static_cast<void*>(Glib::Threads::Thread::self()));
2238 persson 1261 load_file(filename.c_str());
2239 persson 1725 current_gig_dir = Glib::path_get_dirname(filename);
2240 schoenebeck 1225 }
2241     }
2242    
2243     void MainWindow::load_file(const char* name)
2244     {
2245 persson 1303 __clear();
2246 schoenebeck 2683
2247     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2248     _("Loading") + Glib::ustring(" '") +
2249     Glib::filename_display_basename(name) + "' ...",
2250     *this
2251     );
2252 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2253 schoenebeck 2683 progress_dialog->show_all();
2254 schoenebeck 3364 #endif
2255 schoenebeck 2683 loader = new Loader(name); //FIXME: memory leak!
2256 schoenebeck 1225 loader->signal_progress().connect(
2257     sigc::mem_fun(*this, &MainWindow::on_loader_progress));
2258     loader->signal_finished().connect(
2259     sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2260 schoenebeck 2683 loader->signal_error().connect(
2261     sigc::mem_fun(*this, &MainWindow::on_loader_error));
2262 schoenebeck 1225 loader->launch();
2263     }
2264    
2265     void MainWindow::load_instrument(gig::Instrument* instr) {
2266     if (!instr) {
2267     Glib::ustring txt = "Provided instrument is NULL!\n";
2268     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2269     msg.run();
2270     Gtk::Main::quit();
2271     }
2272 schoenebeck 1328 // clear all GUI elements
2273     __clear();
2274     // load the instrument
2275 schoenebeck 1225 gig::File* pFile = (gig::File*) instr->GetParent();
2276 schoenebeck 1382 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2277 schoenebeck 2664 // automatically select the given instrument
2278     int i = 0;
2279     for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2280     instrument = pFile->GetNextInstrument(), ++i)
2281     {
2282     if (instrument == instr) {
2283     // select item in "instruments" tree view
2284     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2285     // make sure the selected item in the "instruments" tree view is
2286     // visible (scroll to it)
2287     m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2288 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2289 schoenebeck 2664 // select item in instrument menu
2290     {
2291     const std::vector<Gtk::Widget*> children =
2292     instrument_menu->get_children();
2293     static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2294     }
2295 schoenebeck 3364 #endif
2296 schoenebeck 2664 // update region chooser and dimension region chooser
2297     m_RegionChooser.set_instrument(instr);
2298     break;
2299     }
2300     }
2301 schoenebeck 1225 }
2302    
2303     void MainWindow::on_loader_progress()
2304     {
2305 schoenebeck 2683 progress_dialog->set_fraction(loader->get_progress());
2306 schoenebeck 1225 }
2307    
2308     void MainWindow::on_loader_finished()
2309     {
2310     printf("Loader finished!\n");
2311 persson 2841 printf("on_loader_finished self=%p\n",
2312     static_cast<void*>(Glib::Threads::Thread::self()));
2313 schoenebeck 2683 load_gig(loader->gig, loader->filename.c_str());
2314     progress_dialog->hide();
2315 schoenebeck 1225 }
2316    
2317 schoenebeck 2683 void MainWindow::on_loader_error()
2318     {
2319     Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2320     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2321     msg.run();
2322     progress_dialog->hide();
2323     }
2324    
2325 schoenebeck 1225 void MainWindow::on_action_file_save()
2326     {
2327 persson 1261 file_save();
2328     }
2329    
2330 persson 1303 bool MainWindow::check_if_savable()
2331     {
2332     if (!file) return false;
2333    
2334     if (!file->GetFirstSample()) {
2335     Gtk::MessageDialog(*this, _("The file could not be saved "
2336     "because it contains no samples"),
2337     false, Gtk::MESSAGE_ERROR).run();
2338     return false;
2339     }
2340    
2341     for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
2342     instrument = file->GetNextInstrument()) {
2343     if (!instrument->GetFirstRegion()) {
2344     Gtk::MessageDialog(*this, _("The file could not be saved "
2345     "because there are instruments "
2346     "that have no regions"),
2347     false, Gtk::MESSAGE_ERROR).run();
2348     return false;
2349     }
2350     }
2351     return true;
2352     }
2353    
2354 persson 1261 bool MainWindow::file_save()
2355     {
2356 persson 1303 if (!check_if_savable()) return false;
2357 schoenebeck 1382 if (!file_is_shared && !file_has_name) return file_save_as();
2358 persson 1261
2359 schoenebeck 1225 std::cout << "Saving file\n" << std::flush;
2360 schoenebeck 1322 file_structure_to_be_changed_signal.emit(this->file);
2361 schoenebeck 2683
2362     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2363     _("Saving") + Glib::ustring(" '") +
2364     Glib::filename_display_basename(this->filename) + "' ...",
2365     *this
2366     );
2367 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2368 schoenebeck 2683 progress_dialog->show_all();
2369 schoenebeck 3364 #endif
2370 schoenebeck 2683 saver = new Saver(this->file); //FIXME: memory leak!
2371     saver->signal_progress().connect(
2372     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2373     saver->signal_finished().connect(
2374     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2375     saver->signal_error().connect(
2376     sigc::mem_fun(*this, &MainWindow::on_saver_error));
2377     saver->launch();
2378    
2379     return true;
2380     }
2381    
2382     void MainWindow::on_saver_progress()
2383     {
2384     progress_dialog->set_fraction(saver->get_progress());
2385     }
2386    
2387     void MainWindow::on_saver_error()
2388     {
2389     file_structure_changed_signal.emit(this->file);
2390     Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2391     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2392     msg.run();
2393     }
2394    
2395     void MainWindow::on_saver_finished()
2396     {
2397     this->file = saver->gig;
2398     this->filename = saver->filename;
2399     current_gig_dir = Glib::path_get_dirname(filename);
2400     set_title(Glib::filename_display_basename(filename));
2401     file_has_name = true;
2402     file_is_changed = false;
2403     std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
2404 schoenebeck 1225 __import_queued_samples();
2405 schoenebeck 2683 std::cout << "Importing queued samples done.\n" << std::flush;
2406    
2407 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
2408 schoenebeck 2683
2409 schoenebeck 2697 __refreshEntireGUI();
2410 schoenebeck 2683 progress_dialog->hide();
2411 schoenebeck 1225 }
2412    
2413     void MainWindow::on_action_file_save_as()
2414     {
2415 persson 1303 if (!check_if_savable()) return;
2416 persson 1261 file_save_as();
2417     }
2418    
2419     bool MainWindow::file_save_as()
2420     {
2421 schoenebeck 3158 Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2422 schoenebeck 3364 #if HAS_GTKMM_STOCK
2423 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2424     dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2425 schoenebeck 3364 #else
2426     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2427     dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2428     #endif
2429 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
2430 persson 2151 dialog.set_do_overwrite_confirmation();
2431 persson 1261
2432 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2433 schoenebeck 1225 Gtk::FileFilter filter;
2434     filter.add_pattern("*.gig");
2435 persson 2169 #else
2436     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2437     filter->add_pattern("*.gig");
2438     #endif
2439 schoenebeck 1225 dialog.set_filter(filter);
2440 persson 1261
2441 schoenebeck 1679 // set initial dir and filename of the Save As dialog
2442     // and prepare that initial filename as a copy of the gig
2443     {
2444     std::string basename = Glib::path_get_basename(filename);
2445     std::string dir = Glib::path_get_dirname(filename);
2446 persson 1831 basename = std::string(_("copy_of_")) + basename;
2447 schoenebeck 1679 Glib::ustring copyFileName = Glib::build_filename(dir, basename);
2448     if (Glib::path_is_absolute(filename)) {
2449     dialog.set_filename(copyFileName);
2450     } else {
2451 persson 1725 if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
2452 schoenebeck 1679 }
2453     dialog.set_current_name(Glib::filename_display_basename(copyFileName));
2454 persson 1261 }
2455    
2456 schoenebeck 1679 // show warning in the dialog
2457 schoenebeck 3364 HBox descriptionArea;
2458 schoenebeck 1679 descriptionArea.set_spacing(15);
2459 persson 2845 Gtk::Image warningIcon;
2460     warningIcon.set_from_icon_name("dialog-warning",
2461     Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2462 schoenebeck 1679 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2463 persson 2344 #if GTKMM_MAJOR_VERSION < 3
2464 persson 1799 view::WrapLabel description;
2465 persson 2344 #else
2466     Gtk::Label description;
2467     description.set_line_wrap();
2468     #endif
2469 schoenebeck 1679 description.set_markup(
2470     _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
2471     "<span style=\"italic\">\"Save\"</span> dialog instead of "
2472     "<span style=\"italic\">\"Save As...\"</span> if you want to save "
2473     "to the same .gig file. Using "
2474     "<span style=\"italic\">\"Save As...\"</span> for writing to the "
2475     "same .gig file will end up in corrupted sample wave data!\n")
2476     );
2477 persson 1799 descriptionArea.pack_start(description);
2478 schoenebeck 3364 #if USE_GTKMM_BOX
2479     dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2480     #else
2481 schoenebeck 1679 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2482 schoenebeck 3364 #endif
2483     #if HAS_GTKMM_SHOW_ALL_CHILDREN
2484 persson 1799 descriptionArea.show_all();
2485 schoenebeck 3364 #endif
2486 schoenebeck 1679
2487 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
2488 schoenebeck 2683 std::string filename = dialog.get_filename();
2489     if (!Glib::str_has_suffix(filename, ".gig")) {
2490     filename += ".gig";
2491 schoenebeck 1225 }
2492 schoenebeck 2683 printf("filename=%s\n", filename.c_str());
2493    
2494     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2495     _("Saving") + Glib::ustring(" '") +
2496     Glib::filename_display_basename(filename) + "' ...",
2497     *this
2498     );
2499 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2500 schoenebeck 2683 progress_dialog->show_all();
2501 schoenebeck 3364 #endif
2502 schoenebeck 2683
2503     saver = new Saver(file, filename); //FIXME: memory leak!
2504     saver->signal_progress().connect(
2505     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2506     saver->signal_finished().connect(
2507     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2508     saver->signal_error().connect(
2509     sigc::mem_fun(*this, &MainWindow::on_saver_error));
2510     saver->launch();
2511    
2512 persson 1261 return true;
2513 schoenebeck 1225 }
2514 persson 1261 return false;
2515 schoenebeck 1225 }
2516    
2517     // actually write the sample(s)' data to the gig file
2518     void MainWindow::__import_queued_samples() {
2519     std::cout << "Starting sample import\n" << std::flush;
2520     Glib::ustring error_files;
2521 persson 2841 printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2522 schoenebeck 3116 for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2523 schoenebeck 1225 iter != m_SampleImportQueue.end(); ) {
2524 schoenebeck 3116 printf("Importing sample %s\n",iter->second.sample_path.c_str());
2525 schoenebeck 1225 SF_INFO info;
2526     info.format = 0;
2527 schoenebeck 3116 SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2528 persson 2398 sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2529 schoenebeck 1225 try {
2530 persson 1831 if (!hFile) throw std::string(_("could not open file"));
2531 schoenebeck 1225 // determine sample's bit depth
2532     int bitdepth;
2533     switch (info.format & 0xff) {
2534     case SF_FORMAT_PCM_S8:
2535     case SF_FORMAT_PCM_16:
2536 persson 1265 case SF_FORMAT_PCM_U8:
2537 schoenebeck 1225 bitdepth = 16;
2538     break;
2539     case SF_FORMAT_PCM_24:
2540     case SF_FORMAT_PCM_32:
2541     case SF_FORMAT_FLOAT:
2542     case SF_FORMAT_DOUBLE:
2543 persson 1265 bitdepth = 24;
2544 schoenebeck 1225 break;
2545     default:
2546     sf_close(hFile); // close sound file
2547 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
2548 schoenebeck 1225 }
2549 persson 1265
2550 schoenebeck 3116 // reset write position for sample
2551     iter->first->SetPos(0);
2552    
2553 persson 1265 const int bufsize = 10000;
2554 schoenebeck 1225 switch (bitdepth) {
2555 persson 1265 case 16: {
2556     short* buffer = new short[bufsize * info.channels];
2557     sf_count_t cnt = info.frames;
2558     while (cnt) {
2559     // libsndfile does the conversion for us (if needed)
2560     int n = sf_readf_short(hFile, buffer, bufsize);
2561     // write from buffer directly (physically) into .gig file
2562 schoenebeck 3116 iter->first->Write(buffer, n);
2563 persson 1265 cnt -= n;
2564     }
2565     delete[] buffer;
2566 schoenebeck 1225 break;
2567 persson 1265 }
2568     case 24: {
2569     int* srcbuf = new int[bufsize * info.channels];
2570     uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
2571     sf_count_t cnt = info.frames;
2572     while (cnt) {
2573     // libsndfile returns 32 bits, convert to 24
2574     int n = sf_readf_int(hFile, srcbuf, bufsize);
2575     int j = 0;
2576     for (int i = 0 ; i < n * info.channels ; i++) {
2577     dstbuf[j++] = srcbuf[i] >> 8;
2578     dstbuf[j++] = srcbuf[i] >> 16;
2579     dstbuf[j++] = srcbuf[i] >> 24;
2580     }
2581     // write from buffer directly (physically) into .gig file
2582 schoenebeck 3116 iter->first->Write(dstbuf, n);
2583 persson 1265 cnt -= n;
2584     }
2585     delete[] srcbuf;
2586     delete[] dstbuf;
2587 schoenebeck 1225 break;
2588 persson 1265 }
2589 schoenebeck 1225 }
2590     // cleanup
2591     sf_close(hFile);
2592 schoenebeck 1853 // let the sampler re-cache the sample if needed
2593 schoenebeck 3116 sample_changed_signal.emit(iter->first);
2594 schoenebeck 1225 // on success we remove the sample from the import queue,
2595     // otherwise keep it, maybe it works the next time ?
2596 schoenebeck 3116 std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2597 schoenebeck 1225 ++iter;
2598     m_SampleImportQueue.erase(cur);
2599     } catch (std::string what) {
2600     // remember the files that made trouble (and their cause)
2601 persson 2442 if (!error_files.empty()) error_files += "\n";
2602 schoenebeck 3116 error_files += iter->second.sample_path += " (" + what + ")";
2603 schoenebeck 1225 ++iter;
2604     }
2605     }
2606     // show error message box when some sample(s) could not be imported
2607 persson 2442 if (!error_files.empty()) {
2608 schoenebeck 1382 Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
2609 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2610     msg.run();
2611     }
2612     }
2613    
2614     void MainWindow::on_action_file_properties()
2615     {
2616     propDialog.show();
2617     propDialog.deiconify();
2618     }
2619    
2620 schoenebeck 2541 void MainWindow::on_action_warn_user_on_extensions() {
2621     Settings::singleton()->warnUserOnExtensions =
2622     !Settings::singleton()->warnUserOnExtensions;
2623     }
2624    
2625 schoenebeck 3409 void MainWindow::on_action_show_tooltips() {
2626     Settings::singleton()->showTooltips =
2627     !Settings::singleton()->showTooltips;
2628    
2629     on_show_tooltips_changed();
2630     }
2631    
2632     void MainWindow::on_show_tooltips_changed() {
2633     const bool b = Settings::singleton()->showTooltips;
2634    
2635     dimreg_label.set_has_tooltip(b);
2636     dimreg_all_regions.set_has_tooltip(b);
2637     dimreg_all_dimregs.set_has_tooltip(b);
2638     dimreg_stereo.set_has_tooltip(b);
2639     m_TreeView.set_has_tooltip(b);
2640     m_TreeViewSamples.set_has_tooltip(b);
2641     m_TreeViewScripts.set_has_tooltip(b);
2642    
2643     set_has_tooltip(b);
2644     }
2645    
2646 schoenebeck 2689 void MainWindow::on_action_sync_sampler_instrument_selection() {
2647     Settings::singleton()->syncSamplerInstrumentSelection =
2648     !Settings::singleton()->syncSamplerInstrumentSelection;
2649     }
2650    
2651 schoenebeck 2773 void MainWindow::on_action_move_root_note_with_region_moved() {
2652     Settings::singleton()->moveRootNoteWithRegionMoved =
2653     !Settings::singleton()->moveRootNoteWithRegionMoved;
2654     }
2655    
2656 schoenebeck 1225 void MainWindow::on_action_help_about()
2657     {
2658     Gtk::AboutDialog dialog;
2659 persson 1959 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
2660     dialog.set_program_name("Gigedit");
2661     #else
2662     dialog.set_name("Gigedit");
2663     #endif
2664 schoenebeck 1225 dialog.set_version(VERSION);
2665 schoenebeck 3089 dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
2666 schoenebeck 2476 const std::string sComment =
2667     _("Built " __DATE__ "\nUsing ") +
2668     ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
2669     _(
2670     "Gigedit is released under the GNU General Public License.\n"
2671     "\n"
2672 schoenebeck 2627 "This program is distributed WITHOUT ANY WARRANTY; So better "
2673     "backup your Gigasampler/GigaStudio files before editing them with "
2674 schoenebeck 2476 "this application.\n"
2675     "\n"
2676     "Please report bugs to: http://bugs.linuxsampler.org"
2677     );
2678     dialog.set_comments(sComment.c_str());
2679 schoenebeck 1436 dialog.set_website("http://www.linuxsampler.org");
2680     dialog.set_website_label("http://www.linuxsampler.org");
2681 schoenebeck 3225 dialog.set_position(Gtk::WIN_POS_CENTER);
2682 schoenebeck 1225 dialog.run();
2683     }
2684    
2685     PropDialog::PropDialog()
2686 schoenebeck 2560 : eFileFormat(_("File Format")),
2687     eName(_("Name")),
2688 persson 1831 eCreationDate(_("Creation date")),
2689     eComments(_("Comments")),
2690     eProduct(_("Product")),
2691     eCopyright(_("Copyright")),
2692     eArtists(_("Artists")),
2693     eGenre(_("Genre")),
2694     eKeywords(_("Keywords")),
2695     eEngineer(_("Engineer")),
2696     eTechnician(_("Technician")),
2697     eSoftware(_("Software")),
2698     eMedium(_("Medium")),
2699     eSource(_("Source")),
2700     eSourceForm(_("Source form")),
2701     eCommissioned(_("Commissioned")),
2702     eSubject(_("Subject")),
2703 schoenebeck 3364 #if HAS_GTKMM_STOCK
2704 schoenebeck 3158 quitButton(Gtk::Stock::CLOSE),
2705 schoenebeck 3364 #else
2706     quitButton(_("_Close")),
2707     #endif
2708 schoenebeck 2560 table(2, 1),
2709     m_file(NULL)
2710 schoenebeck 1225 {
2711 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
2712     set_default_size(470, 390);
2713     set_position(Gtk::WIN_POS_MOUSE);
2714     }
2715    
2716 persson 1831 set_title(_("File Properties"));
2717 persson 1582 eName.set_width_chars(50);
2718    
2719     connect(eName, &DLS::Info::Name);
2720     connect(eCreationDate, &DLS::Info::CreationDate);
2721     connect(eComments, &DLS::Info::Comments);
2722     connect(eProduct, &DLS::Info::Product);
2723     connect(eCopyright, &DLS::Info::Copyright);
2724     connect(eArtists, &DLS::Info::Artists);
2725     connect(eGenre, &DLS::Info::Genre);
2726     connect(eKeywords, &DLS::Info::Keywords);
2727     connect(eEngineer, &DLS::Info::Engineer);
2728     connect(eTechnician, &DLS::Info::Technician);
2729     connect(eSoftware, &DLS::Info::Software);
2730     connect(eMedium, &DLS::Info::Medium);
2731     connect(eSource, &DLS::Info::Source);
2732     connect(eSourceForm, &DLS::Info::SourceForm);
2733     connect(eCommissioned, &DLS::Info::Commissioned);
2734     connect(eSubject, &DLS::Info::Subject);
2735    
2736 schoenebeck 2560 table.add(eFileFormat);
2737 persson 1582 table.add(eName);
2738     table.add(eCreationDate);
2739     table.add(eComments);
2740     table.add(eProduct);
2741     table.add(eCopyright);
2742     table.add(eArtists);
2743     table.add(eGenre);
2744     table.add(eKeywords);
2745     table.add(eEngineer);
2746     table.add(eTechnician);
2747     table.add(eSoftware);
2748     table.add(eMedium);
2749     table.add(eSource);
2750     table.add(eSourceForm);
2751     table.add(eCommissioned);
2752     table.add(eSubject);
2753    
2754 schoenebeck 3364 #if USE_GTKMM_GRID
2755     table.set_column_spacing(5);
2756     #else
2757 schoenebeck 1225 table.set_col_spacings(5);
2758 schoenebeck 3364 #endif
2759    
2760 persson 1582 add(vbox);
2761 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2762     table.set_margin(5);
2763     #else
2764 persson 1582 table.set_border_width(5);
2765 schoenebeck 3364 #endif
2766 persson 1582 vbox.add(table);
2767     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2768     buttonBox.set_layout(Gtk::BUTTONBOX_END);
2769 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2770     buttonBox.set_margin(5);
2771     #else
2772 persson 1582 buttonBox.set_border_width(5);
2773 schoenebeck 3364 #endif
2774 persson 1582 buttonBox.show();
2775     buttonBox.pack_start(quitButton);
2776 persson 2151 quitButton.set_can_default();
2777 persson 1582 quitButton.grab_focus();
2778     quitButton.signal_clicked().connect(
2779     sigc::mem_fun(*this, &PropDialog::hide));
2780 schoenebeck 2560 eFileFormat.signal_value_changed().connect(
2781     sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
2782 schoenebeck 1225
2783 persson 1582 quitButton.show();
2784     vbox.show();
2785 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2786 schoenebeck 1225 show_all_children();
2787 schoenebeck 3364 #endif
2788 schoenebeck 1225 }
2789    
2790 schoenebeck 2560 void PropDialog::set_file(gig::File* file)
2791     {
2792     m_file = file;
2793    
2794     // update file format version combo box
2795     const std::string sGiga = "Gigasampler/GigaStudio v";
2796     const int major = file->pVersion->major;
2797     std::vector<std::string> txts;
2798     std::vector<int> values;
2799     txts.push_back(sGiga + "2"); values.push_back(2);
2800 schoenebeck 2566 txts.push_back(sGiga + "3/v4"); values.push_back(3);
2801 schoenebeck 2560 if (major != 2 && major != 3) {
2802     txts.push_back(sGiga + ToString(major)); values.push_back(major);
2803     }
2804     std::vector<const char*> texts;
2805     for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2806 persson 2579 texts.push_back(NULL); values.push_back(0);
2807 schoenebeck 2560 eFileFormat.set_choices(&texts[0], &values[0]);
2808     eFileFormat.set_value(major);
2809     }
2810    
2811     void PropDialog::onFileFormatChanged() {
2812     const int major = eFileFormat.get_value();
2813     if (m_file) m_file->pVersion->major = major;
2814     }
2815    
2816 schoenebeck 1225 void PropDialog::set_info(DLS::Info* info)
2817     {
2818 persson 2423 update(info);
2819 schoenebeck 1225 }
2820    
2821 persson 1582
2822 persson 2445 void InstrumentProps::set_Name(const gig::String& name)
2823     {
2824     m->pInfo->Name = name;
2825     }
2826    
2827     void InstrumentProps::update_name()
2828     {
2829     update_model++;
2830     eName.set_value(m->pInfo->Name);
2831     update_model--;
2832     }
2833    
2834 persson 1460 void InstrumentProps::set_IsDrum(bool value)
2835     {
2836 persson 2423 m->IsDrum = value;
2837 persson 1460 }
2838    
2839     void InstrumentProps::set_MIDIBank(uint16_t value)
2840     {
2841 persson 2423 m->MIDIBank = value;
2842 persson 1460 }
2843    
2844     void InstrumentProps::set_MIDIProgram(uint32_t value)
2845     {
2846 persson 2423 m->MIDIProgram = value;
2847 persson 1460 }
2848    
2849 persson 2423 InstrumentProps::InstrumentProps() :
2850 schoenebeck 3364 #if HAS_GTKMM_STOCK
2851 schoenebeck 3158 quitButton(Gtk::Stock::CLOSE),
2852 schoenebeck 3364 #else
2853     quitButton(_("_Close")),
2854     #endif
2855 persson 2423 table(2,1),
2856     eName(_("Name")),
2857     eIsDrum(_("Is drum")),
2858     eMIDIBank(_("MIDI bank"), 0, 16383),
2859     eMIDIProgram(_("MIDI program")),
2860     eAttenuation(_("Attenuation"), 0, 96, 0, 1),
2861     eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2862     eEffectSend(_("Effect send"), 0, 65535),
2863     eFineTune(_("Fine tune"), -8400, 8400),
2864 schoenebeck 3363 ePitchbendRange(_("Pitchbend range"), 0, 48),
2865 persson 2423 ePianoReleaseMode(_("Piano release mode")),
2866     eDimensionKeyRangeLow(_("Keyswitching range low")),
2867     eDimensionKeyRangeHigh(_("Keyswitching range high"))
2868 persson 1460 {
2869 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
2870     //set_default_size(470, 390);
2871     set_position(Gtk::WIN_POS_MOUSE);
2872     }
2873    
2874 persson 1831 set_title(_("Instrument Properties"));
2875 schoenebeck 1225
2876 schoenebeck 1656 eDimensionKeyRangeLow.set_tip(
2877     _("start of the keyboard area which should switch the "
2878     "\"keyswitching\" dimension")
2879     );
2880     eDimensionKeyRangeHigh.set_tip(
2881     _("end of the keyboard area which should switch the "
2882     "\"keyswitching\" dimension")
2883     );
2884    
2885 persson 2445 connect(eName, &InstrumentProps::set_Name);
2886 persson 1460 connect(eIsDrum, &InstrumentProps::set_IsDrum);
2887     connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2888     connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
2889     connect(eAttenuation, &gig::Instrument::Attenuation);
2890     connect(eGainPlus6, &gig::Instrument::Attenuation);
2891     connect(eEffectSend, &gig::Instrument::EffectSend);
2892     connect(eFineTune, &gig::Instrument::FineTune);
2893     connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
2894     connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
2895 persson 2423 connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
2896     &gig::Instrument::DimensionKeyRange);
2897 persson 1460
2898 persson 2445 eName.signal_value_changed().connect(sig_name_changed.make_slot());
2899    
2900 schoenebeck 3364 #if USE_GTKMM_GRID
2901     table.set_column_spacing(5);
2902     #else
2903 schoenebeck 1225 table.set_col_spacings(5);
2904 schoenebeck 3364 #endif
2905 schoenebeck 1225
2906 persson 1582 table.add(eName);
2907     table.add(eIsDrum);
2908     table.add(eMIDIBank);
2909     table.add(eMIDIProgram);
2910     table.add(eAttenuation);
2911     table.add(eGainPlus6);
2912     table.add(eEffectSend);
2913     table.add(eFineTune);
2914     table.add(ePitchbendRange);
2915     table.add(ePianoReleaseMode);
2916     table.add(eDimensionKeyRangeLow);
2917     table.add(eDimensionKeyRangeHigh);
2918 schoenebeck 1225
2919     add(vbox);
2920 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2921     table.set_margin(5);
2922     #else
2923 schoenebeck 1225 table.set_border_width(5);
2924 schoenebeck 3364 #endif
2925 schoenebeck 1225 vbox.pack_start(table);
2926     table.show();
2927     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2928     buttonBox.set_layout(Gtk::BUTTONBOX_END);
2929 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
2930     buttonBox.set_margin(5);
2931     #else
2932 schoenebeck 1225 buttonBox.set_border_width(5);
2933 schoenebeck 3364 #endif
2934 schoenebeck 1225 buttonBox.show();
2935     buttonBox.pack_start(quitButton);
2936 persson 2151 quitButton.set_can_default();
2937 schoenebeck 1225 quitButton.grab_focus();
2938    
2939     quitButton.signal_clicked().connect(
2940     sigc::mem_fun(*this, &InstrumentProps::hide));
2941    
2942     quitButton.show();
2943     vbox.show();
2944 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2945 schoenebeck 1225 show_all_children();
2946 schoenebeck 3364 #endif
2947 schoenebeck 1225 }
2948    
2949     void InstrumentProps::set_instrument(gig::Instrument* instrument)
2950     {
2951 persson 2423 update(instrument);
2952 persson 1460
2953     update_model++;
2954 persson 2445 eName.set_value(instrument->pInfo->Name);
2955 persson 1460 eIsDrum.set_value(instrument->IsDrum);
2956     eMIDIBank.set_value(instrument->MIDIBank);
2957     eMIDIProgram.set_value(instrument->MIDIProgram);
2958     update_model--;
2959 schoenebeck 1225 }
2960    
2961    
2962 persson 1261 void MainWindow::file_changed()
2963     {
2964     if (file && !file_is_changed) {
2965     set_title("*" + get_title());
2966     file_is_changed = true;
2967 schoenebeck 1225 }
2968 persson 1261 }
2969 schoenebeck 1225
2970 schoenebeck 2621 void MainWindow::updateSampleRefCountMap(gig::File* gig) {
2971     sample_ref_count.clear();
2972    
2973     if (!gig) return;
2974    
2975     for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
2976     instrument = gig->GetNextInstrument())
2977     {
2978     for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2979     rgn = instrument->GetNextRegion())
2980     {
2981     for (int i = 0; i < 256; ++i) {
2982     if (!rgn->pDimensionRegions[i]) continue;
2983     if (rgn->pDimensionRegions[i]->pSample) {
2984     sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
2985     }
2986     }
2987     }
2988     }
2989     }
2990    
2991 schoenebeck 1382 void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
2992 persson 1261 {
2993     file = 0;
2994 schoenebeck 1411 set_file_is_shared(isSharedInstrument);
2995 persson 1261
2996 schoenebeck 2772 this->filename =
2997     (filename && strlen(filename) > 0) ?
2998     filename : (!gig->GetFileName().empty()) ?
2999     gig->GetFileName() : _("Unsaved Gig File");
3000 persson 1261 set_title(Glib::filename_display_basename(this->filename));
3001     file_has_name = filename;
3002     file_is_changed = false;
3003    
3004 schoenebeck 2560 propDialog.set_file(gig);
3005 schoenebeck 1225 propDialog.set_info(gig->pInfo);
3006    
3007 persson 2442 instrument_name_connection.block();
3008 schoenebeck 2994 int index = 0;
3009 schoenebeck 1225 for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
3010 schoenebeck 2994 instrument = gig->GetNextInstrument(), ++index) {
3011 persson 2446 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3012 schoenebeck 3197 const int iScriptSlots = instrument->ScriptSlotCount();
3013 persson 2442
3014 schoenebeck 1225 Gtk::TreeModel::iterator iter = m_refTreeModel->append();
3015     Gtk::TreeModel::Row row = *iter;
3016 schoenebeck 2994 row[m_Columns.m_col_nr] = index;
3017 persson 2442 row[m_Columns.m_col_name] = name;
3018 schoenebeck 1225 row[m_Columns.m_col_instr] = instrument;
3019 schoenebeck 3197 row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3020 persson 2442
3021 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3022 persson 2442 add_instrument_to_menu(name);
3023 schoenebeck 3364 #endif
3024 schoenebeck 1225 }
3025 persson 2442 instrument_name_connection.unblock();
3026 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3027 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
3028 schoenebeck 3364 #endif
3029 schoenebeck 1225
3030 schoenebeck 2621 updateSampleRefCountMap(gig);
3031    
3032 schoenebeck 1225 for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
3033     if (group->Name != "") {
3034     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3035     Gtk::TreeModel::Row rowGroup = *iterGroup;
3036 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3037 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_group] = group;
3038     rowGroup[m_SamplesModel.m_col_sample] = NULL;
3039     for (gig::Sample* sample = group->GetFirstSample();
3040     sample; sample = group->GetNextSample()) {
3041     Gtk::TreeModel::iterator iterSample =
3042     m_refSamplesTreeModel->append(rowGroup.children());
3043     Gtk::TreeModel::Row rowSample = *iterSample;
3044 persson 2446 rowSample[m_SamplesModel.m_col_name] =
3045     gig_to_utf8(sample->pInfo->Name);
3046 schoenebeck 1225 rowSample[m_SamplesModel.m_col_sample] = sample;
3047     rowSample[m_SamplesModel.m_col_group] = NULL;
3048 schoenebeck 2621 int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
3049     rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3050 schoenebeck 2625 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3051 schoenebeck 1225 }
3052     }
3053     }
3054 schoenebeck 2604
3055     for (int i = 0; gig->GetScriptGroup(i); ++i) {
3056     gig::ScriptGroup* group = gig->GetScriptGroup(i);
3057 schoenebeck 1225
3058 schoenebeck 2604 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3059     Gtk::TreeModel::Row rowGroup = *iterGroup;
3060     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3061     rowGroup[m_ScriptsModel.m_col_group] = group;
3062     rowGroup[m_ScriptsModel.m_col_script] = NULL;
3063     for (int s = 0; group->GetScript(s); ++s) {
3064     gig::Script* script = group->GetScript(s);
3065    
3066     Gtk::TreeModel::iterator iterScript =
3067     m_refScriptsTreeModel->append(rowGroup.children());
3068     Gtk::TreeModel::Row rowScript = *iterScript;
3069     rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
3070     rowScript[m_ScriptsModel.m_col_script] = script;
3071     rowScript[m_ScriptsModel.m_col_group] = NULL;
3072     }
3073     }
3074 schoenebeck 2624 // unfold all sample groups & script groups by default
3075     m_TreeViewSamples.expand_all();
3076 schoenebeck 2604 m_TreeViewScripts.expand_all();
3077    
3078 persson 1261 file = gig;
3079    
3080 schoenebeck 1225 // select the first instrument
3081 persson 2442 m_TreeView.get_selection()->select(Gtk::TreePath("0"));
3082 persson 2423
3083 persson 2445 instr_props_set_instrument();
3084 persson 2507 gig::Instrument* instrument = get_instrument();
3085     if (instrument) {
3086     midiRules.set_instrument(instrument);
3087     }
3088 persson 2445 }
3089    
3090     bool MainWindow::instr_props_set_instrument()
3091     {
3092     instrumentProps.signal_name_changed().clear();
3093    
3094 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3095     if (rows.empty()) {
3096     instrumentProps.hide();
3097     return false;
3098     }
3099 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.
3100     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3101 persson 2445 if (it) {
3102     Gtk::TreeModel::Row row = *it;
3103     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3104    
3105 persson 2423 instrumentProps.set_instrument(instrument);
3106 persson 2445
3107     // make sure instrument tree is updated when user changes the
3108     // instrument name in instrument properties window
3109     instrumentProps.signal_name_changed().connect(
3110     sigc::bind(
3111     sigc::mem_fun(*this,
3112     &MainWindow::instr_name_changed_by_instr_props),
3113     it));
3114     } else {
3115     instrumentProps.hide();
3116 persson 2423 }
3117 schoenebeck 3364 //NOTE: explicit boolean cast required for GTKMM4 development branch here
3118     return it ? true : false;
3119 schoenebeck 1225 }
3120    
3121     void MainWindow::show_instr_props()
3122     {
3123 persson 2445 if (instr_props_set_instrument()) {
3124 persson 1533 instrumentProps.show();
3125     instrumentProps.deiconify();
3126 schoenebeck 1225 }
3127     }
3128    
3129 persson 2445 void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3130     {
3131     Gtk::TreeModel::Row row = *it;
3132     Glib::ustring name = row[m_Columns.m_col_name];
3133    
3134     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3135 persson 2446 Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3136     if (gigname != name) {
3137     row[m_Columns.m_col_name] = gigname;
3138 persson 2445 }
3139     }
3140    
3141 persson 2507 void MainWindow::show_midi_rules()
3142     {
3143     if (gig::Instrument* instrument = get_instrument())
3144     {
3145     midiRules.set_instrument(instrument);
3146     midiRules.show();
3147     midiRules.deiconify();
3148     }
3149     }
3150    
3151 schoenebeck 2610 void MainWindow::show_script_slots() {
3152     if (!file) return;
3153     // get selected instrument
3154 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3155     if (rows.empty()) return;
3156     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3157 schoenebeck 2610 if (!it) return;
3158     Gtk::TreeModel::Row row = *it;
3159     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3160     if (!instrument) return;
3161    
3162     ScriptSlots* window = new ScriptSlots;
3163     window->setInstrument(instrument);
3164 schoenebeck 3197 window->signal_script_slots_changed().connect(
3165     sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3166     );
3167 schoenebeck 2610 //window->reparent(*this);
3168     window->show();
3169     }
3170    
3171 schoenebeck 3197 void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3172     if (!pInstrument) return;
3173     const int iScriptSlots = pInstrument->ScriptSlotCount();
3174    
3175 schoenebeck 3340 //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
3176     //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3177     Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3178    
3179 schoenebeck 3197 for (int i = 0; i < model->children().size(); ++i) {
3180     Gtk::TreeModel::Row row = model->children()[i];
3181     if (row[m_Columns.m_col_instr] != pInstrument) continue;
3182     row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3183     break;
3184     }
3185 schoenebeck 3339
3186     // causes the sampler to reload the instrument with the new script
3187     on_sel_change();
3188 schoenebeck 3197 }
3189    
3190 schoenebeck 3339 void MainWindow::assignScript(gig::Script* pScript) {
3191     if (!pScript) {
3192     printf("assignScript() : !script\n");
3193     return;
3194     }
3195     printf("assignScript('%s')\n", pScript->Name.c_str());
3196    
3197     gig::Instrument* pInstrument = get_instrument();
3198     if (!pInstrument) {
3199     printf("!instrument\n");
3200     return;
3201     }
3202    
3203     pInstrument->AddScriptSlot(pScript);
3204    
3205     onScriptSlotsModified(pInstrument);
3206     }
3207    
3208 schoenebeck 2772 void MainWindow::on_action_refresh_all() {
3209     __refreshEntireGUI();
3210     }
3211    
3212 schoenebeck 1415 void MainWindow::on_action_view_status_bar() {
3213 schoenebeck 3364 #if USE_GLIB_ACTION
3214     bool active = false;
3215     m_actionToggleStatusBar->get_state(active);
3216     // for some reason toggle state does not change automatically
3217     active = !active;
3218     m_actionToggleStatusBar->change_state(active);
3219     if (active)
3220     m_StatusBar.show();
3221     else
3222     m_StatusBar.hide();
3223     #else
3224 schoenebeck 1415 Gtk::CheckMenuItem* item =
3225     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3226     if (!item) {
3227     std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
3228     return;
3229     }
3230     if (item->get_active()) m_StatusBar.show();
3231     else m_StatusBar.hide();
3232 schoenebeck 3364 #endif
3233 schoenebeck 1415 }
3234    
3235 schoenebeck 2918 void MainWindow::on_auto_restore_win_dim() {
3236 schoenebeck 3364 #if USE_GLIB_ACTION
3237     bool active = false;
3238     m_actionToggleRestoreWinDim->get_state(active);
3239     // for some reason toggle state does not change automatically
3240     active = !active;
3241     m_actionToggleRestoreWinDim->change_state(active);
3242     Settings::singleton()->autoRestoreWindowDimension = active;
3243     #else
3244 schoenebeck 2918 Gtk::CheckMenuItem* item =
3245     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3246     if (!item) {
3247     std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
3248     return;
3249     }
3250     Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3251 schoenebeck 3364 #endif
3252 schoenebeck 2918 }
3253    
3254 schoenebeck 2967 void MainWindow::on_save_with_temporary_file() {
3255 schoenebeck 3364 #if USE_GLIB_ACTION
3256     bool active = false;
3257     m_actionToggleSaveWithTempFile->get_state(active);
3258     // for some reason toggle state does not change automatically
3259     active = !active;
3260     m_actionToggleSaveWithTempFile->change_state(active);
3261     Settings::singleton()->saveWithTemporaryFile = active;
3262     #else
3263 schoenebeck 2967 Gtk::CheckMenuItem* item =
3264     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3265     if (!item) {
3266     std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
3267     return;
3268     }
3269     Settings::singleton()->saveWithTemporaryFile = item->get_active();
3270 schoenebeck 3364 #endif
3271 schoenebeck 2967 }
3272    
3273 schoenebeck 2464 bool MainWindow::is_copy_samples_unity_note_enabled() const {
3274 schoenebeck 3364 #if USE_GLIB_ACTION
3275     bool active = false;
3276     m_actionToggleCopySampleUnity->get_state(active);
3277     return active;
3278     #else
3279 schoenebeck 2464 Gtk::CheckMenuItem* item =
3280     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3281     if (!item) {
3282     std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
3283     return true;
3284     }
3285     return item->get_active();
3286 schoenebeck 3364 #endif
3287 schoenebeck 2464 }
3288    
3289     bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3290 schoenebeck 3364 #if USE_GLIB_ACTION
3291     bool active = false;
3292     m_actionToggleCopySampleTune->get_state(active);
3293     return active;
3294     #else
3295 schoenebeck 2464 Gtk::CheckMenuItem* item =
3296     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3297     if (!item) {
3298     std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
3299     return true;
3300     }
3301     return item->get_active();
3302 schoenebeck 3364 #endif
3303 schoenebeck 2464 }
3304    
3305     bool MainWindow::is_copy_samples_loop_enabled() const {
3306 schoenebeck 3364 #if USE_GLIB_ACTION
3307     bool active = false;
3308     m_actionToggleCopySampleLoop->get_state(active);
3309     return active;
3310     #else
3311 schoenebeck 2464 Gtk::CheckMenuItem* item =
3312     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3313     if (!item) {
3314     std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
3315     return true;
3316     }
3317     return item->get_active();
3318 schoenebeck 3364 #endif
3319 schoenebeck 2464 }
3320    
3321 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
3322     bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3323     GdkEventButton* button = _button.gobj();
3324     #else
3325     void MainWindow::on_button_release(GdkEventButton* button) {
3326     #endif
3327 schoenebeck 1225 if (button->type == GDK_2BUTTON_PRESS) {
3328     show_instr_props();
3329     } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3330 persson 2507 // gig v2 files have no midi rules
3331 schoenebeck 2625 const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3332 schoenebeck 3364 #if USE_GTKMM_BUILDER
3333     m_actionMIDIRules->property_enabled() = bEnabled;
3334     #else
3335 persson 2507 static_cast<Gtk::MenuItem*>(
3336 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3337     bEnabled
3338     );
3339     static_cast<Gtk::MenuItem*>(
3340 persson 2507 uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3341 schoenebeck 2625 bEnabled
3342     );
3343 schoenebeck 3364 #endif
3344 schoenebeck 1225 popup_menu->popup(button->button, button->time);
3345     }
3346 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
3347     return false;
3348     #endif
3349 schoenebeck 1225 }
3350    
3351 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3352 persson 2442 void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3353     if (item->get_active()) {
3354     const std::vector<Gtk::Widget*> children =
3355     instrument_menu->get_children();
3356     std::vector<Gtk::Widget*>::const_iterator it =
3357     find(children.begin(), children.end(), item);
3358     if (it != children.end()) {
3359     int index = it - children.begin();
3360     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
3361    
3362     m_RegionChooser.set_instrument(file->GetInstrument(index));
3363     }
3364     }
3365 schoenebeck 1225 }
3366 schoenebeck 3364 #endif
3367 schoenebeck 1225
3368 schoenebeck 2701 void MainWindow::select_instrument(gig::Instrument* instrument) {
3369     if (!instrument) return;
3370    
3371 schoenebeck 3340 //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
3372 schoenebeck 2701 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3373 schoenebeck 3340 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3374    
3375 schoenebeck 2701 for (int i = 0; i < model->children().size(); ++i) {
3376     Gtk::TreeModel::Row row = model->children()[i];
3377     if (row[m_Columns.m_col_instr] == instrument) {
3378     // select and show the respective instrument in the list view
3379     show_intruments_tab();
3380 schoenebeck 2994 m_TreeView.get_selection()->unselect_all();
3381 schoenebeck 3364
3382     #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3383     auto iterSel = model->children()[i].get_iter();
3384     m_TreeView.get_selection()->select(iterSel);
3385     #else
3386 schoenebeck 2701 m_TreeView.get_selection()->select(model->children()[i]);
3387 schoenebeck 3364 #endif
3388 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3389     m_TreeView.get_selection()->get_selected_rows();
3390     if (!rows.empty())
3391     m_TreeView.scroll_to_row(rows[0]);
3392 schoenebeck 2701 on_sel_change(); // the regular instrument selection change callback
3393     }
3394     }
3395     }
3396    
3397 schoenebeck 2695 /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
3398     bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
3399     gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3400     gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3401    
3402 schoenebeck 3340 //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
3403 schoenebeck 2695 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3404 schoenebeck 3340 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3405    
3406 schoenebeck 2695 for (int i = 0; i < model->children().size(); ++i) {
3407     Gtk::TreeModel::Row row = model->children()[i];
3408     if (row[m_Columns.m_col_instr] == pInstrument) {
3409     // select and show the respective instrument in the list view
3410     show_intruments_tab();
3411 schoenebeck 2994 m_TreeView.get_selection()->unselect_all();
3412 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3413     auto iterSel = model->children()[i].get_iter();
3414     m_TreeView.get_selection()->select(iterSel);
3415     #else
3416 schoenebeck 2695 m_TreeView.get_selection()->select(model->children()[i]);
3417 schoenebeck 3364 #endif
3418 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3419     m_TreeView.get_selection()->get_selected_rows();
3420     if (!rows.empty())
3421     m_TreeView.scroll_to_row(rows[0]);
3422 schoenebeck 2695 on_sel_change(); // the regular instrument selection change callback
3423    
3424     // select respective region in the region selector
3425     m_RegionChooser.set_region(pRegion);
3426    
3427     // select and show the respective dimension region in the editor
3428     //update_dimregs();
3429     if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
3430     //dimreg_edit.set_dim_region(dimRgn);
3431    
3432     return true;
3433     }
3434     }
3435    
3436     return false;
3437     }
3438    
3439 schoenebeck 2691 void MainWindow::select_sample(gig::Sample* sample) {
3440     Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3441     for (int g = 0; g < model->children().size(); ++g) {
3442     Gtk::TreeModel::Row rowGroup = model->children()[g];
3443     for (int s = 0; s < rowGroup.children().size(); ++s) {
3444     Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3445     if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3446     show_samples_tab();
3447 schoenebeck 2994 m_TreeViewSamples.get_selection()->unselect_all();
3448 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
3449     auto iterSel = rowGroup.children()[s].get_iter();
3450     m_TreeViewSamples.get_selection()->select(iterSel);
3451     #else
3452 schoenebeck 2691 m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3453 schoenebeck 3364 #endif
3454 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3455     m_TreeViewSamples.get_selection()->get_selected_rows();
3456     if (rows.empty()) return;
3457     m_TreeViewSamples.scroll_to_row(rows[0]);
3458 schoenebeck 2691 return;
3459     }
3460     }
3461     }
3462     }
3463    
3464 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
3465     bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3466     GdkEventButton* button = _button.gobj();
3467     #else
3468 schoenebeck 1225 void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3469 schoenebeck 3364 #endif
3470 schoenebeck 1225 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3471 schoenebeck 2994 // by default if Ctrl keys is pressed down, then a mouse right-click
3472     // does not select the respective row, so we must assure this
3473     // programmatically ...
3474     /*{
3475     Gtk::TreeModel::Path path;
3476     Gtk::TreeViewColumn* pColumn = NULL;
3477     int cellX, cellY;
3478     bool bSuccess = m_TreeViewSamples.get_path_at_pos(
3479     (int)button->x, (int)button->y,
3480     path, pColumn, cellX, cellY
3481     );
3482     if (bSuccess) {
3483     if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
3484     printf("not selected !!!\n");
3485     m_TreeViewSamples.get_selection()->select(path);
3486     }
3487     }
3488     }*/
3489    
3490 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3491 schoenebeck 1225 Gtk::Menu* sample_popup =
3492     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
3493 schoenebeck 3364 #endif
3494    
3495 schoenebeck 1225 // update enabled/disabled state of sample popup items
3496     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3497 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3498     const int n = rows.size();
3499     int nGroups = 0;
3500     int nSamples = 0;
3501     for (int r = 0; r < n; ++r) {
3502     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3503     if (!it) continue;
3504 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
3505 schoenebeck 2994 if (row[m_SamplesModel.m_col_group]) nGroups++;
3506     if (row[m_SamplesModel.m_col_sample]) nSamples++;
3507 schoenebeck 1225 }
3508 schoenebeck 2994
3509 schoenebeck 3364 #if USE_GTKMM_BUILDER
3510     m_actionSampleProperties->property_enabled() = (n == 1);
3511     m_actionAddSample->property_enabled() = (n);
3512     m_actionAddSampleGroup->property_enabled() = (file);
3513     m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
3514     m_actionRemoveSample->property_enabled() = (n);
3515     m_actionReplaceSample->property_enabled() = (nSamples == 1);
3516     #else
3517 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
3518 schoenebeck 2994 set_sensitive(n == 1);
3519 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
3520 schoenebeck 2994 set_sensitive(n);
3521 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
3522     set_sensitive(file);
3523 schoenebeck 2624 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
3524 schoenebeck 2994 set_sensitive(nSamples == 1);
3525 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
3526 schoenebeck 2994 set_sensitive(n);
3527 schoenebeck 3364 #endif
3528 schoenebeck 1225 // show sample popup
3529     sample_popup->popup(button->button, button->time);
3530 schoenebeck 2625
3531 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3532 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
3533 schoenebeck 2994 set_sensitive(n == 1);
3534 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
3535 schoenebeck 2994 set_sensitive(n);
3536 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
3537     set_sensitive(file);
3538     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
3539 schoenebeck 2994 set_sensitive(nSamples == 1);
3540 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3541 schoenebeck 2994 set_sensitive(n);
3542 schoenebeck 3364 #endif
3543 schoenebeck 1225 }
3544 schoenebeck 3364
3545     #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
3546     return false;
3547     #endif
3548 schoenebeck 1225 }
3549    
3550 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
3551     bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3552     GdkEventButton* button = _button.gobj();
3553     #else
3554 schoenebeck 2604 void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3555 schoenebeck 3364 #endif
3556 schoenebeck 2604 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3557 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3558 schoenebeck 2604 Gtk::Menu* script_popup =
3559     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3560 schoenebeck 3364 #endif
3561 schoenebeck 2604 // update enabled/disabled state of sample popup items
3562     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3563     Gtk::TreeModel::iterator it = sel->get_selected();
3564     bool group_selected = false;
3565     bool script_selected = false;
3566     if (it) {
3567     Gtk::TreeModel::Row row = *it;
3568     group_selected = row[m_ScriptsModel.m_col_group];
3569     script_selected = row[m_ScriptsModel.m_col_script];
3570     }
3571 schoenebeck 3364 #if USE_GTKMM_BUILDER
3572     m_actionAddScript->property_enabled() = (group_selected || script_selected);
3573     m_actionAddScriptGroup->property_enabled() = (file);
3574     m_actionEditScript->property_enabled() = (script_selected);
3575     m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
3576     #else
3577 schoenebeck 2604 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
3578     set_sensitive(group_selected || script_selected);
3579     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
3580     set_sensitive(file);
3581     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
3582     set_sensitive(script_selected);
3583     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3584     set_sensitive(group_selected || script_selected);
3585 schoenebeck 3364 #endif
3586 schoenebeck 2604 // show sample popup
3587     script_popup->popup(button->button, button->time);
3588 schoenebeck 2625
3589 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3590 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3591     set_sensitive(group_selected || script_selected);
3592     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
3593     set_sensitive(file);
3594     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
3595     set_sensitive(script_selected);
3596     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3597     set_sensitive(group_selected || script_selected);
3598 schoenebeck 3364 #endif
3599 schoenebeck 2604 }
3600 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
3601     return false;
3602     #endif
3603 schoenebeck 2604 }
3604 persson 2442
3605 schoenebeck 3339 void MainWindow::updateScriptListOfMenu() {
3606     // remove all entries from "Assign Script" menu
3607     {
3608     const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
3609     for (int i = 0; i < children.size(); ++i) {
3610     Gtk::Widget* child = children[i];
3611     assign_scripts_menu->remove(*child);
3612     delete child;
3613     }
3614     }
3615    
3616     int iTotalScripts = 0;
3617    
3618     if (!file) goto noScripts;
3619    
3620     // add all configured macros as menu items to the "Macro" menu
3621     for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
3622     gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
3623     for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
3624     gig::Script* pScript = pGroup->GetScript(iScript);
3625     std::string name = pScript->Name;
3626    
3627     Gtk::MenuItem* item = new Gtk::MenuItem(name);
3628     item->signal_activate().connect(
3629     sigc::bind(
3630     sigc::mem_fun(*this, &MainWindow::assignScript), pScript
3631     )
3632     );
3633     assign_scripts_menu->append(*item);
3634     item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
3635     //item->set_tooltip_text(comment);
3636     }
3637     }
3638    
3639     noScripts:
3640    
3641     // if there are no macros configured at all, then show a dummy entry instead
3642     if (!iTotalScripts) {
3643     Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
3644     item->set_sensitive(false);
3645     assign_scripts_menu->append(*item);
3646     }
3647    
3648 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
3649 schoenebeck 3339 assign_scripts_menu->show_all_children();
3650 schoenebeck 3364 #endif
3651 schoenebeck 3339 }
3652    
3653 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3654 persson 2442 Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
3655     const Glib::ustring& name, int position) {
3656    
3657     Gtk::RadioMenuItem::Group instrument_group;
3658     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
3659     if (!children.empty()) {
3660     instrument_group =
3661     static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
3662     }
3663     Gtk::RadioMenuItem* item =
3664     new Gtk::RadioMenuItem(instrument_group, name);
3665     if (position < 0) {
3666     instrument_menu->append(*item);
3667     } else {
3668     instrument_menu->insert(*item, position);
3669     }
3670     item->show();
3671     item->signal_activate().connect(
3672     sigc::bind(
3673     sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
3674     item));
3675     return item;
3676     }
3677 schoenebeck 3364 #endif
3678 persson 2442
3679 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3680 persson 2442 void MainWindow::remove_instrument_from_menu(int index) {
3681     const std::vector<Gtk::Widget*> children =
3682     instrument_menu->get_children();
3683     Gtk::Widget* child = children[index];
3684     instrument_menu->remove(*child);
3685     delete child;
3686     }
3687 schoenebeck 3364 #endif
3688 persson 2442
3689     void MainWindow::add_instrument(gig::Instrument* instrument) {
3690 persson 2446 const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3691 persson 2442
3692     // update instrument tree view
3693     instrument_name_connection.block();
3694     Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3695     Gtk::TreeModel::Row rowInstr = *iterInstr;
3696 schoenebeck 2994 rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
3697 persson 2442 rowInstr[m_Columns.m_col_name] = name;
3698     rowInstr[m_Columns.m_col_instr] = instrument;
3699 schoenebeck 3197 rowInstr[m_Columns.m_col_scripts] = "";
3700 persson 2442 instrument_name_connection.unblock();
3701    
3702 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3703 persson 2442 add_instrument_to_menu(name);
3704 schoenebeck 3364 #endif
3705 schoenebeck 3339 select_instrument(instrument);
3706 persson 2442 file_changed();
3707     }
3708    
3709 schoenebeck 1225 void MainWindow::on_action_add_instrument() {
3710     static int __instrument_indexer = 0;
3711     if (!file) return;
3712     gig::Instrument* instrument = file->AddInstrument();
3713     __instrument_indexer++;
3714 persson 2446 instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
3715     ToString(__instrument_indexer));
3716 persson 2442
3717     add_instrument(instrument);
3718 schoenebeck 1225 }
3719    
3720 schoenebeck 2395 void MainWindow::on_action_duplicate_instrument() {
3721     if (!file) return;
3722 persson 2442
3723 schoenebeck 2395 // retrieve the currently selected instrument
3724     // (being the original instrument to be duplicated)
3725     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3726 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3727     for (int r = 0; r < rows.size(); ++r) {
3728     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3729     if (it) {
3730     Gtk::TreeModel::Row row = *it;
3731     gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
3732     if (instrOrig) {
3733     // duplicate the orginal instrument
3734     gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
3735     instrNew->pInfo->Name =
3736     instrOrig->pInfo->Name +
3737     gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
3738 persson 2442
3739 schoenebeck 2994 add_instrument(instrNew);
3740     }
3741     }
3742     }
3743 schoenebeck 2395 }
3744    
3745 schoenebeck 1225 void MainWindow::on_action_remove_instrument() {
3746     if (!file) return;
3747 schoenebeck 1382 if (file_is_shared) {
3748     Gtk::MessageDialog msg(
3749     *this,
3750     _("You cannot delete an instrument from this file, since it's "
3751     "currently used by the sampler."),
3752     false, Gtk::MESSAGE_INFO
3753     );
3754     msg.run();
3755     return;
3756     }
3757    
3758 schoenebeck 1225 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3759 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3760     for (int r = rows.size() - 1; r >= 0; --r) {
3761     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3762     if (!it) continue;
3763 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
3764     gig::Instrument* instr = row[m_Columns.m_col_instr];
3765     try {
3766 persson 2442 Gtk::TreePath path(it);
3767     int index = path[0];
3768    
3769 schoenebeck 1225 // remove instrument from the gig file
3770     if (instr) file->DeleteInstrument(instr);
3771 persson 1261 file_changed();
3772 persson 2423
3773 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3774 persson 2442 remove_instrument_from_menu(index);
3775 schoenebeck 3364 #endif
3776 persson 2442
3777     // remove row from instruments tree view
3778     m_refTreeModel->erase(it);
3779 schoenebeck 2994 // update "Nr" column of all instrument rows
3780     {
3781     int index = 0;
3782     for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
3783     it != m_refTreeModel->children().end(); ++it, ++index)
3784     {
3785     Gtk::TreeModel::Row row = *it;
3786     row[m_Columns.m_col_nr] = index;
3787     }
3788     }
3789 persson 2442
3790     #if GTKMM_MAJOR_VERSION < 3
3791     // select another instrument (in gtk3 this is done
3792     // automatically)
3793     if (!m_refTreeModel->children().empty()) {
3794     if (index == m_refTreeModel->children().size()) {
3795     index--;
3796     }
3797     m_TreeView.get_selection()->select(
3798     Gtk::TreePath(ToString(index)));
3799     }
3800     #endif
3801 persson 2445 instr_props_set_instrument();
3802 persson 2507 instr = get_instrument();
3803     if (instr) {
3804     midiRules.set_instrument(instr);
3805     } else {
3806     midiRules.hide();
3807     }
3808 schoenebeck 1225 } catch (RIFF::Exception e) {
3809     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3810     msg.run();
3811     }
3812     }
3813     }
3814    
3815     void MainWindow::on_action_sample_properties() {
3816     //TODO: show a dialog where the selected sample's properties can be edited
3817     Gtk::MessageDialog msg(
3818 persson 1831 *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
3819 schoenebeck 1225 );
3820     msg.run();
3821     }
3822    
3823 schoenebeck 2604 void MainWindow::on_action_add_script_group() {
3824     static int __script_indexer = 0;
3825     if (!file) return;
3826     gig::ScriptGroup* group = file->AddScriptGroup();
3827     group->Name = gig_from_utf8(_("Unnamed Group"));
3828     if (__script_indexer) group->Name += " " + ToString(__script_indexer);
3829     __script_indexer++;
3830     // update sample tree view
3831     Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3832     Gtk::TreeModel::Row rowGroup = *iterGroup;
3833     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3834     rowGroup[m_ScriptsModel.m_col_script] = NULL;
3835     rowGroup[m_ScriptsModel.m_col_group] = group;
3836     file_changed();
3837     }
3838    
3839     void MainWindow::on_action_add_script() {
3840     if (!file) return;
3841     // get selected group
3842     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3843     Gtk::TreeModel::iterator it = sel->get_selected();
3844     if (!it) return;
3845     Gtk::TreeModel::Row row = *it;
3846     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3847     if (!group) { // not a group, but a script is selected (probably)
3848     gig::Script* script = row[m_ScriptsModel.m_col_script];
3849     if (!script) return;
3850     it = row.parent(); // resolve parent (that is the script's group)
3851     if (!it) return;
3852     row = *it;
3853     group = row[m_ScriptsModel.m_col_group];
3854     if (!group) return;
3855     }
3856    
3857     // add a new script to the .gig file
3858     gig::Script* script = group->AddScript();
3859     Glib::ustring name = _("Unnamed Script");
3860     script->Name = gig_from_utf8(name);
3861    
3862     // add script to the tree view
3863     Gtk::TreeModel::iterator iterScript =
3864     m_refScriptsTreeModel->append(row.children());
3865     Gtk::TreeModel::Row rowScript = *iterScript;
3866     rowScript[m_ScriptsModel.m_col_name] = name;
3867     rowScript[m_ScriptsModel.m_col_script] = script;
3868     rowScript[m_ScriptsModel.m_col_group] = NULL;
3869    
3870     // unfold group of new script item in treeview
3871     Gtk::TreeModel::Path path(iterScript);
3872     m_TreeViewScripts.expand_to_path(path);
3873     }
3874    
3875     void MainWindow::on_action_edit_script() {
3876     if (!file) return;
3877     // get selected script
3878     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3879     Gtk::TreeModel::iterator it = sel->get_selected();
3880     if (!it) return;
3881     Gtk::TreeModel::Row row = *it;
3882     gig::Script* script = row[m_ScriptsModel.m_col_script];
3883     if (!script) return;
3884    
3885     ScriptEditor* editor = new ScriptEditor;
3886 schoenebeck 2903 editor->signal_script_to_be_changed.connect(
3887     signal_script_to_be_changed.make_slot()
3888     );
3889     editor->signal_script_changed.connect(
3890     signal_script_changed.make_slot()
3891     );
3892 schoenebeck 2604 editor->setScript(script);
3893     //editor->reparent(*this);
3894     editor->show();
3895     }
3896    
3897     void MainWindow::on_action_remove_script() {
3898     if (!file) return;
3899     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3900     Gtk::TreeModel::iterator it = sel->get_selected();
3901     if (it) {
3902     Gtk::TreeModel::Row row = *it;
3903     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3904     gig::Script* script = row[m_ScriptsModel.m_col_script];
3905     Glib::ustring name = row[m_ScriptsModel.m_col_name];
3906     try {
3907     // remove script group or script from the gig file
3908     if (group) {
3909     // notify everybody that we're going to remove these samples
3910     //TODO: scripts_to_be_removed_signal.emit(members);
3911     // delete the group in the .gig file including the
3912     // samples that belong to the group
3913     file->DeleteScriptGroup(group);
3914     // notify that we're done with removal
3915     //TODO: scripts_removed_signal.emit();
3916     file_changed();
3917     } else if (script) {
3918     // notify everybody that we're going to remove this sample
3919     //TODO: std::list<gig::Script*> lscripts;
3920     //TODO: lscripts.push_back(script);
3921     //TODO: scripts_to_be_removed_signal.emit(lscripts);
3922     // remove sample from the .gig file
3923     script->GetGroup()->DeleteScript(script);
3924     // notify that we're done with removal
3925     //TODO: scripts_removed_signal.emit();
3926     dimreg_changed();
3927     file_changed();
3928     }
3929     // remove respective row(s) from samples tree view
3930     m_refScriptsTreeModel->erase(it);
3931     } catch (RIFF::Exception e) {
3932     // pretend we're done with removal (i.e. to avoid dead locks)
3933     //TODO: scripts_removed_signal.emit();
3934     // show error message
3935     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3936     msg.run();
3937     }
3938     }
3939     }
3940    
3941 schoenebeck 1225 void MainWindow::on_action_add_group() {
3942     static int __sample_indexer = 0;
3943     if (!file) return;
3944     gig::Group* group = file->AddGroup();
3945 persson 2446 group->Name = gig_from_utf8(_("Unnamed Group"));
3946 schoenebeck 1225 if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
3947     __sample_indexer++;
3948     // update sample tree view
3949     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3950     Gtk::TreeModel::Row rowGroup = *iterGroup;
3951 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3952 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_sample] = NULL;
3953     rowGroup[m_SamplesModel.m_col_group] = group;
3954 persson 1261 file_changed();
3955 schoenebeck 1225 }
3956    
3957 schoenebeck 2715 void MainWindow::on_action_replace_sample() {
3958     add_or_replace_sample(true);
3959     }
3960    
3961 schoenebeck 1225 void MainWindow::on_action_add_sample() {
3962 schoenebeck 2715 add_or_replace_sample(false);
3963     }
3964    
3965     void MainWindow::add_or_replace_sample(bool replace) {
3966 schoenebeck 1225 if (!file) return;
3967 schoenebeck 2715
3968     // get selected group (and probably selected sample)
3969 schoenebeck 1225 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3970 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3971     if (rows.empty()) return;
3972     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3973 schoenebeck 1225 if (!it) return;
3974     Gtk::TreeModel::Row row = *it;
3975 schoenebeck 2715 gig::Sample* sample = NULL;
3976 schoenebeck 1225 gig::Group* group = row[m_SamplesModel.m_col_group];
3977     if (!group) { // not a group, but a sample is selected (probably)
3978 schoenebeck 2715 if (replace) sample = row[m_SamplesModel.m_col_sample];
3979     if (!row[m_SamplesModel.m_col_sample]) return;
3980 schoenebeck 1225 it = row.parent(); // resolve parent (that is the sample's group)
3981     if (!it) return;
3982 schoenebeck 2715 if (!replace) row = *it;
3983     group = (*it)[m_SamplesModel.m_col_group];
3984 schoenebeck 1225 if (!group) return;
3985     }
3986 schoenebeck 2715 if (replace && !sample) return;
3987    
3988 schoenebeck 1225 // show 'browse for file' dialog
3989 schoenebeck 2715 Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
3990 schoenebeck 3364 #if HAS_GTKMM_STOCK
3991 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
3992     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
3993 schoenebeck 3364 #else
3994     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
3995     dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
3996     #endif
3997 schoenebeck 2715 dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
3998 persson 2169
3999     // matches all file types supported by libsndfile
4000     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4001     Gtk::FileFilter soundfilter;
4002     #else
4003     Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
4004     #endif
4005 persson 1262 const char* const supportedFileTypes[] = {
4006 schoenebeck 1225 "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
4007     "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
4008     "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
4009     "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
4010     "*.caf", "*.CAF", NULL
4011     };
4012 persson 2169 const char* soundfiles = _("Sound Files");
4013     const char* allfiles = _("All Files");
4014     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4015 schoenebeck 1225 for (int i = 0; supportedFileTypes[i]; i++)
4016     soundfilter.add_pattern(supportedFileTypes[i]);
4017 persson 2169 soundfilter.set_name(soundfiles);
4018    
4019     // matches every file
4020     Gtk::FileFilter allpassfilter;
4021 schoenebeck 1225 allpassfilter.add_pattern("*.*");
4022 persson 2169 allpassfilter.set_name(allfiles);
4023     #else
4024     for (int i = 0; supportedFileTypes[i]; i++)
4025     soundfilter->add_pattern(supportedFileTypes[i]);
4026     soundfilter->set_name(soundfiles);
4027    
4028     // matches every file
4029     Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
4030     allpassfilter->add_pattern("*.*");
4031     allpassfilter->set_name(allfiles);
4032     #endif
4033 schoenebeck 1225 dialog.add_filter(soundfilter);
4034     dialog.add_filter(allpassfilter);
4035 persson 1725 if (current_sample_dir != "") {
4036     dialog.set_current_folder(current_sample_dir);
4037     }
4038 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
4039 persson 1725 current_sample_dir = dialog.get_current_folder();
4040 schoenebeck 1225 Glib::ustring error_files;
4041 persson 2169 std::vector<std::string> filenames = dialog.get_filenames();
4042     for (std::vector<std::string>::iterator iter = filenames.begin();
4043 schoenebeck 1225 iter != filenames.end(); ++iter) {
4044     printf("Adding sample %s\n",(*iter).c_str());
4045 schoenebeck 3408 // use libsndfile to retrieve file information
4046 schoenebeck 1225 SF_INFO info;
4047     info.format = 0;
4048     SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
4049     try {
4050 persson 1831 if (!hFile) throw std::string(_("could not open file"));
4051 schoenebeck 1225 int bitdepth;
4052     switch (info.format & 0xff) {
4053     case SF_FORMAT_PCM_S8:
4054     case SF_FORMAT_PCM_16:
4055 persson 1265 case SF_FORMAT_PCM_U8:
4056 schoenebeck 1225 bitdepth = 16;
4057     break;
4058     case SF_FORMAT_PCM_24:
4059     case SF_FORMAT_PCM_32:
4060     case SF_FORMAT_FLOAT:
4061     case SF_FORMAT_DOUBLE:
4062 persson 1265 bitdepth = 24;
4063 schoenebeck 1225 break;
4064     default:
4065     sf_close(hFile); // close sound file
4066 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
4067 schoenebeck 1225 }
4068 schoenebeck 2715 // add a new sample to the .gig file (if adding is requested actually)
4069     if (!replace) sample = file->AddSample();
4070 schoenebeck 1225 // file name without path
4071 persson 1262 Glib::ustring filename = Glib::filename_display_basename(*iter);
4072     // remove file extension if there is one
4073     for (int i = 0; supportedFileTypes[i]; i++) {
4074     if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) {
4075     filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1));
4076     break;
4077     }
4078     }
4079 persson 2446 sample->pInfo->Name = gig_from_utf8(filename);
4080 schoenebeck 1225 sample->Channels = info.channels;
4081     sample->BitDepth = bitdepth;
4082     sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
4083     sample->SamplesPerSecond = info.samplerate;
4084 persson 1265 sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond;
4085     sample->BlockAlign = sample->FrameSize;
4086     sample->SamplesTotal = info.frames;
4087    
4088     SF_INSTRUMENT instrument;
4089     if (sf_command(hFile, SFC_GET_INSTRUMENT,
4090     &instrument, sizeof(instrument)) != SF_FALSE)
4091     {
4092     sample->MIDIUnityNote = instrument.basenote;
4093 schoenebeck 2466 sample->FineTune = instrument.detune;
4094 persson 1265
4095     if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
4096     sample->Loops = 1;
4097    
4098     switch (instrument.loops[0].mode) {
4099     case SF_LOOP_FORWARD:
4100     sample->LoopType = gig::loop_type_normal;
4101     break;
4102     case SF_LOOP_BACKWARD:
4103     sample->LoopType = gig::loop_type_backward;
4104     break;
4105     case SF_LOOP_ALTERNATING:
4106     sample->LoopType = gig::loop_type_bidirectional;
4107     break;
4108     }
4109     sample->LoopStart = instrument.loops[0].start;
4110     sample->LoopEnd = instrument.loops[0].end;
4111     sample->LoopPlayCount = instrument.loops[0].count;
4112     sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
4113     }
4114     }
4115    
4116 schoenebeck 1225 // schedule resizing the sample (which will be done
4117     // physically when File::Save() is called)
4118     sample->Resize(info.frames);
4119     // make sure sample is part of the selected group
4120 schoenebeck 2715 if (!replace) group->AddSample(sample);
4121 schoenebeck 1225 // schedule that physical resize and sample import
4122     // (data copying), performed when "Save" is requested
4123     SampleImportItem sched_item;
4124     sched_item.gig_sample = sample;
4125     sched_item.sample_path = *iter;
4126 schoenebeck 3116 m_SampleImportQueue[sample] = sched_item;
4127 schoenebeck 1225 // add sample to the tree view
4128 schoenebeck 2715 if (replace) {
4129     row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
4130     } else {
4131     Gtk::TreeModel::iterator iterSample =
4132     m_refSamplesTreeModel->append(row.children());
4133     Gtk::TreeModel::Row rowSample = *iterSample;
4134     rowSample[m_SamplesModel.m_col_name] =
4135     gig_to_utf8(sample->pInfo->Name);
4136     rowSample[m_SamplesModel.m_col_sample] = sample;
4137     rowSample[m_SamplesModel.m_col_group] = NULL;
4138     }
4139 schoenebeck 1225 // close sound file
4140     sf_close(hFile);
4141 persson 1261 file_changed();
4142 schoenebeck 1225 } catch (std::string what) { // remember the files that made trouble (and their cause)
4143 persson 2442 if (!error_files.empty()) error_files += "\n";
4144 schoenebeck 1225 error_files += *iter += " (" + what + ")";
4145     }
4146     }
4147     // show error message box when some file(s) could not be opened / added
4148 persson 2442 if (!error_files.empty()) {
4149 schoenebeck 2715 Glib::ustring txt =
4150     (replace
4151     ? _("Failed to replace sample with:\n")
4152     : _("Could not add the following sample(s):\n"))
4153     + error_files;
4154 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4155     msg.run();
4156     }
4157     }
4158     }
4159    
4160 schoenebeck 1673 void MainWindow::on_action_replace_all_samples_in_all_groups()
4161     {
4162     if (!file) return;
4163     Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
4164     Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
4165 persson 2442 const char* str =
4166 schoenebeck 1673 _("This is a very specific function. It tries to replace all samples "
4167 persson 1799 "in the current gig file by samples located in the chosen "
4168     "directory.\n\n"
4169     "It works like this: For each sample in the gig file, it tries to "
4170 schoenebeck 1673 "find a sample file in the selected directory with the same name as "
4171 persson 1799 "the sample in the gig file. Optionally, you can add a filename "
4172     "extension below, which will be added to the filename expected to be "
4173 schoenebeck 1673 "found. That is, assume you have a gig file with a sample called "
4174     "'Snare', if you enter '.wav' below (like it's done by default), it "
4175 persson 1799 "expects to find a sample file called 'Snare.wav' and will replace "
4176     "the sample in the gig file accordingly. If you don't need an "
4177     "extension, blank the field below. Any gig sample where no "
4178     "appropriate sample file could be found will be reported and left "
4179 persson 2344 "untouched.\n");
4180     #if GTKMM_MAJOR_VERSION < 3
4181     view::WrapLabel description(str);
4182     #else
4183     Gtk::Label description(str);
4184     description.set_line_wrap();
4185     #endif
4186 schoenebeck 3364 HBox entryArea;
4187 persson 2169 Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4188 schoenebeck 1673 Gtk::Entry postfixEntryBox;
4189     postfixEntryBox.set_text(".wav");
4190     entryArea.pack_start(entryLabel);
4191     entryArea.pack_start(postfixEntryBox);
4192 schoenebeck 3364 #if USE_GTKMM_BOX
4193     dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4194     dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4195     #else
4196 schoenebeck 1673 dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4197     dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4198 schoenebeck 3364 #endif
4199 schoenebeck 1673 description.show();
4200 schoenebeck 3364
4201     #if HAS_GTKMM_SHOW_ALL_CHILDREN
4202 persson 1799 entryArea.show_all();
4203 schoenebeck 3364 #else
4204     entryArea.show();
4205     #endif
4206    
4207     #if HAS_GTKMM_STOCK
4208 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4209 schoenebeck 3364 #else
4210     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4211     #endif
4212 schoenebeck 1673 dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4213     dialog.set_select_multiple(false);
4214 persson 1725 if (current_sample_dir != "") {
4215     dialog.set_current_folder(current_sample_dir);
4216     }
4217 schoenebeck 1673 if (dialog.run() == Gtk::RESPONSE_OK)
4218     {
4219 persson 1725 current_sample_dir = dialog.get_current_folder();
4220 schoenebeck 1673 Glib::ustring error_files;
4221 persson 2169 std::string folder = dialog.get_filename();
4222 schoenebeck 1673 for (gig::Sample* sample = file->GetFirstSample();
4223     sample; sample = file->GetNextSample())
4224     {
4225     std::string filename =
4226 persson 2446 folder + G_DIR_SEPARATOR_S +
4227     Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
4228     postfixEntryBox.get_text());
4229 schoenebeck 1673 SF_INFO info;
4230     info.format = 0;
4231     SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
4232     try
4233     {
4234 persson 1831 if (!hFile) throw std::string(_("could not open file"));
4235 schoenebeck 1673 switch (info.format & 0xff) {
4236     case SF_FORMAT_PCM_S8:
4237     case SF_FORMAT_PCM_16:
4238     case SF_FORMAT_PCM_U8:
4239     case SF_FORMAT_PCM_24:
4240     case SF_FORMAT_PCM_32:
4241     case SF_FORMAT_FLOAT:
4242     case SF_FORMAT_DOUBLE:
4243     break;
4244     default:
4245     sf_close(hFile);
4246 persson 1831 throw std::string(_("format not supported"));
4247 schoenebeck 1673 }
4248     SampleImportItem sched_item;
4249     sched_item.gig_sample = sample;
4250     sched_item.sample_path = filename;
4251 schoenebeck 3116 m_SampleImportQueue[sample] = sched_item;
4252 schoenebeck 1673 sf_close(hFile);
4253     file_changed();
4254     }
4255     catch (std::string what)
4256     {
4257 persson 2442 if (!error_files.empty()) error_files += "\n";
4258 persson 2446 error_files += Glib::filename_to_utf8(filename) +
4259     " (" + what + ")";
4260 schoenebeck 1673 }
4261     }
4262     // show error message box when some file(s) could not be opened / added
4263 persson 2442 if (!error_files.empty()) {
4264 schoenebeck 1673 Glib::ustring txt =
4265     _("Could not replace the following sample(s):\n") + error_files;
4266     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4267     msg.run();
4268     }
4269     }
4270     }
4271    
4272 schoenebeck 1225 void MainWindow::on_action_remove_sample() {
4273     if (!file) return;
4274     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4275 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4276     for (int r = rows.size() - 1; r >= 0; --r) {
4277     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4278     if (!it) continue;
4279 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
4280     gig::Group* group = row[m_SamplesModel.m_col_group];
4281     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4282     Glib::ustring name = row[m_SamplesModel.m_col_name];
4283     try {
4284     // remove group or sample from the gig file
4285     if (group) {
4286 persson 2446 // temporarily remember the samples that belong to
4287 schoenebeck 1225 // that group (we need that to clean the queue)
4288     std::list<gig::Sample*> members;
4289     for (gig::Sample* pSample = group->GetFirstSample();
4290     pSample; pSample = group->GetNextSample()) {
4291     members.push_back(pSample);
4292     }
4293 schoenebeck 1322 // notify everybody that we're going to remove these samples
4294     samples_to_be_removed_signal.emit(members);
4295 schoenebeck 1225 // delete the group in the .gig file including the
4296     // samples that belong to the group
4297     file->DeleteGroup(group);
4298 schoenebeck 1322 // notify that we're done with removal
4299     samples_removed_signal.emit();
4300 schoenebeck 1225 // if sample(s) were just previously added, remove
4301     // them from the import queue
4302     for (std::list<gig::Sample*>::iterator member = members.begin();
4303 schoenebeck 3116 member != members.end(); ++member)
4304     {
4305     if (m_SampleImportQueue.count(*member)) {
4306     printf("Removing previously added sample '%s' from group '%s'\n",
4307     m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
4308     m_SampleImportQueue.erase(*member);
4309 schoenebeck 1225 }
4310     }
4311 persson 1261 file_changed();
4312 schoenebeck 1225 } else if (sample) {
4313 schoenebeck 1322 // notify everybody that we're going to remove this sample
4314     std::list<gig::Sample*> lsamples;
4315     lsamples.push_back(sample);
4316     samples_to_be_removed_signal.emit(lsamples);
4317 schoenebeck 1225 // remove sample from the .gig file
4318     file->DeleteSample(sample);
4319 schoenebeck 1322 // notify that we're done with removal
4320     samples_removed_signal.emit();
4321 schoenebeck 1225 // if sample was just previously added, remove it from
4322     // the import queue
4323 schoenebeck 3116 if (m_SampleImportQueue.count(sample)) {
4324     printf("Removing previously added sample '%s'\n",
4325     m_SampleImportQueue[sample].sample_path.c_str());
4326     m_SampleImportQueue.erase(sample);
4327 schoenebeck 1225 }
4328 persson 1303 dimreg_changed();
4329 persson 1261 file_changed();
4330 schoenebeck 1225 }
4331     // remove respective row(s) from samples tree view
4332     m_refSamplesTreeModel->erase(it);
4333     } catch (RIFF::Exception e) {
4334 schoenebeck 1322 // pretend we're done with removal (i.e. to avoid dead locks)
4335     samples_removed_signal.emit();
4336     // show error message
4337 schoenebeck 1225 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4338     msg.run();
4339     }
4340     }
4341     }
4342    
4343 schoenebeck 2772 void MainWindow::on_action_remove_unused_samples() {
4344     if (!file) return;
4345    
4346     // collect all samples that are not referenced by any instrument
4347     std::list<gig::Sample*> lsamples;
4348     for (int iSample = 0; file->GetSample(iSample); ++iSample) {
4349     gig::Sample* sample = file->GetSample(iSample);
4350     bool isUsed = false;
4351     for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
4352     instrument = file->GetNextInstrument())
4353     {
4354     for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
4355     rgn = instrument->GetNextRegion())
4356     {
4357     for (int i = 0; i < 256; ++i) {
4358     if (!rgn->pDimensionRegions[i]) continue;
4359     if (rgn->pDimensionRegions[i]->pSample != sample) continue;
4360     isUsed = true;
4361     goto endOfRefSearch;
4362     }
4363     }
4364     }
4365     endOfRefSearch:
4366     if (!isUsed) lsamples.push_back(sample);
4367     }
4368    
4369     if (lsamples.empty()) return;
4370    
4371     // notify everybody that we're going to remove these samples
4372     samples_to_be_removed_signal.emit(lsamples);
4373    
4374     // remove collected samples
4375     try {
4376     for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
4377     itSample != lsamples.end(); ++itSample)
4378     {
4379     gig::Sample* sample = *itSample;
4380     // remove sample from the .gig file
4381     file->DeleteSample(sample);
4382 schoenebeck 3116 // if sample was just previously added, remove it from the import queue
4383     if (m_SampleImportQueue.count(sample)) {
4384     printf("Removing previously added sample '%s'\n",
4385     m_SampleImportQueue[sample].sample_path.c_str());
4386     m_SampleImportQueue.erase(sample);
4387 schoenebeck 2772 }
4388     }
4389     } catch (RIFF::Exception e) {
4390     // show error message
4391     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4392     msg.run();
4393     }
4394    
4395     // notify everybody that we're done with removal
4396     samples_removed_signal.emit();
4397    
4398     dimreg_changed();
4399     file_changed();
4400     __refreshEntireGUI();
4401     }
4402    
4403 schoenebeck 2610 // see comment on on_sample_treeview_drag_begin()
4404     void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4405     {
4406     first_call_to_drag_data_get = true;
4407     }
4408    
4409     void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4410     Gtk::SelectionData& selection_data, guint, guint)
4411     {
4412     if (!first_call_to_drag_data_get) return;
4413     first_call_to_drag_data_get = false;
4414    
4415     // get selected script
4416     gig::Script* script = NULL;
4417     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4418     Gtk::TreeModel::iterator it = sel->get_selected();
4419     if (it) {
4420     Gtk::TreeModel::Row row = *it;
4421     script = row[m_ScriptsModel.m_col_script];
4422     }
4423     // pass the gig::Script as pointer
4424     selection_data.set(selection_data.get_target(), 0/*unused*/,
4425     (const guchar*)&script,
4426     sizeof(script)/*length of data in bytes*/);
4427     }
4428    
4429 schoenebeck 2701 // see comment on on_sample_treeview_drag_begin()
4430     void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4431     {
4432     first_call_to_drag_data_get = true;
4433     }
4434    
4435     void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4436     Gtk::SelectionData& selection_data, guint, guint)
4437     {
4438     if (!first_call_to_drag_data_get) return;
4439     first_call_to_drag_data_get = false;
4440    
4441     // get selected source instrument
4442     gig::Instrument* src = NULL;
4443     {
4444     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4445 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4446     if (!rows.empty()) {
4447     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
4448     if (it) {
4449     Gtk::TreeModel::Row row = *it;
4450     src = row[m_Columns.m_col_instr];
4451     }
4452 schoenebeck 2701 }
4453     }
4454     if (!src) return;
4455    
4456     // pass the source gig::Instrument as pointer
4457     selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
4458     sizeof(src)/*length of data in bytes*/);
4459     }
4460    
4461     void MainWindow::on_instruments_treeview_drop_drag_data_received(
4462     const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
4463     const Gtk::SelectionData& selection_data, guint, guint time)
4464     {
4465     gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
4466     if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
4467     return;
4468    
4469     gig::Instrument* dst = NULL;
4470     {
4471     Gtk::TreeModel::Path path;
4472     const bool found = m_TreeView.get_path_at_pos(x, y, path);
4473     if (!found) return;
4474    
4475     Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
4476     if (!iter) return;
4477     Gtk::TreeModel::Row row = *iter;
4478     dst = row[m_Columns.m_col_instr];
4479     }
4480     if (!dst) return;
4481    
4482     //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
4483     src->MoveTo(dst);
4484     __refreshEntireGUI();
4485     select_instrument(src);
4486     }
4487    
4488 persson 1303 // For some reason drag_data_get gets called two times for each
4489     // drag'n'drop (at least when target is an Entry). This work-around
4490     // makes sure the code in drag_data_get and drop_drag_data_received is
4491     // only executed once, as drag_begin only gets called once.
4492     void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4493     {
4494     first_call_to_drag_data_get = true;
4495     }
4496    
4497 schoenebeck 1225 void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4498     Gtk::SelectionData& selection_data, guint, guint)
4499     {
4500 persson 1303 if (!first_call_to_drag_data_get) return;
4501     first_call_to_drag_data_get = false;
4502    
4503 schoenebeck 1225 // get selected sample
4504     gig::Sample* sample = NULL;
4505     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4506 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4507     if (!rows.empty()) {
4508     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4509     if (it) {
4510     Gtk::TreeModel::Row row = *it;
4511     sample = row[m_SamplesModel.m_col_sample];
4512     }
4513 schoenebeck 1225 }
4514     // pass the gig::Sample as pointer
4515     selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
4516     sizeof(sample)/*length of data in bytes*/);
4517     }
4518    
4519     void MainWindow::on_sample_label_drop_drag_data_received(
4520     const Glib::RefPtr<Gdk::DragContext>& context, int, int,
4521     const Gtk::SelectionData& selection_data, guint, guint time)
4522     {
4523     gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
4524    
4525 persson 1265 if (sample && selection_data.get_length() == sizeof(gig::Sample*)) {
4526 persson 1303 std::cout << "Drop received sample \"" <<
4527     sample->pInfo->Name << "\"" << std::endl;
4528     // drop success
4529     context->drop_reply(true, time);
4530    
4531 schoenebeck 1322 //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
4532    
4533     // notify everybody that we're going to alter the region
4534     gig::Region* region = m_RegionChooser.get_region();
4535     region_to_be_changed_signal.emit(region);
4536    
4537 persson 1303 // find the samplechannel dimension
4538     gig::dimension_def_t* stereo_dimension = 0;
4539     for (int i = 0 ; i < region->Dimensions ; i++) {
4540     if (region->pDimensionDefinitions[i].dimension ==
4541     gig::dimension_samplechannel) {
4542     stereo_dimension = &region->pDimensionDefinitions[i];
4543     break;
4544     }
4545 schoenebeck 1225 }
4546 persson 1303 bool channels_changed = false;
4547     if (sample->Channels == 1 && stereo_dimension) {
4548     // remove the samplechannel dimension
4549 schoenebeck 2550 /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
4550 persson 1303 region->DeleteDimension(stereo_dimension);
4551     channels_changed = true;
4552     region_changed();
4553 schoenebeck 2550 */
4554 persson 1303 }
4555 schoenebeck 2464 dimreg_edit.set_sample(
4556     sample,
4557     is_copy_samples_unity_note_enabled(),
4558     is_copy_samples_fine_tune_enabled(),
4559     is_copy_samples_loop_enabled()
4560     );
4561 persson 1303
4562     if (sample->Channels == 2 && !stereo_dimension) {
4563     // add samplechannel dimension
4564     gig::dimension_def_t dim;
4565     dim.dimension = gig::dimension_samplechannel;
4566     dim.bits = 1;
4567     dim.zones = 2;
4568     region->AddDimension(&dim);
4569     channels_changed = true;
4570     region_changed();
4571     }
4572     if (channels_changed) {
4573     // unmap all samples with wrong number of channels
4574     // TODO: maybe there should be a warning dialog for this
4575     for (int i = 0 ; i < region->DimensionRegions ; i++) {
4576     gig::DimensionRegion* d = region->pDimensionRegions[i];
4577     if (d->pSample && d->pSample->Channels != sample->Channels) {
4578 schoenebeck 1322 gig::Sample* oldref = d->pSample;
4579     d->pSample = NULL;
4580     sample_ref_changed_signal.emit(oldref, NULL);
4581 persson 1303 }
4582     }
4583     }
4584    
4585 schoenebeck 1322 // notify we're done with altering
4586     region_changed_signal.emit(region);
4587    
4588 persson 1460 file_changed();
4589    
4590 persson 1303 return;
4591 schoenebeck 1225 }
4592     // drop failed
4593     context->drop_reply(false, time);
4594     }
4595    
4596     void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path,
4597     const Gtk::TreeModel::iterator& iter) {
4598     if (!iter) return;
4599     Gtk::TreeModel::Row row = *iter;
4600     Glib::ustring name = row[m_SamplesModel.m_col_name];
4601     gig::Group* group = row[m_SamplesModel.m_col_group];
4602     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4603 persson 2446 gig::String gigname(gig_from_utf8(name));
4604 schoenebeck 1225 if (group) {
4605 persson 2446 if (group->Name != gigname) {
4606     group->Name = gigname;
4607 persson 1261 printf("group name changed\n");
4608     file_changed();
4609     }
4610 schoenebeck 1225 } else if (sample) {
4611 persson 2446 if (sample->pInfo->Name != gigname) {
4612     sample->pInfo->Name = gigname;
4613 persson 1261 printf("sample name changed\n");
4614     file_changed();
4615     }
4616 schoenebeck 1225 }
4617     }
4618    
4619 schoenebeck 2604 void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
4620     const Gtk::TreeModel::iterator& iter) {
4621     if (!iter) return;
4622     Gtk::TreeModel::Row row = *iter;
4623     Glib::ustring name = row[m_ScriptsModel.m_col_name];
4624     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
4625     gig::Script* script = row[m_ScriptsModel.m_col_script];
4626     gig::String gigname(gig_from_utf8(name));
4627     if (group) {
4628     if (group->Name != gigname) {
4629     group->Name = gigname;
4630     printf("script group name changed\n");
4631     file_changed();
4632     }
4633     } else if (script) {
4634     if (script->Name != gigname) {
4635     script->Name = gigname;
4636     printf("script name changed\n");
4637     file_changed();
4638     }
4639     }
4640     }
4641    
4642 schoenebeck 2644 void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
4643     Gtk::TreeViewColumn* column)
4644     {
4645     Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
4646     if (!iter) return;
4647     Gtk::TreeModel::Row row = *iter;
4648     gig::Script* script = row[m_ScriptsModel.m_col_script];
4649     if (!script) return;
4650    
4651     ScriptEditor* editor = new ScriptEditor;
4652 schoenebeck 2903 editor->signal_script_to_be_changed.connect(
4653     signal_script_to_be_changed.make_slot()
4654     );
4655     editor->signal_script_changed.connect(
4656     signal_script_changed.make_slot()
4657     );
4658 schoenebeck 2644 editor->setScript(script);
4659     //editor->reparent(*this);
4660     editor->show();
4661     }
4662    
4663 schoenebeck 1225 void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
4664     const Gtk::TreeModel::iterator& iter) {
4665     if (!iter) return;
4666     Gtk::TreeModel::Row row = *iter;
4667     Glib::ustring name = row[m_Columns.m_col_name];
4668 persson 2442
4669 schoenebeck 3364 #if !USE_GTKMM_BUILDER
4670 persson 2442 // change name in instrument menu
4671     int index = path[0];
4672     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
4673     if (index < children.size()) {
4674     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
4675     static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
4676     #else
4677     remove_instrument_from_menu(index);
4678     Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
4679     item->set_active();
4680     #endif
4681     }
4682 schoenebeck 3364 #endif
4683 persson 2442
4684     // change name in gig
4685 schoenebeck 1225 gig::Instrument* instrument = row[m_Columns.m_col_instr];
4686 persson 2446 gig::String gigname(gig_from_utf8(name));
4687     if (instrument && instrument->pInfo->Name != gigname) {
4688     instrument->pInfo->Name = gigname;
4689 persson 2445
4690     // change name in the instrument properties window
4691     if (instrumentProps.get_instrument() == instrument) {
4692     instrumentProps.update_name();
4693     }
4694    
4695 persson 1261 file_changed();
4696     }
4697 schoenebeck 1225 }
4698 schoenebeck 1322
4699 schoenebeck 3340 bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
4700     if (!iter)
4701     return true;
4702    
4703     Glib::ustring pattern = m_searchText.get_text().lowercase();
4704     trim(pattern);
4705     if (pattern.empty()) return true;
4706    
4707 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)
4708     //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4709     Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4710     #else
4711 schoenebeck 3340 Gtk::TreeModel::Row row = *iter;
4712 schoenebeck 3364 #endif
4713 schoenebeck 3340 Glib::ustring name = row[m_Columns.m_col_name];
4714     name = name.lowercase();
4715    
4716     std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
4717     for (int t = 0; t < tokens.size(); ++t)
4718     if (name.find(tokens[t]) == Glib::ustring::npos)
4719     return false;
4720    
4721     return true;
4722     }
4723    
4724 schoenebeck 2548 void MainWindow::on_action_combine_instruments() {
4725     CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
4726 schoenebeck 3299
4727     // take over selection from instruments list view for the combine dialog's
4728     // list view as pre-selection
4729     std::set<int> indeces;
4730     {
4731     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4732     std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4733     for (int r = 0; r < rows.size(); ++r) {
4734     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4735     if (it) {
4736     Gtk::TreeModel::Row row = *it;
4737     int index = row[m_Columns.m_col_nr];
4738     indeces.insert(index);
4739     }
4740     }
4741     }
4742     d->setSelectedInstruments(indeces);
4743    
4744 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4745 schoenebeck 2548 d->show_all();
4746 schoenebeck 3364 #else
4747     d->show();
4748     #endif
4749 schoenebeck 2548 d->run();
4750     if (d->fileWasChanged()) {
4751     // update GUI with new instrument just created
4752     add_instrument(d->newCombinedInstrument());
4753     }
4754     delete d;
4755     }
4756    
4757 schoenebeck 2624 void MainWindow::on_action_view_references() {
4758     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4759 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4760     if (rows.empty()) return;
4761     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4762 schoenebeck 2624 if (!it) return;
4763     Gtk::TreeModel::Row row = *it;
4764     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4765     if (!sample) return;
4766    
4767     ReferencesView* d = new ReferencesView(*this);
4768     d->setSample(sample);
4769 schoenebeck 2695 d->dimension_region_selected.connect(
4770     sigc::mem_fun(*this, &MainWindow::select_dimension_region)
4771     );
4772 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4773 schoenebeck 2624 d->show_all();
4774 schoenebeck 3364 #else
4775     d->show();
4776     #endif
4777 schoenebeck 2624 d->resize(500, 400);
4778     d->run();
4779     delete d;
4780     }
4781    
4782 schoenebeck 2553 void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
4783     struct _Source {
4784     std::vector<RIFF::File*> riffs;
4785     std::vector<gig::File*> gigs;
4786    
4787     ~_Source() {
4788     for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
4789     for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
4790     riffs.clear();
4791     gigs.clear();
4792     }
4793     } sources;
4794    
4795     if (filenames.empty())
4796     throw RIFF::Exception(_("No files selected, so nothing done."));
4797    
4798     // first open all input files (to avoid output file corruption)
4799     int i;
4800     try {
4801     for (i = 0; i < filenames.size(); ++i) {
4802     const std::string& filename = filenames[i];
4803     printf("opening file=%s\n", filename.c_str());
4804    
4805     RIFF::File* riff = new RIFF::File(filename);
4806     sources.riffs.push_back(riff);
4807    
4808     gig::File* gig = new gig::File(riff);
4809     sources.gigs.push_back(gig);
4810     }
4811     } catch (RIFF::Exception e) {
4812     throw RIFF::Exception(
4813     _("Error occurred while opening '") +
4814     filenames[i] +
4815     "': " +
4816     e.Message
4817     );
4818     } catch (...) {
4819     throw RIFF::Exception(
4820     _("Unknown exception occurred while opening '") +
4821     filenames[i] + "'"
4822     );
4823     }
4824    
4825     // now merge the opened .gig files to the main .gig file currently being
4826     // open in gigedit
4827     try {
4828     for (i = 0; i < filenames.size(); ++i) {
4829     const std::string& filename = filenames[i];
4830     printf("merging file=%s\n", filename.c_str());
4831     assert(i < sources.gigs.size());
4832    
4833     this->file->AddContentOf(sources.gigs[i]);
4834     }
4835     } catch (RIFF::Exception e) {
4836     throw RIFF::Exception(
4837     _("Error occurred while merging '") +
4838     filenames[i] +
4839     "': " +
4840     e.Message
4841     );
4842     } catch (...) {
4843     throw RIFF::Exception(
4844     _("Unknown exception occurred while merging '") +
4845     filenames[i] + "'"
4846     );
4847     }
4848    
4849 schoenebeck 2683 // Finally save gig file persistently to disk ...
4850     //NOTE: requires that this gig file already has a filename !
4851     {
4852     std::cout << "Saving file\n" << std::flush;
4853     file_structure_to_be_changed_signal.emit(this->file);
4854    
4855     progress_dialog = new ProgressDialog( //FIXME: memory leak!
4856     _("Saving") + Glib::ustring(" '") +
4857     Glib::filename_display_basename(this->filename) + "' ...",
4858     *this
4859     );
4860 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4861 schoenebeck 2683 progress_dialog->show_all();
4862 schoenebeck 3364 #else
4863     progress_dialog->show();
4864     #endif
4865 schoenebeck 2683 saver = new Saver(this->file); //FIXME: memory leak!
4866     saver->signal_progress().connect(
4867     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
4868     saver->signal_finished().connect(
4869     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
4870     saver->signal_error().connect(
4871     sigc::mem_fun(*this, &MainWindow::on_saver_error));
4872     saver->launch();
4873     }
4874 schoenebeck 2553 }
4875    
4876     void MainWindow::on_action_merge_files() {
4877     if (this->file->GetFileName().empty()) {
4878     Glib::ustring txt = _(
4879     "You seem to have a new .gig file open that has not been saved "
4880     "yet. You must save it somewhere before starting to merge it with "
4881     "other .gig files though, because during the merge operation the "
4882     "other files' sample data must be written on file level to the "
4883     "target .gig file."
4884     );
4885     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4886     msg.run();
4887     return;
4888     }
4889    
4890     Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4891 schoenebeck 3364 #if HAS_GTKMM_STOCK
4892 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4893 schoenebeck 3364 #else
4894     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4895     #endif
4896 schoenebeck 2553 dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
4897     dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4898     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4899     Gtk::FileFilter filter;
4900     filter.add_pattern("*.gig");
4901     #else
4902     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
4903     filter->add_pattern("*.gig");
4904     #endif
4905     dialog.set_filter(filter);
4906     if (current_gig_dir != "") {
4907     dialog.set_current_folder(current_gig_dir);
4908     }
4909     dialog.set_select_multiple(true);
4910    
4911     // show warning in the file picker dialog
4912 schoenebeck 3364 HBox descriptionArea;
4913 schoenebeck 2553 descriptionArea.set_spacing(15);
4914 persson 2845 Gtk::Image warningIcon;
4915     warningIcon.set_from_icon_name("dialog-warning",
4916     Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
4917 schoenebeck 2553 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
4918     #if GTKMM_MAJOR_VERSION < 3
4919     view::WrapLabel description;
4920     #else
4921     Gtk::Label description;
4922     description.set_line_wrap();
4923     #endif
4924     description.set_markup(_(
4925     "\nSelect at least one .gig file that shall be merged to the .gig file "
4926     "currently being open in gigedit.\n\n"
4927     "<b>Please Note:</b> Merging with other files will modify your "
4928     "currently open .gig file on file level! And be aware that the current "
4929     "merge algorithm does not detect duplicate samples yet. So if you are "
4930     "merging files which are using equivalent sample data, those "
4931     "equivalent samples will currently be treated as separate samples and "
4932     "will accordingly be stored separately in the target .gig file!"
4933     ));
4934     descriptionArea.pack_start(description);
4935 schoenebeck 3364 #if USE_GTKMM_BOX
4936     # warning No description area implemented for dialog on GTKMM 3
4937     #else
4938 schoenebeck 2553 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
4939 schoenebeck 3364 #endif
4940     #if HAS_GTKMM_SHOW_ALL_CHILDREN
4941 schoenebeck 2553 descriptionArea.show_all();
4942 schoenebeck 3364 #else
4943     descriptionArea.show();
4944     #endif
4945 schoenebeck 2553
4946     if (dialog.run() == Gtk::RESPONSE_OK) {
4947 persson 2841 printf("on_action_merge_files self=%p\n",
4948     static_cast<void*>(Glib::Threads::Thread::self()));
4949 schoenebeck 2553 std::vector<std::string> filenames = dialog.get_filenames();
4950    
4951     // merge the selected files to the currently open .gig file
4952     try {
4953     mergeFiles(filenames);
4954     } catch (RIFF::Exception e) {
4955     Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
4956     msg.run();
4957     }
4958    
4959     // update GUI
4960 schoenebeck 2772 __refreshEntireGUI();
4961 schoenebeck 2553 }
4962     }
4963    
4964 schoenebeck 1411 void MainWindow::set_file_is_shared(bool b) {
4965     this->file_is_shared = b;
4966    
4967     if (file_is_shared) {
4968     m_AttachedStateLabel.set_label(_("live-mode"));
4969     m_AttachedStateImage.set(
4970     Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
4971     );
4972     } else {
4973     m_AttachedStateLabel.set_label(_("stand-alone"));
4974     m_AttachedStateImage.set(
4975     Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
4976     );
4977     }
4978 schoenebeck 2689
4979     {
4980 schoenebeck 3364 #if USE_GTKMM_BUILDER
4981     m_actionToggleSyncSamplerSelection->property_enabled() = b;
4982     #else
4983 schoenebeck 2689 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
4984     uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
4985     if (item) item->set_sensitive(b);
4986 schoenebeck 3364 #endif
4987 schoenebeck 2689 }
4988 schoenebeck 1411 }
4989    
4990 schoenebeck 2621 void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
4991     if (!sample) return;
4992     sample_ref_count[sample] += offset;
4993     const int refcount = sample_ref_count[sample];
4994    
4995     Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
4996     for (int g = 0; g < model->children().size(); ++g) {
4997     Gtk::TreeModel::Row rowGroup = model->children()[g];
4998     for (int s = 0; s < rowGroup.children().size(); ++s) {
4999     Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
5000     if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
5001     rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
5002 schoenebeck 2625 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
5003 schoenebeck 2621 }
5004     }
5005     }
5006    
5007     void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
5008     on_sample_ref_count_incremented(oldSample, -1);
5009     on_sample_ref_count_incremented(newSample, +1);
5010     }
5011    
5012     void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
5013     // just in case a new sample is added later with exactly the same memory
5014     // address, which would lead to incorrect refcount if not deleted here
5015     for (std::list<gig::Sample*>::const_iterator it = samples.begin();
5016 schoenebeck 2666 it != samples.end(); ++it)
5017 schoenebeck 2621 {
5018     sample_ref_count.erase(*it);
5019     }
5020     }
5021    
5022 schoenebeck 2625 void MainWindow::show_samples_tab() {
5023     m_TreeViewNotebook.set_current_page(0);
5024     }
5025    
5026     void MainWindow::show_intruments_tab() {
5027     m_TreeViewNotebook.set_current_page(1);
5028     }
5029    
5030     void MainWindow::show_scripts_tab() {
5031     m_TreeViewNotebook.set_current_page(2);
5032     }
5033    
5034 schoenebeck 3339 void MainWindow::select_instrument_by_dir(int dir) {
5035     if (!file) return;
5036     gig::Instrument* pInstrument = get_instrument();
5037     if (!pInstrument) {
5038     select_instrument( file->GetInstrument(0) );
5039     return;
5040     }
5041     for (int i = 0; file->GetInstrument(i); ++i) {
5042     if (file->GetInstrument(i) == pInstrument) {
5043     select_instrument( file->GetInstrument(i + dir) );
5044     return;
5045     }
5046     }
5047     }
5048    
5049     void MainWindow::select_prev_instrument() {
5050     select_instrument_by_dir(-1);
5051     }
5052    
5053     void MainWindow::select_next_instrument() {
5054     select_instrument_by_dir(1);
5055     }
5056    
5057 schoenebeck 3123 void MainWindow::select_prev_region() {
5058     m_RegionChooser.select_prev_region();
5059     }
5060    
5061     void MainWindow::select_next_region() {
5062     m_RegionChooser.select_next_region();
5063     }
5064    
5065     void MainWindow::select_next_dim_rgn_zone() {
5066     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5067     m_DimRegionChooser.select_next_dimzone();
5068     }
5069    
5070     void MainWindow::select_prev_dim_rgn_zone() {
5071     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5072     m_DimRegionChooser.select_prev_dimzone();
5073     }
5074    
5075 schoenebeck 3134 void MainWindow::select_add_next_dim_rgn_zone() {
5076     m_DimRegionChooser.select_next_dimzone(true);
5077     }
5078    
5079     void MainWindow::select_add_prev_dim_rgn_zone() {
5080     m_DimRegionChooser.select_prev_dimzone(true);
5081     }
5082    
5083 schoenebeck 3123 void MainWindow::select_prev_dimension() {
5084     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5085     m_DimRegionChooser.select_prev_dimension();
5086     }
5087    
5088     void MainWindow::select_next_dimension() {
5089     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5090     m_DimRegionChooser.select_next_dimension();
5091     }
5092    
5093 schoenebeck 3144 #define CLIPBOARD_DIMENSIONREGION_TARGET \
5094     ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
5095    
5096     void MainWindow::copy_selected_dimrgn() {
5097     gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5098     if (!pDimRgn) {
5099     updateClipboardPasteAvailable();
5100     updateClipboardCopyAvailable();
5101     return;
5102     }
5103    
5104     std::vector<Gtk::TargetEntry> targets;
5105     targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
5106    
5107     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5108     clipboard->set(
5109     targets,
5110     sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
5111     sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
5112     );
5113    
5114     m_serializationArchive.serialize(pDimRgn);
5115    
5116     updateClipboardPasteAvailable();
5117     }
5118    
5119     void MainWindow::paste_copied_dimrgn() {
5120     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5121     clipboard->request_contents(
5122     CLIPBOARD_DIMENSIONREGION_TARGET,
5123     sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
5124     );
5125     updateClipboardPasteAvailable();
5126     }
5127    
5128 schoenebeck 3151 void MainWindow::adjust_clipboard_content() {
5129 schoenebeck 3155 MacroEditor* editor = new MacroEditor();
5130 schoenebeck 3162 editor->setMacro(&m_serializationArchive, true);
5131 schoenebeck 3151 editor->show();
5132     }
5133    
5134 schoenebeck 3144 void MainWindow::updateClipboardPasteAvailable() {
5135     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5136     clipboard->request_targets(
5137     sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
5138     );
5139     }
5140    
5141     void MainWindow::updateClipboardCopyAvailable() {
5142     bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5143 schoenebeck 3364 #if USE_GTKMM_BUILDER
5144     m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5145     #else
5146 schoenebeck 3144 static_cast<Gtk::MenuItem*>(
5147     uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5148     )->set_sensitive(bDimensionRegionCopyIsPossible);
5149 schoenebeck 3364 #endif
5150 schoenebeck 3144 }
5151    
5152 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
5153     void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5154     #else
5155 schoenebeck 3144 void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5156 schoenebeck 3364 #endif
5157 schoenebeck 3144 updateClipboardPasteAvailable();
5158     }
5159    
5160     void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
5161     const std::string target = selection_data.get_target();
5162     if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5163     selection_data.set(
5164     CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
5165     &m_serializationArchive.rawData()[0],
5166     m_serializationArchive.rawData().size()
5167     );
5168     } else {
5169     std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
5170     }
5171     }
5172    
5173     void MainWindow::on_clipboard_clear() {
5174     m_serializationArchive.clear();
5175     updateClipboardPasteAvailable();
5176     updateClipboardCopyAvailable();
5177     }
5178    
5179 schoenebeck 3157 //NOTE: Might throw exception !!!
5180     void MainWindow::applyMacro(Serialization::Archive& macro) {
5181     gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5182     if (!pDimRgn) return;
5183    
5184     for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5185     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5186     {
5187     gig::DimensionRegion* pDimRgn = *itDimReg;
5188 schoenebeck 3177 DimRegionChangeGuard(this, pDimRgn);
5189 schoenebeck 3160 macro.deserialize(pDimRgn);
5190 schoenebeck 3157 }
5191     //region_changed()
5192     file_changed();
5193     dimreg_changed();
5194     }
5195    
5196 schoenebeck 3144 void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5197     const std::string target = selection_data.get_target();
5198     if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5199     Glib::ustring errorText;
5200     try {
5201     m_serializationArchive.decode(
5202     selection_data.get_data(), selection_data.get_length()
5203     );
5204 schoenebeck 3157 applyMacro(m_serializationArchive);
5205 schoenebeck 3144 } catch (Serialization::Exception e) {
5206     errorText = e.Message;
5207     } catch (...) {
5208 schoenebeck 3157 errorText = _("Unknown exception while pasting DimensionRegion");
5209 schoenebeck 3144 }
5210     if (!errorText.empty()) {
5211     Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
5212     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5213     msg.run();
5214     }
5215     }
5216     }
5217    
5218     void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
5219     const bool bDimensionRegionPasteIsPossible =
5220     std::find(targets.begin(), targets.end(),
5221     CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5222    
5223 schoenebeck 3364 #if USE_GTKMM_BUILDER
5224     m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5225     m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5226     #else
5227 schoenebeck 3144 static_cast<Gtk::MenuItem*>(
5228     uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5229     )->set_sensitive(bDimensionRegionPasteIsPossible);
5230 schoenebeck 3151
5231     static_cast<Gtk::MenuItem*>(
5232     uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5233     )->set_sensitive(bDimensionRegionPasteIsPossible);
5234 schoenebeck 3364 #endif
5235 schoenebeck 3144 }
5236    
5237 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
5238 schoenebeck 1322 return file_structure_to_be_changed_signal;
5239     }
5240    
5241 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
5242 schoenebeck 1322 return file_structure_changed_signal;
5243     }
5244    
5245 schoenebeck 1339 sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
5246 schoenebeck 1322 return samples_to_be_removed_signal;
5247     }
5248    
5249 schoenebeck 1339 sigc::signal<void>& MainWindow::signal_samples_removed() {
5250 schoenebeck 1322 return samples_removed_signal;
5251     }
5252    
5253 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
5254 schoenebeck 1322 return region_to_be_changed_signal;
5255     }
5256    
5257 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
5258 schoenebeck 1322 return region_changed_signal;
5259     }
5260    
5261 schoenebeck 1853 sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
5262     return sample_changed_signal;
5263     }
5264    
5265 schoenebeck 1339 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
5266 schoenebeck 1322 return sample_ref_changed_signal;
5267     }
5268    
5269 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
5270 schoenebeck 1322 return dimreg_to_be_changed_signal;
5271     }
5272    
5273 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
5274 schoenebeck 1322 return dimreg_changed_signal;
5275     }
5276 schoenebeck 1654
5277     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
5278     return note_on_signal;
5279     }
5280    
5281     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
5282     return note_off_signal;
5283     }
5284 schoenebeck 1660
5285     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
5286     return m_RegionChooser.signal_keyboard_key_hit();
5287     }
5288    
5289     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
5290     return m_RegionChooser.signal_keyboard_key_released();
5291     }
5292 schoenebeck 2689
5293     sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
5294     return switch_sampler_instrument_signal;
5295     }

  ViewVC Help
Powered by ViewVC