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