/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3177 - (show annotations) (download)
Thu May 11 20:59:46 2017 UTC (6 years, 10 months ago) by schoenebeck
File size: 155262 byte(s)
* Live mode performance optimization: fixed the editor to be non-responsive
  for a very long time, which happened if changing instrument parameters of
  a very large amount of dimension regions was requested.
* Bumped version (1.0.0.svn45).

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

  ViewVC Help
Powered by ViewVC