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