/[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 3408 - (hide annotations) (download)
Fri Jan 19 19:17:41 2018 UTC (6 years, 2 months ago) by schoenebeck
File size: 205437 byte(s)
* Spelling fixes (patch provided by Debian maintainer Jaromír
  Mikeš).

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

  ViewVC Help
Powered by ViewVC