/[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 3418 - (hide annotations) (download)
Sat Feb 10 11:36:16 2018 UTC (6 years, 1 month ago) by schoenebeck
File size: 210802 byte(s)
* List assigned scripts as colored tooltip when hovering mouse over the
  "Scripts" column in the instruments list.
* Bumped version (1.1.0.svn5).

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

  ViewVC Help
Powered by ViewVC