/[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 3197 - (show annotations) (download)
Sat May 20 17:15:36 2017 UTC (6 years, 10 months ago) by schoenebeck
File size: 156173 byte(s)
* Instruments list view: show amount of real-time instruments scripts used
  by instrument.
* Bumped version (1.0.0.svn49).

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

  ViewVC Help
Powered by ViewVC