/[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 3160 - (show annotations) (download)
Mon May 8 21:31:45 2017 UTC (6 years, 10 months ago) by schoenebeck
File size: 155183 byte(s)
* Macro Setup (WIP): Implemented adding new macro from
  clipboard or from currently selected DimensionRegion.
* Bumped version (1.0.0.svn40).

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

  ViewVC Help
Powered by ViewVC