/[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 3470 - (hide annotations) (download)
Thu Feb 14 19:10:49 2019 UTC (5 years, 2 months ago) by persson
File size: 210171 byte(s)
* Refactor code: add common base class for Loader and Saver

1 schoenebeck 1225 /*
2 persson 3456 * Copyright (C) 2006-2019 Andreas Persson
3 schoenebeck 1225 *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #include <iostream>
21 persson 1714 #include <cstring>
22 schoenebeck 1225
23 schoenebeck 3364 #include "compat.h"
24 persson 2841 // threads.h must be included first to be able to build with
25     // G_DISABLE_DEPRECATED
26     #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \
27     (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2
28     #include <glibmm/threads.h>
29     #endif
30    
31 persson 2325 #include <glibmm/convert.h>
32     #include <glibmm/dispatcher.h>
33     #include <glibmm/miscutils.h>
34     #include <glibmm/stringutils.h>
35 schoenebeck 3340 #include <glibmm/regex.h>
36 persson 2151 #include <gtkmm/aboutdialog.h>
37 schoenebeck 1225 #include <gtkmm/filechooserdialog.h>
38     #include <gtkmm/messagedialog.h>
39 schoenebeck 3364 #if HAS_GTKMM_STOCK
40     # include <gtkmm/stock.h>
41     #endif
42 schoenebeck 1225 #include <gtkmm/targetentry.h>
43     #include <gtkmm/main.h>
44 schoenebeck 3364 #if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89)
45     # include <gtkmm/toggleaction.h>
46     #endif
47 schoenebeck 3157 #include <gtkmm/accelmap.h>
48 persson 2344 #if GTKMM_MAJOR_VERSION < 3
49 persson 1799 #include "wrapLabel.hh"
50 persson 2344 #endif
51 schoenebeck 1225
52 schoenebeck 1396 #include "global.h"
53 persson 2169 #include "compat.h"
54 schoenebeck 1396
55 schoenebeck 1225 #include <stdio.h>
56 schoenebeck 3364 #ifdef LIBSNDFILE_HEADER_FILE
57     # include LIBSNDFILE_HEADER_FILE(sndfile.h)
58     #else
59     # include <sndfile.h>
60     #endif
61 schoenebeck 2553 #include <assert.h>
62 schoenebeck 1225
63     #include "mainwindow.h"
64 schoenebeck 2541 #include "Settings.h"
65 schoenebeck 2548 #include "CombineInstrumentsDialog.h"
66 schoenebeck 2604 #include "scripteditor.h"
67 schoenebeck 2610 #include "scriptslots.h"
68 schoenebeck 2624 #include "ReferencesView.h"
69 schoenebeck 1411 #include "../../gfx/status_attached.xpm"
70     #include "../../gfx/status_detached.xpm"
71 schoenebeck 3106 #include "gfx/builtinpix.h"
72 schoenebeck 3151 #include "MacroEditor.h"
73 schoenebeck 3157 #include "MacrosSetup.h"
74 schoenebeck 3258 #if defined(__APPLE__)
75     # include "MacHelper.h"
76     #endif
77 schoenebeck 1411
78 schoenebeck 3299 static const Gdk::ModifierType primaryModifierKey =
79     #if defined(__APPLE__)
80     Gdk::META_MASK; // Cmd key on Mac
81     #else
82     Gdk::CONTROL_MASK; // Ctrl key on all other OSs
83     #endif
84    
85 persson 1533 MainWindow::MainWindow() :
86 schoenebeck 2626 m_DimRegionChooser(*this),
87 persson 1533 dimreg_label(_("Changes apply to:")),
88     dimreg_all_regions(_("all regions")),
89     dimreg_all_dimregs(_("all dimension splits")),
90 schoenebeck 3106 dimreg_stereo(_("both channels")),
91 schoenebeck 3109 labelLegend(_("Legend:")),
92 schoenebeck 3106 labelNoSample(_(" No Sample")),
93     labelMissingSample(_(" Missing some Sample(s)")),
94     labelLooped(_(" Looped")),
95     labelSomeLoops(_(" Some Loop(s)"))
96 schoenebeck 1225 {
97 schoenebeck 3106 loadBuiltInPix();
98    
99 schoenebeck 3339 this->file = NULL;
100    
101 schoenebeck 1225 // set_border_width(5);
102    
103 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
104 schoenebeck 3368 #if GTKMM_MAJOR_VERSION >= 3
105     set_default_size(895, 600);
106     #else
107 schoenebeck 3225 set_default_size(800, 600);
108 schoenebeck 3368 #endif
109 schoenebeck 3225 set_position(Gtk::WIN_POS_CENTER);
110     }
111    
112 schoenebeck 1225 add(m_VBox);
113    
114     // Handle selection
115 persson 2442 m_TreeView.get_selection()->signal_changed().connect(
116 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_sel_change));
117    
118     // m_TreeView.set_reorderable();
119    
120 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
121     m_TreeView.signal_button_press_event().connect(
122     sigc::mem_fun(*this, &MainWindow::on_button_release));
123     #else
124 schoenebeck 1225 m_TreeView.signal_button_press_event().connect_notify(
125     sigc::mem_fun(*this, &MainWindow::on_button_release));
126 schoenebeck 3364 #endif
127 schoenebeck 1225
128     // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
129     m_ScrolledWindow.add(m_TreeView);
130     // m_ScrolledWindow.set_size_request(200, 600);
131     m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132    
133     m_ScrolledWindowSamples.add(m_TreeViewSamples);
134     m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
135    
136 schoenebeck 2604 m_ScrolledWindowScripts.add(m_TreeViewScripts);
137     m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
138 schoenebeck 1225
139 schoenebeck 3368 #if GTKMM_MAJOR_VERSION < 3
140 schoenebeck 1225 m_TreeViewNotebook.set_size_request(300);
141 schoenebeck 3368 #endif
142 schoenebeck 1225
143 schoenebeck 3340 m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
144     m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
145     m_searchField.pack_start(m_searchText);
146     m_searchField.set_spacing(5);
147    
148     m_left_vbox.pack_start(m_TreeViewNotebook);
149     m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
150    
151     m_HPaned.add1(m_left_vbox);
152    
153 persson 1533 dimreg_hbox.add(dimreg_label);
154     dimreg_hbox.add(dimreg_all_regions);
155     dimreg_hbox.add(dimreg_all_dimregs);
156     dimreg_stereo.set_active();
157     dimreg_hbox.add(dimreg_stereo);
158     dimreg_vbox.add(dimreg_edit);
159 persson 1582 dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
160 schoenebeck 3106 {
161 schoenebeck 3109 legend_hbox.add(labelLegend);
162    
163 schoenebeck 3106 imageNoSample.set(redDot);
164 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
165 schoenebeck 3108 imageNoSample.set_alignment(Gtk::ALIGN_END);
166     labelNoSample.set_alignment(Gtk::ALIGN_START);
167 schoenebeck 3364 #else
168     imageNoSample.set_halign(Gtk::ALIGN_END);
169     labelNoSample.set_halign(Gtk::ALIGN_START);
170     #endif
171 schoenebeck 3106 legend_hbox.add(imageNoSample);
172     legend_hbox.add(labelNoSample);
173    
174     imageMissingSample.set(yellowDot);
175 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
176 schoenebeck 3108 imageMissingSample.set_alignment(Gtk::ALIGN_END);
177     labelMissingSample.set_alignment(Gtk::ALIGN_START);
178 schoenebeck 3364 #else
179     imageMissingSample.set_halign(Gtk::ALIGN_END);
180     labelMissingSample.set_halign(Gtk::ALIGN_START);
181     #endif
182 schoenebeck 3106 legend_hbox.add(imageMissingSample);
183     legend_hbox.add(labelMissingSample);
184    
185     imageLooped.set(blackLoop);
186 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
187 schoenebeck 3108 imageLooped.set_alignment(Gtk::ALIGN_END);
188     labelLooped.set_alignment(Gtk::ALIGN_START);
189 schoenebeck 3364 #else
190     imageLooped.set_halign(Gtk::ALIGN_END);
191     labelLooped.set_halign(Gtk::ALIGN_START);
192     #endif
193 schoenebeck 3106 legend_hbox.add(imageLooped);
194     legend_hbox.add(labelLooped);
195    
196     imageSomeLoops.set(grayLoop);
197 schoenebeck 3364 #if HAS_GTKMM_ALIGNMENT
198 schoenebeck 3108 imageSomeLoops.set_alignment(Gtk::ALIGN_END);
199     labelSomeLoops.set_alignment(Gtk::ALIGN_START);
200 schoenebeck 3364 #else
201     imageSomeLoops.set_halign(Gtk::ALIGN_END);
202     labelSomeLoops.set_halign(Gtk::ALIGN_START);
203     #endif
204 schoenebeck 3106 legend_hbox.add(imageSomeLoops);
205     legend_hbox.add(labelSomeLoops);
206    
207 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
208 schoenebeck 3106 legend_hbox.show_all_children();
209 schoenebeck 3364 #endif
210 schoenebeck 3106 }
211     dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
212 persson 1533 m_HPaned.add2(dimreg_vbox);
213 schoenebeck 1225
214 schoenebeck 2536 dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
215     dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
216     dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
217     dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
218 schoenebeck 1225
219 persson 1831 m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
220     m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
221 schoenebeck 2604 m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
222 schoenebeck 1225
223 schoenebeck 3364 #if USE_GLIB_ACTION
224     m_actionGroup = Gio::SimpleActionGroup::create();
225     m_actionGroup->add_action(
226     "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new)
227     );
228     m_actionGroup->add_action(
229     "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open)
230     );
231     m_actionGroup->add_action(
232     "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save)
233     );
234     m_actionGroup->add_action(
235     "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as)
236     );
237     m_actionGroup->add_action(
238     "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties)
239     );
240     m_actionGroup->add_action(
241     "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props)
242     );
243     m_actionMIDIRules = m_actionGroup->add_action(
244     "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules)
245     );
246     m_actionGroup->add_action(
247     "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots)
248     );
249     m_actionGroup->add_action(
250     "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit)
251     );
252     m_actionGroup->add_action(
253     "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab)
254     );
255     m_actionGroup->add_action(
256     "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
257     );
258     m_actionGroup->add_action(
259     "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
260     );
261     #else
262 schoenebeck 1225 actionGroup = Gtk::ActionGroup::create();
263    
264     actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
265 schoenebeck 3158 actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
266 schoenebeck 1225 sigc::mem_fun(
267     *this, &MainWindow::on_action_file_new));
268 schoenebeck 3158 Glib::RefPtr<Gtk::Action> action =
269     Gtk::Action::create("Open", Gtk::Stock::OPEN);
270     action->property_label() = action->property_label() + "...";
271     actionGroup->add(action,
272 schoenebeck 1225 sigc::mem_fun(
273     *this, &MainWindow::on_action_file_open));
274 schoenebeck 3158 actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
275 schoenebeck 1225 sigc::mem_fun(
276     *this, &MainWindow::on_action_file_save));
277 schoenebeck 3158 action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
278     action->property_label() = action->property_label() + "...";
279     actionGroup->add(action,
280 persson 1261 Gtk::AccelKey("<shift><control>s"),
281 schoenebeck 1225 sigc::mem_fun(
282 persson 1261 *this, &MainWindow::on_action_file_save_as));
283 schoenebeck 1225 actionGroup->add(Gtk::Action::create("Properties",
284 schoenebeck 3158 Gtk::Stock::PROPERTIES),
285 schoenebeck 1225 sigc::mem_fun(
286     *this, &MainWindow::on_action_file_properties));
287     actionGroup->add(Gtk::Action::create("InstrProperties",
288 schoenebeck 3158 Gtk::Stock::PROPERTIES),
289 schoenebeck 1225 sigc::mem_fun(
290     *this, &MainWindow::show_instr_props));
291 persson 2507 actionGroup->add(Gtk::Action::create("MidiRules",
292 schoenebeck 2610 _("_Midi Rules...")),
293 persson 2507 sigc::mem_fun(
294     *this, &MainWindow::show_midi_rules));
295 schoenebeck 2610 actionGroup->add(Gtk::Action::create("ScriptSlots",
296     _("_Script Slots...")),
297     sigc::mem_fun(
298     *this, &MainWindow::show_script_slots));
299 schoenebeck 3158 actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
300 schoenebeck 1225 sigc::mem_fun(
301 persson 1261 *this, &MainWindow::on_action_quit));
302 schoenebeck 2625 actionGroup->add(
303     Gtk::Action::create("MenuSample", _("_Sample")),
304     sigc::mem_fun(*this, &MainWindow::show_samples_tab)
305     );
306     actionGroup->add(
307     Gtk::Action::create("MenuInstrument", _("_Instrument")),
308     sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
309     );
310     actionGroup->add(
311 schoenebeck 3144 Gtk::Action::create("MenuScript", _("Scr_ipt")),
312 schoenebeck 2625 sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
313     );
314     actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
315 schoenebeck 3339 actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
316 schoenebeck 1225
317 schoenebeck 2464 actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
318 schoenebeck 3364 #endif
319 schoenebeck 2464
320 schoenebeck 3123 const Gdk::ModifierType primaryModifierKey =
321     #if defined(__APPLE__)
322     Gdk::META_MASK; // Cmd key on Mac
323     #else
324     Gdk::CONTROL_MASK; // Ctrl key on all other OSs
325     #endif
326    
327 schoenebeck 3364 #if USE_GLIB_ACTION
328     m_actionCopyDimRgn = m_actionGroup->add_action(
329     "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)
330     );
331     m_actionPasteDimRgn = m_actionGroup->add_action(
332     "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)
333     );
334     m_actionAdjustClipboard = m_actionGroup->add_action(
335     "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)
336     );
337     m_actionGroup->add_action(
338     "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument)
339     );
340     m_actionGroup->add_action(
341     "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument)
342     );
343     m_actionGroup->add_action(
344     "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region)
345     );
346     m_actionGroup->add_action(
347     "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region)
348     );
349     m_actionGroup->add_action(
350     "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)
351     );
352     m_actionGroup->add_action(
353     "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)
354     );
355     m_actionGroup->add_action(
356     "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension)
357     );
358     m_actionGroup->add_action(
359     "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension)
360     );
361     m_actionGroup->add_action(
362     "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)
363     );
364     m_actionGroup->add_action(
365     "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)
366     );
367     #else
368 schoenebeck 3144 actionGroup->add(Gtk::Action::create("CopyDimRgn",
369     _("Copy selected dimension region")),
370     Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
371     sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
372    
373     actionGroup->add(Gtk::Action::create("PasteDimRgn",
374     _("Paste dimension region")),
375     Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
376     sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
377    
378 schoenebeck 3151 actionGroup->add(Gtk::Action::create("AdjustClipboard",
379     _("Adjust Clipboard Content")),
380     Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
381     sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
382    
383 schoenebeck 3339 actionGroup->add(Gtk::Action::create("SelectPrevInstr",
384     _("Select Previous Instrument")),
385     Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
386     sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
387    
388     actionGroup->add(Gtk::Action::create("SelectNextInstr",
389     _("Select Next Instrument")),
390     Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
391     sigc::mem_fun(*this, &MainWindow::select_next_instrument));
392    
393 schoenebeck 3123 actionGroup->add(Gtk::Action::create("SelectPrevRegion",
394     _("Select Previous Region")),
395     Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
396     sigc::mem_fun(*this, &MainWindow::select_prev_region));
397    
398     actionGroup->add(Gtk::Action::create("SelectNextRegion",
399     _("Select Next Region")),
400     Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
401     sigc::mem_fun(*this, &MainWindow::select_next_region));
402    
403     actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
404     _("Select Previous Dimension Region Zone")),
405     Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
406     sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
407    
408     actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
409     _("Select Next Dimension Region Zone")),
410     Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
411     sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
412    
413     actionGroup->add(Gtk::Action::create("SelectPrevDimension",
414     _("Select Previous Dimension")),
415     Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
416     sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
417    
418     actionGroup->add(Gtk::Action::create("SelectNextDimension",
419     _("Select Next Dimension")),
420     Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
421     sigc::mem_fun(*this, &MainWindow::select_next_dimension));
422    
423 schoenebeck 3134 actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
424     _("Add Previous Dimension Region Zone to Selection")),
425     Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
426     sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
427 schoenebeck 3123
428 schoenebeck 3134 actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
429     _("Add Next Dimension Region Zone to Selection")),
430     Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
431     sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
432 schoenebeck 3364 #endif
433 schoenebeck 3134
434 schoenebeck 3364 #if USE_GLIB_ACTION
435     m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true);
436     m_actionToggleCopySampleTune = m_actionGroup->add_action_bool("CopySampleTune", true);
437     m_actionToggleCopySampleLoop = m_actionGroup->add_action_bool("CopySampleLoop", true);
438     #else
439 schoenebeck 2464 Glib::RefPtr<Gtk::ToggleAction> toggle_action =
440 schoenebeck 2536 Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
441 schoenebeck 2464 toggle_action->set_active(true);
442     actionGroup->add(toggle_action);
443    
444     toggle_action =
445     Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
446     toggle_action->set_active(true);
447     actionGroup->add(toggle_action);
448    
449     toggle_action =
450     Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
451     toggle_action->set_active(true);
452     actionGroup->add(toggle_action);
453 schoenebeck 3364 #endif
454 schoenebeck 2464
455 schoenebeck 3364 #if USE_GLIB_ACTION
456     m_actionToggleStatusBar =
457     m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458     m_actionToggleRestoreWinDim =
459     m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460 schoenebeck 3409 m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
461     "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
462     Settings::singleton()->showTooltips
463     );
464 schoenebeck 3364 m_actionToggleSaveWithTempFile =
465     m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
466     m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
467     #else
468 schoenebeck 3157 actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro")));
469    
470    
471 schoenebeck 3144 actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
472 schoenebeck 2464 toggle_action =
473 schoenebeck 1415 Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
474     toggle_action->set_active(true);
475     actionGroup->add(toggle_action,
476     sigc::mem_fun(
477     *this, &MainWindow::on_action_view_status_bar));
478 schoenebeck 2918
479     toggle_action =
480     Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension"));
481     toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension);
482     actionGroup->add(toggle_action,
483     sigc::mem_fun(
484     *this, &MainWindow::on_auto_restore_win_dim));
485    
486 schoenebeck 2967 toggle_action =
487 schoenebeck 3409 Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
488     toggle_action->set_active(Settings::singleton()->showTooltips);
489     actionGroup->add(
490     toggle_action,
491     sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips)
492     );
493    
494     toggle_action =
495 schoenebeck 2967 Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
496     toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
497     actionGroup->add(toggle_action,
498     sigc::mem_fun(
499     *this, &MainWindow::on_save_with_temporary_file));
500    
501 schoenebeck 2772 actionGroup->add(
502     Gtk::Action::create("RefreshAll", _("_Refresh All")),
503     sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
504     );
505 schoenebeck 3364 #endif
506 schoenebeck 1415
507 schoenebeck 3364 #if USE_GLIB_ACTION
508     m_actionGroup->add_action(
509     "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about)
510     );
511     m_actionGroup->add_action(
512     "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
513     );
514     m_actionGroup->add_action(
515     "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
516     );
517     m_actionGroup->add_action(
518     "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
519     );
520     m_actionGroup->add_action(
521     "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
522     );
523     #else
524 schoenebeck 3158 action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
525     actionGroup->add(Gtk::Action::create("MenuHelp",
526     action->property_label()));
527     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
528 schoenebeck 1225 sigc::mem_fun(
529     *this, &MainWindow::on_action_help_about));
530     actionGroup->add(
531     Gtk::Action::create("AddInstrument", _("Add _Instrument")),
532     sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
533     );
534     actionGroup->add(
535 schoenebeck 2395 Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
536     sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
537     );
538     actionGroup->add(
539 schoenebeck 3299 Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
540     Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
541     sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
542     );
543     actionGroup->add(
544 schoenebeck 3158 Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
545 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
546     );
547 schoenebeck 3364 #endif
548 schoenebeck 1225
549 schoenebeck 3364 #if USE_GLIB_ACTION
550     m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool(
551     "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions),
552     Settings::singleton()->warnUserOnExtensions
553     );
554     m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool(
555     "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection),
556     Settings::singleton()->syncSamplerInstrumentSelection
557     );
558     m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool(
559     "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved),
560     Settings::singleton()->moveRootNoteWithRegionMoved
561     );
562     #else
563 schoenebeck 2541 actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
564    
565     toggle_action =
566     Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
567     toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
568     actionGroup->add(
569     toggle_action,
570     sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
571     );
572    
573 schoenebeck 2689 toggle_action =
574     Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
575     toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
576     actionGroup->add(
577     toggle_action,
578     sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
579     );
580 schoenebeck 2541
581 schoenebeck 2773 toggle_action =
582     Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
583     toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
584     actionGroup->add(
585     toggle_action,
586     sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
587     );
588 schoenebeck 3364 #endif
589 schoenebeck 2689
590 schoenebeck 3364 #if USE_GLIB_ACTION
591     m_actionGroup->add_action(
592     "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
593     );
594     m_actionGroup->add_action(
595     "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
596     );
597     #else
598 schoenebeck 2548 actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
599    
600     actionGroup->add(
601     Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
602     sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
603     );
604    
605 schoenebeck 2553 actionGroup->add(
606     Gtk::Action::create("MergeFiles", _("_Merge Files...")),
607     sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
608     );
609 schoenebeck 3364 #endif
610 schoenebeck 2548
611 schoenebeck 1225 // sample right-click popup actions
612 schoenebeck 3364 #if USE_GLIB_ACTION
613     m_actionSampleProperties = m_actionGroup->add_action(
614     "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
615     );
616     m_actionAddSampleGroup = m_actionGroup->add_action(
617     "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group)
618     );
619     m_actionAddSample = m_actionGroup->add_action(
620     "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
621     );
622     m_actionRemoveSample = m_actionGroup->add_action(
623     "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
624     );
625     m_actionGroup->add_action(
626     "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
627     );
628     m_actionViewSampleRefs = m_actionGroup->add_action(
629     "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references)
630     );
631     m_actionReplaceSample = m_actionGroup->add_action(
632     "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
633     );
634     m_actionGroup->add_action(
635     "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
636     );
637     #else
638 schoenebeck 1225 actionGroup->add(
639 schoenebeck 3158 Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
640 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
641     );
642     actionGroup->add(
643     Gtk::Action::create("AddGroup", _("Add _Group")),
644     sigc::mem_fun(*this, &MainWindow::on_action_add_group)
645     );
646     actionGroup->add(
647 persson 1799 Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
648 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
649     );
650     actionGroup->add(
651 schoenebeck 3158 Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
652 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
653     );
654 schoenebeck 1673 actionGroup->add(
655 schoenebeck 2772 Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
656     sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
657     );
658     actionGroup->add(
659 schoenebeck 2624 Gtk::Action::create("ShowSampleRefs", _("Show References...")),
660     sigc::mem_fun(*this, &MainWindow::on_action_view_references)
661     );
662     actionGroup->add(
663 schoenebeck 2715 Gtk::Action::create("ReplaceSample",
664     _("Replace Sample...")),
665     sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
666     );
667     actionGroup->add(
668 persson 1799 Gtk::Action::create("ReplaceAllSamplesInAllGroups",
669     _("Replace All Samples in All Groups...")),
670 schoenebeck 1673 sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
671     );
672 schoenebeck 3364 #endif
673 schoenebeck 2604
674     // script right-click popup actions
675 schoenebeck 3364 #if USE_GLIB_ACTION
676     m_actionAddScriptGroup = m_actionGroup->add_action(
677     "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
678     );
679     m_actionAddScript = m_actionGroup->add_action(
680     "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script)
681     );
682     m_actionEditScript = m_actionGroup->add_action(
683     "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
684     );
685     m_actionRemoveScript = m_actionGroup->add_action(
686     "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
687     );
688     #else
689 schoenebeck 2604 actionGroup->add(
690     Gtk::Action::create("AddScriptGroup", _("Add _Group")),
691     sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
692     );
693     actionGroup->add(
694     Gtk::Action::create("AddScript", _("Add _Script")),
695     sigc::mem_fun(*this, &MainWindow::on_action_add_script)
696     );
697     actionGroup->add(
698     Gtk::Action::create("EditScript", _("_Edit Script...")),
699     sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
700     );
701     actionGroup->add(
702 schoenebeck 3158 Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
703 schoenebeck 2604 sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
704     );
705 schoenebeck 3364 #endif
706 schoenebeck 1225
707 schoenebeck 3364 #if USE_GTKMM_BUILDER
708     insert_action_group("AppMenu", m_actionGroup);
709    
710     m_uiManager = Gtk::Builder::create();
711     Glib::ustring ui_info =
712     "<interface>"
713     " <menubar id='MenuBar'>"
714     " <menu id='MenuFile'>"
715     " <attribute name='label' translatable='yes'>_File</attribute>"
716     " <section>"
717     " <item id='New'>"
718     " <attribute name='label' translatable='yes'>New</attribute>"
719     " <attribute name='action'>AppMenu.New</attribute>"
720     " </item>"
721     " <item id='Open'>"
722     " <attribute name='label' translatable='yes'>Open</attribute>"
723     " <attribute name='action'>AppMenu.Open</attribute>"
724     " </item>"
725     " </section>"
726     " <section>"
727     " <item id='Save'>"
728     " <attribute name='label' translatable='yes'>Save</attribute>"
729     " <attribute name='action'>AppMenu.Save</attribute>"
730     " </item>"
731     " <item id='SaveAs'>"
732     " <attribute name='label' translatable='yes'>Save As</attribute>"
733     " <attribute name='action'>AppMenu.SaveAs</attribute>"
734     " </item>"
735     " </section>"
736     " <section>"
737     " <item id='Properties'>"
738     " <attribute name='label' translatable='yes'>Properties</attribute>"
739     " <attribute name='action'>AppMenu.Properties</attribute>"
740     " </item>"
741     " </section>"
742     " <section>"
743     " <item id='Quit'>"
744     " <attribute name='label' translatable='yes'>Quit</attribute>"
745     " <attribute name='action'>AppMenu.Quit</attribute>"
746     " </item>"
747     " </section>"
748     " </menu>"
749     " <menu id='MenuEdit'>"
750     " <attribute name='label' translatable='yes'>Edit</attribute>"
751     " <section>"
752     " <item id='CopyDimRgn'>"
753     " <attribute name='label' translatable='yes'>Copy Dimension Region</attribute>"
754     " <attribute name='action'>AppMenu.CopyDimRgn</attribute>"
755     " </item>"
756     " <item id='AdjustClipboard'>"
757     " <attribute name='label' translatable='yes'>Adjust Clipboard</attribute>"
758     " <attribute name='action'>AppMenu.AdjustClipboard</attribute>"
759     " </item>"
760     " <item id='PasteDimRgn'>"
761     " <attribute name='label' translatable='yes'>Paste Dimension Region</attribute>"
762     " <attribute name='action'>AppMenu.PasteDimRgn</attribute>"
763     " </item>"
764     " </section>"
765     " <item id='SelectPrevInstr'>"
766     " <attribute name='label' translatable='yes'>Previous Instrument</attribute>"
767     " <attribute name='action'>AppMenu.SelectPrevInstr</attribute>"
768     " </item>"
769     " <item id='SelectNextInstr'>"
770     " <attribute name='label' translatable='yes'>Next Instrument</attribute>"
771     " <attribute name='action'>AppMenu.SelectNextInstr</attribute>"
772     " </item>"
773     " <section>"
774     " <item id='SelectPrevRegion'>"
775     " <attribute name='label' translatable='yes'>Previous Region</attribute>"
776     " <attribute name='action'>AppMenu.SelectPrevRegion</attribute>"
777     " </item>"
778     " <item id='SelectNextRegion'>"
779     " <attribute name='label' translatable='yes'>Next Region</attribute>"
780     " <attribute name='action'>AppMenu.SelectNextRegion</attribute>"
781     " </item>"
782     " </section>"
783     " <item id='SelectPrevDimension'>"
784     " <attribute name='label' translatable='yes'>Previous Dimension</attribute>"
785     " <attribute name='action'>AppMenu.SelectPrevDimension</attribute>"
786     " </item>"
787     " <item id='SelectNextDimension'>"
788     " <attribute name='label' translatable='yes'>Next Dimension</attribute>"
789     " <attribute name='action'>AppMenu.SelectNextDimension</attribute>"
790     " </item>"
791     " <item id='SelectPrevDimRgnZone'>"
792     " <attribute name='label' translatable='yes'>Previous Dimension Region Zone</attribute>"
793     " <attribute name='action'>AppMenu.SelectPrevDimRgnZone</attribute>"
794     " </item>"
795     " <item id='SelectNextDimRgnZone'>"
796     " <attribute name='label' translatable='yes'>Next Dimension Region Zone</attribute>"
797     " <attribute name='action'>AppMenu.SelectNextDimRgnZone</attribute>"
798     " </item>"
799     " <item id='SelectAddPrevDimRgnZone'>"
800     " <attribute name='label' translatable='yes'>Add Previous Dimension Region Zone</attribute>"
801     " <attribute name='action'>AppMenu.SelectAddPrevDimRgnZone</attribute>"
802     " </item>"
803     " <item id='SelectAddNextDimRgnZone'>"
804     " <attribute name='label' translatable='yes'>Add Next Dimension Region Zone</attribute>"
805     " <attribute name='action'>AppMenu.SelectAddNextDimRgnZone</attribute>"
806     " </item>"
807     " <section>"
808     " <item id='CopySampleUnity'>"
809     " <attribute name='label' translatable='yes'>Copy Sample Unity</attribute>"
810     " <attribute name='action'>AppMenu.CopySampleUnity</attribute>"
811     " </item>"
812     " <item id='CopySampleTune'>"
813     " <attribute name='label' translatable='yes'>Copy Sample Tune</attribute>"
814     " <attribute name='action'>AppMenu.CopySampleTune</attribute>"
815     " </item>"
816     " <item id='CopySampleLoop'>"
817     " <attribute name='label' translatable='yes'>Copy Sample Loop</attribute>"
818     " <attribute name='action'>AppMenu.CopySampleLoop</attribute>"
819     " </item>"
820     " </section>"
821     " </menu>"
822     " <menu id='MenuMacro'>"
823     " <attribute name='label' translatable='yes'>Macro</attribute>"
824     " <section>"
825     " </section>"
826     " </menu>"
827     " <menu id='MenuSample'>"
828     " <attribute name='label' translatable='yes'>Sample</attribute>"
829     " <section>"
830     " <item id='SampleProperties'>"
831     " <attribute name='label' translatable='yes'>Properties</attribute>"
832     " <attribute name='action'>AppMenu.SampleProperties</attribute>"
833     " </item>"
834     " <item id='AddGroup'>"
835     " <attribute name='label' translatable='yes'>Add Group</attribute>"
836     " <attribute name='action'>AppMenu.AddGroup</attribute>"
837     " </item>"
838     " <item id='AddSample'>"
839     " <attribute name='label' translatable='yes'>Add Sample</attribute>"
840     " <attribute name='action'>AppMenu.AddSample</attribute>"
841     " </item>"
842     " <item id='ShowSampleRefs'>"
843     " <attribute name='label' translatable='yes'>Show Sample References</attribute>"
844     " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
845     " </item>"
846     " <item id='ReplaceSample'>"
847     " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
848     " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
849     " </item>"
850     " <item id='ReplaceAllSamplesInAllGroups'>"
851     " <attribute name='label' translatable='yes'>Replace all Samples in all Groups</attribute>"
852     " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
853     " </item>"
854     " </section>"
855     " <section>"
856     " <item id='RemoveSample'>"
857     " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
858     " <attribute name='action'>AppMenu.RemoveSample</attribute>"
859     " </item>"
860     " <item id='RemoveUnusedSamples'>"
861     " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
862     " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
863     " </item>"
864     " </section>"
865     " </menu>"
866     " <menu id='MenuInstrument'>"
867     " <attribute name='label' translatable='yes'>Instrument</attribute>"
868     " <section>"
869     " <item id='InstrProperties'>"
870     " <attribute name='label' translatable='yes'>Properties</attribute>"
871     " <attribute name='action'>AppMenu.InstrProperties</attribute>"
872     " </item>"
873     " <item id='MidiRules'>"
874     " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
875     " <attribute name='action'>AppMenu.MidiRules</attribute>"
876     " </item>"
877     " <item id='ScriptSlots'>"
878     " <attribute name='label' translatable='yes'>Script Slots</attribute>"
879     " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
880     " </item>"
881     " </section>"
882     " <submenu id='AssignScripts'>"
883     " <attribute name='label' translatable='yes'>Assign Scripts</attribute>"
884     " </submenu>"
885     " <section>"
886     " <item id='AddInstrument'>"
887     " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
888     " <attribute name='action'>AppMenu.AddInstrument</attribute>"
889     " </item>"
890     " <item id='DupInstrument'>"
891     " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
892     " <attribute name='action'>AppMenu.DupInstrument</attribute>"
893     " </item>"
894     " <item id='CombInstruments'>"
895     " <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
896     " <attribute name='action'>AppMenu.CombInstruments</attribute>"
897     " </item>"
898     " </section>"
899     " <section>"
900     " <item id='RemoveInstrument'>"
901     " <attribute name='label' translatable='yes'>Remove Instrument</attribute>"
902     " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
903     " </item>"
904     " </section>"
905     " </menu>"
906     " <menu id='MenuScript'>"
907     " <attribute name='label' translatable='yes'>Script</attribute>"
908     " <section>"
909     " <item id='AddScriptGroup'>"
910     " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
911     " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
912     " </item>"
913     " <item id='AddScript'>"
914     " <attribute name='label' translatable='yes'>Add Script</attribute>"
915     " <attribute name='action'>AppMenu.AddScript</attribute>"
916     " </item>"
917     " <item id='EditScript'>"
918     " <attribute name='label' translatable='yes'>Edit Script</attribute>"
919     " <attribute name='action'>AppMenu.EditScript</attribute>"
920     " </item>"
921     " </section>"
922     " <section>"
923     " <item id='RemoveScript'>"
924     " <attribute name='label' translatable='yes'>Remove Script</attribute>"
925     " <attribute name='action'>AppMenu.RemoveScript</attribute>"
926     " </item>"
927     " </section>"
928     " </menu>"
929     " <menu id='MenuView'>"
930     " <attribute name='label' translatable='yes'>View</attribute>"
931     " <section>"
932     " <item id='Statusbar'>"
933     " <attribute name='label' translatable='yes'>Statusbar</attribute>"
934     " <attribute name='action'>AppMenu.Statusbar</attribute>"
935     " </item>"
936 schoenebeck 3409 " <item id='ShowTooltips'>"
937     " <attribute name='label' translatable='yes'>Tooltips for Beginners</attribute>"
938     " <attribute name='action'>AppMenu.ShowTooltips</attribute>"
939     " </item>"
940 schoenebeck 3364 " <item id='AutoRestoreWinDim'>"
941     " <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
942     " <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
943     " </item>"
944     " </section>"
945     " <section>"
946     " <item id='RefreshAll'>"
947     " <attribute name='label' translatable='yes'>Refresh All</attribute>"
948     " <attribute name='action'>AppMenu.RefreshAll</attribute>"
949     " </item>"
950     " </section>"
951     " </menu>"
952     " <menu id='MenuTools'>"
953     " <attribute name='label' translatable='yes'>Tools</attribute>"
954     " <section>"
955     " <item id='CombineInstruments'>"
956     " <attribute name='label' translatable='yes'>Combine Instruments ...</attribute>"
957     " <attribute name='action'>AppMenu.CombineInstruments</attribute>"
958     " </item>"
959     " <item id='MergeFiles'>"
960     " <attribute name='label' translatable='yes'>Merge Files ...</attribute>"
961     " <attribute name='action'>AppMenu.MergeFiles</attribute>"
962     " </item>"
963     " </section>"
964     " </menu>"
965     " <menu id='MenuSettings'>"
966     " <attribute name='label' translatable='yes'>Settings</attribute>"
967     " <section>"
968     " <item id='WarnUserOnExtensions'>"
969     " <attribute name='label' translatable='yes'>Warning on Format Extensions</attribute>"
970     " <attribute name='action'>AppMenu.WarnUserOnExtensions</attribute>"
971     " </item>"
972     " <item id='SyncSamplerInstrumentSelection'>"
973     " <attribute name='label' translatable='yes'>Synchronize Sampler Selection</attribute>"
974     " <attribute name='action'>AppMenu.SyncSamplerInstrumentSelection</attribute>"
975     " </item>"
976     " <item id='MoveRootNoteWithRegionMoved'>"
977     " <attribute name='label' translatable='yes'>Move Root Note with Region moved</attribute>"
978     " <attribute name='action'>AppMenu.MoveRootNoteWithRegionMoved</attribute>"
979     " </item>"
980     " <item id='SaveWithTemporaryFile'>"
981     " <attribute name='label' translatable='yes'>Save with temporary file</attribute>"
982     " <attribute name='action'>AppMenu.SaveWithTemporaryFile</attribute>"
983     " </item>"
984     " </section>"
985     " </menu>"
986     " <menu id='MenuHelp'>"
987     " <attribute name='label' translatable='yes'>Help</attribute>"
988     " <section>"
989     " <item id='About'>"
990     " <attribute name='label' translatable='yes'>About ...</attribute>"
991     " <attribute name='action'>AppMenu.About</attribute>"
992     " </item>"
993     " </section>"
994     " </menu>"
995     " </menubar>"
996     // popups
997     " <menu id='PopupMenu'>"
998     " <section>"
999     " <item id='InstrProperties'>"
1000     " <attribute name='label' translatable='yes'>Instrument Properties</attribute>"
1001     " <attribute name='action'>AppMenu.InstrProperties</attribute>"
1002     " </item>"
1003     " <item id='MidiRules'>"
1004     " <attribute name='label' translatable='yes'>MIDI Rules</attribute>"
1005     " <attribute name='action'>AppMenu.MidiRules</attribute>"
1006     " </item>"
1007     " <item id='ScriptSlots'>"
1008     " <attribute name='label' translatable='yes'>Script Slots</attribute>"
1009     " <attribute name='action'>AppMenu.ScriptSlots</attribute>"
1010     " </item>"
1011     " <item id='AddInstrument'>"
1012     " <attribute name='label' translatable='yes'>Add Instrument</attribute>"
1013     " <attribute name='action'>AppMenu.AddInstrument</attribute>"
1014     " </item>"
1015     " <item id='DupInstrument'>"
1016     " <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1017     " <attribute name='action'>AppMenu.DupInstrument</attribute>"
1018     " </item>"
1019     " <item id='CombInstruments'>"
1020     " <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1021     " <attribute name='action'>AppMenu.CombInstruments</attribute>"
1022     " </item>"
1023     " </section>"
1024     " <section>"
1025     " <item id='RemoveInstrument'>"
1026     " <attribute name='label' translatable='yes'>Remove Instruments</attribute>"
1027     " <attribute name='action'>AppMenu.RemoveInstrument</attribute>"
1028     " </item>"
1029     " </section>"
1030     " </menu>"
1031     " <menu id='SamplePopupMenu'>"
1032     " <section>"
1033     " <item id='SampleProperties'>"
1034     " <attribute name='label' translatable='yes'>Sample Properties</attribute>"
1035     " <attribute name='action'>AppMenu.SampleProperties</attribute>"
1036     " </item>"
1037     " <item id='AddGroup'>"
1038     " <attribute name='label' translatable='yes'>Add Sample Group</attribute>"
1039     " <attribute name='action'>AppMenu.AddGroup</attribute>"
1040     " </item>"
1041     " <item id='AddSample'>"
1042     " <attribute name='label' translatable='yes'>Add Sample</attribute>"
1043     " <attribute name='action'>AppMenu.AddSample</attribute>"
1044     " </item>"
1045     " <item id='ShowSampleRefs'>"
1046     " <attribute name='label' translatable='yes'>Show Sample References ...</attribute>"
1047     " <attribute name='action'>AppMenu.ShowSampleRefs</attribute>"
1048     " </item>"
1049     " <item id='ReplaceSample'>"
1050     " <attribute name='label' translatable='yes'>Replace Sample</attribute>"
1051     " <attribute name='action'>AppMenu.ReplaceSample</attribute>"
1052     " </item>"
1053     " <item id='ReplaceAllSamplesInAllGroups'>"
1054     " <attribute name='label' translatable='yes'>Replace all Samples ...</attribute>"
1055     " <attribute name='action'>AppMenu.ReplaceAllSamplesInAllGroups</attribute>"
1056     " </item>"
1057     " </section>"
1058     " <section>"
1059     " <item id='RemoveSample'>"
1060     " <attribute name='label' translatable='yes'>Remove Sample</attribute>"
1061     " <attribute name='action'>AppMenu.RemoveSample</attribute>"
1062     " </item>"
1063     " <item id='RemoveUnusedSamples'>"
1064     " <attribute name='label' translatable='yes'>Remove unused Samples</attribute>"
1065     " <attribute name='action'>AppMenu.RemoveUnusedSamples</attribute>"
1066     " </item>"
1067     " </section>"
1068     " </menu>"
1069     " <menu id='ScriptPopupMenu'>"
1070     " <section>"
1071     " <item id='AddScriptGroup'>"
1072     " <attribute name='label' translatable='yes'>Add Script Group</attribute>"
1073     " <attribute name='action'>AppMenu.AddScriptGroup</attribute>"
1074     " </item>"
1075     " <item id='AddScript'>"
1076     " <attribute name='label' translatable='yes'>Add Script</attribute>"
1077     " <attribute name='action'>AppMenu.AddScript</attribute>"
1078     " </item>"
1079     " <item id='EditScript'>"
1080     " <attribute name='label' translatable='yes'>Edit Script</attribute>"
1081     " <attribute name='action'>AppMenu.EditScript</attribute>"
1082     " </item>"
1083     " </section>"
1084     " <section>"
1085     " <item id='RemoveScript'>"
1086     " <attribute name='label' translatable='yes'>Remove Script</attribute>"
1087     " <attribute name='action'>AppMenu.RemoveScript</attribute>"
1088     " </item>"
1089     " </section>"
1090     " </menu>"
1091     "</interface>";
1092     m_uiManager->add_from_string(ui_info);
1093     #else
1094 schoenebeck 1225 uiManager = Gtk::UIManager::create();
1095     uiManager->insert_action_group(actionGroup);
1096 persson 1261 add_accel_group(uiManager->get_accel_group());
1097 schoenebeck 1225
1098     Glib::ustring ui_info =
1099     "<ui>"
1100     " <menubar name='MenuBar'>"
1101     " <menu action='MenuFile'>"
1102     " <menuitem action='New'/>"
1103     " <menuitem action='Open'/>"
1104     " <separator/>"
1105     " <menuitem action='Save'/>"
1106     " <menuitem action='SaveAs'/>"
1107     " <separator/>"
1108     " <menuitem action='Properties'/>"
1109     " <separator/>"
1110     " <menuitem action='Quit'/>"
1111     " </menu>"
1112 schoenebeck 2464 " <menu action='MenuEdit'>"
1113 schoenebeck 3144 " <menuitem action='CopyDimRgn'/>"
1114 schoenebeck 3151 " <menuitem action='AdjustClipboard'/>"
1115 schoenebeck 3144 " <menuitem action='PasteDimRgn'/>"
1116     " <separator/>"
1117 schoenebeck 3339 " <menuitem action='SelectPrevInstr'/>"
1118     " <menuitem action='SelectNextInstr'/>"
1119     " <separator/>"
1120 schoenebeck 3123 " <menuitem action='SelectPrevRegion'/>"
1121     " <menuitem action='SelectNextRegion'/>"
1122     " <separator/>"
1123 schoenebeck 3134 " <menuitem action='SelectPrevDimension'/>"
1124     " <menuitem action='SelectNextDimension'/>"
1125 schoenebeck 3123 " <menuitem action='SelectPrevDimRgnZone'/>"
1126     " <menuitem action='SelectNextDimRgnZone'/>"
1127 schoenebeck 3134 " <menuitem action='SelectAddPrevDimRgnZone'/>"
1128     " <menuitem action='SelectAddNextDimRgnZone'/>"
1129 schoenebeck 3123 " <separator/>"
1130 schoenebeck 2464 " <menuitem action='CopySampleUnity'/>"
1131     " <menuitem action='CopySampleTune'/>"
1132     " <menuitem action='CopySampleLoop'/>"
1133     " </menu>"
1134 schoenebeck 3157 " <menu action='MenuMacro'>"
1135     " </menu>"
1136 schoenebeck 2625 " <menu action='MenuSample'>"
1137     " <menuitem action='SampleProperties'/>"
1138     " <menuitem action='AddGroup'/>"
1139     " <menuitem action='AddSample'/>"
1140     " <menuitem action='ShowSampleRefs'/>"
1141 schoenebeck 2715 " <menuitem action='ReplaceSample' />"
1142 schoenebeck 2625 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1143     " <separator/>"
1144     " <menuitem action='RemoveSample'/>"
1145 schoenebeck 2772 " <menuitem action='RemoveUnusedSamples'/>"
1146 schoenebeck 2625 " </menu>"
1147 schoenebeck 1225 " <menu action='MenuInstrument'>"
1148 schoenebeck 2625 " <menu action='AllInstruments'>"
1149     " </menu>"
1150     " <separator/>"
1151     " <menuitem action='InstrProperties'/>"
1152     " <menuitem action='MidiRules'/>"
1153     " <menuitem action='ScriptSlots'/>"
1154 schoenebeck 3339 " <menu action='AssignScripts'/>"
1155 schoenebeck 2625 " <menuitem action='AddInstrument'/>"
1156     " <menuitem action='DupInstrument'/>"
1157 schoenebeck 3299 " <menuitem action='CombInstruments'/>"
1158 schoenebeck 2625 " <separator/>"
1159     " <menuitem action='RemoveInstrument'/>"
1160 schoenebeck 1225 " </menu>"
1161 schoenebeck 2625 " <menu action='MenuScript'>"
1162     " <menuitem action='AddScriptGroup'/>"
1163     " <menuitem action='AddScript'/>"
1164     " <menuitem action='EditScript'/>"
1165     " <separator/>"
1166     " <menuitem action='RemoveScript'/>"
1167     " </menu>"
1168 schoenebeck 1415 " <menu action='MenuView'>"
1169     " <menuitem action='Statusbar'/>"
1170 schoenebeck 3409 " <menuitem action='ShowTooltips'/>"
1171 schoenebeck 2918 " <menuitem action='AutoRestoreWinDim'/>"
1172 schoenebeck 2772 " <separator/>"
1173     " <menuitem action='RefreshAll'/>"
1174 schoenebeck 1415 " </menu>"
1175 schoenebeck 2548 " <menu action='MenuTools'>"
1176     " <menuitem action='CombineInstruments'/>"
1177 schoenebeck 2553 " <menuitem action='MergeFiles'/>"
1178 schoenebeck 2548 " </menu>"
1179 schoenebeck 2541 " <menu action='MenuSettings'>"
1180     " <menuitem action='WarnUserOnExtensions'/>"
1181 schoenebeck 2689 " <menuitem action='SyncSamplerInstrumentSelection'/>"
1182 schoenebeck 2773 " <menuitem action='MoveRootNoteWithRegionMoved'/>"
1183 schoenebeck 2967 " <menuitem action='SaveWithTemporaryFile'/>"
1184 schoenebeck 2541 " </menu>"
1185 schoenebeck 1225 " <menu action='MenuHelp'>"
1186     " <menuitem action='About'/>"
1187     " </menu>"
1188     " </menubar>"
1189     " <popup name='PopupMenu'>"
1190     " <menuitem action='InstrProperties'/>"
1191 persson 2507 " <menuitem action='MidiRules'/>"
1192 schoenebeck 2610 " <menuitem action='ScriptSlots'/>"
1193 schoenebeck 1225 " <menuitem action='AddInstrument'/>"
1194 schoenebeck 2395 " <menuitem action='DupInstrument'/>"
1195 schoenebeck 3299 " <menuitem action='CombInstruments'/>"
1196 schoenebeck 1225 " <separator/>"
1197     " <menuitem action='RemoveInstrument'/>"
1198     " </popup>"
1199     " <popup name='SamplePopupMenu'>"
1200     " <menuitem action='SampleProperties'/>"
1201     " <menuitem action='AddGroup'/>"
1202     " <menuitem action='AddSample'/>"
1203 schoenebeck 2624 " <menuitem action='ShowSampleRefs'/>"
1204 schoenebeck 2715 " <menuitem action='ReplaceSample' />"
1205 persson 2442 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
1206 schoenebeck 1225 " <separator/>"
1207     " <menuitem action='RemoveSample'/>"
1208 schoenebeck 2772 " <menuitem action='RemoveUnusedSamples'/>"
1209 schoenebeck 1225 " </popup>"
1210 schoenebeck 2604 " <popup name='ScriptPopupMenu'>"
1211     " <menuitem action='AddScriptGroup'/>"
1212     " <menuitem action='AddScript'/>"
1213     " <menuitem action='EditScript'/>"
1214     " <separator/>"
1215     " <menuitem action='RemoveScript'/>"
1216     " </popup>"
1217 schoenebeck 1225 "</ui>";
1218     uiManager->add_ui_from_string(ui_info);
1219 schoenebeck 3364 #endif
1220 schoenebeck 1225
1221 schoenebeck 3364 #if USE_GTKMM_BUILDER
1222     popup_menu = new Gtk::Menu(
1223     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1224     m_uiManager->get_object("PopupMenu")
1225     )
1226     );
1227     sample_popup = new Gtk::Menu(
1228     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1229     m_uiManager->get_object("SamplePopupMenu")
1230     )
1231     );
1232     script_popup = new Gtk::Menu(
1233     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1234     m_uiManager->get_object("ScriptPopupMenu")
1235     )
1236     );
1237     #else
1238 schoenebeck 1225 popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
1239 schoenebeck 2536
1240     // Set tooltips for menu items (for some reason, setting a tooltip on the
1241     // respective Gtk::Action objects above will simply be ignored, no matter
1242     // if using Gtk::Action::set_tooltip() or passing the tooltip string on
1243     // Gtk::Action::create()).
1244     {
1245     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1246     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1247     item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
1248     }
1249     {
1250     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1251     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1252     item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
1253     }
1254     {
1255     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1256     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1257 schoenebeck 3408 item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop information to be altered by this action."));
1258 schoenebeck 2536 }
1259 schoenebeck 2541 {
1260     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1261     uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
1262     item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
1263     }
1264 schoenebeck 2553 {
1265     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1266 schoenebeck 2689 uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
1267     item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
1268     }
1269     {
1270     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1271 schoenebeck 2773 uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
1272 schoenebeck 3408 item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keyboard position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
1273 schoenebeck 2773 }
1274     {
1275     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1276 schoenebeck 2772 uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
1277     item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
1278     // copy tooltip to popup menu
1279     Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
1280     uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
1281     item2->set_tooltip_text(item->get_tooltip_text());
1282     }
1283     {
1284     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1285     uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
1286     item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
1287     }
1288     {
1289     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1290 schoenebeck 2918 uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
1291     item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time."));
1292     }
1293     {
1294     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1295 schoenebeck 2553 uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1296     item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1297     }
1298     {
1299     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1300     uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
1301     item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
1302     }
1303 schoenebeck 3364 #endif
1304 schoenebeck 1225
1305 schoenebeck 3364 #if USE_GTKMM_BUILDER
1306     assign_scripts_menu = new Gtk::Menu(
1307     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1308     m_uiManager->get_object("AssignScripts")
1309     )
1310     );
1311     #else
1312 persson 2442 instrument_menu = static_cast<Gtk::MenuItem*>(
1313 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
1314 persson 2442
1315 schoenebeck 3339 assign_scripts_menu = static_cast<Gtk::MenuItem*>(
1316     uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
1317 schoenebeck 3364 #endif
1318 schoenebeck 3339
1319 schoenebeck 3364 #if USE_GTKMM_BUILDER
1320     Gtk::Widget* menuBar = NULL;
1321     m_uiManager->get_widget("MenuBar", menuBar);
1322     #else
1323 schoenebeck 1225 Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
1324 schoenebeck 3364 #endif
1325    
1326 schoenebeck 1225 m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
1327     m_VBox.pack_start(m_HPaned);
1328     m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
1329 schoenebeck 1661 m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
1330 schoenebeck 1225 m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
1331 schoenebeck 1411 m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
1332 schoenebeck 1225
1333 persson 2246 set_file_is_shared(false);
1334    
1335 schoenebeck 1411 // Status Bar:
1336 schoenebeck 3364 #if USE_GTKMM_BOX
1337     # warning No status bar layout for GTKMM 4 yet
1338     #else
1339 schoenebeck 1411 m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
1340     m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
1341 schoenebeck 3364 #endif
1342 schoenebeck 1411 m_StatusBar.show();
1343    
1344 persson 1261 m_RegionChooser.signal_region_selected().connect(
1345 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::region_changed) );
1346 persson 1261 m_DimRegionChooser.signal_dimregion_selected().connect(
1347 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::dimreg_changed) );
1348    
1349    
1350     // Create the Tree model:
1351     m_refTreeModel = Gtk::ListStore::create(m_Columns);
1352 schoenebeck 3340 m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
1353     m_refTreeModelFilter->set_visible_func(
1354     sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1355     );
1356     m_TreeView.set_model(m_refTreeModelFilter);
1357    
1358 schoenebeck 2994 m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1359 schoenebeck 3418 m_TreeView.set_has_tooltip(true);
1360     m_TreeView.signal_query_tooltip().connect(
1361     sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1362     );
1363 persson 2442 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1364 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1365     );
1366    
1367     // Add the TreeView's view columns:
1368 schoenebeck 2994 m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
1369     m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
1370 schoenebeck 3197 m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
1371 schoenebeck 2994 m_TreeView.set_headers_visible(true);
1372 schoenebeck 2701
1373     // establish drag&drop within the instrument tree view, allowing to reorder
1374     // the sequence of instruments within the gig file
1375     {
1376     std::vector<Gtk::TargetEntry> drag_target_instrument;
1377     drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1378     m_TreeView.drag_source_set(drag_target_instrument);
1379     m_TreeView.drag_dest_set(drag_target_instrument);
1380     m_TreeView.signal_drag_begin().connect(
1381     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1382     );
1383     m_TreeView.signal_drag_data_get().connect(
1384     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1385     );
1386     m_TreeView.signal_drag_data_received().connect(
1387     sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1388     );
1389     }
1390 schoenebeck 1225
1391     // create samples treeview (including its data model)
1392     m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
1393     m_TreeViewSamples.set_model(m_refSamplesTreeModel);
1394 schoenebeck 2994 m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1395 schoenebeck 2536 m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
1396 schoenebeck 1225 // m_TreeViewSamples.set_reorderable();
1397 schoenebeck 2621 m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
1398     m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
1399     {
1400     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
1401     Gtk::CellRendererText* cellrenderer =
1402 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1403 schoenebeck 2621 column->add_attribute(
1404     cellrenderer->property_foreground(), m_SamplesModel.m_color
1405     );
1406     }
1407     {
1408     Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
1409     Gtk::CellRendererText* cellrenderer =
1410 persson 2658 dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell());
1411 schoenebeck 2621 column->add_attribute(
1412     cellrenderer->property_foreground(), m_SamplesModel.m_color
1413     );
1414     }
1415     m_TreeViewSamples.set_headers_visible(true);
1416 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1417     m_TreeViewSamples.signal_button_press_event().connect(
1418     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1419     );
1420     #else
1421 schoenebeck 1225 m_TreeViewSamples.signal_button_press_event().connect_notify(
1422     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
1423     );
1424 schoenebeck 3364 #endif
1425 schoenebeck 1225 m_refSamplesTreeModel->signal_row_changed().connect(
1426     sigc::mem_fun(*this, &MainWindow::sample_name_changed)
1427     );
1428    
1429 schoenebeck 2604 // create scripts treeview (including its data model)
1430     m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
1431     m_TreeViewScripts.set_model(m_refScriptsTreeModel);
1432     m_TreeViewScripts.set_tooltip_text(_(
1433 schoenebeck 2644 "Use CTRL + double click for editing a script."
1434     "\n\n"
1435 schoenebeck 2604 "Note: instrument scripts are a LinuxSampler extension of the gig "
1436     "format. This feature will not work with the GigaStudio software!"
1437     ));
1438     // m_TreeViewScripts.set_reorderable();
1439     m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
1440     m_TreeViewScripts.set_headers_visible(false);
1441 schoenebeck 3364 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
1442     m_TreeViewScripts.signal_button_press_event().connect(
1443     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1444     );
1445     #else
1446 schoenebeck 2604 m_TreeViewScripts.signal_button_press_event().connect_notify(
1447     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
1448     );
1449 schoenebeck 3364 #endif
1450 schoenebeck 2695 //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
1451 schoenebeck 2644 m_TreeViewScripts.signal_row_activated().connect(
1452     sigc::mem_fun(*this, &MainWindow::script_double_clicked)
1453     );
1454 schoenebeck 2604 m_refScriptsTreeModel->signal_row_changed().connect(
1455     sigc::mem_fun(*this, &MainWindow::script_name_changed)
1456     );
1457    
1458 schoenebeck 2610 // establish drag&drop between scripts tree view and ScriptSlots window
1459     std::vector<Gtk::TargetEntry> drag_target_gig_script;
1460     drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
1461     m_TreeViewScripts.drag_source_set(drag_target_gig_script);
1462     m_TreeViewScripts.signal_drag_begin().connect(
1463     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
1464     );
1465     m_TreeViewScripts.signal_drag_data_get().connect(
1466     sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
1467     );
1468    
1469 schoenebeck 1225 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
1470 persson 2169 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
1471     drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
1472 schoenebeck 1225 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
1473 persson 1303 m_TreeViewSamples.signal_drag_begin().connect(
1474     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
1475     );
1476 schoenebeck 1225 m_TreeViewSamples.signal_drag_data_get().connect(
1477     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
1478     );
1479     dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
1480     dimreg_edit.wSample->signal_drag_data_received().connect(
1481     sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
1482     );
1483 persson 1261 dimreg_edit.signal_dimreg_changed().connect(
1484 schoenebeck 1322 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
1485 persson 1261 m_RegionChooser.signal_instrument_changed().connect(
1486     sigc::mem_fun(*this, &MainWindow::file_changed));
1487 schoenebeck 2773 m_RegionChooser.signal_instrument_changed().connect(
1488     sigc::mem_fun(*this, &MainWindow::region_changed));
1489 persson 1261 m_DimRegionChooser.signal_region_changed().connect(
1490     sigc::mem_fun(*this, &MainWindow::file_changed));
1491 persson 2423 instrumentProps.signal_changed().connect(
1492 persson 1261 sigc::mem_fun(*this, &MainWindow::file_changed));
1493 persson 2423 propDialog.signal_changed().connect(
1494 persson 1582 sigc::mem_fun(*this, &MainWindow::file_changed));
1495 persson 2507 midiRules.signal_changed().connect(
1496     sigc::mem_fun(*this, &MainWindow::file_changed));
1497 schoenebeck 1322
1498     dimreg_edit.signal_dimreg_to_be_changed().connect(
1499     dimreg_to_be_changed_signal.make_slot());
1500     dimreg_edit.signal_dimreg_changed().connect(
1501     dimreg_changed_signal.make_slot());
1502     dimreg_edit.signal_sample_ref_changed().connect(
1503     sample_ref_changed_signal.make_slot());
1504 schoenebeck 2621 sample_ref_changed_signal.connect(
1505     sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
1506     );
1507     samples_to_be_removed_signal.connect(
1508     sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
1509     );
1510 schoenebeck 1322
1511 schoenebeck 2691 dimreg_edit.signal_select_sample().connect(
1512     sigc::mem_fun(*this, &MainWindow::select_sample)
1513     );
1514    
1515 schoenebeck 1322 m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1516     sigc::hide(
1517     sigc::bind(
1518     file_structure_to_be_changed_signal.make_slot(),
1519 persson 3461 #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1520     std::ref(this->file)
1521     #else
1522 schoenebeck 1322 sigc::ref(this->file)
1523 persson 3461 #endif
1524 schoenebeck 1322 )
1525     )
1526     );
1527     m_RegionChooser.signal_instrument_struct_changed().connect(
1528     sigc::hide(
1529     sigc::bind(
1530     file_structure_changed_signal.make_slot(),
1531 persson 3461 #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1532     std::ref(this->file)
1533     #else
1534 schoenebeck 1322 sigc::ref(this->file)
1535 persson 3461 #endif
1536 schoenebeck 1322 )
1537     )
1538     );
1539     m_RegionChooser.signal_region_to_be_changed().connect(
1540     region_to_be_changed_signal.make_slot());
1541     m_RegionChooser.signal_region_changed_signal().connect(
1542     region_changed_signal.make_slot());
1543    
1544 schoenebeck 1654 note_on_signal.connect(
1545     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
1546     note_off_signal.connect(
1547     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
1548    
1549 persson 1533 dimreg_all_regions.signal_toggled().connect(
1550     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1551     dimreg_all_dimregs.signal_toggled().connect(
1552     sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
1553     dimreg_stereo.signal_toggled().connect(
1554     sigc::mem_fun(*this, &MainWindow::update_dimregs));
1555    
1556 schoenebeck 3340 m_searchText.signal_changed().connect(
1557 persson 3461 sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1558 schoenebeck 3340 );
1559    
1560 schoenebeck 1225 file = 0;
1561 persson 1261 file_is_changed = false;
1562 schoenebeck 1225
1563 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1564 schoenebeck 1225 show_all_children();
1565 schoenebeck 3364 #endif
1566 schoenebeck 1300
1567     // start with a new gig file by default
1568     on_action_file_new();
1569 schoenebeck 2550
1570 schoenebeck 3340 m_TreeViewNotebook.signal_switch_page().connect(
1571     sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
1572     );
1573    
1574 schoenebeck 2550 // select 'Instruments' tab by default
1575     // (gtk allows this only if the tab childs are visible, thats why it's here)
1576 schoenebeck 3144 m_TreeViewNotebook.set_current_page(1);
1577    
1578     Gtk::Clipboard::get()->signal_owner_change().connect(
1579     sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
1580     );
1581     updateClipboardPasteAvailable();
1582     updateClipboardCopyAvailable();
1583 schoenebeck 3157
1584     // setup macros and their keyboard accelerators
1585     {
1586 schoenebeck 3364 #if USE_GTKMM_BUILDER
1587     menuMacro = new Gtk::Menu(
1588     Glib::RefPtr<Gio::Menu>::cast_dynamic(
1589     m_uiManager->get_object("MenuMacro")
1590     )
1591     );
1592     #else
1593 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1594     uiManager->get_widget("/MenuBar/MenuMacro")
1595     )->get_submenu();
1596 schoenebeck 3364 #endif
1597 schoenebeck 3157
1598     const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
1599     Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
1600     Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
1601     Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier);
1602     Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier);
1603     Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier);
1604     Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier);
1605     Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier);
1606     Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier);
1607     Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier);
1608     Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1609     Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1610     Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1611 schoenebeck 3417 Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1612     Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1613     Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1614     Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1615     Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1616     Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1617     Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1618 schoenebeck 3157 Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1619    
1620     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1621     menuMacro->set_accel_group(accelGroup);
1622    
1623     updateMacroMenu();
1624     }
1625 schoenebeck 3258
1626 schoenebeck 3339 // setup "Assign Scripts" keyboard accelerators
1627     {
1628     Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
1629     Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
1630     Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
1631     Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
1632     Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
1633     Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
1634     Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
1635     Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
1636     Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
1637     Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1638     Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1639     Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1640 schoenebeck 3417 Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1641     Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1642     Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1643     Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1644     Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1645     Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1646     Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1647 schoenebeck 3419 Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1648 schoenebeck 3339
1649     Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1650     assign_scripts_menu->set_accel_group(accelGroup);
1651     }
1652    
1653 schoenebeck 3409 on_show_tooltips_changed();
1654    
1655 schoenebeck 3258 Glib::signal_idle().connect_once(
1656     sigc::mem_fun(*this, &MainWindow::bringToFront),
1657     200
1658     );
1659 schoenebeck 1225 }
1660    
1661     MainWindow::~MainWindow()
1662     {
1663     }
1664    
1665 schoenebeck 3258 void MainWindow::bringToFront() {
1666     #if defined(__APPLE__)
1667     macRaiseAppWindow();
1668     #endif
1669     raise();
1670     present();
1671     }
1672    
1673 schoenebeck 3157 void MainWindow::updateMacroMenu() {
1674 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1675 schoenebeck 3157 Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
1676     uiManager->get_widget("/MenuBar/MenuMacro")
1677     )->get_submenu();
1678 schoenebeck 3364 #endif
1679 schoenebeck 3157
1680     // remove all entries from "Macro" menu
1681     {
1682     const std::vector<Gtk::Widget*> children = menuMacro->get_children();
1683     for (int i = 0; i < children.size(); ++i) {
1684     Gtk::Widget* child = children[i];
1685     menuMacro->remove(*child);
1686     delete child;
1687     }
1688     }
1689    
1690     // (re)load all macros from config file
1691     try {
1692     Settings::singleton()->loadMacros(m_macros);
1693     } catch (Serialization::Exception e) {
1694     std::cerr << "Exception while loading macros: " << e.Message << std::endl;
1695     } catch (...) {
1696     std::cerr << "Unknown exception while loading macros!" << std::endl;
1697     }
1698    
1699     // add all configured macros as menu items to the "Macro" menu
1700     for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) {
1701     const Serialization::Archive& macro = m_macros[iMacro];
1702     std::string name =
1703     macro.name().empty() ?
1704     (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name();
1705     Gtk::MenuItem* item = new Gtk::MenuItem(name);
1706     item->signal_activate().connect(
1707     sigc::bind(
1708     sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro
1709     )
1710     );
1711     menuMacro->append(*item);
1712     item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1713 schoenebeck 3174 Glib::ustring comment = macro.comment();
1714     if (!comment.empty())
1715     item->set_tooltip_text(comment);
1716 schoenebeck 3157 }
1717     // if there are no macros configured at all, then show a dummy entry instead
1718     if (m_macros.empty()) {
1719     Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros"));
1720     item->set_sensitive(false);
1721     menuMacro->append(*item);
1722     }
1723    
1724     // add separator line to menu
1725     menuMacro->append(*new Gtk::SeparatorMenuItem);
1726    
1727     {
1728     Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ..."));
1729     item->signal_activate().connect(
1730     sigc::mem_fun(*this, &MainWindow::setupMacros)
1731     );
1732     menuMacro->append(*item);
1733     item->set_accel_path("<Macros>/SetupMacros");
1734     }
1735    
1736 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
1737 schoenebeck 3157 menuMacro->show_all_children();
1738 schoenebeck 3364 #endif
1739 schoenebeck 3157 }
1740    
1741     void MainWindow::onMacroSelected(int iMacro) {
1742     printf("onMacroSelected(%d)\n", iMacro);
1743     if (iMacro < 0 || iMacro >= m_macros.size()) return;
1744     Glib::ustring errorText;
1745     try {
1746     applyMacro(m_macros[iMacro]);
1747     } catch (Serialization::Exception e) {
1748     errorText = e.Message;
1749     } catch (...) {
1750     errorText = _("Unknown exception while applying macro");
1751     }
1752     if (!errorText.empty()) {
1753     Glib::ustring txt = _("Applying macro failed:\n") + errorText;
1754     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1755     msg.run();
1756     }
1757     }
1758    
1759     void MainWindow::setupMacros() {
1760     MacrosSetup* setup = new MacrosSetup();
1761 schoenebeck 3160 gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
1762     setup->setMacros(m_macros, &m_serializationArchive, pDimRgn);
1763 schoenebeck 3157 setup->signal_macros_changed().connect(
1764     sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged)
1765     );
1766     setup->show();
1767     }
1768    
1769     void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) {
1770     m_macros = macros;
1771     Settings::singleton()->saveMacros(m_macros);
1772     updateMacroMenu();
1773     }
1774    
1775 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.
1776     void MainWindow::on_notebook_tab_switched(void* page, guint page_num) {
1777 schoenebeck 3340 bool isInstrumentsPage = (page_num == 1);
1778     // so far we only support filtering for the instruments list, so hide the
1779     // filter text entry field if another tab is selected
1780     m_searchField.set_visible(isInstrumentsPage);
1781     }
1782    
1783 persson 1261 bool MainWindow::on_delete_event(GdkEventAny* event)
1784     {
1785 schoenebeck 1382 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
1786 persson 1261 }
1787    
1788     void MainWindow::on_action_quit()
1789     {
1790 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
1791 persson 1261 hide();
1792     }
1793    
1794 schoenebeck 1225 void MainWindow::region_changed()
1795     {
1796     m_DimRegionChooser.set_region(m_RegionChooser.get_region());
1797     }
1798    
1799 persson 1533 gig::Instrument* MainWindow::get_instrument()
1800 schoenebeck 1225 {
1801 persson 1533 gig::Instrument* instrument = 0;
1802 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1803     if (rows.empty()) return NULL;
1804 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.
1805     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1806 schoenebeck 1225 if (it) {
1807     Gtk::TreeModel::Row row = *it;
1808 persson 1533 instrument = row[m_Columns.m_col_instr];
1809     }
1810     return instrument;
1811     }
1812 schoenebeck 1225
1813 persson 1533 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
1814     {
1815     if (all_dimregs) {
1816     for (int i = 0 ; i < region->DimensionRegions ; i++) {
1817     if (region->pDimensionRegions[i]) {
1818     dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
1819     }
1820     }
1821 schoenebeck 1225 } else {
1822 persson 1533 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
1823 schoenebeck 1225 }
1824     }
1825    
1826 persson 1533 void MainWindow::update_dimregs()
1827     {
1828     dimreg_edit.dimregs.clear();
1829     bool all_regions = dimreg_all_regions.get_active();
1830     bool stereo = dimreg_stereo.get_active();
1831     bool all_dimregs = dimreg_all_dimregs.get_active();
1832    
1833     if (all_regions) {
1834     gig::Instrument* instrument = get_instrument();
1835     if (instrument) {
1836     for (gig::Region* region = instrument->GetFirstRegion() ;
1837     region ;
1838     region = instrument->GetNextRegion()) {
1839     add_region_to_dimregs(region, stereo, all_dimregs);
1840     }
1841     }
1842     } else {
1843     gig::Region* region = m_RegionChooser.get_region();
1844     if (region) {
1845     add_region_to_dimregs(region, stereo, all_dimregs);
1846     }
1847     }
1848 schoenebeck 3089
1849 schoenebeck 3148 m_RegionChooser.setModifyAllRegions(all_regions);
1850 schoenebeck 3089 m_DimRegionChooser.setModifyAllRegions(all_regions);
1851     m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
1852     m_DimRegionChooser.setModifyBothChannels(stereo);
1853 schoenebeck 3144
1854     updateClipboardCopyAvailable();
1855 persson 1533 }
1856    
1857     void MainWindow::dimreg_all_dimregs_toggled()
1858     {
1859     dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
1860     update_dimregs();
1861     }
1862    
1863     void MainWindow::dimreg_changed()
1864     {
1865     update_dimregs();
1866 schoenebeck 2626 dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
1867 persson 1533 }
1868    
1869     void MainWindow::on_sel_change()
1870     {
1871 schoenebeck 3364 #if !USE_GTKMM_BUILDER
1872 persson 2442 // select item in instrument menu
1873 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1874     if (!rows.empty()) {
1875     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
1876     if (it) {
1877     Gtk::TreePath path(it);
1878     int index = path[0];
1879     const std::vector<Gtk::Widget*> children =
1880     instrument_menu->get_children();
1881     static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
1882     }
1883 persson 2442 }
1884 schoenebeck 3364 #endif
1885 persson 2442
1886 schoenebeck 3339 updateScriptListOfMenu();
1887    
1888 persson 1533 m_RegionChooser.set_instrument(get_instrument());
1889 schoenebeck 2689
1890     if (Settings::singleton()->syncSamplerInstrumentSelection) {
1891     switch_sampler_instrument_signal.emit(get_instrument());
1892     }
1893 persson 1533 }
1894    
1895 persson 3470
1896     LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :
1897     filename(filename), gig(gig), thread(0), progress(0.f)
1898     {
1899     }
1900    
1901 schoenebeck 1225 void loader_progress_callback(gig::progress_t* progress)
1902     {
1903 persson 3470 LoaderSaverBase* loader = static_cast<LoaderSaverBase*>(progress->custom);
1904 schoenebeck 1225 loader->progress_callback(progress->factor);
1905     }
1906    
1907 persson 3470 void LoaderSaverBase::progress_callback(float fraction)
1908 schoenebeck 1225 {
1909     {
1910 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
1911 schoenebeck 1225 progress = fraction;
1912     }
1913     progress_dispatcher();
1914     }
1915    
1916 persson 3021 #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
1917     // make sure stack is 16-byte aligned for SSE instructions
1918     __attribute__((force_align_arg_pointer))
1919     #endif
1920 persson 3470 void LoaderSaverBase::thread_function()
1921 schoenebeck 1225 {
1922 persson 2841 printf("thread_function self=%p\n",
1923     static_cast<void*>(Glib::Threads::Thread::self()));
1924 schoenebeck 2683 printf("Start %s\n", filename.c_str());
1925     try {
1926     gig::progress_t progress;
1927     progress.callback = loader_progress_callback;
1928     progress.custom = this;
1929 schoenebeck 1225
1930 persson 3470 thread_function_sub(progress);
1931 schoenebeck 2683 printf("End\n");
1932     finished_dispatcher();
1933     } catch (RIFF::Exception e) {
1934     error_message = e.Message;
1935     error_dispatcher.emit();
1936     } catch (...) {
1937     error_message = _("Unknown exception occurred");
1938     error_dispatcher.emit();
1939     }
1940 schoenebeck 1225 }
1941    
1942 persson 3470 void LoaderSaverBase::launch()
1943 schoenebeck 1225 {
1944 persson 2332 #ifdef OLD_THREADS
1945 persson 3470 thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);
1946 persson 2332 #else
1947 persson 3470 thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));
1948 persson 2332 #endif
1949 persson 2841 printf("launch thread=%p\n", static_cast<void*>(thread));
1950 schoenebeck 1225 }
1951    
1952 persson 3470 float LoaderSaverBase::get_progress()
1953 schoenebeck 1225 {
1954 persson 3470 Glib::Threads::Mutex::Lock lock(progressMutex);
1955     return progress;
1956 schoenebeck 1225 }
1957    
1958 persson 3470 Glib::Dispatcher& LoaderSaverBase::signal_progress()
1959 schoenebeck 1225 {
1960     return progress_dispatcher;
1961     }
1962    
1963 persson 3470 Glib::Dispatcher& LoaderSaverBase::signal_finished()
1964 schoenebeck 1225 {
1965     return finished_dispatcher;
1966     }
1967    
1968 persson 3470 Glib::Dispatcher& LoaderSaverBase::signal_error()
1969 schoenebeck 2683 {
1970     return error_dispatcher;
1971     }
1972    
1973    
1974 persson 3470 Loader::Loader(const char* filename) :
1975     LoaderSaverBase(filename, 0)
1976 schoenebeck 2683 {
1977     }
1978    
1979 persson 3470 void Loader::thread_function_sub(gig::progress_t& progress)
1980 schoenebeck 2683 {
1981 persson 3470 RIFF::File* riff = new RIFF::File(filename);
1982     gig = new gig::File(riff);
1983 schoenebeck 2683
1984 persson 3470 gig->GetInstrument(0, &progress);
1985 schoenebeck 2683 }
1986    
1987 persson 3470
1988     Saver::Saver(gig::File* file, Glib::ustring filename) :
1989     LoaderSaverBase(filename, file)
1990 schoenebeck 2683 {
1991     }
1992    
1993 persson 3470 void Saver::thread_function_sub(gig::progress_t& progress)
1994 schoenebeck 2683 {
1995 persson 3470 // if no filename was provided, that means "save", if filename was provided means "save as"
1996     if (filename.empty()) {
1997     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     gig::String tmpname = filename + ".TMP";
2007     gig->Save(tmpname, &progress);
2008     #if defined(WIN32)
2009     if (!DeleteFile(filename.c_str())) {
2010     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     throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2015     }
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 schoenebeck 2683 #else
2021 persson 3470 throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2022 schoenebeck 2683 #endif
2023 persson 3470 }
2024     }
2025     } else {
2026     gig->Save(filename, &progress);
2027 schoenebeck 2683 }
2028     }
2029    
2030    
2031     ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2032 schoenebeck 1225 : Gtk::Dialog(title, parent, true)
2033     {
2034 schoenebeck 3364 #if USE_GTKMM_BOX
2035     get_content_area()->pack_start(progressBar);
2036     #else
2037 schoenebeck 1225 get_vbox()->pack_start(progressBar);
2038 schoenebeck 3364 #endif
2039     #if HAS_GTKMM_SHOW_ALL_CHILDREN
2040 schoenebeck 1225 show_all_children();
2041 schoenebeck 3364 #endif
2042 schoenebeck 2683 resize(600,50);
2043 schoenebeck 1225 }
2044    
2045     // Clear all GUI elements / controls. This method is typically called
2046     // before a new .gig file is to be created or to be loaded.
2047     void MainWindow::__clear() {
2048     // forget all samples that ought to be imported
2049     m_SampleImportQueue.clear();
2050     // clear the samples and instruments tree views
2051     m_refTreeModel->clear();
2052     m_refSamplesTreeModel->clear();
2053 schoenebeck 2615 m_refScriptsTreeModel->clear();
2054 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2055 persson 2442 // remove all entries from "Instrument" menu
2056     while (!instrument_menu->get_children().empty()) {
2057     remove_instrument_from_menu(0);
2058     }
2059 schoenebeck 3364 #endif
2060 schoenebeck 1225 // free libgig's gig::File instance
2061 schoenebeck 1382 if (file && !file_is_shared) delete file;
2062     file = NULL;
2063 schoenebeck 1411 set_file_is_shared(false);
2064 schoenebeck 1225 }
2065    
2066 schoenebeck 2553 void MainWindow::__refreshEntireGUI() {
2067     // clear the samples and instruments tree views
2068     m_refTreeModel->clear();
2069     m_refSamplesTreeModel->clear();
2070 schoenebeck 2615 m_refScriptsTreeModel->clear();
2071 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2072 schoenebeck 2553 // remove all entries from "Instrument" menu
2073     while (!instrument_menu->get_children().empty()) {
2074     remove_instrument_from_menu(0);
2075     }
2076 schoenebeck 3364 #endif
2077 schoenebeck 2553
2078     if (!this->file) return;
2079    
2080     load_gig(
2081     this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
2082     );
2083     }
2084    
2085 schoenebeck 1225 void MainWindow::on_action_file_new()
2086     {
2087 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2088 persson 1261
2089 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2090    
2091 schoenebeck 1225 // clear all GUI elements
2092     __clear();
2093     // create a new .gig file (virtually yet)
2094     gig::File* pFile = new gig::File;
2095     // already add one new instrument by default
2096     gig::Instrument* pInstrument = pFile->AddInstrument();
2097 persson 2446 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
2098 schoenebeck 1225 // update GUI with that new gig::File
2099 persson 1261 load_gig(pFile, 0 /*no file name yet*/);
2100 schoenebeck 1225 }
2101    
2102 persson 1261 bool MainWindow::close_confirmation_dialog()
2103     {
2104     gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
2105     Glib::filename_display_basename(filename).c_str());
2106     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2107     g_free(msg);
2108     dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
2109     dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
2110 schoenebeck 3364 #if HAS_GTKMM_STOCK
2111 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2112     dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
2113 schoenebeck 3364 #else
2114     dialog.add_button(_("_OK"), Gtk::RESPONSE_OK);
2115     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2116     #endif
2117 persson 1261 dialog.set_default_response(Gtk::RESPONSE_YES);
2118     int response = dialog.run();
2119 persson 1303 dialog.hide();
2120 schoenebeck 2683
2121 schoenebeck 2694 // user decided to exit app without saving
2122     if (response == Gtk::RESPONSE_NO) return true;
2123    
2124     // user cancelled dialog, thus don't close app
2125     if (response == Gtk::RESPONSE_CANCEL) return false;
2126    
2127 schoenebeck 2683 // TODO: the following return valid is disabled and hard coded instead for
2128     // now, due to the fact that saving with progress bar is now implemented
2129     // asynchronously, as a result the app does not close automatically anymore
2130     // after saving the file has completed
2131     //
2132     // if (response == Gtk::RESPONSE_YES) return file_save();
2133     // return response != Gtk::RESPONSE_CANCEL;
2134     //
2135     if (response == Gtk::RESPONSE_YES) file_save();
2136     return false; // always prevent closing the app for now (see comment above)
2137 persson 1261 }
2138    
2139 schoenebeck 1382 bool MainWindow::leaving_shared_mode_dialog() {
2140     Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
2141     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
2142     dialog.set_secondary_text(
2143     _("If you proceed to work on another instrument file, it won't be "
2144     "used by the sampler until you tell the sampler explicitly to "
2145 persson 2151 "load it."));
2146 schoenebeck 1382 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
2147 schoenebeck 3364 #if HAS_GTKMM_STOCK
2148 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2149 schoenebeck 3364 #else
2150     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2151     #endif
2152 schoenebeck 1382 dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2153     int response = dialog.run();
2154     dialog.hide();
2155     return response == Gtk::RESPONSE_YES;
2156     }
2157    
2158 schoenebeck 1225 void MainWindow::on_action_file_open()
2159     {
2160 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
2161 persson 1261
2162 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
2163    
2164 schoenebeck 1225 Gtk::FileChooserDialog dialog(*this, _("Open file"));
2165 schoenebeck 3364 #if HAS_GTKMM_STOCK
2166 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2167     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2168 schoenebeck 3364 #else
2169     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2170     dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
2171     #endif
2172 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
2173 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2174 schoenebeck 1225 Gtk::FileFilter filter;
2175     filter.add_pattern("*.gig");
2176 persson 2169 #else
2177     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2178     filter->add_pattern("*.gig");
2179     #endif
2180 schoenebeck 1225 dialog.set_filter(filter);
2181 persson 1725 if (current_gig_dir != "") {
2182     dialog.set_current_folder(current_gig_dir);
2183 persson 1261 }
2184 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
2185 persson 1261 std::string filename = dialog.get_filename();
2186     printf("filename=%s\n", filename.c_str());
2187 persson 2841 printf("on_action_file_open self=%p\n",
2188     static_cast<void*>(Glib::Threads::Thread::self()));
2189 persson 1261 load_file(filename.c_str());
2190 persson 1725 current_gig_dir = Glib::path_get_dirname(filename);
2191 schoenebeck 1225 }
2192     }
2193    
2194     void MainWindow::load_file(const char* name)
2195     {
2196 persson 1303 __clear();
2197 schoenebeck 2683
2198     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2199     _("Loading") + Glib::ustring(" '") +
2200     Glib::filename_display_basename(name) + "' ...",
2201     *this
2202     );
2203 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2204 schoenebeck 2683 progress_dialog->show_all();
2205 schoenebeck 3364 #endif
2206 schoenebeck 2683 loader = new Loader(name); //FIXME: memory leak!
2207 schoenebeck 1225 loader->signal_progress().connect(
2208     sigc::mem_fun(*this, &MainWindow::on_loader_progress));
2209     loader->signal_finished().connect(
2210     sigc::mem_fun(*this, &MainWindow::on_loader_finished));
2211 schoenebeck 2683 loader->signal_error().connect(
2212     sigc::mem_fun(*this, &MainWindow::on_loader_error));
2213 schoenebeck 1225 loader->launch();
2214     }
2215    
2216     void MainWindow::load_instrument(gig::Instrument* instr) {
2217     if (!instr) {
2218     Glib::ustring txt = "Provided instrument is NULL!\n";
2219     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2220     msg.run();
2221     Gtk::Main::quit();
2222     }
2223 schoenebeck 1328 // clear all GUI elements
2224     __clear();
2225     // load the instrument
2226 schoenebeck 1225 gig::File* pFile = (gig::File*) instr->GetParent();
2227 schoenebeck 1382 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
2228 schoenebeck 2664 // automatically select the given instrument
2229     int i = 0;
2230     for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
2231     instrument = pFile->GetNextInstrument(), ++i)
2232     {
2233     if (instrument == instr) {
2234     // select item in "instruments" tree view
2235     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
2236     // make sure the selected item in the "instruments" tree view is
2237     // visible (scroll to it)
2238     m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
2239 schoenebeck 3364 #if !USE_GTKMM_BUILDER
2240 schoenebeck 2664 // select item in instrument menu
2241     {
2242     const std::vector<Gtk::Widget*> children =
2243     instrument_menu->get_children();
2244     static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
2245     }
2246 schoenebeck 3364 #endif
2247 schoenebeck 2664 // update region chooser and dimension region chooser
2248     m_RegionChooser.set_instrument(instr);
2249     break;
2250     }
2251     }
2252 schoenebeck 1225 }
2253    
2254     void MainWindow::on_loader_progress()
2255     {
2256 schoenebeck 2683 progress_dialog->set_fraction(loader->get_progress());
2257 schoenebeck 1225 }
2258    
2259     void MainWindow::on_loader_finished()
2260     {
2261     printf("Loader finished!\n");
2262 persson 2841 printf("on_loader_finished self=%p\n",
2263     static_cast<void*>(Glib::Threads::Thread::self()));
2264 schoenebeck 2683 load_gig(loader->gig, loader->filename.c_str());
2265     progress_dialog->hide();
2266 schoenebeck 1225 }
2267    
2268 schoenebeck 2683 void MainWindow::on_loader_error()
2269     {
2270     Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2271     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2272     msg.run();
2273     progress_dialog->hide();
2274     }
2275    
2276 schoenebeck 1225 void MainWindow::on_action_file_save()
2277     {
2278 persson 1261 file_save();
2279     }
2280    
2281 persson 1303 bool MainWindow::check_if_savable()
2282     {
2283     if (!file) return false;
2284    
2285     if (!file->GetFirstSample()) {
2286     Gtk::MessageDialog(*this, _("The file could not be saved "
2287     "because it contains no samples"),
2288     false, Gtk::MESSAGE_ERROR).run();
2289     return false;
2290     }
2291    
2292     for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
2293     instrument = file->GetNextInstrument()) {
2294     if (!instrument->GetFirstRegion()) {
2295     Gtk::MessageDialog(*this, _("The file could not be saved "
2296     "because there are instruments "
2297     "that have no regions"),
2298     false, Gtk::MESSAGE_ERROR).run();
2299     return false;
2300     }
2301     }
2302     return true;
2303     }
2304    
2305 persson 1261 bool MainWindow::file_save()
2306     {
2307 persson 1303 if (!check_if_savable()) return false;
2308 schoenebeck 1382 if (!file_is_shared && !file_has_name) return file_save_as();
2309 persson 1261
2310 schoenebeck 1225 std::cout << "Saving file\n" << std::flush;
2311 schoenebeck 1322 file_structure_to_be_changed_signal.emit(this->file);
2312 schoenebeck 2683
2313     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2314     _("Saving") + Glib::ustring(" '") +
2315     Glib::filename_display_basename(this->filename) + "' ...",
2316     *this
2317     );
2318 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2319 schoenebeck 2683 progress_dialog->show_all();
2320 schoenebeck 3364 #endif
2321 schoenebeck 2683 saver = new Saver(this->file); //FIXME: memory leak!
2322     saver->signal_progress().connect(
2323     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2324     saver->signal_finished().connect(
2325     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2326     saver->signal_error().connect(
2327     sigc::mem_fun(*this, &MainWindow::on_saver_error));
2328     saver->launch();
2329    
2330     return true;
2331     }
2332    
2333     void MainWindow::on_saver_progress()
2334     {
2335     progress_dialog->set_fraction(saver->get_progress());
2336     }
2337    
2338     void MainWindow::on_saver_error()
2339     {
2340     file_structure_changed_signal.emit(this->file);
2341     Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2342     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2343     msg.run();
2344     }
2345    
2346     void MainWindow::on_saver_finished()
2347     {
2348     this->file = saver->gig;
2349     this->filename = saver->filename;
2350     current_gig_dir = Glib::path_get_dirname(filename);
2351     set_title(Glib::filename_display_basename(filename));
2352     file_has_name = true;
2353     file_is_changed = false;
2354     std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush;
2355 schoenebeck 1225 __import_queued_samples();
2356 schoenebeck 2683 std::cout << "Importing queued samples done.\n" << std::flush;
2357    
2358 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
2359 schoenebeck 2683
2360 schoenebeck 2697 __refreshEntireGUI();
2361 schoenebeck 2683 progress_dialog->hide();
2362 schoenebeck 1225 }
2363    
2364     void MainWindow::on_action_file_save_as()
2365     {
2366 persson 1303 if (!check_if_savable()) return;
2367 persson 1261 file_save_as();
2368     }
2369    
2370     bool MainWindow::file_save_as()
2371     {
2372 schoenebeck 3158 Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
2373 schoenebeck 3364 #if HAS_GTKMM_STOCK
2374 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2375     dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
2376 schoenebeck 3364 #else
2377     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
2378     dialog.add_button(_("_Save"), Gtk::RESPONSE_OK);
2379     #endif
2380 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
2381 persson 2151 dialog.set_do_overwrite_confirmation();
2382 persson 1261
2383 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2384 schoenebeck 1225 Gtk::FileFilter filter;
2385     filter.add_pattern("*.gig");
2386 persson 2169 #else
2387     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2388     filter->add_pattern("*.gig");
2389     #endif
2390 schoenebeck 1225 dialog.set_filter(filter);
2391 persson 1261
2392 schoenebeck 1679 // set initial dir and filename of the Save As dialog
2393     // and prepare that initial filename as a copy of the gig
2394     {
2395     std::string basename = Glib::path_get_basename(filename);
2396     std::string dir = Glib::path_get_dirname(filename);
2397 persson 1831 basename = std::string(_("copy_of_")) + basename;
2398 schoenebeck 1679 Glib::ustring copyFileName = Glib::build_filename(dir, basename);
2399     if (Glib::path_is_absolute(filename)) {
2400     dialog.set_filename(copyFileName);
2401     } else {
2402 persson 1725 if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
2403 schoenebeck 1679 }
2404     dialog.set_current_name(Glib::filename_display_basename(copyFileName));
2405 persson 1261 }
2406    
2407 schoenebeck 1679 // show warning in the dialog
2408 schoenebeck 3364 HBox descriptionArea;
2409 schoenebeck 1679 descriptionArea.set_spacing(15);
2410 persson 2845 Gtk::Image warningIcon;
2411     warningIcon.set_from_icon_name("dialog-warning",
2412     Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2413 schoenebeck 1679 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2414 persson 2344 #if GTKMM_MAJOR_VERSION < 3
2415 persson 1799 view::WrapLabel description;
2416 persson 2344 #else
2417     Gtk::Label description;
2418     description.set_line_wrap();
2419     #endif
2420 schoenebeck 1679 description.set_markup(
2421     _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
2422     "<span style=\"italic\">\"Save\"</span> dialog instead of "
2423     "<span style=\"italic\">\"Save As...\"</span> if you want to save "
2424     "to the same .gig file. Using "
2425     "<span style=\"italic\">\"Save As...\"</span> for writing to the "
2426     "same .gig file will end up in corrupted sample wave data!\n")
2427     );
2428 persson 1799 descriptionArea.pack_start(description);
2429 schoenebeck 3364 #if USE_GTKMM_BOX
2430     dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2431     #else
2432 schoenebeck 1679 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2433 schoenebeck 3364 #endif
2434     #if HAS_GTKMM_SHOW_ALL_CHILDREN
2435 persson 1799 descriptionArea.show_all();
2436 schoenebeck 3364 #endif
2437 schoenebeck 1679
2438 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
2439 schoenebeck 2683 std::string filename = dialog.get_filename();
2440     if (!Glib::str_has_suffix(filename, ".gig")) {
2441     filename += ".gig";
2442 schoenebeck 1225 }
2443 schoenebeck 2683 printf("filename=%s\n", filename.c_str());
2444    
2445     progress_dialog = new ProgressDialog( //FIXME: memory leak!
2446     _("Saving") + Glib::ustring(" '") +
2447     Glib::filename_display_basename(filename) + "' ...",
2448     *this
2449     );
2450 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2451 schoenebeck 2683 progress_dialog->show_all();
2452 schoenebeck 3364 #endif
2453 schoenebeck 2683
2454     saver = new Saver(file, filename); //FIXME: memory leak!
2455     saver->signal_progress().connect(
2456     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
2457     saver->signal_finished().connect(
2458     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
2459     saver->signal_error().connect(
2460     sigc::mem_fun(*this, &MainWindow::on_saver_error));
2461     saver->launch();
2462    
2463 persson 1261 return true;
2464 schoenebeck 1225 }
2465 persson 1261 return false;
2466 schoenebeck 1225 }
2467    
2468     // actually write the sample(s)' data to the gig file
2469     void MainWindow::__import_queued_samples() {
2470     std::cout << "Starting sample import\n" << std::flush;
2471     Glib::ustring error_files;
2472 persson 2841 printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
2473 schoenebeck 3116 for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2474 schoenebeck 1225 iter != m_SampleImportQueue.end(); ) {
2475 schoenebeck 3116 printf("Importing sample %s\n",iter->second.sample_path.c_str());
2476 schoenebeck 1225 SF_INFO info;
2477     info.format = 0;
2478 schoenebeck 3116 SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
2479 persson 2398 sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
2480 schoenebeck 1225 try {
2481 persson 1831 if (!hFile) throw std::string(_("could not open file"));
2482 schoenebeck 1225 // determine sample's bit depth
2483     int bitdepth;
2484     switch (info.format & 0xff) {
2485     case SF_FORMAT_PCM_S8:
2486     case SF_FORMAT_PCM_16:
2487 persson 1265 case SF_FORMAT_PCM_U8:
2488 schoenebeck 1225 bitdepth = 16;
2489     break;
2490     case SF_FORMAT_PCM_24:
2491     case SF_FORMAT_PCM_32:
2492     case SF_FORMAT_FLOAT:
2493     case SF_FORMAT_DOUBLE:
2494 persson 1265 bitdepth = 24;
2495 schoenebeck 1225 break;
2496     default:
2497     sf_close(hFile); // close sound file
2498 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
2499 schoenebeck 1225 }
2500 persson 1265
2501 schoenebeck 3116 // reset write position for sample
2502     iter->first->SetPos(0);
2503    
2504 persson 1265 const int bufsize = 10000;
2505 schoenebeck 1225 switch (bitdepth) {
2506 persson 1265 case 16: {
2507     short* buffer = new short[bufsize * info.channels];
2508     sf_count_t cnt = info.frames;
2509     while (cnt) {
2510     // libsndfile does the conversion for us (if needed)
2511     int n = sf_readf_short(hFile, buffer, bufsize);
2512     // write from buffer directly (physically) into .gig file
2513 schoenebeck 3116 iter->first->Write(buffer, n);
2514 persson 1265 cnt -= n;
2515     }
2516     delete[] buffer;
2517 schoenebeck 1225 break;
2518 persson 1265 }
2519     case 24: {
2520     int* srcbuf = new int[bufsize * info.channels];
2521     uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
2522     sf_count_t cnt = info.frames;
2523     while (cnt) {
2524     // libsndfile returns 32 bits, convert to 24
2525     int n = sf_readf_int(hFile, srcbuf, bufsize);
2526     int j = 0;
2527     for (int i = 0 ; i < n * info.channels ; i++) {
2528     dstbuf[j++] = srcbuf[i] >> 8;
2529     dstbuf[j++] = srcbuf[i] >> 16;
2530     dstbuf[j++] = srcbuf[i] >> 24;
2531     }
2532     // write from buffer directly (physically) into .gig file
2533 schoenebeck 3116 iter->first->Write(dstbuf, n);
2534 persson 1265 cnt -= n;
2535     }
2536     delete[] srcbuf;
2537     delete[] dstbuf;
2538 schoenebeck 1225 break;
2539 persson 1265 }
2540 schoenebeck 1225 }
2541     // cleanup
2542     sf_close(hFile);
2543 schoenebeck 1853 // let the sampler re-cache the sample if needed
2544 schoenebeck 3116 sample_changed_signal.emit(iter->first);
2545 schoenebeck 1225 // on success we remove the sample from the import queue,
2546     // otherwise keep it, maybe it works the next time ?
2547 schoenebeck 3116 std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
2548 schoenebeck 1225 ++iter;
2549     m_SampleImportQueue.erase(cur);
2550     } catch (std::string what) {
2551     // remember the files that made trouble (and their cause)
2552 persson 2442 if (!error_files.empty()) error_files += "\n";
2553 schoenebeck 3116 error_files += iter->second.sample_path += " (" + what + ")";
2554 schoenebeck 1225 ++iter;
2555     }
2556     }
2557     // show error message box when some sample(s) could not be imported
2558 persson 2442 if (!error_files.empty()) {
2559 schoenebeck 1382 Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
2560 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2561     msg.run();
2562     }
2563     }
2564    
2565     void MainWindow::on_action_file_properties()
2566     {
2567     propDialog.show();
2568     propDialog.deiconify();
2569     }
2570    
2571 schoenebeck 2541 void MainWindow::on_action_warn_user_on_extensions() {
2572     Settings::singleton()->warnUserOnExtensions =
2573     !Settings::singleton()->warnUserOnExtensions;
2574     }
2575    
2576 schoenebeck 3409 void MainWindow::on_action_show_tooltips() {
2577     Settings::singleton()->showTooltips =
2578     !Settings::singleton()->showTooltips;
2579    
2580     on_show_tooltips_changed();
2581     }
2582    
2583     void MainWindow::on_show_tooltips_changed() {
2584     const bool b = Settings::singleton()->showTooltips;
2585    
2586     dimreg_label.set_has_tooltip(b);
2587     dimreg_all_regions.set_has_tooltip(b);
2588     dimreg_all_dimregs.set_has_tooltip(b);
2589     dimreg_stereo.set_has_tooltip(b);
2590 schoenebeck 3418
2591     // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2592     //m_TreeView.set_has_tooltip(b);
2593    
2594 schoenebeck 3409 m_TreeViewSamples.set_has_tooltip(b);
2595     m_TreeViewScripts.set_has_tooltip(b);
2596    
2597     set_has_tooltip(b);
2598     }
2599    
2600 schoenebeck 2689 void MainWindow::on_action_sync_sampler_instrument_selection() {
2601     Settings::singleton()->syncSamplerInstrumentSelection =
2602     !Settings::singleton()->syncSamplerInstrumentSelection;
2603     }
2604    
2605 schoenebeck 2773 void MainWindow::on_action_move_root_note_with_region_moved() {
2606     Settings::singleton()->moveRootNoteWithRegionMoved =
2607     !Settings::singleton()->moveRootNoteWithRegionMoved;
2608     }
2609    
2610 schoenebeck 1225 void MainWindow::on_action_help_about()
2611     {
2612     Gtk::AboutDialog dialog;
2613 persson 1959 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
2614     dialog.set_program_name("Gigedit");
2615     #else
2616     dialog.set_name("Gigedit");
2617     #endif
2618 schoenebeck 1225 dialog.set_version(VERSION);
2619 persson 3456 dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2620 schoenebeck 2476 const std::string sComment =
2621     _("Built " __DATE__ "\nUsing ") +
2622     ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
2623     _(
2624     "Gigedit is released under the GNU General Public License.\n"
2625     "\n"
2626 schoenebeck 2627 "This program is distributed WITHOUT ANY WARRANTY; So better "
2627     "backup your Gigasampler/GigaStudio files before editing them with "
2628 schoenebeck 2476 "this application.\n"
2629     "\n"
2630     "Please report bugs to: http://bugs.linuxsampler.org"
2631     );
2632     dialog.set_comments(sComment.c_str());
2633 schoenebeck 1436 dialog.set_website("http://www.linuxsampler.org");
2634     dialog.set_website_label("http://www.linuxsampler.org");
2635 schoenebeck 3225 dialog.set_position(Gtk::WIN_POS_CENTER);
2636 schoenebeck 1225 dialog.run();
2637     }
2638    
2639     PropDialog::PropDialog()
2640 schoenebeck 2560 : eFileFormat(_("File Format")),
2641     eName(_("Name")),
2642 persson 1831 eCreationDate(_("Creation date")),
2643     eComments(_("Comments")),
2644     eProduct(_("Product")),
2645     eCopyright(_("Copyright")),
2646     eArtists(_("Artists")),
2647     eGenre(_("Genre")),
2648     eKeywords(_("Keywords")),
2649     eEngineer(_("Engineer")),
2650     eTechnician(_("Technician")),
2651     eSoftware(_("Software")),
2652     eMedium(_("Medium")),
2653     eSource(_("Source")),
2654     eSourceForm(_("Source form")),
2655     eCommissioned(_("Commissioned")),
2656     eSubject(_("Subject")),
2657 schoenebeck 3364 #if HAS_GTKMM_STOCK
2658 schoenebeck 3158 quitButton(Gtk::Stock::CLOSE),
2659 schoenebeck 3364 #else
2660     quitButton(_("_Close")),
2661     #endif
2662 schoenebeck 2560 table(2, 1),
2663     m_file(NULL)
2664 schoenebeck 1225 {
2665 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
2666     set_default_size(470, 390);
2667     set_position(Gtk::WIN_POS_MOUSE);
2668     }
2669    
2670 persson 1831 set_title(_("File Properties"));
2671 persson 1582 eName.set_width_chars(50);
2672    
2673 persson 3469 connect(eFileFormat, &PropDialog::set_FileFormat);
2674 persson 1582 connect(eName, &DLS::Info::Name);
2675     connect(eCreationDate, &DLS::Info::CreationDate);
2676     connect(eComments, &DLS::Info::Comments);
2677     connect(eProduct, &DLS::Info::Product);
2678     connect(eCopyright, &DLS::Info::Copyright);
2679     connect(eArtists, &DLS::Info::Artists);
2680     connect(eGenre, &DLS::Info::Genre);
2681     connect(eKeywords, &DLS::Info::Keywords);
2682     connect(eEngineer, &DLS::Info::Engineer);
2683     connect(eTechnician, &DLS::Info::Technician);
2684     connect(eSoftware, &DLS::Info::Software);
2685     connect(eMedium, &DLS::Info::Medium);
2686     connect(eSource, &DLS::Info::Source);
2687     connect(eSourceForm, &DLS::Info::SourceForm);
2688     connect(eCommissioned, &DLS::Info::Commissioned);
2689     connect(eSubject, &DLS::Info::Subject);
2690    
2691 schoenebeck 2560 table.add(eFileFormat);
2692 persson 1582 table.add(eName);
2693     table.add(eCreationDate);
2694     table.add(eComments);
2695     table.add(eProduct);
2696     table.add(eCopyright);
2697     table.add(eArtists);
2698     table.add(eGenre);
2699     table.add(eKeywords);
2700     table.add(eEngineer);
2701     table.add(eTechnician);
2702     table.add(eSoftware);
2703     table.add(eMedium);
2704     table.add(eSource);
2705     table.add(eSourceForm);
2706     table.add(eCommissioned);
2707     table.add(eSubject);
2708    
2709 schoenebeck 3364 #if USE_GTKMM_GRID
2710     table.set_column_spacing(5);
2711     #else
2712 schoenebeck 1225 table.set_col_spacings(5);
2713 schoenebeck 3364 #endif
2714    
2715 persson 1582 add(vbox);
2716 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2717 schoenebeck 3364 table.set_margin(5);
2718     #else
2719 persson 1582 table.set_border_width(5);
2720 schoenebeck 3364 #endif
2721 persson 1582 vbox.add(table);
2722     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2723     buttonBox.set_layout(Gtk::BUTTONBOX_END);
2724 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2725 schoenebeck 3364 buttonBox.set_margin(5);
2726     #else
2727 persson 1582 buttonBox.set_border_width(5);
2728 schoenebeck 3364 #endif
2729 persson 1582 buttonBox.show();
2730     buttonBox.pack_start(quitButton);
2731 persson 2151 quitButton.set_can_default();
2732 persson 1582 quitButton.grab_focus();
2733     quitButton.signal_clicked().connect(
2734     sigc::mem_fun(*this, &PropDialog::hide));
2735 schoenebeck 1225
2736 persson 1582 quitButton.show();
2737     vbox.show();
2738 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2739 schoenebeck 1225 show_all_children();
2740 schoenebeck 3364 #endif
2741 schoenebeck 1225 }
2742    
2743 schoenebeck 2560 void PropDialog::set_file(gig::File* file)
2744     {
2745     m_file = file;
2746 persson 3469 update(file->pInfo);
2747 schoenebeck 2560
2748     // update file format version combo box
2749     const std::string sGiga = "Gigasampler/GigaStudio v";
2750     const int major = file->pVersion->major;
2751     std::vector<std::string> txts;
2752     std::vector<int> values;
2753     txts.push_back(sGiga + "2"); values.push_back(2);
2754 schoenebeck 3441 txts.push_back(sGiga + "3"); values.push_back(3);
2755     txts.push_back(sGiga + "4"); values.push_back(4);
2756     if (major < 2 || major > 4) {
2757 schoenebeck 2560 txts.push_back(sGiga + ToString(major)); values.push_back(major);
2758     }
2759     std::vector<const char*> texts;
2760     for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2761 persson 2579 texts.push_back(NULL); values.push_back(0);
2762 persson 3469
2763     update_model++;
2764 schoenebeck 2560 eFileFormat.set_choices(&texts[0], &values[0]);
2765     eFileFormat.set_value(major);
2766 persson 3469 update_model--;
2767 schoenebeck 2560 }
2768    
2769 persson 3469 void PropDialog::set_FileFormat(int value)
2770 schoenebeck 1225 {
2771 persson 3469 m_file->pVersion->major = value;
2772 schoenebeck 1225 }
2773    
2774 persson 1582
2775 persson 2445 void InstrumentProps::set_Name(const gig::String& name)
2776     {
2777     m->pInfo->Name = name;
2778     }
2779    
2780     void InstrumentProps::update_name()
2781     {
2782     update_model++;
2783     eName.set_value(m->pInfo->Name);
2784     update_model--;
2785     }
2786    
2787 persson 1460 void InstrumentProps::set_IsDrum(bool value)
2788     {
2789 persson 2423 m->IsDrum = value;
2790 persson 1460 }
2791    
2792     void InstrumentProps::set_MIDIBank(uint16_t value)
2793     {
2794 persson 2423 m->MIDIBank = value;
2795 persson 1460 }
2796    
2797     void InstrumentProps::set_MIDIProgram(uint32_t value)
2798     {
2799 persson 2423 m->MIDIProgram = value;
2800 persson 1460 }
2801    
2802 persson 2423 InstrumentProps::InstrumentProps() :
2803 schoenebeck 3364 #if HAS_GTKMM_STOCK
2804 schoenebeck 3158 quitButton(Gtk::Stock::CLOSE),
2805 schoenebeck 3364 #else
2806     quitButton(_("_Close")),
2807     #endif
2808 persson 2423 table(2,1),
2809     eName(_("Name")),
2810     eIsDrum(_("Is drum")),
2811     eMIDIBank(_("MIDI bank"), 0, 16383),
2812     eMIDIProgram(_("MIDI program")),
2813     eAttenuation(_("Attenuation"), 0, 96, 0, 1),
2814     eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
2815     eEffectSend(_("Effect send"), 0, 65535),
2816     eFineTune(_("Fine tune"), -8400, 8400),
2817 schoenebeck 3363 ePitchbendRange(_("Pitchbend range"), 0, 48),
2818 persson 2423 ePianoReleaseMode(_("Piano release mode")),
2819     eDimensionKeyRangeLow(_("Keyswitching range low")),
2820     eDimensionKeyRangeHigh(_("Keyswitching range high"))
2821 persson 1460 {
2822 schoenebeck 3225 if (!Settings::singleton()->autoRestoreWindowDimension) {
2823     //set_default_size(470, 390);
2824     set_position(Gtk::WIN_POS_MOUSE);
2825     }
2826    
2827 persson 1831 set_title(_("Instrument Properties"));
2828 schoenebeck 1225
2829 schoenebeck 1656 eDimensionKeyRangeLow.set_tip(
2830     _("start of the keyboard area which should switch the "
2831     "\"keyswitching\" dimension")
2832     );
2833     eDimensionKeyRangeHigh.set_tip(
2834     _("end of the keyboard area which should switch the "
2835     "\"keyswitching\" dimension")
2836     );
2837    
2838 persson 2445 connect(eName, &InstrumentProps::set_Name);
2839 persson 1460 connect(eIsDrum, &InstrumentProps::set_IsDrum);
2840     connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2841     connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
2842     connect(eAttenuation, &gig::Instrument::Attenuation);
2843     connect(eGainPlus6, &gig::Instrument::Attenuation);
2844     connect(eEffectSend, &gig::Instrument::EffectSend);
2845     connect(eFineTune, &gig::Instrument::FineTune);
2846     connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
2847     connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
2848 persson 2423 connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
2849     &gig::Instrument::DimensionKeyRange);
2850 persson 1460
2851 persson 2445 eName.signal_value_changed().connect(sig_name_changed.make_slot());
2852    
2853 schoenebeck 3364 #if USE_GTKMM_GRID
2854     table.set_column_spacing(5);
2855     #else
2856 schoenebeck 1225 table.set_col_spacings(5);
2857 schoenebeck 3364 #endif
2858 schoenebeck 1225
2859 persson 1582 table.add(eName);
2860     table.add(eIsDrum);
2861     table.add(eMIDIBank);
2862     table.add(eMIDIProgram);
2863     table.add(eAttenuation);
2864     table.add(eGainPlus6);
2865     table.add(eEffectSend);
2866     table.add(eFineTune);
2867     table.add(ePitchbendRange);
2868     table.add(ePianoReleaseMode);
2869     table.add(eDimensionKeyRangeLow);
2870     table.add(eDimensionKeyRangeHigh);
2871 schoenebeck 1225
2872     add(vbox);
2873 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2874 schoenebeck 3364 table.set_margin(5);
2875     #else
2876 schoenebeck 1225 table.set_border_width(5);
2877 schoenebeck 3364 #endif
2878 schoenebeck 1225 vbox.pack_start(table);
2879     table.show();
2880     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2881     buttonBox.set_layout(Gtk::BUTTONBOX_END);
2882 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2883 schoenebeck 3364 buttonBox.set_margin(5);
2884     #else
2885 schoenebeck 1225 buttonBox.set_border_width(5);
2886 schoenebeck 3364 #endif
2887 schoenebeck 1225 buttonBox.show();
2888     buttonBox.pack_start(quitButton);
2889 persson 2151 quitButton.set_can_default();
2890 schoenebeck 1225 quitButton.grab_focus();
2891    
2892     quitButton.signal_clicked().connect(
2893     sigc::mem_fun(*this, &InstrumentProps::hide));
2894    
2895     quitButton.show();
2896     vbox.show();
2897 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
2898 schoenebeck 1225 show_all_children();
2899 schoenebeck 3364 #endif
2900 schoenebeck 1225 }
2901    
2902     void InstrumentProps::set_instrument(gig::Instrument* instrument)
2903     {
2904 persson 2423 update(instrument);
2905 persson 1460
2906     update_model++;
2907 persson 2445 eName.set_value(instrument->pInfo->Name);
2908 persson 1460 eIsDrum.set_value(instrument->IsDrum);
2909     eMIDIBank.set_value(instrument->MIDIBank);
2910     eMIDIProgram.set_value(instrument->MIDIProgram);
2911     update_model--;
2912 schoenebeck 1225 }
2913    
2914    
2915 persson 1261 void MainWindow::file_changed()
2916     {
2917     if (file && !file_is_changed) {
2918     set_title("*" + get_title());
2919     file_is_changed = true;
2920 schoenebeck 1225 }
2921 persson 1261 }
2922 schoenebeck 1225
2923 schoenebeck 2621 void MainWindow::updateSampleRefCountMap(gig::File* gig) {
2924     sample_ref_count.clear();
2925    
2926     if (!gig) return;
2927    
2928     for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
2929     instrument = gig->GetNextInstrument())
2930     {
2931     for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2932     rgn = instrument->GetNextRegion())
2933     {
2934     for (int i = 0; i < 256; ++i) {
2935     if (!rgn->pDimensionRegions[i]) continue;
2936     if (rgn->pDimensionRegions[i]->pSample) {
2937     sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
2938     }
2939     }
2940     }
2941     }
2942     }
2943    
2944 schoenebeck 3418 bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
2945     Gtk::TreeModel::iterator iter;
2946 persson 3460 if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
2947     return false;
2948     }
2949 schoenebeck 3418 Gtk::TreeModel::Path path(iter);
2950     Gtk::TreeModel::Row row = *iter;
2951     Gtk::TreeViewColumn* pointedColumn = NULL;
2952     // resolve the precise table column the mouse points to
2953     {
2954     Gtk::TreeModel::Path path; // unused
2955     int cellX, cellY; // unused
2956     m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
2957     }
2958     Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
2959     if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
2960     // show the script(s) assigned to the hovered instrument as tooltip
2961     tooltip->set_markup( row[m_Columns.m_col_tooltip] );
2962     m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
2963     } else {
2964     // if beginners' tooltips is disabled then don't show the following one
2965     if (!Settings::singleton()->showTooltips)
2966     return false;
2967     // yeah, a beginners tooltip
2968     tooltip->set_text(_(
2969     "Right click here for actions on instruments & MIDI Rules. "
2970     "Drag & drop to change the order of instruments."
2971     ));
2972     m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
2973     }
2974     return true;
2975     }
2976    
2977     static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
2978     Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2979     const int iScriptSlots = instrument->ScriptSlotCount();
2980 persson 3460 Glib::ustring tooltip = "<u>(" + ToString(index) + ") ���" + name + "���</u>\n\n";
2981 schoenebeck 3418 if (!iScriptSlots)
2982     tooltip += "<span foreground='red'><i>No script assigned</i></span>";
2983     else {
2984     for (int i = 0; i < iScriptSlots; ++i) {
2985 persson 3460 tooltip += "��� " + ToString(i+1) + ". Script: ���<span foreground='#46DEFF'><b>" +
2986 schoenebeck 3418 instrument->GetScriptOfSlot(i)->Name + "</b></span>���";
2987     if (i + 1 < iScriptSlots) tooltip += "\n\n";
2988     }
2989     }
2990     return tooltip;
2991     }
2992    
2993 schoenebeck 1382 void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
2994 persson 1261 {
2995     file = 0;
2996 schoenebeck 1411 set_file_is_shared(isSharedInstrument);
2997 persson 1261
2998 schoenebeck 2772 this->filename =
2999     (filename && strlen(filename) > 0) ?
3000     filename : (!gig->GetFileName().empty()) ?
3001     gig->GetFileName() : _("Unsaved Gig File");
3002 persson 1261 set_title(Glib::filename_display_basename(this->filename));
3003     file_has_name = filename;
3004     file_is_changed = false;
3005    
3006 schoenebeck 2560 propDialog.set_file(gig);
3007 schoenebeck 1225
3008 persson 2442 instrument_name_connection.block();
3009 schoenebeck 2994 int index = 0;
3010 schoenebeck 1225 for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
3011 schoenebeck 2994 instrument = gig->GetNextInstrument(), ++index) {
3012 persson 2446 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3013 schoenebeck 3197 const int iScriptSlots = instrument->ScriptSlotCount();
3014 persson 2442
3015 schoenebeck 1225 Gtk::TreeModel::iterator iter = m_refTreeModel->append();
3016     Gtk::TreeModel::Row row = *iter;
3017 schoenebeck 2994 row[m_Columns.m_col_nr] = index;
3018 persson 2442 row[m_Columns.m_col_name] = name;
3019 schoenebeck 1225 row[m_Columns.m_col_instr] = instrument;
3020 schoenebeck 3197 row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3021 schoenebeck 3418 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3022 persson 2442
3023 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3024 persson 2442 add_instrument_to_menu(name);
3025 schoenebeck 3364 #endif
3026 schoenebeck 1225 }
3027 persson 2442 instrument_name_connection.unblock();
3028 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3029 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
3030 schoenebeck 3364 #endif
3031 schoenebeck 1225
3032 schoenebeck 2621 updateSampleRefCountMap(gig);
3033    
3034 schoenebeck 1225 for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
3035     if (group->Name != "") {
3036     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3037     Gtk::TreeModel::Row rowGroup = *iterGroup;
3038 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3039 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_group] = group;
3040     rowGroup[m_SamplesModel.m_col_sample] = NULL;
3041     for (gig::Sample* sample = group->GetFirstSample();
3042     sample; sample = group->GetNextSample()) {
3043     Gtk::TreeModel::iterator iterSample =
3044     m_refSamplesTreeModel->append(rowGroup.children());
3045     Gtk::TreeModel::Row rowSample = *iterSample;
3046 persson 2446 rowSample[m_SamplesModel.m_col_name] =
3047     gig_to_utf8(sample->pInfo->Name);
3048 schoenebeck 1225 rowSample[m_SamplesModel.m_col_sample] = sample;
3049     rowSample[m_SamplesModel.m_col_group] = NULL;
3050 schoenebeck 2621 int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
3051     rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
3052 schoenebeck 2625 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
3053 schoenebeck 1225 }
3054     }
3055     }
3056 schoenebeck 2604
3057     for (int i = 0; gig->GetScriptGroup(i); ++i) {
3058     gig::ScriptGroup* group = gig->GetScriptGroup(i);
3059 schoenebeck 1225
3060 schoenebeck 2604 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3061     Gtk::TreeModel::Row rowGroup = *iterGroup;
3062     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3063     rowGroup[m_ScriptsModel.m_col_group] = group;
3064     rowGroup[m_ScriptsModel.m_col_script] = NULL;
3065     for (int s = 0; group->GetScript(s); ++s) {
3066     gig::Script* script = group->GetScript(s);
3067    
3068     Gtk::TreeModel::iterator iterScript =
3069     m_refScriptsTreeModel->append(rowGroup.children());
3070     Gtk::TreeModel::Row rowScript = *iterScript;
3071     rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
3072     rowScript[m_ScriptsModel.m_col_script] = script;
3073     rowScript[m_ScriptsModel.m_col_group] = NULL;
3074     }
3075     }
3076 schoenebeck 2624 // unfold all sample groups & script groups by default
3077     m_TreeViewSamples.expand_all();
3078 schoenebeck 2604 m_TreeViewScripts.expand_all();
3079    
3080 persson 1261 file = gig;
3081    
3082 schoenebeck 1225 // select the first instrument
3083 persson 2442 m_TreeView.get_selection()->select(Gtk::TreePath("0"));
3084 persson 2423
3085 persson 2445 instr_props_set_instrument();
3086 persson 2507 gig::Instrument* instrument = get_instrument();
3087     if (instrument) {
3088     midiRules.set_instrument(instrument);
3089     }
3090 persson 2445 }
3091    
3092     bool MainWindow::instr_props_set_instrument()
3093     {
3094     instrumentProps.signal_name_changed().clear();
3095    
3096 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3097     if (rows.empty()) {
3098     instrumentProps.hide();
3099     return false;
3100     }
3101 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.
3102     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3103 persson 2445 if (it) {
3104     Gtk::TreeModel::Row row = *it;
3105     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3106    
3107 persson 2423 instrumentProps.set_instrument(instrument);
3108 persson 2445
3109     // make sure instrument tree is updated when user changes the
3110     // instrument name in instrument properties window
3111     instrumentProps.signal_name_changed().connect(
3112     sigc::bind(
3113     sigc::mem_fun(*this,
3114     &MainWindow::instr_name_changed_by_instr_props),
3115     it));
3116     } else {
3117     instrumentProps.hide();
3118 persson 2423 }
3119 schoenebeck 3364 //NOTE: explicit boolean cast required for GTKMM4 development branch here
3120     return it ? true : false;
3121 schoenebeck 1225 }
3122    
3123     void MainWindow::show_instr_props()
3124     {
3125 persson 2445 if (instr_props_set_instrument()) {
3126 persson 1533 instrumentProps.show();
3127     instrumentProps.deiconify();
3128 schoenebeck 1225 }
3129     }
3130    
3131 persson 2445 void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3132     {
3133     Gtk::TreeModel::Row row = *it;
3134     Glib::ustring name = row[m_Columns.m_col_name];
3135    
3136     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3137 persson 2446 Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3138     if (gigname != name) {
3139 schoenebeck 3418 Gtk::TreeModel::Path path(*it);
3140     const int index = path[0];
3141 persson 2446 row[m_Columns.m_col_name] = gigname;
3142 schoenebeck 3418 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3143 persson 2445 }
3144     }
3145    
3146 persson 2507 void MainWindow::show_midi_rules()
3147     {
3148     if (gig::Instrument* instrument = get_instrument())
3149     {
3150     midiRules.set_instrument(instrument);
3151     midiRules.show();
3152     midiRules.deiconify();
3153     }
3154     }
3155    
3156 schoenebeck 2610 void MainWindow::show_script_slots() {
3157     if (!file) return;
3158     // get selected instrument
3159 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
3160     if (rows.empty()) return;
3161     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3162 schoenebeck 2610 if (!it) return;
3163     Gtk::TreeModel::Row row = *it;
3164     gig::Instrument* instrument = row[m_Columns.m_col_instr];
3165     if (!instrument) return;
3166    
3167     ScriptSlots* window = new ScriptSlots;
3168     window->setInstrument(instrument);
3169 schoenebeck 3197 window->signal_script_slots_changed().connect(
3170     sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
3171     );
3172 schoenebeck 2610 //window->reparent(*this);
3173     window->show();
3174     }
3175    
3176 schoenebeck 3197 void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
3177     if (!pInstrument) return;
3178     const int iScriptSlots = pInstrument->ScriptSlotCount();
3179    
3180 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!
3181     //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3182     Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3183    
3184 schoenebeck 3197 for (int i = 0; i < model->children().size(); ++i) {
3185     Gtk::TreeModel::Row row = model->children()[i];
3186     if (row[m_Columns.m_col_instr] != pInstrument) continue;
3187     row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3188 schoenebeck 3418 row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3189 schoenebeck 3197 break;
3190     }
3191 schoenebeck 3339
3192     // causes the sampler to reload the instrument with the new script
3193     on_sel_change();
3194 schoenebeck 3197 }
3195    
3196 schoenebeck 3339 void MainWindow::assignScript(gig::Script* pScript) {
3197     if (!pScript) {
3198     printf("assignScript() : !script\n");
3199     return;
3200     }
3201     printf("assignScript('%s')\n", pScript->Name.c_str());
3202    
3203     gig::Instrument* pInstrument = get_instrument();
3204     if (!pInstrument) {
3205     printf("!instrument\n");
3206     return;
3207     }
3208    
3209     pInstrument->AddScriptSlot(pScript);
3210    
3211     onScriptSlotsModified(pInstrument);
3212     }
3213    
3214 schoenebeck 3419 void MainWindow::dropAllScriptSlots() {
3215     gig::Instrument* pInstrument = get_instrument();
3216     if (!pInstrument) {
3217     printf("!instrument\n");
3218     return;
3219     }
3220    
3221     const int iScriptSlots = pInstrument->ScriptSlotCount();
3222     for (int i = iScriptSlots - 1; i >= 0; --i)
3223     pInstrument->RemoveScriptSlot(i);
3224    
3225     onScriptSlotsModified(pInstrument);
3226     }
3227    
3228 schoenebeck 2772 void MainWindow::on_action_refresh_all() {
3229     __refreshEntireGUI();
3230     }
3231    
3232 schoenebeck 1415 void MainWindow::on_action_view_status_bar() {
3233 schoenebeck 3364 #if USE_GLIB_ACTION
3234     bool active = false;
3235     m_actionToggleStatusBar->get_state(active);
3236     // for some reason toggle state does not change automatically
3237     active = !active;
3238     m_actionToggleStatusBar->change_state(active);
3239     if (active)
3240     m_StatusBar.show();
3241     else
3242     m_StatusBar.hide();
3243     #else
3244 schoenebeck 1415 Gtk::CheckMenuItem* item =
3245     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
3246     if (!item) {
3247     std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
3248     return;
3249     }
3250     if (item->get_active()) m_StatusBar.show();
3251     else m_StatusBar.hide();
3252 schoenebeck 3364 #endif
3253 schoenebeck 1415 }
3254    
3255 schoenebeck 2918 void MainWindow::on_auto_restore_win_dim() {
3256 schoenebeck 3364 #if USE_GLIB_ACTION
3257     bool active = false;
3258     m_actionToggleRestoreWinDim->get_state(active);
3259     // for some reason toggle state does not change automatically
3260     active = !active;
3261     m_actionToggleRestoreWinDim->change_state(active);
3262     Settings::singleton()->autoRestoreWindowDimension = active;
3263     #else
3264 schoenebeck 2918 Gtk::CheckMenuItem* item =
3265     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim"));
3266     if (!item) {
3267     std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n";
3268     return;
3269     }
3270     Settings::singleton()->autoRestoreWindowDimension = item->get_active();
3271 schoenebeck 3364 #endif
3272 schoenebeck 2918 }
3273    
3274 schoenebeck 2967 void MainWindow::on_save_with_temporary_file() {
3275 schoenebeck 3364 #if USE_GLIB_ACTION
3276     bool active = false;
3277     m_actionToggleSaveWithTempFile->get_state(active);
3278     // for some reason toggle state does not change automatically
3279     active = !active;
3280     m_actionToggleSaveWithTempFile->change_state(active);
3281     Settings::singleton()->saveWithTemporaryFile = active;
3282     #else
3283 schoenebeck 2967 Gtk::CheckMenuItem* item =
3284     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
3285     if (!item) {
3286     std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
3287     return;
3288     }
3289     Settings::singleton()->saveWithTemporaryFile = item->get_active();
3290 schoenebeck 3364 #endif
3291 schoenebeck 2967 }
3292    
3293 schoenebeck 2464 bool MainWindow::is_copy_samples_unity_note_enabled() const {
3294 schoenebeck 3364 #if USE_GLIB_ACTION
3295     bool active = false;
3296     m_actionToggleCopySampleUnity->get_state(active);
3297     return active;
3298     #else
3299 schoenebeck 2464 Gtk::CheckMenuItem* item =
3300     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
3301     if (!item) {
3302     std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
3303     return true;
3304     }
3305     return item->get_active();
3306 schoenebeck 3364 #endif
3307 schoenebeck 2464 }
3308    
3309     bool MainWindow::is_copy_samples_fine_tune_enabled() const {
3310 schoenebeck 3364 #if USE_GLIB_ACTION
3311     bool active = false;
3312     m_actionToggleCopySampleTune->get_state(active);
3313     return active;
3314     #else
3315 schoenebeck 2464 Gtk::CheckMenuItem* item =
3316     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
3317     if (!item) {
3318     std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
3319     return true;
3320     }
3321     return item->get_active();
3322 schoenebeck 3364 #endif
3323 schoenebeck 2464 }
3324    
3325     bool MainWindow::is_copy_samples_loop_enabled() const {
3326 schoenebeck 3364 #if USE_GLIB_ACTION
3327     bool active = false;
3328     m_actionToggleCopySampleLoop->get_state(active);
3329     return active;
3330     #else
3331 schoenebeck 2464 Gtk::CheckMenuItem* item =
3332     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
3333     if (!item) {
3334     std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
3335     return true;
3336     }
3337     return item->get_active();
3338 schoenebeck 3364 #endif
3339 schoenebeck 2464 }
3340    
3341 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
3342     bool MainWindow::on_button_release(Gdk::EventButton& _button) {
3343     GdkEventButton* button = _button.gobj();
3344     #else
3345     void MainWindow::on_button_release(GdkEventButton* button) {
3346     #endif
3347 schoenebeck 1225 if (button->type == GDK_2BUTTON_PRESS) {
3348     show_instr_props();
3349     } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3350 persson 2507 // gig v2 files have no midi rules
3351 schoenebeck 2625 const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
3352 schoenebeck 3364 #if USE_GTKMM_BUILDER
3353     m_actionMIDIRules->property_enabled() = bEnabled;
3354     #else
3355 persson 2507 static_cast<Gtk::MenuItem*>(
3356 schoenebeck 2625 uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
3357     bEnabled
3358     );
3359     static_cast<Gtk::MenuItem*>(
3360 persson 2507 uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
3361 schoenebeck 2625 bEnabled
3362     );
3363 schoenebeck 3364 #endif
3364 schoenebeck 1225 popup_menu->popup(button->button, button->time);
3365     }
3366 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
3367     return false;
3368     #endif
3369 schoenebeck 1225 }
3370    
3371 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3372 persson 2442 void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
3373     if (item->get_active()) {
3374     const std::vector<Gtk::Widget*> children =
3375     instrument_menu->get_children();
3376     std::vector<Gtk::Widget*>::const_iterator it =
3377     find(children.begin(), children.end(), item);
3378     if (it != children.end()) {
3379     int index = it - children.begin();
3380     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
3381    
3382     m_RegionChooser.set_instrument(file->GetInstrument(index));
3383     }
3384     }
3385 schoenebeck 1225 }
3386 schoenebeck 3364 #endif
3387 schoenebeck 1225
3388 schoenebeck 2701 void MainWindow::select_instrument(gig::Instrument* instrument) {
3389     if (!instrument) return;
3390    
3391 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!
3392 schoenebeck 2701 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3393 schoenebeck 3340 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3394    
3395 schoenebeck 2701 for (int i = 0; i < model->children().size(); ++i) {
3396     Gtk::TreeModel::Row row = model->children()[i];
3397     if (row[m_Columns.m_col_instr] == instrument) {
3398     // select and show the respective instrument in the list view
3399     show_intruments_tab();
3400 schoenebeck 2994 m_TreeView.get_selection()->unselect_all();
3401 schoenebeck 3364
3402 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3403 schoenebeck 3364 auto iterSel = model->children()[i].get_iter();
3404     m_TreeView.get_selection()->select(iterSel);
3405     #else
3406 schoenebeck 2701 m_TreeView.get_selection()->select(model->children()[i]);
3407 schoenebeck 3364 #endif
3408 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3409     m_TreeView.get_selection()->get_selected_rows();
3410     if (!rows.empty())
3411     m_TreeView.scroll_to_row(rows[0]);
3412 schoenebeck 2701 on_sel_change(); // the regular instrument selection change callback
3413     }
3414     }
3415     }
3416    
3417 schoenebeck 2695 /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
3418     bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
3419     gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
3420     gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
3421    
3422 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!
3423 schoenebeck 2695 Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
3424 schoenebeck 3340 //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
3425    
3426 schoenebeck 2695 for (int i = 0; i < model->children().size(); ++i) {
3427     Gtk::TreeModel::Row row = model->children()[i];
3428     if (row[m_Columns.m_col_instr] == pInstrument) {
3429     // select and show the respective instrument in the list view
3430     show_intruments_tab();
3431 schoenebeck 2994 m_TreeView.get_selection()->unselect_all();
3432 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3433 schoenebeck 3364 auto iterSel = model->children()[i].get_iter();
3434     m_TreeView.get_selection()->select(iterSel);
3435     #else
3436 schoenebeck 2695 m_TreeView.get_selection()->select(model->children()[i]);
3437 schoenebeck 3364 #endif
3438 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3439     m_TreeView.get_selection()->get_selected_rows();
3440     if (!rows.empty())
3441     m_TreeView.scroll_to_row(rows[0]);
3442 schoenebeck 2695 on_sel_change(); // the regular instrument selection change callback
3443    
3444     // select respective region in the region selector
3445     m_RegionChooser.set_region(pRegion);
3446    
3447     // select and show the respective dimension region in the editor
3448     //update_dimregs();
3449     if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
3450     //dimreg_edit.set_dim_region(dimRgn);
3451    
3452     return true;
3453     }
3454     }
3455    
3456     return false;
3457     }
3458    
3459 schoenebeck 2691 void MainWindow::select_sample(gig::Sample* sample) {
3460     Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
3461     for (int g = 0; g < model->children().size(); ++g) {
3462     Gtk::TreeModel::Row rowGroup = model->children()[g];
3463     for (int s = 0; s < rowGroup.children().size(); ++s) {
3464     Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
3465     if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3466     show_samples_tab();
3467 schoenebeck 2994 m_TreeViewSamples.get_selection()->unselect_all();
3468 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3469 schoenebeck 3364 auto iterSel = rowGroup.children()[s].get_iter();
3470     m_TreeViewSamples.get_selection()->select(iterSel);
3471     #else
3472 schoenebeck 2691 m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
3473 schoenebeck 3364 #endif
3474 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows =
3475     m_TreeViewSamples.get_selection()->get_selected_rows();
3476     if (rows.empty()) return;
3477     m_TreeViewSamples.scroll_to_row(rows[0]);
3478 schoenebeck 2691 return;
3479     }
3480     }
3481     }
3482     }
3483    
3484 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
3485     bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) {
3486     GdkEventButton* button = _button.gobj();
3487     #else
3488 schoenebeck 1225 void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
3489 schoenebeck 3364 #endif
3490 schoenebeck 1225 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3491 schoenebeck 2994 // by default if Ctrl keys is pressed down, then a mouse right-click
3492     // does not select the respective row, so we must assure this
3493     // programmatically ...
3494     /*{
3495     Gtk::TreeModel::Path path;
3496     Gtk::TreeViewColumn* pColumn = NULL;
3497     int cellX, cellY;
3498     bool bSuccess = m_TreeViewSamples.get_path_at_pos(
3499     (int)button->x, (int)button->y,
3500     path, pColumn, cellX, cellY
3501     );
3502     if (bSuccess) {
3503     if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
3504     printf("not selected !!!\n");
3505     m_TreeViewSamples.get_selection()->select(path);
3506     }
3507     }
3508     }*/
3509    
3510 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3511 schoenebeck 1225 Gtk::Menu* sample_popup =
3512     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
3513 schoenebeck 3364 #endif
3514    
3515 schoenebeck 1225 // update enabled/disabled state of sample popup items
3516     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3517 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3518     const int n = rows.size();
3519     int nGroups = 0;
3520     int nSamples = 0;
3521     for (int r = 0; r < n; ++r) {
3522     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
3523     if (!it) continue;
3524 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
3525 schoenebeck 2994 if (row[m_SamplesModel.m_col_group]) nGroups++;
3526     if (row[m_SamplesModel.m_col_sample]) nSamples++;
3527 schoenebeck 1225 }
3528 schoenebeck 2994
3529 schoenebeck 3364 #if USE_GTKMM_BUILDER
3530     m_actionSampleProperties->property_enabled() = (n == 1);
3531     m_actionAddSample->property_enabled() = (n);
3532     m_actionAddSampleGroup->property_enabled() = (file);
3533     m_actionViewSampleRefs->property_enabled() = (nSamples == 1);
3534     m_actionRemoveSample->property_enabled() = (n);
3535     m_actionReplaceSample->property_enabled() = (nSamples == 1);
3536     #else
3537 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
3538 schoenebeck 2994 set_sensitive(n == 1);
3539 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
3540 schoenebeck 2994 set_sensitive(n);
3541 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
3542     set_sensitive(file);
3543 schoenebeck 2624 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
3544 schoenebeck 2994 set_sensitive(nSamples == 1);
3545 schoenebeck 1225 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
3546 schoenebeck 2994 set_sensitive(n);
3547 schoenebeck 3364 #endif
3548 schoenebeck 1225 // show sample popup
3549     sample_popup->popup(button->button, button->time);
3550 schoenebeck 2625
3551 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3552 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
3553 schoenebeck 2994 set_sensitive(n == 1);
3554 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
3555 schoenebeck 2994 set_sensitive(n);
3556 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
3557     set_sensitive(file);
3558     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
3559 schoenebeck 2994 set_sensitive(nSamples == 1);
3560 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
3561 schoenebeck 2994 set_sensitive(n);
3562 schoenebeck 3364 #endif
3563 schoenebeck 1225 }
3564 schoenebeck 3364
3565     #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
3566     return false;
3567     #endif
3568 schoenebeck 1225 }
3569    
3570 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
3571     bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) {
3572     GdkEventButton* button = _button.gobj();
3573     #else
3574 schoenebeck 2604 void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
3575 schoenebeck 3364 #endif
3576 schoenebeck 2604 if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3577 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3578 schoenebeck 2604 Gtk::Menu* script_popup =
3579     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
3580 schoenebeck 3364 #endif
3581 schoenebeck 2604 // update enabled/disabled state of sample popup items
3582     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3583     Gtk::TreeModel::iterator it = sel->get_selected();
3584     bool group_selected = false;
3585     bool script_selected = false;
3586     if (it) {
3587     Gtk::TreeModel::Row row = *it;
3588     group_selected = row[m_ScriptsModel.m_col_group];
3589     script_selected = row[m_ScriptsModel.m_col_script];
3590     }
3591 schoenebeck 3364 #if USE_GTKMM_BUILDER
3592     m_actionAddScript->property_enabled() = (group_selected || script_selected);
3593     m_actionAddScriptGroup->property_enabled() = (file);
3594     m_actionEditScript->property_enabled() = (script_selected);
3595     m_actionRemoveScript->property_enabled() = (group_selected || script_selected);
3596     #else
3597 schoenebeck 2604 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
3598     set_sensitive(group_selected || script_selected);
3599     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
3600     set_sensitive(file);
3601     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
3602     set_sensitive(script_selected);
3603     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
3604     set_sensitive(group_selected || script_selected);
3605 schoenebeck 3364 #endif
3606 schoenebeck 2604 // show sample popup
3607     script_popup->popup(button->button, button->time);
3608 schoenebeck 2625
3609 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3610 schoenebeck 2625 dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
3611     set_sensitive(group_selected || script_selected);
3612     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
3613     set_sensitive(file);
3614     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
3615     set_sensitive(script_selected);
3616     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
3617     set_sensitive(group_selected || script_selected);
3618 schoenebeck 3364 #endif
3619 schoenebeck 2604 }
3620 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
3621     return false;
3622     #endif
3623 schoenebeck 2604 }
3624 persson 2442
3625 schoenebeck 3339 void MainWindow::updateScriptListOfMenu() {
3626     // remove all entries from "Assign Script" menu
3627     {
3628     const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
3629     for (int i = 0; i < children.size(); ++i) {
3630     Gtk::Widget* child = children[i];
3631     assign_scripts_menu->remove(*child);
3632     delete child;
3633     }
3634     }
3635    
3636     int iTotalScripts = 0;
3637    
3638     if (!file) goto noScripts;
3639    
3640     // add all configured macros as menu items to the "Macro" menu
3641     for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
3642     gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
3643     for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
3644     gig::Script* pScript = pGroup->GetScript(iScript);
3645     std::string name = pScript->Name;
3646    
3647     Gtk::MenuItem* item = new Gtk::MenuItem(name);
3648     item->signal_activate().connect(
3649     sigc::bind(
3650     sigc::mem_fun(*this, &MainWindow::assignScript), pScript
3651     )
3652     );
3653     assign_scripts_menu->append(*item);
3654     item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
3655     //item->set_tooltip_text(comment);
3656     }
3657     }
3658    
3659     noScripts:
3660    
3661     // if there are no macros configured at all, then show a dummy entry instead
3662     if (!iTotalScripts) {
3663     Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
3664     item->set_sensitive(false);
3665     assign_scripts_menu->append(*item);
3666     }
3667    
3668 schoenebeck 3419 // add separator line to menu
3669     assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
3670    
3671     {
3672     Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
3673     item->signal_activate().connect(
3674     sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
3675     );
3676     assign_scripts_menu->append(*item);
3677     item->set_accel_path("<Scripts>/DropAllScriptSlots");
3678     }
3679    
3680 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
3681 schoenebeck 3339 assign_scripts_menu->show_all_children();
3682 schoenebeck 3364 #endif
3683 schoenebeck 3339 }
3684    
3685 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3686 persson 2442 Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
3687     const Glib::ustring& name, int position) {
3688    
3689     Gtk::RadioMenuItem::Group instrument_group;
3690     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
3691     if (!children.empty()) {
3692     instrument_group =
3693     static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
3694     }
3695     Gtk::RadioMenuItem* item =
3696     new Gtk::RadioMenuItem(instrument_group, name);
3697     if (position < 0) {
3698     instrument_menu->append(*item);
3699     } else {
3700     instrument_menu->insert(*item, position);
3701     }
3702     item->show();
3703     item->signal_activate().connect(
3704     sigc::bind(
3705     sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
3706     item));
3707     return item;
3708     }
3709 schoenebeck 3364 #endif
3710 persson 2442
3711 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3712 persson 2442 void MainWindow::remove_instrument_from_menu(int index) {
3713     const std::vector<Gtk::Widget*> children =
3714     instrument_menu->get_children();
3715     Gtk::Widget* child = children[index];
3716     instrument_menu->remove(*child);
3717     delete child;
3718     }
3719 schoenebeck 3364 #endif
3720 persson 2442
3721     void MainWindow::add_instrument(gig::Instrument* instrument) {
3722 persson 2446 const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3723 persson 2442
3724     // update instrument tree view
3725     instrument_name_connection.block();
3726     Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3727     Gtk::TreeModel::Row rowInstr = *iterInstr;
3728 schoenebeck 3418 const int index = m_refTreeModel->children().size() - 1;
3729     rowInstr[m_Columns.m_col_nr] = index;
3730 persson 2442 rowInstr[m_Columns.m_col_name] = name;
3731     rowInstr[m_Columns.m_col_instr] = instrument;
3732 schoenebeck 3197 rowInstr[m_Columns.m_col_scripts] = "";
3733 schoenebeck 3418 rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3734 persson 2442 instrument_name_connection.unblock();
3735    
3736 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3737 persson 2442 add_instrument_to_menu(name);
3738 schoenebeck 3364 #endif
3739 schoenebeck 3339 select_instrument(instrument);
3740 persson 2442 file_changed();
3741     }
3742    
3743 schoenebeck 1225 void MainWindow::on_action_add_instrument() {
3744     static int __instrument_indexer = 0;
3745     if (!file) return;
3746     gig::Instrument* instrument = file->AddInstrument();
3747     __instrument_indexer++;
3748 persson 2446 instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
3749     ToString(__instrument_indexer));
3750 persson 2442
3751     add_instrument(instrument);
3752 schoenebeck 1225 }
3753    
3754 schoenebeck 2395 void MainWindow::on_action_duplicate_instrument() {
3755     if (!file) return;
3756 persson 2442
3757 schoenebeck 2395 // retrieve the currently selected instrument
3758     // (being the original instrument to be duplicated)
3759     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3760 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3761     for (int r = 0; r < rows.size(); ++r) {
3762     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3763     if (it) {
3764     Gtk::TreeModel::Row row = *it;
3765     gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
3766     if (instrOrig) {
3767     // duplicate the orginal instrument
3768     gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
3769     instrNew->pInfo->Name =
3770     instrOrig->pInfo->Name +
3771     gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
3772 persson 2442
3773 schoenebeck 2994 add_instrument(instrNew);
3774     }
3775     }
3776     }
3777 schoenebeck 2395 }
3778    
3779 schoenebeck 1225 void MainWindow::on_action_remove_instrument() {
3780     if (!file) return;
3781 schoenebeck 1382 if (file_is_shared) {
3782     Gtk::MessageDialog msg(
3783     *this,
3784     _("You cannot delete an instrument from this file, since it's "
3785     "currently used by the sampler."),
3786     false, Gtk::MESSAGE_INFO
3787     );
3788     msg.run();
3789     return;
3790     }
3791    
3792 schoenebeck 1225 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3793 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3794     for (int r = rows.size() - 1; r >= 0; --r) {
3795     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3796     if (!it) continue;
3797 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
3798     gig::Instrument* instr = row[m_Columns.m_col_instr];
3799     try {
3800 persson 2442 Gtk::TreePath path(it);
3801     int index = path[0];
3802    
3803 schoenebeck 1225 // remove instrument from the gig file
3804     if (instr) file->DeleteInstrument(instr);
3805 persson 1261 file_changed();
3806 persson 2423
3807 schoenebeck 3364 #if !USE_GTKMM_BUILDER
3808 persson 2442 remove_instrument_from_menu(index);
3809 schoenebeck 3364 #endif
3810 persson 2442
3811     // remove row from instruments tree view
3812     m_refTreeModel->erase(it);
3813 schoenebeck 2994 // update "Nr" column of all instrument rows
3814     {
3815     int index = 0;
3816     for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
3817     it != m_refTreeModel->children().end(); ++it, ++index)
3818     {
3819     Gtk::TreeModel::Row row = *it;
3820 schoenebeck 3418 gig::Instrument* instrument = row[m_Columns.m_col_instr];
3821 schoenebeck 2994 row[m_Columns.m_col_nr] = index;
3822 schoenebeck 3418 row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3823 schoenebeck 2994 }
3824     }
3825 persson 2442
3826     #if GTKMM_MAJOR_VERSION < 3
3827     // select another instrument (in gtk3 this is done
3828     // automatically)
3829     if (!m_refTreeModel->children().empty()) {
3830     if (index == m_refTreeModel->children().size()) {
3831     index--;
3832     }
3833     m_TreeView.get_selection()->select(
3834     Gtk::TreePath(ToString(index)));
3835     }
3836     #endif
3837 persson 2445 instr_props_set_instrument();
3838 persson 2507 instr = get_instrument();
3839     if (instr) {
3840     midiRules.set_instrument(instr);
3841     } else {
3842     midiRules.hide();
3843     }
3844 schoenebeck 1225 } catch (RIFF::Exception e) {
3845     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3846     msg.run();
3847     }
3848     }
3849     }
3850    
3851     void MainWindow::on_action_sample_properties() {
3852     //TODO: show a dialog where the selected sample's properties can be edited
3853     Gtk::MessageDialog msg(
3854 persson 1831 *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
3855 schoenebeck 1225 );
3856     msg.run();
3857     }
3858    
3859 schoenebeck 2604 void MainWindow::on_action_add_script_group() {
3860     static int __script_indexer = 0;
3861     if (!file) return;
3862     gig::ScriptGroup* group = file->AddScriptGroup();
3863     group->Name = gig_from_utf8(_("Unnamed Group"));
3864     if (__script_indexer) group->Name += " " + ToString(__script_indexer);
3865     __script_indexer++;
3866     // update sample tree view
3867     Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
3868     Gtk::TreeModel::Row rowGroup = *iterGroup;
3869     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
3870     rowGroup[m_ScriptsModel.m_col_script] = NULL;
3871     rowGroup[m_ScriptsModel.m_col_group] = group;
3872     file_changed();
3873     }
3874    
3875     void MainWindow::on_action_add_script() {
3876     if (!file) return;
3877     // get selected group
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::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3883     if (!group) { // not a group, but a script is selected (probably)
3884     gig::Script* script = row[m_ScriptsModel.m_col_script];
3885     if (!script) return;
3886     it = row.parent(); // resolve parent (that is the script's group)
3887     if (!it) return;
3888     row = *it;
3889     group = row[m_ScriptsModel.m_col_group];
3890     if (!group) return;
3891     }
3892    
3893     // add a new script to the .gig file
3894     gig::Script* script = group->AddScript();
3895     Glib::ustring name = _("Unnamed Script");
3896     script->Name = gig_from_utf8(name);
3897    
3898     // add script to the tree view
3899     Gtk::TreeModel::iterator iterScript =
3900     m_refScriptsTreeModel->append(row.children());
3901     Gtk::TreeModel::Row rowScript = *iterScript;
3902     rowScript[m_ScriptsModel.m_col_name] = name;
3903     rowScript[m_ScriptsModel.m_col_script] = script;
3904     rowScript[m_ScriptsModel.m_col_group] = NULL;
3905    
3906     // unfold group of new script item in treeview
3907     Gtk::TreeModel::Path path(iterScript);
3908     m_TreeViewScripts.expand_to_path(path);
3909     }
3910    
3911     void MainWindow::on_action_edit_script() {
3912     if (!file) return;
3913     // get selected script
3914     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3915     Gtk::TreeModel::iterator it = sel->get_selected();
3916     if (!it) return;
3917     Gtk::TreeModel::Row row = *it;
3918     gig::Script* script = row[m_ScriptsModel.m_col_script];
3919     if (!script) return;
3920    
3921     ScriptEditor* editor = new ScriptEditor;
3922 schoenebeck 2903 editor->signal_script_to_be_changed.connect(
3923     signal_script_to_be_changed.make_slot()
3924     );
3925     editor->signal_script_changed.connect(
3926     signal_script_changed.make_slot()
3927     );
3928 schoenebeck 2604 editor->setScript(script);
3929     //editor->reparent(*this);
3930     editor->show();
3931     }
3932    
3933     void MainWindow::on_action_remove_script() {
3934     if (!file) return;
3935     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
3936     Gtk::TreeModel::iterator it = sel->get_selected();
3937     if (it) {
3938     Gtk::TreeModel::Row row = *it;
3939     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
3940     gig::Script* script = row[m_ScriptsModel.m_col_script];
3941     Glib::ustring name = row[m_ScriptsModel.m_col_name];
3942     try {
3943     // remove script group or script from the gig file
3944     if (group) {
3945     // notify everybody that we're going to remove these samples
3946     //TODO: scripts_to_be_removed_signal.emit(members);
3947     // delete the group in the .gig file including the
3948     // samples that belong to the group
3949     file->DeleteScriptGroup(group);
3950     // notify that we're done with removal
3951     //TODO: scripts_removed_signal.emit();
3952     file_changed();
3953     } else if (script) {
3954     // notify everybody that we're going to remove this sample
3955     //TODO: std::list<gig::Script*> lscripts;
3956     //TODO: lscripts.push_back(script);
3957     //TODO: scripts_to_be_removed_signal.emit(lscripts);
3958     // remove sample from the .gig file
3959     script->GetGroup()->DeleteScript(script);
3960     // notify that we're done with removal
3961     //TODO: scripts_removed_signal.emit();
3962     dimreg_changed();
3963     file_changed();
3964     }
3965     // remove respective row(s) from samples tree view
3966     m_refScriptsTreeModel->erase(it);
3967     } catch (RIFF::Exception e) {
3968     // pretend we're done with removal (i.e. to avoid dead locks)
3969     //TODO: scripts_removed_signal.emit();
3970     // show error message
3971     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
3972     msg.run();
3973     }
3974     }
3975     }
3976    
3977 schoenebeck 1225 void MainWindow::on_action_add_group() {
3978     static int __sample_indexer = 0;
3979     if (!file) return;
3980     gig::Group* group = file->AddGroup();
3981 persson 2446 group->Name = gig_from_utf8(_("Unnamed Group"));
3982 schoenebeck 1225 if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
3983     __sample_indexer++;
3984     // update sample tree view
3985     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
3986     Gtk::TreeModel::Row rowGroup = *iterGroup;
3987 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
3988 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_sample] = NULL;
3989     rowGroup[m_SamplesModel.m_col_group] = group;
3990 persson 1261 file_changed();
3991 schoenebeck 1225 }
3992    
3993 schoenebeck 2715 void MainWindow::on_action_replace_sample() {
3994     add_or_replace_sample(true);
3995     }
3996    
3997 schoenebeck 1225 void MainWindow::on_action_add_sample() {
3998 schoenebeck 2715 add_or_replace_sample(false);
3999     }
4000    
4001     void MainWindow::add_or_replace_sample(bool replace) {
4002 schoenebeck 1225 if (!file) return;
4003 schoenebeck 2715
4004     // get selected group (and probably selected sample)
4005 schoenebeck 1225 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4006 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4007     if (rows.empty()) return;
4008     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4009 schoenebeck 1225 if (!it) return;
4010     Gtk::TreeModel::Row row = *it;
4011 schoenebeck 2715 gig::Sample* sample = NULL;
4012 schoenebeck 1225 gig::Group* group = row[m_SamplesModel.m_col_group];
4013     if (!group) { // not a group, but a sample is selected (probably)
4014 schoenebeck 2715 if (replace) sample = row[m_SamplesModel.m_col_sample];
4015     if (!row[m_SamplesModel.m_col_sample]) return;
4016 schoenebeck 1225 it = row.parent(); // resolve parent (that is the sample's group)
4017     if (!it) return;
4018 schoenebeck 2715 if (!replace) row = *it;
4019     group = (*it)[m_SamplesModel.m_col_group];
4020 schoenebeck 1225 if (!group) return;
4021     }
4022 schoenebeck 2715 if (replace && !sample) return;
4023    
4024 schoenebeck 1225 // show 'browse for file' dialog
4025 schoenebeck 2715 Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
4026 schoenebeck 3364 #if HAS_GTKMM_STOCK
4027 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4028     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
4029 schoenebeck 3364 #else
4030     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4031     dialog.add_button(_("_Open"), Gtk::RESPONSE_OK);
4032     #endif
4033 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
4034 persson 2169
4035     // matches all file types supported by libsndfile
4036     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4037     Gtk::FileFilter soundfilter;
4038     #else
4039     Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
4040     #endif
4041 persson 1262 const char* const supportedFileTypes[] = {
4042 schoenebeck 1225 "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
4043     "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
4044     "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
4045     "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
4046     "*.caf", "*.CAF", NULL
4047     };
4048 persson 2169 const char* soundfiles = _("Sound Files");
4049     const char* allfiles = _("All Files");
4050     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4051 schoenebeck 1225 for (int i = 0; supportedFileTypes[i]; i++)
4052     soundfilter.add_pattern(supportedFileTypes[i]);
4053 persson 2169 soundfilter.set_name(soundfiles);
4054    
4055     // matches every file
4056     Gtk::FileFilter allpassfilter;
4057 schoenebeck 1225 allpassfilter.add_pattern("*.*");
4058 persson 2169 allpassfilter.set_name(allfiles);
4059     #else
4060     for (int i = 0; supportedFileTypes[i]; i++)
4061     soundfilter->add_pattern(supportedFileTypes[i]);
4062     soundfilter->set_name(soundfiles);
4063    
4064     // matches every file
4065     Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
4066     allpassfilter->add_pattern("*.*");
4067     allpassfilter->set_name(allfiles);
4068     #endif
4069 schoenebeck 1225 dialog.add_filter(soundfilter);
4070     dialog.add_filter(allpassfilter);
4071 persson 1725 if (current_sample_dir != "") {
4072     dialog.set_current_folder(current_sample_dir);
4073     }
4074 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
4075 persson 1725 current_sample_dir = dialog.get_current_folder();
4076 schoenebeck 1225 Glib::ustring error_files;
4077 persson 2169 std::vector<std::string> filenames = dialog.get_filenames();
4078     for (std::vector<std::string>::iterator iter = filenames.begin();
4079 schoenebeck 1225 iter != filenames.end(); ++iter) {
4080     printf("Adding sample %s\n",(*iter).c_str());
4081 schoenebeck 3408 // use libsndfile to retrieve file information
4082 schoenebeck 1225 SF_INFO info;
4083     info.format = 0;
4084     SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
4085     try {
4086 persson 1831 if (!hFile) throw std::string(_("could not open file"));
4087 schoenebeck 1225 int bitdepth;
4088     switch (info.format & 0xff) {
4089     case SF_FORMAT_PCM_S8:
4090     case SF_FORMAT_PCM_16:
4091 persson 1265 case SF_FORMAT_PCM_U8:
4092 schoenebeck 1225 bitdepth = 16;
4093     break;
4094     case SF_FORMAT_PCM_24:
4095     case SF_FORMAT_PCM_32:
4096     case SF_FORMAT_FLOAT:
4097     case SF_FORMAT_DOUBLE:
4098 persson 1265 bitdepth = 24;
4099 schoenebeck 1225 break;
4100     default:
4101     sf_close(hFile); // close sound file
4102 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
4103 schoenebeck 1225 }
4104 schoenebeck 2715 // add a new sample to the .gig file (if adding is requested actually)
4105     if (!replace) sample = file->AddSample();
4106 schoenebeck 1225 // file name without path
4107 persson 1262 Glib::ustring filename = Glib::filename_display_basename(*iter);
4108     // remove file extension if there is one
4109     for (int i = 0; supportedFileTypes[i]; i++) {
4110     if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) {
4111     filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1));
4112     break;
4113     }
4114     }
4115 persson 2446 sample->pInfo->Name = gig_from_utf8(filename);
4116 schoenebeck 1225 sample->Channels = info.channels;
4117     sample->BitDepth = bitdepth;
4118     sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
4119     sample->SamplesPerSecond = info.samplerate;
4120 persson 1265 sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond;
4121     sample->BlockAlign = sample->FrameSize;
4122     sample->SamplesTotal = info.frames;
4123    
4124     SF_INSTRUMENT instrument;
4125     if (sf_command(hFile, SFC_GET_INSTRUMENT,
4126     &instrument, sizeof(instrument)) != SF_FALSE)
4127     {
4128     sample->MIDIUnityNote = instrument.basenote;
4129 schoenebeck 2466 sample->FineTune = instrument.detune;
4130 persson 1265
4131     if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
4132     sample->Loops = 1;
4133    
4134     switch (instrument.loops[0].mode) {
4135     case SF_LOOP_FORWARD:
4136     sample->LoopType = gig::loop_type_normal;
4137     break;
4138     case SF_LOOP_BACKWARD:
4139     sample->LoopType = gig::loop_type_backward;
4140     break;
4141     case SF_LOOP_ALTERNATING:
4142     sample->LoopType = gig::loop_type_bidirectional;
4143     break;
4144     }
4145     sample->LoopStart = instrument.loops[0].start;
4146     sample->LoopEnd = instrument.loops[0].end;
4147     sample->LoopPlayCount = instrument.loops[0].count;
4148     sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
4149     }
4150     }
4151    
4152 schoenebeck 1225 // schedule resizing the sample (which will be done
4153     // physically when File::Save() is called)
4154     sample->Resize(info.frames);
4155     // make sure sample is part of the selected group
4156 schoenebeck 2715 if (!replace) group->AddSample(sample);
4157 schoenebeck 1225 // schedule that physical resize and sample import
4158     // (data copying), performed when "Save" is requested
4159     SampleImportItem sched_item;
4160     sched_item.gig_sample = sample;
4161     sched_item.sample_path = *iter;
4162 schoenebeck 3116 m_SampleImportQueue[sample] = sched_item;
4163 schoenebeck 1225 // add sample to the tree view
4164 schoenebeck 2715 if (replace) {
4165     row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
4166     } else {
4167     Gtk::TreeModel::iterator iterSample =
4168     m_refSamplesTreeModel->append(row.children());
4169     Gtk::TreeModel::Row rowSample = *iterSample;
4170     rowSample[m_SamplesModel.m_col_name] =
4171     gig_to_utf8(sample->pInfo->Name);
4172     rowSample[m_SamplesModel.m_col_sample] = sample;
4173     rowSample[m_SamplesModel.m_col_group] = NULL;
4174     }
4175 schoenebeck 1225 // close sound file
4176     sf_close(hFile);
4177 persson 1261 file_changed();
4178 schoenebeck 1225 } catch (std::string what) { // remember the files that made trouble (and their cause)
4179 persson 2442 if (!error_files.empty()) error_files += "\n";
4180 schoenebeck 1225 error_files += *iter += " (" + what + ")";
4181     }
4182     }
4183     // show error message box when some file(s) could not be opened / added
4184 persson 2442 if (!error_files.empty()) {
4185 schoenebeck 2715 Glib::ustring txt =
4186     (replace
4187     ? _("Failed to replace sample with:\n")
4188     : _("Could not add the following sample(s):\n"))
4189     + error_files;
4190 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4191     msg.run();
4192     }
4193     }
4194     }
4195    
4196 schoenebeck 1673 void MainWindow::on_action_replace_all_samples_in_all_groups()
4197     {
4198     if (!file) return;
4199     Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
4200     Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
4201 persson 2442 const char* str =
4202 schoenebeck 1673 _("This is a very specific function. It tries to replace all samples "
4203 persson 1799 "in the current gig file by samples located in the chosen "
4204     "directory.\n\n"
4205     "It works like this: For each sample in the gig file, it tries to "
4206 schoenebeck 1673 "find a sample file in the selected directory with the same name as "
4207 persson 1799 "the sample in the gig file. Optionally, you can add a filename "
4208     "extension below, which will be added to the filename expected to be "
4209 schoenebeck 1673 "found. That is, assume you have a gig file with a sample called "
4210     "'Snare', if you enter '.wav' below (like it's done by default), it "
4211 persson 1799 "expects to find a sample file called 'Snare.wav' and will replace "
4212     "the sample in the gig file accordingly. If you don't need an "
4213     "extension, blank the field below. Any gig sample where no "
4214     "appropriate sample file could be found will be reported and left "
4215 persson 2344 "untouched.\n");
4216     #if GTKMM_MAJOR_VERSION < 3
4217     view::WrapLabel description(str);
4218     #else
4219     Gtk::Label description(str);
4220     description.set_line_wrap();
4221     #endif
4222 schoenebeck 3364 HBox entryArea;
4223 persson 2169 Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
4224 schoenebeck 1673 Gtk::Entry postfixEntryBox;
4225     postfixEntryBox.set_text(".wav");
4226     entryArea.pack_start(entryLabel);
4227     entryArea.pack_start(postfixEntryBox);
4228 schoenebeck 3364 #if USE_GTKMM_BOX
4229     dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK);
4230     dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK);
4231     #else
4232 schoenebeck 1673 dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
4233     dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
4234 schoenebeck 3364 #endif
4235 schoenebeck 1673 description.show();
4236 schoenebeck 3364
4237     #if HAS_GTKMM_SHOW_ALL_CHILDREN
4238 persson 1799 entryArea.show_all();
4239 schoenebeck 3364 #else
4240     entryArea.show();
4241     #endif
4242    
4243     #if HAS_GTKMM_STOCK
4244 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4245 schoenebeck 3364 #else
4246     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4247     #endif
4248 schoenebeck 1673 dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
4249     dialog.set_select_multiple(false);
4250 persson 1725 if (current_sample_dir != "") {
4251     dialog.set_current_folder(current_sample_dir);
4252     }
4253 schoenebeck 1673 if (dialog.run() == Gtk::RESPONSE_OK)
4254     {
4255 persson 1725 current_sample_dir = dialog.get_current_folder();
4256 schoenebeck 1673 Glib::ustring error_files;
4257 persson 2169 std::string folder = dialog.get_filename();
4258 schoenebeck 1673 for (gig::Sample* sample = file->GetFirstSample();
4259     sample; sample = file->GetNextSample())
4260     {
4261     std::string filename =
4262 persson 2446 folder + G_DIR_SEPARATOR_S +
4263     Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
4264     postfixEntryBox.get_text());
4265 schoenebeck 1673 SF_INFO info;
4266     info.format = 0;
4267     SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
4268     try
4269     {
4270 persson 1831 if (!hFile) throw std::string(_("could not open file"));
4271 schoenebeck 1673 switch (info.format & 0xff) {
4272     case SF_FORMAT_PCM_S8:
4273     case SF_FORMAT_PCM_16:
4274     case SF_FORMAT_PCM_U8:
4275     case SF_FORMAT_PCM_24:
4276     case SF_FORMAT_PCM_32:
4277     case SF_FORMAT_FLOAT:
4278     case SF_FORMAT_DOUBLE:
4279     break;
4280     default:
4281     sf_close(hFile);
4282 persson 1831 throw std::string(_("format not supported"));
4283 schoenebeck 1673 }
4284     SampleImportItem sched_item;
4285     sched_item.gig_sample = sample;
4286     sched_item.sample_path = filename;
4287 schoenebeck 3116 m_SampleImportQueue[sample] = sched_item;
4288 schoenebeck 1673 sf_close(hFile);
4289     file_changed();
4290     }
4291     catch (std::string what)
4292     {
4293 persson 2442 if (!error_files.empty()) error_files += "\n";
4294 persson 2446 error_files += Glib::filename_to_utf8(filename) +
4295     " (" + what + ")";
4296 schoenebeck 1673 }
4297     }
4298     // show error message box when some file(s) could not be opened / added
4299 persson 2442 if (!error_files.empty()) {
4300 schoenebeck 1673 Glib::ustring txt =
4301     _("Could not replace the following sample(s):\n") + error_files;
4302     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4303     msg.run();
4304     }
4305     }
4306     }
4307    
4308 schoenebeck 1225 void MainWindow::on_action_remove_sample() {
4309     if (!file) return;
4310     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4311 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4312     for (int r = rows.size() - 1; r >= 0; --r) {
4313     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
4314     if (!it) continue;
4315 schoenebeck 1225 Gtk::TreeModel::Row row = *it;
4316     gig::Group* group = row[m_SamplesModel.m_col_group];
4317     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4318     Glib::ustring name = row[m_SamplesModel.m_col_name];
4319     try {
4320     // remove group or sample from the gig file
4321     if (group) {
4322 persson 2446 // temporarily remember the samples that belong to
4323 schoenebeck 1225 // that group (we need that to clean the queue)
4324     std::list<gig::Sample*> members;
4325     for (gig::Sample* pSample = group->GetFirstSample();
4326     pSample; pSample = group->GetNextSample()) {
4327     members.push_back(pSample);
4328     }
4329 schoenebeck 1322 // notify everybody that we're going to remove these samples
4330     samples_to_be_removed_signal.emit(members);
4331 schoenebeck 1225 // delete the group in the .gig file including the
4332     // samples that belong to the group
4333     file->DeleteGroup(group);
4334 schoenebeck 1322 // notify that we're done with removal
4335     samples_removed_signal.emit();
4336 schoenebeck 1225 // if sample(s) were just previously added, remove
4337     // them from the import queue
4338     for (std::list<gig::Sample*>::iterator member = members.begin();
4339 schoenebeck 3116 member != members.end(); ++member)
4340     {
4341     if (m_SampleImportQueue.count(*member)) {
4342     printf("Removing previously added sample '%s' from group '%s'\n",
4343     m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
4344     m_SampleImportQueue.erase(*member);
4345 schoenebeck 1225 }
4346     }
4347 persson 1261 file_changed();
4348 schoenebeck 1225 } else if (sample) {
4349 schoenebeck 1322 // notify everybody that we're going to remove this sample
4350     std::list<gig::Sample*> lsamples;
4351     lsamples.push_back(sample);
4352     samples_to_be_removed_signal.emit(lsamples);
4353 schoenebeck 1225 // remove sample from the .gig file
4354     file->DeleteSample(sample);
4355 schoenebeck 1322 // notify that we're done with removal
4356     samples_removed_signal.emit();
4357 schoenebeck 1225 // if sample was just previously added, remove it from
4358     // the import queue
4359 schoenebeck 3116 if (m_SampleImportQueue.count(sample)) {
4360     printf("Removing previously added sample '%s'\n",
4361     m_SampleImportQueue[sample].sample_path.c_str());
4362     m_SampleImportQueue.erase(sample);
4363 schoenebeck 1225 }
4364 persson 1303 dimreg_changed();
4365 persson 1261 file_changed();
4366 schoenebeck 1225 }
4367     // remove respective row(s) from samples tree view
4368     m_refSamplesTreeModel->erase(it);
4369     } catch (RIFF::Exception e) {
4370 schoenebeck 1322 // pretend we're done with removal (i.e. to avoid dead locks)
4371     samples_removed_signal.emit();
4372     // show error message
4373 schoenebeck 1225 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4374     msg.run();
4375     }
4376     }
4377     }
4378    
4379 schoenebeck 2772 void MainWindow::on_action_remove_unused_samples() {
4380     if (!file) return;
4381    
4382     // collect all samples that are not referenced by any instrument
4383     std::list<gig::Sample*> lsamples;
4384     for (int iSample = 0; file->GetSample(iSample); ++iSample) {
4385     gig::Sample* sample = file->GetSample(iSample);
4386     bool isUsed = false;
4387     for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
4388     instrument = file->GetNextInstrument())
4389     {
4390     for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
4391     rgn = instrument->GetNextRegion())
4392     {
4393     for (int i = 0; i < 256; ++i) {
4394     if (!rgn->pDimensionRegions[i]) continue;
4395     if (rgn->pDimensionRegions[i]->pSample != sample) continue;
4396     isUsed = true;
4397     goto endOfRefSearch;
4398     }
4399     }
4400     }
4401     endOfRefSearch:
4402     if (!isUsed) lsamples.push_back(sample);
4403     }
4404    
4405     if (lsamples.empty()) return;
4406    
4407     // notify everybody that we're going to remove these samples
4408     samples_to_be_removed_signal.emit(lsamples);
4409    
4410     // remove collected samples
4411     try {
4412     for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
4413     itSample != lsamples.end(); ++itSample)
4414     {
4415     gig::Sample* sample = *itSample;
4416     // remove sample from the .gig file
4417     file->DeleteSample(sample);
4418 schoenebeck 3116 // if sample was just previously added, remove it from the import queue
4419     if (m_SampleImportQueue.count(sample)) {
4420     printf("Removing previously added sample '%s'\n",
4421     m_SampleImportQueue[sample].sample_path.c_str());
4422     m_SampleImportQueue.erase(sample);
4423 schoenebeck 2772 }
4424     }
4425     } catch (RIFF::Exception e) {
4426     // show error message
4427     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
4428     msg.run();
4429     }
4430    
4431     // notify everybody that we're done with removal
4432     samples_removed_signal.emit();
4433    
4434     dimreg_changed();
4435     file_changed();
4436     __refreshEntireGUI();
4437     }
4438    
4439 schoenebeck 2610 // see comment on on_sample_treeview_drag_begin()
4440     void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4441     {
4442     first_call_to_drag_data_get = true;
4443     }
4444    
4445     void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4446     Gtk::SelectionData& selection_data, guint, guint)
4447     {
4448     if (!first_call_to_drag_data_get) return;
4449     first_call_to_drag_data_get = false;
4450    
4451     // get selected script
4452     gig::Script* script = NULL;
4453     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
4454     Gtk::TreeModel::iterator it = sel->get_selected();
4455     if (it) {
4456     Gtk::TreeModel::Row row = *it;
4457     script = row[m_ScriptsModel.m_col_script];
4458     }
4459     // pass the gig::Script as pointer
4460     selection_data.set(selection_data.get_target(), 0/*unused*/,
4461     (const guchar*)&script,
4462     sizeof(script)/*length of data in bytes*/);
4463     }
4464    
4465 schoenebeck 2701 // see comment on on_sample_treeview_drag_begin()
4466     void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4467     {
4468     first_call_to_drag_data_get = true;
4469     }
4470    
4471     void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4472     Gtk::SelectionData& selection_data, guint, guint)
4473     {
4474     if (!first_call_to_drag_data_get) return;
4475     first_call_to_drag_data_get = false;
4476    
4477     // get selected source instrument
4478     gig::Instrument* src = NULL;
4479     {
4480     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4481 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4482     if (!rows.empty()) {
4483     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
4484     if (it) {
4485     Gtk::TreeModel::Row row = *it;
4486     src = row[m_Columns.m_col_instr];
4487     }
4488 schoenebeck 2701 }
4489     }
4490     if (!src) return;
4491    
4492     // pass the source gig::Instrument as pointer
4493     selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
4494     sizeof(src)/*length of data in bytes*/);
4495     }
4496    
4497     void MainWindow::on_instruments_treeview_drop_drag_data_received(
4498     const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
4499     const Gtk::SelectionData& selection_data, guint, guint time)
4500     {
4501     gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
4502     if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
4503     return;
4504    
4505     gig::Instrument* dst = NULL;
4506     {
4507     Gtk::TreeModel::Path path;
4508     const bool found = m_TreeView.get_path_at_pos(x, y, path);
4509     if (!found) return;
4510    
4511     Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
4512     if (!iter) return;
4513     Gtk::TreeModel::Row row = *iter;
4514     dst = row[m_Columns.m_col_instr];
4515     }
4516     if (!dst) return;
4517    
4518     //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
4519     src->MoveTo(dst);
4520     __refreshEntireGUI();
4521     select_instrument(src);
4522     }
4523    
4524 persson 1303 // For some reason drag_data_get gets called two times for each
4525     // drag'n'drop (at least when target is an Entry). This work-around
4526     // makes sure the code in drag_data_get and drop_drag_data_received is
4527     // only executed once, as drag_begin only gets called once.
4528     void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
4529     {
4530     first_call_to_drag_data_get = true;
4531     }
4532    
4533 schoenebeck 1225 void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
4534     Gtk::SelectionData& selection_data, guint, guint)
4535     {
4536 persson 1303 if (!first_call_to_drag_data_get) return;
4537     first_call_to_drag_data_get = false;
4538    
4539 schoenebeck 1225 // get selected sample
4540     gig::Sample* sample = NULL;
4541     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4542 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4543     if (!rows.empty()) {
4544     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4545     if (it) {
4546     Gtk::TreeModel::Row row = *it;
4547     sample = row[m_SamplesModel.m_col_sample];
4548     }
4549 schoenebeck 1225 }
4550     // pass the gig::Sample as pointer
4551     selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
4552     sizeof(sample)/*length of data in bytes*/);
4553     }
4554    
4555     void MainWindow::on_sample_label_drop_drag_data_received(
4556     const Glib::RefPtr<Gdk::DragContext>& context, int, int,
4557     const Gtk::SelectionData& selection_data, guint, guint time)
4558     {
4559     gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
4560    
4561 persson 1265 if (sample && selection_data.get_length() == sizeof(gig::Sample*)) {
4562 persson 1303 std::cout << "Drop received sample \"" <<
4563     sample->pInfo->Name << "\"" << std::endl;
4564     // drop success
4565     context->drop_reply(true, time);
4566    
4567 schoenebeck 1322 //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
4568    
4569     // notify everybody that we're going to alter the region
4570     gig::Region* region = m_RegionChooser.get_region();
4571     region_to_be_changed_signal.emit(region);
4572    
4573 persson 1303 // find the samplechannel dimension
4574     gig::dimension_def_t* stereo_dimension = 0;
4575     for (int i = 0 ; i < region->Dimensions ; i++) {
4576     if (region->pDimensionDefinitions[i].dimension ==
4577     gig::dimension_samplechannel) {
4578     stereo_dimension = &region->pDimensionDefinitions[i];
4579     break;
4580     }
4581 schoenebeck 1225 }
4582 persson 1303 bool channels_changed = false;
4583     if (sample->Channels == 1 && stereo_dimension) {
4584     // remove the samplechannel dimension
4585 schoenebeck 2550 /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
4586 persson 1303 region->DeleteDimension(stereo_dimension);
4587     channels_changed = true;
4588     region_changed();
4589 schoenebeck 2550 */
4590 persson 1303 }
4591 schoenebeck 2464 dimreg_edit.set_sample(
4592     sample,
4593     is_copy_samples_unity_note_enabled(),
4594     is_copy_samples_fine_tune_enabled(),
4595     is_copy_samples_loop_enabled()
4596     );
4597 persson 1303
4598     if (sample->Channels == 2 && !stereo_dimension) {
4599     // add samplechannel dimension
4600     gig::dimension_def_t dim;
4601     dim.dimension = gig::dimension_samplechannel;
4602     dim.bits = 1;
4603     dim.zones = 2;
4604     region->AddDimension(&dim);
4605     channels_changed = true;
4606     region_changed();
4607     }
4608     if (channels_changed) {
4609     // unmap all samples with wrong number of channels
4610     // TODO: maybe there should be a warning dialog for this
4611     for (int i = 0 ; i < region->DimensionRegions ; i++) {
4612     gig::DimensionRegion* d = region->pDimensionRegions[i];
4613     if (d->pSample && d->pSample->Channels != sample->Channels) {
4614 schoenebeck 1322 gig::Sample* oldref = d->pSample;
4615     d->pSample = NULL;
4616     sample_ref_changed_signal.emit(oldref, NULL);
4617 persson 1303 }
4618     }
4619     }
4620    
4621 schoenebeck 1322 // notify we're done with altering
4622     region_changed_signal.emit(region);
4623    
4624 persson 1460 file_changed();
4625    
4626 persson 1303 return;
4627 schoenebeck 1225 }
4628     // drop failed
4629     context->drop_reply(false, time);
4630     }
4631    
4632     void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path,
4633     const Gtk::TreeModel::iterator& iter) {
4634     if (!iter) return;
4635     Gtk::TreeModel::Row row = *iter;
4636     Glib::ustring name = row[m_SamplesModel.m_col_name];
4637     gig::Group* group = row[m_SamplesModel.m_col_group];
4638     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4639 persson 2446 gig::String gigname(gig_from_utf8(name));
4640 schoenebeck 1225 if (group) {
4641 persson 2446 if (group->Name != gigname) {
4642     group->Name = gigname;
4643 persson 1261 printf("group name changed\n");
4644     file_changed();
4645     }
4646 schoenebeck 1225 } else if (sample) {
4647 persson 2446 if (sample->pInfo->Name != gigname) {
4648     sample->pInfo->Name = gigname;
4649 persson 1261 printf("sample name changed\n");
4650     file_changed();
4651     }
4652 schoenebeck 1225 }
4653     }
4654    
4655 schoenebeck 2604 void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
4656     const Gtk::TreeModel::iterator& iter) {
4657     if (!iter) return;
4658     Gtk::TreeModel::Row row = *iter;
4659     Glib::ustring name = row[m_ScriptsModel.m_col_name];
4660     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
4661     gig::Script* script = row[m_ScriptsModel.m_col_script];
4662     gig::String gigname(gig_from_utf8(name));
4663     if (group) {
4664     if (group->Name != gigname) {
4665     group->Name = gigname;
4666     printf("script group name changed\n");
4667     file_changed();
4668     }
4669     } else if (script) {
4670     if (script->Name != gigname) {
4671     script->Name = gigname;
4672     printf("script name changed\n");
4673     file_changed();
4674     }
4675     }
4676     }
4677    
4678 schoenebeck 2644 void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
4679     Gtk::TreeViewColumn* column)
4680     {
4681     Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
4682     if (!iter) return;
4683     Gtk::TreeModel::Row row = *iter;
4684     gig::Script* script = row[m_ScriptsModel.m_col_script];
4685     if (!script) return;
4686    
4687     ScriptEditor* editor = new ScriptEditor;
4688 schoenebeck 2903 editor->signal_script_to_be_changed.connect(
4689     signal_script_to_be_changed.make_slot()
4690     );
4691     editor->signal_script_changed.connect(
4692     signal_script_changed.make_slot()
4693     );
4694 schoenebeck 2644 editor->setScript(script);
4695     //editor->reparent(*this);
4696     editor->show();
4697     }
4698    
4699 schoenebeck 1225 void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
4700     const Gtk::TreeModel::iterator& iter) {
4701     if (!iter) return;
4702     Gtk::TreeModel::Row row = *iter;
4703     Glib::ustring name = row[m_Columns.m_col_name];
4704 persson 2442
4705 schoenebeck 3364 #if !USE_GTKMM_BUILDER
4706 persson 2442 // change name in instrument menu
4707     int index = path[0];
4708     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
4709     if (index < children.size()) {
4710     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
4711     static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
4712     #else
4713     remove_instrument_from_menu(index);
4714     Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
4715     item->set_active();
4716     #endif
4717     }
4718 schoenebeck 3364 #endif
4719 persson 2442
4720     // change name in gig
4721 schoenebeck 1225 gig::Instrument* instrument = row[m_Columns.m_col_instr];
4722 persson 2446 gig::String gigname(gig_from_utf8(name));
4723     if (instrument && instrument->pInfo->Name != gigname) {
4724     instrument->pInfo->Name = gigname;
4725 persson 2445
4726     // change name in the instrument properties window
4727     if (instrumentProps.get_instrument() == instrument) {
4728     instrumentProps.update_name();
4729     }
4730    
4731 persson 1261 file_changed();
4732     }
4733 schoenebeck 1225 }
4734 schoenebeck 1322
4735 schoenebeck 3340 bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
4736     if (!iter)
4737     return true;
4738    
4739     Glib::ustring pattern = m_searchText.get_text().lowercase();
4740     trim(pattern);
4741     if (pattern.empty()) return true;
4742    
4743 schoenebeck 3450 #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4744 schoenebeck 3364 //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4745     Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4746     #else
4747 schoenebeck 3340 Gtk::TreeModel::Row row = *iter;
4748 schoenebeck 3364 #endif
4749 schoenebeck 3340 Glib::ustring name = row[m_Columns.m_col_name];
4750     name = name.lowercase();
4751    
4752     std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
4753     for (int t = 0; t < tokens.size(); ++t)
4754     if (name.find(tokens[t]) == Glib::ustring::npos)
4755     return false;
4756    
4757     return true;
4758     }
4759    
4760 schoenebeck 2548 void MainWindow::on_action_combine_instruments() {
4761     CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
4762 schoenebeck 3299
4763     // take over selection from instruments list view for the combine dialog's
4764     // list view as pre-selection
4765     std::set<int> indeces;
4766     {
4767     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
4768     std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4769     for (int r = 0; r < rows.size(); ++r) {
4770     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
4771     if (it) {
4772     Gtk::TreeModel::Row row = *it;
4773     int index = row[m_Columns.m_col_nr];
4774     indeces.insert(index);
4775     }
4776     }
4777     }
4778     d->setSelectedInstruments(indeces);
4779    
4780 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4781 schoenebeck 2548 d->show_all();
4782 schoenebeck 3364 #else
4783     d->show();
4784     #endif
4785 schoenebeck 2548 d->run();
4786     if (d->fileWasChanged()) {
4787     // update GUI with new instrument just created
4788     add_instrument(d->newCombinedInstrument());
4789     }
4790     delete d;
4791     }
4792    
4793 schoenebeck 2624 void MainWindow::on_action_view_references() {
4794     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
4795 schoenebeck 2994 std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4796     if (rows.empty()) return;
4797     Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
4798 schoenebeck 2624 if (!it) return;
4799     Gtk::TreeModel::Row row = *it;
4800     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
4801     if (!sample) return;
4802    
4803     ReferencesView* d = new ReferencesView(*this);
4804     d->setSample(sample);
4805 schoenebeck 2695 d->dimension_region_selected.connect(
4806     sigc::mem_fun(*this, &MainWindow::select_dimension_region)
4807     );
4808 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4809 schoenebeck 2624 d->show_all();
4810 schoenebeck 3364 #else
4811     d->show();
4812     #endif
4813 schoenebeck 2624 d->resize(500, 400);
4814     d->run();
4815     delete d;
4816     }
4817    
4818 schoenebeck 2553 void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
4819     struct _Source {
4820     std::vector<RIFF::File*> riffs;
4821     std::vector<gig::File*> gigs;
4822    
4823     ~_Source() {
4824     for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
4825     for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
4826     riffs.clear();
4827     gigs.clear();
4828     }
4829     } sources;
4830    
4831     if (filenames.empty())
4832     throw RIFF::Exception(_("No files selected, so nothing done."));
4833    
4834     // first open all input files (to avoid output file corruption)
4835     int i;
4836     try {
4837     for (i = 0; i < filenames.size(); ++i) {
4838     const std::string& filename = filenames[i];
4839     printf("opening file=%s\n", filename.c_str());
4840    
4841     RIFF::File* riff = new RIFF::File(filename);
4842     sources.riffs.push_back(riff);
4843    
4844     gig::File* gig = new gig::File(riff);
4845     sources.gigs.push_back(gig);
4846     }
4847     } catch (RIFF::Exception e) {
4848     throw RIFF::Exception(
4849     _("Error occurred while opening '") +
4850     filenames[i] +
4851     "': " +
4852     e.Message
4853     );
4854     } catch (...) {
4855     throw RIFF::Exception(
4856     _("Unknown exception occurred while opening '") +
4857     filenames[i] + "'"
4858     );
4859     }
4860    
4861     // now merge the opened .gig files to the main .gig file currently being
4862     // open in gigedit
4863     try {
4864     for (i = 0; i < filenames.size(); ++i) {
4865     const std::string& filename = filenames[i];
4866     printf("merging file=%s\n", filename.c_str());
4867     assert(i < sources.gigs.size());
4868    
4869     this->file->AddContentOf(sources.gigs[i]);
4870     }
4871     } catch (RIFF::Exception e) {
4872     throw RIFF::Exception(
4873     _("Error occurred while merging '") +
4874     filenames[i] +
4875     "': " +
4876     e.Message
4877     );
4878     } catch (...) {
4879     throw RIFF::Exception(
4880     _("Unknown exception occurred while merging '") +
4881     filenames[i] + "'"
4882     );
4883     }
4884    
4885 schoenebeck 2683 // Finally save gig file persistently to disk ...
4886     //NOTE: requires that this gig file already has a filename !
4887     {
4888     std::cout << "Saving file\n" << std::flush;
4889     file_structure_to_be_changed_signal.emit(this->file);
4890    
4891     progress_dialog = new ProgressDialog( //FIXME: memory leak!
4892     _("Saving") + Glib::ustring(" '") +
4893     Glib::filename_display_basename(this->filename) + "' ...",
4894     *this
4895     );
4896 schoenebeck 3364 #if HAS_GTKMM_SHOW_ALL_CHILDREN
4897 schoenebeck 2683 progress_dialog->show_all();
4898 schoenebeck 3364 #else
4899     progress_dialog->show();
4900     #endif
4901 schoenebeck 2683 saver = new Saver(this->file); //FIXME: memory leak!
4902     saver->signal_progress().connect(
4903     sigc::mem_fun(*this, &MainWindow::on_saver_progress));
4904     saver->signal_finished().connect(
4905     sigc::mem_fun(*this, &MainWindow::on_saver_finished));
4906     saver->signal_error().connect(
4907     sigc::mem_fun(*this, &MainWindow::on_saver_error));
4908     saver->launch();
4909     }
4910 schoenebeck 2553 }
4911    
4912     void MainWindow::on_action_merge_files() {
4913     if (this->file->GetFileName().empty()) {
4914     Glib::ustring txt = _(
4915     "You seem to have a new .gig file open that has not been saved "
4916     "yet. You must save it somewhere before starting to merge it with "
4917     "other .gig files though, because during the merge operation the "
4918     "other files' sample data must be written on file level to the "
4919     "target .gig file."
4920     );
4921     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
4922     msg.run();
4923     return;
4924     }
4925    
4926     Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
4927 schoenebeck 3364 #if HAS_GTKMM_STOCK
4928 schoenebeck 3158 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
4929 schoenebeck 3364 #else
4930     dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
4931     #endif
4932 schoenebeck 2553 dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
4933     dialog.set_default_response(Gtk::RESPONSE_CANCEL);
4934     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4935     Gtk::FileFilter filter;
4936     filter.add_pattern("*.gig");
4937     #else
4938     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
4939     filter->add_pattern("*.gig");
4940     #endif
4941     dialog.set_filter(filter);
4942     if (current_gig_dir != "") {
4943     dialog.set_current_folder(current_gig_dir);
4944     }
4945     dialog.set_select_multiple(true);
4946    
4947     // show warning in the file picker dialog
4948 schoenebeck 3364 HBox descriptionArea;
4949 schoenebeck 2553 descriptionArea.set_spacing(15);
4950 persson 2845 Gtk::Image warningIcon;
4951     warningIcon.set_from_icon_name("dialog-warning",
4952     Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
4953 schoenebeck 2553 descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
4954     #if GTKMM_MAJOR_VERSION < 3
4955     view::WrapLabel description;
4956     #else
4957     Gtk::Label description;
4958     description.set_line_wrap();
4959     #endif
4960     description.set_markup(_(
4961     "\nSelect at least one .gig file that shall be merged to the .gig file "
4962     "currently being open in gigedit.\n\n"
4963     "<b>Please Note:</b> Merging with other files will modify your "
4964     "currently open .gig file on file level! And be aware that the current "
4965     "merge algorithm does not detect duplicate samples yet. So if you are "
4966     "merging files which are using equivalent sample data, those "
4967     "equivalent samples will currently be treated as separate samples and "
4968     "will accordingly be stored separately in the target .gig file!"
4969     ));
4970     descriptionArea.pack_start(description);
4971 schoenebeck 3364 #if USE_GTKMM_BOX
4972     # warning No description area implemented for dialog on GTKMM 3
4973     #else
4974 schoenebeck 2553 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
4975 schoenebeck 3364 #endif
4976     #if HAS_GTKMM_SHOW_ALL_CHILDREN
4977 schoenebeck 2553 descriptionArea.show_all();
4978 schoenebeck 3364 #else
4979     descriptionArea.show();
4980     #endif
4981 schoenebeck 2553
4982     if (dialog.run() == Gtk::RESPONSE_OK) {
4983 persson 2841 printf("on_action_merge_files self=%p\n",
4984     static_cast<void*>(Glib::Threads::Thread::self()));
4985 schoenebeck 2553 std::vector<std::string> filenames = dialog.get_filenames();
4986    
4987     // merge the selected files to the currently open .gig file
4988     try {
4989     mergeFiles(filenames);
4990     } catch (RIFF::Exception e) {
4991     Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
4992     msg.run();
4993     }
4994    
4995     // update GUI
4996 schoenebeck 2772 __refreshEntireGUI();
4997 schoenebeck 2553 }
4998     }
4999    
5000 schoenebeck 1411 void MainWindow::set_file_is_shared(bool b) {
5001     this->file_is_shared = b;
5002    
5003     if (file_is_shared) {
5004     m_AttachedStateLabel.set_label(_("live-mode"));
5005     m_AttachedStateImage.set(
5006     Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
5007     );
5008     } else {
5009     m_AttachedStateLabel.set_label(_("stand-alone"));
5010     m_AttachedStateImage.set(
5011     Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
5012     );
5013     }
5014 schoenebeck 2689
5015     {
5016 schoenebeck 3364 #if USE_GTKMM_BUILDER
5017     m_actionToggleSyncSamplerSelection->property_enabled() = b;
5018     #else
5019 schoenebeck 2689 Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
5020     uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
5021     if (item) item->set_sensitive(b);
5022 schoenebeck 3364 #endif
5023 schoenebeck 2689 }
5024 schoenebeck 1411 }
5025    
5026 schoenebeck 2621 void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
5027     if (!sample) return;
5028     sample_ref_count[sample] += offset;
5029     const int refcount = sample_ref_count[sample];
5030    
5031     Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
5032     for (int g = 0; g < model->children().size(); ++g) {
5033     Gtk::TreeModel::Row rowGroup = model->children()[g];
5034     for (int s = 0; s < rowGroup.children().size(); ++s) {
5035     Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
5036     if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
5037     rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
5038 schoenebeck 2625 rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
5039 schoenebeck 2621 }
5040     }
5041     }
5042    
5043     void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
5044     on_sample_ref_count_incremented(oldSample, -1);
5045     on_sample_ref_count_incremented(newSample, +1);
5046     }
5047    
5048     void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
5049     // just in case a new sample is added later with exactly the same memory
5050     // address, which would lead to incorrect refcount if not deleted here
5051     for (std::list<gig::Sample*>::const_iterator it = samples.begin();
5052 schoenebeck 2666 it != samples.end(); ++it)
5053 schoenebeck 2621 {
5054     sample_ref_count.erase(*it);
5055     }
5056     }
5057    
5058 schoenebeck 2625 void MainWindow::show_samples_tab() {
5059     m_TreeViewNotebook.set_current_page(0);
5060     }
5061    
5062     void MainWindow::show_intruments_tab() {
5063     m_TreeViewNotebook.set_current_page(1);
5064     }
5065    
5066     void MainWindow::show_scripts_tab() {
5067     m_TreeViewNotebook.set_current_page(2);
5068     }
5069    
5070 schoenebeck 3339 void MainWindow::select_instrument_by_dir(int dir) {
5071     if (!file) return;
5072     gig::Instrument* pInstrument = get_instrument();
5073     if (!pInstrument) {
5074     select_instrument( file->GetInstrument(0) );
5075     return;
5076     }
5077     for (int i = 0; file->GetInstrument(i); ++i) {
5078     if (file->GetInstrument(i) == pInstrument) {
5079     select_instrument( file->GetInstrument(i + dir) );
5080     return;
5081     }
5082     }
5083     }
5084    
5085     void MainWindow::select_prev_instrument() {
5086     select_instrument_by_dir(-1);
5087     }
5088    
5089     void MainWindow::select_next_instrument() {
5090     select_instrument_by_dir(1);
5091     }
5092    
5093 schoenebeck 3123 void MainWindow::select_prev_region() {
5094     m_RegionChooser.select_prev_region();
5095     }
5096    
5097     void MainWindow::select_next_region() {
5098     m_RegionChooser.select_next_region();
5099     }
5100    
5101     void MainWindow::select_next_dim_rgn_zone() {
5102     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5103     m_DimRegionChooser.select_next_dimzone();
5104     }
5105    
5106     void MainWindow::select_prev_dim_rgn_zone() {
5107     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5108     m_DimRegionChooser.select_prev_dimzone();
5109     }
5110    
5111 schoenebeck 3134 void MainWindow::select_add_next_dim_rgn_zone() {
5112     m_DimRegionChooser.select_next_dimzone(true);
5113     }
5114    
5115     void MainWindow::select_add_prev_dim_rgn_zone() {
5116     m_DimRegionChooser.select_prev_dimzone(true);
5117     }
5118    
5119 schoenebeck 3123 void MainWindow::select_prev_dimension() {
5120     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5121     m_DimRegionChooser.select_prev_dimension();
5122     }
5123    
5124     void MainWindow::select_next_dimension() {
5125     if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
5126     m_DimRegionChooser.select_next_dimension();
5127     }
5128    
5129 schoenebeck 3144 #define CLIPBOARD_DIMENSIONREGION_TARGET \
5130     ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
5131    
5132     void MainWindow::copy_selected_dimrgn() {
5133     gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5134     if (!pDimRgn) {
5135     updateClipboardPasteAvailable();
5136     updateClipboardCopyAvailable();
5137     return;
5138     }
5139    
5140     std::vector<Gtk::TargetEntry> targets;
5141     targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
5142    
5143     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5144     clipboard->set(
5145     targets,
5146     sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
5147     sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
5148     );
5149    
5150     m_serializationArchive.serialize(pDimRgn);
5151    
5152     updateClipboardPasteAvailable();
5153     }
5154    
5155     void MainWindow::paste_copied_dimrgn() {
5156     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5157     clipboard->request_contents(
5158     CLIPBOARD_DIMENSIONREGION_TARGET,
5159     sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
5160     );
5161     updateClipboardPasteAvailable();
5162     }
5163    
5164 schoenebeck 3151 void MainWindow::adjust_clipboard_content() {
5165 schoenebeck 3155 MacroEditor* editor = new MacroEditor();
5166 schoenebeck 3162 editor->setMacro(&m_serializationArchive, true);
5167 schoenebeck 3151 editor->show();
5168     }
5169    
5170 schoenebeck 3144 void MainWindow::updateClipboardPasteAvailable() {
5171     Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
5172     clipboard->request_targets(
5173     sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
5174     );
5175     }
5176    
5177     void MainWindow::updateClipboardCopyAvailable() {
5178     bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
5179 schoenebeck 3364 #if USE_GTKMM_BUILDER
5180     m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible;
5181     #else
5182 schoenebeck 3144 static_cast<Gtk::MenuItem*>(
5183     uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
5184     )->set_sensitive(bDimensionRegionCopyIsPossible);
5185 schoenebeck 3364 #endif
5186 schoenebeck 3144 }
5187    
5188 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
5189     void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) {
5190     #else
5191 schoenebeck 3144 void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
5192 schoenebeck 3364 #endif
5193 schoenebeck 3144 updateClipboardPasteAvailable();
5194     }
5195    
5196     void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
5197     const std::string target = selection_data.get_target();
5198     if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5199     selection_data.set(
5200     CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
5201     &m_serializationArchive.rawData()[0],
5202     m_serializationArchive.rawData().size()
5203     );
5204     } else {
5205     std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
5206     }
5207     }
5208    
5209     void MainWindow::on_clipboard_clear() {
5210     m_serializationArchive.clear();
5211     updateClipboardPasteAvailable();
5212     updateClipboardCopyAvailable();
5213     }
5214    
5215 schoenebeck 3157 //NOTE: Might throw exception !!!
5216     void MainWindow::applyMacro(Serialization::Archive& macro) {
5217     gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
5218     if (!pDimRgn) return;
5219    
5220     for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
5221     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
5222     {
5223     gig::DimensionRegion* pDimRgn = *itDimReg;
5224 schoenebeck 3177 DimRegionChangeGuard(this, pDimRgn);
5225 schoenebeck 3160 macro.deserialize(pDimRgn);
5226 schoenebeck 3157 }
5227     //region_changed()
5228     file_changed();
5229     dimreg_changed();
5230     }
5231    
5232 schoenebeck 3144 void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
5233     const std::string target = selection_data.get_target();
5234     if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
5235     Glib::ustring errorText;
5236     try {
5237     m_serializationArchive.decode(
5238     selection_data.get_data(), selection_data.get_length()
5239     );
5240 schoenebeck 3157 applyMacro(m_serializationArchive);
5241 schoenebeck 3144 } catch (Serialization::Exception e) {
5242     errorText = e.Message;
5243     } catch (...) {
5244 schoenebeck 3157 errorText = _("Unknown exception while pasting DimensionRegion");
5245 schoenebeck 3144 }
5246     if (!errorText.empty()) {
5247     Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
5248     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
5249     msg.run();
5250     }
5251     }
5252     }
5253    
5254     void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
5255     const bool bDimensionRegionPasteIsPossible =
5256     std::find(targets.begin(), targets.end(),
5257     CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
5258    
5259 schoenebeck 3364 #if USE_GTKMM_BUILDER
5260     m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible;
5261     m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible;
5262     #else
5263 schoenebeck 3144 static_cast<Gtk::MenuItem*>(
5264     uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
5265     )->set_sensitive(bDimensionRegionPasteIsPossible);
5266 schoenebeck 3151
5267     static_cast<Gtk::MenuItem*>(
5268     uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard")
5269     )->set_sensitive(bDimensionRegionPasteIsPossible);
5270 schoenebeck 3364 #endif
5271 schoenebeck 3144 }
5272    
5273 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
5274 schoenebeck 1322 return file_structure_to_be_changed_signal;
5275     }
5276    
5277 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
5278 schoenebeck 1322 return file_structure_changed_signal;
5279     }
5280    
5281 schoenebeck 1339 sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
5282 schoenebeck 1322 return samples_to_be_removed_signal;
5283     }
5284    
5285 schoenebeck 1339 sigc::signal<void>& MainWindow::signal_samples_removed() {
5286 schoenebeck 1322 return samples_removed_signal;
5287     }
5288    
5289 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
5290 schoenebeck 1322 return region_to_be_changed_signal;
5291     }
5292    
5293 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
5294 schoenebeck 1322 return region_changed_signal;
5295     }
5296    
5297 schoenebeck 1853 sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
5298     return sample_changed_signal;
5299     }
5300    
5301 schoenebeck 1339 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
5302 schoenebeck 1322 return sample_ref_changed_signal;
5303     }
5304    
5305 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
5306 schoenebeck 1322 return dimreg_to_be_changed_signal;
5307     }
5308    
5309 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
5310 schoenebeck 1322 return dimreg_changed_signal;
5311     }
5312 schoenebeck 1654
5313     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
5314     return note_on_signal;
5315     }
5316    
5317     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
5318     return note_off_signal;
5319     }
5320 schoenebeck 1660
5321     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
5322     return m_RegionChooser.signal_keyboard_key_hit();
5323     }
5324    
5325     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
5326     return m_RegionChooser.signal_keyboard_key_released();
5327     }
5328 schoenebeck 2689
5329     sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
5330     return switch_sampler_instrument_signal;
5331     }

  ViewVC Help
Powered by ViewVC