/[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 3540 - (hide annotations) (download)
Sat Jul 27 18:50:28 2019 UTC (4 years, 8 months ago) by schoenebeck
File size: 211037 byte(s)
* Preparations for new release (Gigedit 1.1.1).

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

  ViewVC Help
Powered by ViewVC