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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3300 - (hide annotations) (download)
Sun Jul 9 18:15:02 2017 UTC (6 years, 8 months ago) by schoenebeck
File size: 157945 byte(s)
* Combine Tool: Added a vertical list which represents the order of the
  selected instruments to be combined; dragging them modifies their order.
* Combine Tool: After returning from the combine tool dialog,
  automatically scroll to the newly added (combined) instrument.
* Bumped version (1.0.0.svn55).

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

  ViewVC Help
Powered by ViewVC