/[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 2604 - (hide annotations) (download)
Sat Jun 7 22:34:31 2014 UTC (9 years, 9 months ago) by schoenebeck
File size: 100213 byte(s)
* GIG SOUND FORMAT EXTENSION: Added support for managing and
  editing real-time instrument scripts. Instrument scripts are
  a LinuxSampler extension of the original Giga format and will
  not load with the GigaStudio software.
* Added a new tab "Scripts" where script groups and scripts can
  be created and deleted.
* Added an initial script editor.

1 schoenebeck 1225 /*
2 persson 2507 * Copyright (C) 2006-2014 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 2325 #include <glibmm/convert.h>
24     #include <glibmm/dispatcher.h>
25     #include <glibmm/miscutils.h>
26     #include <glibmm/stringutils.h>
27 persson 2151 #include <gtkmm/aboutdialog.h>
28 schoenebeck 1225 #include <gtkmm/filechooserdialog.h>
29     #include <gtkmm/messagedialog.h>
30     #include <gtkmm/stock.h>
31     #include <gtkmm/targetentry.h>
32     #include <gtkmm/main.h>
33 schoenebeck 1415 #include <gtkmm/toggleaction.h>
34 persson 2344 #if GTKMM_MAJOR_VERSION < 3
35 persson 1799 #include "wrapLabel.hh"
36 persson 2344 #endif
37 schoenebeck 1225
38 schoenebeck 1396 #include "global.h"
39 persson 2169 #include "compat.h"
40 schoenebeck 1396
41 schoenebeck 1225 #include <stdio.h>
42     #include <sndfile.h>
43 schoenebeck 2553 #include <assert.h>
44 schoenebeck 1225
45     #include "mainwindow.h"
46 schoenebeck 2541 #include "Settings.h"
47 schoenebeck 2548 #include "CombineInstrumentsDialog.h"
48 schoenebeck 2604 #include "scripteditor.h"
49 schoenebeck 1411 #include "../../gfx/status_attached.xpm"
50     #include "../../gfx/status_detached.xpm"
51    
52 schoenebeck 1225
53 persson 1533 MainWindow::MainWindow() :
54     dimreg_label(_("Changes apply to:")),
55     dimreg_all_regions(_("all regions")),
56     dimreg_all_dimregs(_("all dimension splits")),
57     dimreg_stereo(_("both channels"))
58 schoenebeck 1225 {
59     // set_border_width(5);
60     // set_default_size(400, 200);
61    
62    
63     add(m_VBox);
64    
65     // Handle selection
66 persson 2442 m_TreeView.get_selection()->signal_changed().connect(
67 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_sel_change));
68    
69     // m_TreeView.set_reorderable();
70    
71     m_TreeView.signal_button_press_event().connect_notify(
72     sigc::mem_fun(*this, &MainWindow::on_button_release));
73    
74     // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
75     m_ScrolledWindow.add(m_TreeView);
76     // m_ScrolledWindow.set_size_request(200, 600);
77     m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
78    
79     m_ScrolledWindowSamples.add(m_TreeViewSamples);
80     m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
81    
82 schoenebeck 2604 m_ScrolledWindowScripts.add(m_TreeViewScripts);
83     m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84 schoenebeck 1225
85 schoenebeck 2604
86 schoenebeck 1225 m_TreeViewNotebook.set_size_request(300);
87    
88     m_HPaned.add1(m_TreeViewNotebook);
89 persson 1533 dimreg_hbox.add(dimreg_label);
90     dimreg_hbox.add(dimreg_all_regions);
91     dimreg_hbox.add(dimreg_all_dimregs);
92     dimreg_stereo.set_active();
93     dimreg_hbox.add(dimreg_stereo);
94     dimreg_vbox.add(dimreg_edit);
95 persson 1582 dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
96 persson 1533 m_HPaned.add2(dimreg_vbox);
97 schoenebeck 1225
98 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."));
99     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."));
100     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."));
101     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)."));
102 schoenebeck 1225
103 persson 1831 m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
104     m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
105 schoenebeck 2604 m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
106 schoenebeck 1225
107     actionGroup = Gtk::ActionGroup::create();
108    
109     actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
110     actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW),
111     sigc::mem_fun(
112     *this, &MainWindow::on_action_file_new));
113     Glib::RefPtr<Gtk::Action> action =
114     Gtk::Action::create("Open", Gtk::Stock::OPEN);
115     action->property_label() = action->property_label() + "...";
116     actionGroup->add(action,
117     sigc::mem_fun(
118     *this, &MainWindow::on_action_file_open));
119     actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE),
120     sigc::mem_fun(
121     *this, &MainWindow::on_action_file_save));
122     action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS);
123     action->property_label() = action->property_label() + "...";
124     actionGroup->add(action,
125 persson 1261 Gtk::AccelKey("<shift><control>s"),
126 schoenebeck 1225 sigc::mem_fun(
127 persson 1261 *this, &MainWindow::on_action_file_save_as));
128 schoenebeck 1225 actionGroup->add(Gtk::Action::create("Properties",
129     Gtk::Stock::PROPERTIES),
130     sigc::mem_fun(
131     *this, &MainWindow::on_action_file_properties));
132     actionGroup->add(Gtk::Action::create("InstrProperties",
133     Gtk::Stock::PROPERTIES),
134     sigc::mem_fun(
135     *this, &MainWindow::show_instr_props));
136 persson 2507 actionGroup->add(Gtk::Action::create("MidiRules",
137     _("_Midi Rules")),
138     sigc::mem_fun(
139     *this, &MainWindow::show_midi_rules));
140 schoenebeck 1225 actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
141     sigc::mem_fun(
142 persson 1261 *this, &MainWindow::on_action_quit));
143 schoenebeck 1225 actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
144    
145 schoenebeck 2464
146     actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
147    
148     Glib::RefPtr<Gtk::ToggleAction> toggle_action =
149 schoenebeck 2536 Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
150 schoenebeck 2464 toggle_action->set_active(true);
151     actionGroup->add(toggle_action);
152    
153     toggle_action =
154     Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
155     toggle_action->set_active(true);
156     actionGroup->add(toggle_action);
157    
158     toggle_action =
159     Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
160     toggle_action->set_active(true);
161     actionGroup->add(toggle_action);
162    
163    
164 schoenebeck 1415 actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
165 schoenebeck 2464 toggle_action =
166 schoenebeck 1415 Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
167     toggle_action->set_active(true);
168     actionGroup->add(toggle_action,
169     sigc::mem_fun(
170     *this, &MainWindow::on_action_view_status_bar));
171    
172 schoenebeck 1225 action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
173     actionGroup->add(Gtk::Action::create("MenuHelp",
174     action->property_label()));
175     actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
176     sigc::mem_fun(
177     *this, &MainWindow::on_action_help_about));
178     actionGroup->add(
179     Gtk::Action::create("AddInstrument", _("Add _Instrument")),
180     sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
181     );
182     actionGroup->add(
183 schoenebeck 2395 Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
184     sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
185     );
186     actionGroup->add(
187 schoenebeck 1225 Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
188     sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
189     );
190    
191 schoenebeck 2541
192     actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
193    
194     toggle_action =
195     Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
196     toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
197     actionGroup->add(
198     toggle_action,
199     sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
200     );
201    
202    
203 schoenebeck 2548 actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
204    
205     actionGroup->add(
206     Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
207     sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
208     );
209    
210 schoenebeck 2553 actionGroup->add(
211     Gtk::Action::create("MergeFiles", _("_Merge Files...")),
212     sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
213     );
214 schoenebeck 2548
215 schoenebeck 2553
216 schoenebeck 1225 // sample right-click popup actions
217     actionGroup->add(
218     Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
219     sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
220     );
221     actionGroup->add(
222     Gtk::Action::create("AddGroup", _("Add _Group")),
223     sigc::mem_fun(*this, &MainWindow::on_action_add_group)
224     );
225     actionGroup->add(
226 persson 1799 Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
227 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
228     );
229     actionGroup->add(
230     Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
231     sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
232     );
233 schoenebeck 1673 actionGroup->add(
234 persson 1799 Gtk::Action::create("ReplaceAllSamplesInAllGroups",
235     _("Replace All Samples in All Groups...")),
236 schoenebeck 1673 sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
237     );
238 schoenebeck 2604
239     // script right-click popup actions
240     actionGroup->add(
241     Gtk::Action::create("AddScriptGroup", _("Add _Group")),
242     sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
243     );
244     actionGroup->add(
245     Gtk::Action::create("AddScript", _("Add _Script")),
246     sigc::mem_fun(*this, &MainWindow::on_action_add_script)
247     );
248     actionGroup->add(
249     Gtk::Action::create("EditScript", _("_Edit Script...")),
250     sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
251     );
252     actionGroup->add(
253     Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
254     sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
255     );
256 schoenebeck 1225
257     uiManager = Gtk::UIManager::create();
258     uiManager->insert_action_group(actionGroup);
259 persson 1261 add_accel_group(uiManager->get_accel_group());
260 schoenebeck 1225
261     Glib::ustring ui_info =
262     "<ui>"
263     " <menubar name='MenuBar'>"
264     " <menu action='MenuFile'>"
265     " <menuitem action='New'/>"
266     " <menuitem action='Open'/>"
267     " <separator/>"
268     " <menuitem action='Save'/>"
269     " <menuitem action='SaveAs'/>"
270     " <separator/>"
271     " <menuitem action='Properties'/>"
272     " <separator/>"
273     " <menuitem action='Quit'/>"
274     " </menu>"
275 schoenebeck 2464 " <menu action='MenuEdit'>"
276     " <menuitem action='CopySampleUnity'/>"
277     " <menuitem action='CopySampleTune'/>"
278     " <menuitem action='CopySampleLoop'/>"
279     " </menu>"
280 schoenebeck 1225 " <menu action='MenuInstrument'>"
281     " </menu>"
282 schoenebeck 1415 " <menu action='MenuView'>"
283     " <menuitem action='Statusbar'/>"
284     " </menu>"
285 schoenebeck 2548 " <menu action='MenuTools'>"
286     " <menuitem action='CombineInstruments'/>"
287 schoenebeck 2553 " <menuitem action='MergeFiles'/>"
288 schoenebeck 2548 " </menu>"
289 schoenebeck 2541 " <menu action='MenuSettings'>"
290     " <menuitem action='WarnUserOnExtensions'/>"
291     " </menu>"
292 schoenebeck 1225 " <menu action='MenuHelp'>"
293     " <menuitem action='About'/>"
294     " </menu>"
295     " </menubar>"
296     " <popup name='PopupMenu'>"
297     " <menuitem action='InstrProperties'/>"
298 persson 2507 " <menuitem action='MidiRules'/>"
299 schoenebeck 1225 " <menuitem action='AddInstrument'/>"
300 schoenebeck 2395 " <menuitem action='DupInstrument'/>"
301 schoenebeck 1225 " <separator/>"
302     " <menuitem action='RemoveInstrument'/>"
303     " </popup>"
304     " <popup name='SamplePopupMenu'>"
305     " <menuitem action='SampleProperties'/>"
306     " <menuitem action='AddGroup'/>"
307     " <menuitem action='AddSample'/>"
308 persson 2442 " <menuitem action='ReplaceAllSamplesInAllGroups' />"
309 schoenebeck 1225 " <separator/>"
310     " <menuitem action='RemoveSample'/>"
311     " </popup>"
312 schoenebeck 2604 " <popup name='ScriptPopupMenu'>"
313     " <menuitem action='AddScriptGroup'/>"
314     " <menuitem action='AddScript'/>"
315     " <menuitem action='EditScript'/>"
316     " <separator/>"
317     " <menuitem action='RemoveScript'/>"
318     " </popup>"
319 schoenebeck 1225 "</ui>";
320     uiManager->add_ui_from_string(ui_info);
321    
322     popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
323 schoenebeck 2536
324     // Set tooltips for menu items (for some reason, setting a tooltip on the
325     // respective Gtk::Action objects above will simply be ignored, no matter
326     // if using Gtk::Action::set_tooltip() or passing the tooltip string on
327     // Gtk::Action::create()).
328     {
329     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
330     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
331     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."));
332     }
333     {
334     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
335     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
336     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."));
337     }
338     {
339     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
340     uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
341     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."));
342     }
343 schoenebeck 2541 {
344     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
345     uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
346     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."));
347     }
348 schoenebeck 2553 {
349     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
350     uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
351     item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
352     }
353     {
354     Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
355     uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
356     item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
357     }
358 schoenebeck 1225
359 schoenebeck 2553
360 persson 2442 instrument_menu = static_cast<Gtk::MenuItem*>(
361     uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
362    
363 schoenebeck 1225 Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
364     m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
365     m_VBox.pack_start(m_HPaned);
366     m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
367 schoenebeck 1661 m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
368 schoenebeck 1225 m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
369 schoenebeck 1411 m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
370 schoenebeck 1225
371 persson 2246 set_file_is_shared(false);
372    
373 schoenebeck 1411 // Status Bar:
374     m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
375     m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
376     m_StatusBar.show();
377    
378 persson 1261 m_RegionChooser.signal_region_selected().connect(
379 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::region_changed) );
380 persson 1261 m_DimRegionChooser.signal_dimregion_selected().connect(
381 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::dimreg_changed) );
382    
383    
384     // Create the Tree model:
385     m_refTreeModel = Gtk::ListStore::create(m_Columns);
386     m_TreeView.set_model(m_refTreeModel);
387 schoenebeck 2536 m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
388 persson 2442 instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
389 schoenebeck 1225 sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
390     );
391    
392     // Add the TreeView's view columns:
393     m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
394     m_TreeView.set_headers_visible(false);
395    
396     // create samples treeview (including its data model)
397     m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
398     m_TreeViewSamples.set_model(m_refSamplesTreeModel);
399 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."));
400 schoenebeck 1225 // m_TreeViewSamples.set_reorderable();
401     m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
402     m_TreeViewSamples.set_headers_visible(false);
403     m_TreeViewSamples.signal_button_press_event().connect_notify(
404     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
405     );
406     m_refSamplesTreeModel->signal_row_changed().connect(
407     sigc::mem_fun(*this, &MainWindow::sample_name_changed)
408     );
409    
410 schoenebeck 2604 // create scripts treeview (including its data model)
411     m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
412     m_TreeViewScripts.set_model(m_refScriptsTreeModel);
413     m_TreeViewScripts.set_tooltip_text(_(
414     "Note: instrument scripts are a LinuxSampler extension of the gig "
415     "format. This feature will not work with the GigaStudio software!"
416     ));
417     // m_TreeViewScripts.set_reorderable();
418     m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
419     m_TreeViewScripts.set_headers_visible(false);
420     m_TreeViewScripts.signal_button_press_event().connect_notify(
421     sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
422     );
423     m_refScriptsTreeModel->signal_row_changed().connect(
424     sigc::mem_fun(*this, &MainWindow::script_name_changed)
425     );
426    
427 schoenebeck 1225 // establish drag&drop between samples tree view and dimension region 'Sample' text entry
428 persson 2169 std::vector<Gtk::TargetEntry> drag_target_gig_sample;
429     drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
430 schoenebeck 1225 m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
431 persson 1303 m_TreeViewSamples.signal_drag_begin().connect(
432     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
433     );
434 schoenebeck 1225 m_TreeViewSamples.signal_drag_data_get().connect(
435     sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get)
436     );
437     dimreg_edit.wSample->drag_dest_set(drag_target_gig_sample);
438     dimreg_edit.wSample->signal_drag_data_received().connect(
439     sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
440     );
441 persson 1261 dimreg_edit.signal_dimreg_changed().connect(
442 schoenebeck 1322 sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
443 persson 1261 m_RegionChooser.signal_instrument_changed().connect(
444     sigc::mem_fun(*this, &MainWindow::file_changed));
445     m_DimRegionChooser.signal_region_changed().connect(
446     sigc::mem_fun(*this, &MainWindow::file_changed));
447 persson 2423 instrumentProps.signal_changed().connect(
448 persson 1261 sigc::mem_fun(*this, &MainWindow::file_changed));
449 persson 2423 propDialog.signal_changed().connect(
450 persson 1582 sigc::mem_fun(*this, &MainWindow::file_changed));
451 persson 2507 midiRules.signal_changed().connect(
452     sigc::mem_fun(*this, &MainWindow::file_changed));
453 schoenebeck 1322
454     dimreg_edit.signal_dimreg_to_be_changed().connect(
455     dimreg_to_be_changed_signal.make_slot());
456     dimreg_edit.signal_dimreg_changed().connect(
457     dimreg_changed_signal.make_slot());
458     dimreg_edit.signal_sample_ref_changed().connect(
459     sample_ref_changed_signal.make_slot());
460    
461     m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
462     sigc::hide(
463     sigc::bind(
464     file_structure_to_be_changed_signal.make_slot(),
465     sigc::ref(this->file)
466     )
467     )
468     );
469     m_RegionChooser.signal_instrument_struct_changed().connect(
470     sigc::hide(
471     sigc::bind(
472     file_structure_changed_signal.make_slot(),
473     sigc::ref(this->file)
474     )
475     )
476     );
477     m_RegionChooser.signal_region_to_be_changed().connect(
478     region_to_be_changed_signal.make_slot());
479     m_RegionChooser.signal_region_changed_signal().connect(
480     region_changed_signal.make_slot());
481    
482 schoenebeck 1654 note_on_signal.connect(
483     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
484     note_off_signal.connect(
485     sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
486    
487 persson 1533 dimreg_all_regions.signal_toggled().connect(
488     sigc::mem_fun(*this, &MainWindow::update_dimregs));
489     dimreg_all_dimregs.signal_toggled().connect(
490     sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
491     dimreg_stereo.signal_toggled().connect(
492     sigc::mem_fun(*this, &MainWindow::update_dimregs));
493    
494 schoenebeck 1225 file = 0;
495 persson 1261 file_is_changed = false;
496 schoenebeck 1225
497     show_all_children();
498 schoenebeck 1300
499     // start with a new gig file by default
500     on_action_file_new();
501 schoenebeck 2550
502     // select 'Instruments' tab by default
503     // (gtk allows this only if the tab childs are visible, thats why it's here)
504     m_TreeViewNotebook.set_current_page(1);
505 schoenebeck 1225 }
506    
507     MainWindow::~MainWindow()
508     {
509     }
510    
511 persson 1261 bool MainWindow::on_delete_event(GdkEventAny* event)
512     {
513 schoenebeck 1382 return !file_is_shared && file_is_changed && !close_confirmation_dialog();
514 persson 1261 }
515    
516     void MainWindow::on_action_quit()
517     {
518 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
519 persson 1261 hide();
520     }
521    
522 schoenebeck 1225 void MainWindow::region_changed()
523     {
524     m_DimRegionChooser.set_region(m_RegionChooser.get_region());
525     }
526    
527 persson 1533 gig::Instrument* MainWindow::get_instrument()
528 schoenebeck 1225 {
529 persson 1533 gig::Instrument* instrument = 0;
530 persson 2442 Gtk::TreeModel::const_iterator it =
531     m_TreeView.get_selection()->get_selected();
532 schoenebeck 1225 if (it) {
533     Gtk::TreeModel::Row row = *it;
534 persson 1533 instrument = row[m_Columns.m_col_instr];
535     }
536     return instrument;
537     }
538 schoenebeck 1225
539 persson 1533 void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
540     {
541     if (all_dimregs) {
542     for (int i = 0 ; i < region->DimensionRegions ; i++) {
543     if (region->pDimensionRegions[i]) {
544     dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
545     }
546     }
547 schoenebeck 1225 } else {
548 persson 1533 m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
549 schoenebeck 1225 }
550     }
551    
552 persson 1533 void MainWindow::update_dimregs()
553     {
554     dimreg_edit.dimregs.clear();
555     bool all_regions = dimreg_all_regions.get_active();
556     bool stereo = dimreg_stereo.get_active();
557     bool all_dimregs = dimreg_all_dimregs.get_active();
558    
559     if (all_regions) {
560     gig::Instrument* instrument = get_instrument();
561     if (instrument) {
562     for (gig::Region* region = instrument->GetFirstRegion() ;
563     region ;
564     region = instrument->GetNextRegion()) {
565     add_region_to_dimregs(region, stereo, all_dimregs);
566     }
567     }
568     } else {
569     gig::Region* region = m_RegionChooser.get_region();
570     if (region) {
571     add_region_to_dimregs(region, stereo, all_dimregs);
572     }
573     }
574     }
575    
576     void MainWindow::dimreg_all_dimregs_toggled()
577     {
578     dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
579     update_dimregs();
580     }
581    
582     void MainWindow::dimreg_changed()
583     {
584     update_dimregs();
585     dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
586     }
587    
588     void MainWindow::on_sel_change()
589     {
590 persson 2442 // select item in instrument menu
591     Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
592     if (it) {
593     Gtk::TreePath path(it);
594     int index = path[0];
595     const std::vector<Gtk::Widget*> children =
596     instrument_menu->get_children();
597     static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
598     }
599    
600 persson 1533 m_RegionChooser.set_instrument(get_instrument());
601     }
602    
603 schoenebeck 1225 void loader_progress_callback(gig::progress_t* progress)
604     {
605     Loader* loader = static_cast<Loader*>(progress->custom);
606     loader->progress_callback(progress->factor);
607     }
608    
609     void Loader::progress_callback(float fraction)
610     {
611     {
612 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
613 schoenebeck 1225 progress = fraction;
614     }
615     progress_dispatcher();
616     }
617    
618     void Loader::thread_function()
619     {
620 persson 2325 printf("thread_function self=%x\n", Glib::Threads::Thread::self());
621 schoenebeck 1225 printf("Start %s\n", filename);
622     RIFF::File* riff = new RIFF::File(filename);
623     gig = new gig::File(riff);
624     gig::progress_t progress;
625     progress.callback = loader_progress_callback;
626     progress.custom = this;
627    
628     gig->GetInstrument(0, &progress);
629     printf("End\n");
630     finished_dispatcher();
631     }
632    
633     Loader::Loader(const char* filename)
634 persson 2151 : filename(filename), thread(0)
635 schoenebeck 1225 {
636     }
637    
638     void Loader::launch()
639     {
640 persson 2332 #ifdef OLD_THREADS
641     thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
642     #else
643     thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
644     #endif
645 schoenebeck 1225 printf("launch thread=%x\n", thread);
646     }
647    
648     float Loader::get_progress()
649     {
650     float res;
651     {
652 persson 2325 Glib::Threads::Mutex::Lock lock(progressMutex);
653 schoenebeck 1225 res = progress;
654     }
655     return res;
656     }
657    
658     Glib::Dispatcher& Loader::signal_progress()
659     {
660     return progress_dispatcher;
661     }
662    
663     Glib::Dispatcher& Loader::signal_finished()
664     {
665     return finished_dispatcher;
666     }
667    
668     LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent)
669     : Gtk::Dialog(title, parent, true)
670     {
671     get_vbox()->pack_start(progressBar);
672     show_all_children();
673     }
674    
675     // Clear all GUI elements / controls. This method is typically called
676     // before a new .gig file is to be created or to be loaded.
677     void MainWindow::__clear() {
678     // forget all samples that ought to be imported
679     m_SampleImportQueue.clear();
680     // clear the samples and instruments tree views
681     m_refTreeModel->clear();
682     m_refSamplesTreeModel->clear();
683 persson 2442 // remove all entries from "Instrument" menu
684     while (!instrument_menu->get_children().empty()) {
685     remove_instrument_from_menu(0);
686     }
687 schoenebeck 1225 // free libgig's gig::File instance
688 schoenebeck 1382 if (file && !file_is_shared) delete file;
689     file = NULL;
690 schoenebeck 1411 set_file_is_shared(false);
691 schoenebeck 1225 }
692    
693 schoenebeck 2553 void MainWindow::__refreshEntireGUI() {
694     // clear the samples and instruments tree views
695     m_refTreeModel->clear();
696     m_refSamplesTreeModel->clear();
697     // remove all entries from "Instrument" menu
698     while (!instrument_menu->get_children().empty()) {
699     remove_instrument_from_menu(0);
700     }
701    
702     if (!this->file) return;
703    
704     load_gig(
705     this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
706     );
707     }
708    
709 schoenebeck 1225 void MainWindow::on_action_file_new()
710     {
711 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
712 persson 1261
713 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
714    
715 schoenebeck 1225 // clear all GUI elements
716     __clear();
717     // create a new .gig file (virtually yet)
718     gig::File* pFile = new gig::File;
719     // already add one new instrument by default
720     gig::Instrument* pInstrument = pFile->AddInstrument();
721 persson 2446 pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
722 schoenebeck 1225 // update GUI with that new gig::File
723 persson 1261 load_gig(pFile, 0 /*no file name yet*/);
724 schoenebeck 1225 }
725    
726 persson 1261 bool MainWindow::close_confirmation_dialog()
727     {
728     gchar* msg = g_strdup_printf(_("Save changes to \"%s\" before closing?"),
729     Glib::filename_display_basename(filename).c_str());
730     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
731     g_free(msg);
732     dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
733     dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
734     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
735     dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
736     dialog.set_default_response(Gtk::RESPONSE_YES);
737     int response = dialog.run();
738 persson 1303 dialog.hide();
739 persson 1261 if (response == Gtk::RESPONSE_YES) return file_save();
740     return response != Gtk::RESPONSE_CANCEL;
741     }
742    
743 schoenebeck 1382 bool MainWindow::leaving_shared_mode_dialog() {
744     Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
745     Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
746     dialog.set_secondary_text(
747     _("If you proceed to work on another instrument file, it won't be "
748     "used by the sampler until you tell the sampler explicitly to "
749 persson 2151 "load it."));
750 schoenebeck 1382 dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
751     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
752     dialog.set_default_response(Gtk::RESPONSE_CANCEL);
753     int response = dialog.run();
754     dialog.hide();
755     return response == Gtk::RESPONSE_YES;
756     }
757    
758 schoenebeck 1225 void MainWindow::on_action_file_open()
759     {
760 schoenebeck 1382 if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
761 persson 1261
762 schoenebeck 1382 if (file_is_shared && !leaving_shared_mode_dialog()) return;
763    
764 schoenebeck 1225 Gtk::FileChooserDialog dialog(*this, _("Open file"));
765     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
766     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
767 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
768 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
769 schoenebeck 1225 Gtk::FileFilter filter;
770     filter.add_pattern("*.gig");
771 persson 2169 #else
772     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
773     filter->add_pattern("*.gig");
774     #endif
775 schoenebeck 1225 dialog.set_filter(filter);
776 persson 1725 if (current_gig_dir != "") {
777     dialog.set_current_folder(current_gig_dir);
778 persson 1261 }
779 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
780 persson 1261 std::string filename = dialog.get_filename();
781     printf("filename=%s\n", filename.c_str());
782 persson 2325 printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
783 persson 1261 load_file(filename.c_str());
784 persson 1725 current_gig_dir = Glib::path_get_dirname(filename);
785 schoenebeck 1225 }
786     }
787    
788     void MainWindow::load_file(const char* name)
789     {
790 persson 1303 __clear();
791 persson 1831 load_dialog = new LoadDialog(_("Loading..."), *this);
792 schoenebeck 1225 load_dialog->show_all();
793     loader = new Loader(strdup(name));
794     loader->signal_progress().connect(
795     sigc::mem_fun(*this, &MainWindow::on_loader_progress));
796     loader->signal_finished().connect(
797     sigc::mem_fun(*this, &MainWindow::on_loader_finished));
798     loader->launch();
799     }
800    
801     void MainWindow::load_instrument(gig::Instrument* instr) {
802     if (!instr) {
803     Glib::ustring txt = "Provided instrument is NULL!\n";
804     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
805     msg.run();
806     Gtk::Main::quit();
807     }
808 schoenebeck 1328 // clear all GUI elements
809     __clear();
810     // load the instrument
811 schoenebeck 1225 gig::File* pFile = (gig::File*) instr->GetParent();
812 schoenebeck 1382 load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
813 schoenebeck 1225 //TODO: automatically select the given instrument
814     }
815    
816     void MainWindow::on_loader_progress()
817     {
818     load_dialog->set_fraction(loader->get_progress());
819     }
820    
821     void MainWindow::on_loader_finished()
822     {
823     printf("Loader finished!\n");
824 persson 2325 printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
825 schoenebeck 1225 load_gig(loader->gig, loader->filename);
826     load_dialog->hide();
827     }
828    
829     void MainWindow::on_action_file_save()
830     {
831 persson 1261 file_save();
832     }
833    
834 persson 1303 bool MainWindow::check_if_savable()
835     {
836     if (!file) return false;
837    
838     if (!file->GetFirstSample()) {
839     Gtk::MessageDialog(*this, _("The file could not be saved "
840     "because it contains no samples"),
841     false, Gtk::MESSAGE_ERROR).run();
842     return false;
843     }
844    
845     for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ;
846     instrument = file->GetNextInstrument()) {
847     if (!instrument->GetFirstRegion()) {
848     Gtk::MessageDialog(*this, _("The file could not be saved "
849     "because there are instruments "
850     "that have no regions"),
851     false, Gtk::MESSAGE_ERROR).run();
852     return false;
853     }
854     }
855     return true;
856     }
857    
858 persson 1261 bool MainWindow::file_save()
859     {
860 persson 1303 if (!check_if_savable()) return false;
861 schoenebeck 1382 if (!file_is_shared && !file_has_name) return file_save_as();
862 persson 1261
863 schoenebeck 1225 std::cout << "Saving file\n" << std::flush;
864 schoenebeck 1322 file_structure_to_be_changed_signal.emit(this->file);
865 schoenebeck 1225 try {
866     file->Save();
867 persson 1261 if (file_is_changed) {
868     set_title(get_title().substr(1));
869     file_is_changed = false;
870     }
871 schoenebeck 1225 } catch (RIFF::Exception e) {
872 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
873 schoenebeck 1382 Glib::ustring txt = _("Could not save file: ") + e.Message;
874 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
875     msg.run();
876 persson 1261 return false;
877 schoenebeck 1225 }
878     std::cout << "Saving file done\n" << std::flush;
879     __import_queued_samples();
880 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
881 persson 1261 return true;
882 schoenebeck 1225 }
883    
884     void MainWindow::on_action_file_save_as()
885     {
886 persson 1303 if (!check_if_savable()) return;
887 persson 1261 file_save_as();
888     }
889    
890     bool MainWindow::file_save_as()
891     {
892     Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE);
893 schoenebeck 1225 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
894     dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
895 persson 1261 dialog.set_default_response(Gtk::RESPONSE_OK);
896 persson 2151 dialog.set_do_overwrite_confirmation();
897 persson 1261
898 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
899 schoenebeck 1225 Gtk::FileFilter filter;
900     filter.add_pattern("*.gig");
901 persson 2169 #else
902     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
903     filter->add_pattern("*.gig");
904     #endif
905 schoenebeck 1225 dialog.set_filter(filter);
906 persson 1261
907 schoenebeck 1679 // set initial dir and filename of the Save As dialog
908     // and prepare that initial filename as a copy of the gig
909     {
910     std::string basename = Glib::path_get_basename(filename);
911     std::string dir = Glib::path_get_dirname(filename);
912 persson 1831 basename = std::string(_("copy_of_")) + basename;
913 schoenebeck 1679 Glib::ustring copyFileName = Glib::build_filename(dir, basename);
914     if (Glib::path_is_absolute(filename)) {
915     dialog.set_filename(copyFileName);
916     } else {
917 persson 1725 if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
918 schoenebeck 1679 }
919     dialog.set_current_name(Glib::filename_display_basename(copyFileName));
920 persson 1261 }
921    
922 schoenebeck 1679 // show warning in the dialog
923     Gtk::HBox descriptionArea;
924     descriptionArea.set_spacing(15);
925     Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
926     descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
927 persson 2344 #if GTKMM_MAJOR_VERSION < 3
928 persson 1799 view::WrapLabel description;
929 persson 2344 #else
930     Gtk::Label description;
931     description.set_line_wrap();
932     #endif
933 schoenebeck 1679 description.set_markup(
934     _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
935     "<span style=\"italic\">\"Save\"</span> dialog instead of "
936     "<span style=\"italic\">\"Save As...\"</span> if you want to save "
937     "to the same .gig file. Using "
938     "<span style=\"italic\">\"Save As...\"</span> for writing to the "
939     "same .gig file will end up in corrupted sample wave data!\n")
940     );
941 persson 1799 descriptionArea.pack_start(description);
942 schoenebeck 1679 dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
943 persson 1799 descriptionArea.show_all();
944 schoenebeck 1679
945 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
946 schoenebeck 1322 file_structure_to_be_changed_signal.emit(this->file);
947 schoenebeck 1225 try {
948 persson 1261 std::string filename = dialog.get_filename();
949     if (!Glib::str_has_suffix(filename, ".gig")) {
950     filename += ".gig";
951     }
952     printf("filename=%s\n", filename.c_str());
953     file->Save(filename);
954     this->filename = filename;
955 persson 1725 current_gig_dir = Glib::path_get_dirname(filename);
956 persson 1261 set_title(Glib::filename_display_basename(filename));
957     file_has_name = true;
958     file_is_changed = false;
959 schoenebeck 1225 } catch (RIFF::Exception e) {
960 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
961 schoenebeck 1382 Glib::ustring txt = _("Could not save file: ") + e.Message;
962 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
963     msg.run();
964 persson 1261 return false;
965 schoenebeck 1225 }
966     __import_queued_samples();
967 schoenebeck 1322 file_structure_changed_signal.emit(this->file);
968 persson 1261 return true;
969 schoenebeck 1225 }
970 persson 1261 return false;
971 schoenebeck 1225 }
972    
973     // actually write the sample(s)' data to the gig file
974     void MainWindow::__import_queued_samples() {
975     std::cout << "Starting sample import\n" << std::flush;
976     Glib::ustring error_files;
977     printf("Samples to import: %d\n", m_SampleImportQueue.size());
978     for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
979     iter != m_SampleImportQueue.end(); ) {
980     printf("Importing sample %s\n",(*iter).sample_path.c_str());
981     SF_INFO info;
982     info.format = 0;
983     SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
984 persson 2398 sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
985 schoenebeck 1225 try {
986 persson 1831 if (!hFile) throw std::string(_("could not open file"));
987 schoenebeck 1225 // determine sample's bit depth
988     int bitdepth;
989     switch (info.format & 0xff) {
990     case SF_FORMAT_PCM_S8:
991     case SF_FORMAT_PCM_16:
992 persson 1265 case SF_FORMAT_PCM_U8:
993 schoenebeck 1225 bitdepth = 16;
994     break;
995     case SF_FORMAT_PCM_24:
996     case SF_FORMAT_PCM_32:
997     case SF_FORMAT_FLOAT:
998     case SF_FORMAT_DOUBLE:
999 persson 1265 bitdepth = 24;
1000 schoenebeck 1225 break;
1001     default:
1002     sf_close(hFile); // close sound file
1003 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
1004 schoenebeck 1225 }
1005 persson 1265
1006     const int bufsize = 10000;
1007 schoenebeck 1225 switch (bitdepth) {
1008 persson 1265 case 16: {
1009     short* buffer = new short[bufsize * info.channels];
1010     sf_count_t cnt = info.frames;
1011     while (cnt) {
1012     // libsndfile does the conversion for us (if needed)
1013     int n = sf_readf_short(hFile, buffer, bufsize);
1014     // write from buffer directly (physically) into .gig file
1015     iter->gig_sample->Write(buffer, n);
1016     cnt -= n;
1017     }
1018     delete[] buffer;
1019 schoenebeck 1225 break;
1020 persson 1265 }
1021     case 24: {
1022     int* srcbuf = new int[bufsize * info.channels];
1023     uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels];
1024     sf_count_t cnt = info.frames;
1025     while (cnt) {
1026     // libsndfile returns 32 bits, convert to 24
1027     int n = sf_readf_int(hFile, srcbuf, bufsize);
1028     int j = 0;
1029     for (int i = 0 ; i < n * info.channels ; i++) {
1030     dstbuf[j++] = srcbuf[i] >> 8;
1031     dstbuf[j++] = srcbuf[i] >> 16;
1032     dstbuf[j++] = srcbuf[i] >> 24;
1033     }
1034     // write from buffer directly (physically) into .gig file
1035     iter->gig_sample->Write(dstbuf, n);
1036     cnt -= n;
1037     }
1038     delete[] srcbuf;
1039     delete[] dstbuf;
1040 schoenebeck 1225 break;
1041 persson 1265 }
1042 schoenebeck 1225 }
1043     // cleanup
1044     sf_close(hFile);
1045 schoenebeck 1853 // let the sampler re-cache the sample if needed
1046     sample_changed_signal.emit(iter->gig_sample);
1047 schoenebeck 1225 // on success we remove the sample from the import queue,
1048     // otherwise keep it, maybe it works the next time ?
1049     std::list<SampleImportItem>::iterator cur = iter;
1050     ++iter;
1051     m_SampleImportQueue.erase(cur);
1052     } catch (std::string what) {
1053     // remember the files that made trouble (and their cause)
1054 persson 2442 if (!error_files.empty()) error_files += "\n";
1055 schoenebeck 1225 error_files += (*iter).sample_path += " (" + what + ")";
1056     ++iter;
1057     }
1058     }
1059     // show error message box when some sample(s) could not be imported
1060 persson 2442 if (!error_files.empty()) {
1061 schoenebeck 1382 Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
1062 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1063     msg.run();
1064     }
1065     }
1066    
1067     void MainWindow::on_action_file_properties()
1068     {
1069     propDialog.show();
1070     propDialog.deiconify();
1071     }
1072    
1073 schoenebeck 2541 void MainWindow::on_action_warn_user_on_extensions() {
1074     Settings::singleton()->warnUserOnExtensions =
1075     !Settings::singleton()->warnUserOnExtensions;
1076     }
1077    
1078 schoenebeck 1225 void MainWindow::on_action_help_about()
1079     {
1080     Gtk::AboutDialog dialog;
1081 persson 1959 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
1082     dialog.set_program_name("Gigedit");
1083     #else
1084     dialog.set_name("Gigedit");
1085     #endif
1086 schoenebeck 1225 dialog.set_version(VERSION);
1087 persson 2507 dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1088 schoenebeck 2476 const std::string sComment =
1089     _("Built " __DATE__ "\nUsing ") +
1090     ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1091     _(
1092     "Gigedit is released under the GNU General Public License.\n"
1093     "\n"
1094     "Please notice that this is still a very young instrument editor. "
1095     "So better backup your Gigasampler files before editing them with "
1096     "this application.\n"
1097     "\n"
1098     "Please report bugs to: http://bugs.linuxsampler.org"
1099     );
1100     dialog.set_comments(sComment.c_str());
1101 schoenebeck 1436 dialog.set_website("http://www.linuxsampler.org");
1102     dialog.set_website_label("http://www.linuxsampler.org");
1103 schoenebeck 1225 dialog.run();
1104     }
1105    
1106     PropDialog::PropDialog()
1107 schoenebeck 2560 : eFileFormat(_("File Format")),
1108     eName(_("Name")),
1109 persson 1831 eCreationDate(_("Creation date")),
1110     eComments(_("Comments")),
1111     eProduct(_("Product")),
1112     eCopyright(_("Copyright")),
1113     eArtists(_("Artists")),
1114     eGenre(_("Genre")),
1115     eKeywords(_("Keywords")),
1116     eEngineer(_("Engineer")),
1117     eTechnician(_("Technician")),
1118     eSoftware(_("Software")),
1119     eMedium(_("Medium")),
1120     eSource(_("Source")),
1121     eSourceForm(_("Source form")),
1122     eCommissioned(_("Commissioned")),
1123     eSubject(_("Subject")),
1124 persson 1582 quitButton(Gtk::Stock::CLOSE),
1125 schoenebeck 2560 table(2, 1),
1126     m_file(NULL)
1127 schoenebeck 1225 {
1128 persson 1831 set_title(_("File Properties"));
1129 persson 1582 eName.set_width_chars(50);
1130    
1131     connect(eName, &DLS::Info::Name);
1132     connect(eCreationDate, &DLS::Info::CreationDate);
1133     connect(eComments, &DLS::Info::Comments);
1134     connect(eProduct, &DLS::Info::Product);
1135     connect(eCopyright, &DLS::Info::Copyright);
1136     connect(eArtists, &DLS::Info::Artists);
1137     connect(eGenre, &DLS::Info::Genre);
1138     connect(eKeywords, &DLS::Info::Keywords);
1139     connect(eEngineer, &DLS::Info::Engineer);
1140     connect(eTechnician, &DLS::Info::Technician);
1141     connect(eSoftware, &DLS::Info::Software);
1142     connect(eMedium, &DLS::Info::Medium);
1143     connect(eSource, &DLS::Info::Source);
1144     connect(eSourceForm, &DLS::Info::SourceForm);
1145     connect(eCommissioned, &DLS::Info::Commissioned);
1146     connect(eSubject, &DLS::Info::Subject);
1147    
1148 schoenebeck 2560 table.add(eFileFormat);
1149 persson 1582 table.add(eName);
1150     table.add(eCreationDate);
1151     table.add(eComments);
1152     table.add(eProduct);
1153     table.add(eCopyright);
1154     table.add(eArtists);
1155     table.add(eGenre);
1156     table.add(eKeywords);
1157     table.add(eEngineer);
1158     table.add(eTechnician);
1159     table.add(eSoftware);
1160     table.add(eMedium);
1161     table.add(eSource);
1162     table.add(eSourceForm);
1163     table.add(eCommissioned);
1164     table.add(eSubject);
1165    
1166 schoenebeck 1225 table.set_col_spacings(5);
1167 persson 1582 add(vbox);
1168     table.set_border_width(5);
1169     vbox.add(table);
1170     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
1171     buttonBox.set_layout(Gtk::BUTTONBOX_END);
1172     buttonBox.set_border_width(5);
1173     buttonBox.show();
1174     buttonBox.pack_start(quitButton);
1175 persson 2151 quitButton.set_can_default();
1176 persson 1582 quitButton.grab_focus();
1177     quitButton.signal_clicked().connect(
1178     sigc::mem_fun(*this, &PropDialog::hide));
1179 schoenebeck 2560 eFileFormat.signal_value_changed().connect(
1180     sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1181 schoenebeck 1225
1182 persson 1582 quitButton.show();
1183     vbox.show();
1184 schoenebeck 1225 show_all_children();
1185     }
1186    
1187 schoenebeck 2560 void PropDialog::set_file(gig::File* file)
1188     {
1189     m_file = file;
1190    
1191     // update file format version combo box
1192     const std::string sGiga = "Gigasampler/GigaStudio v";
1193     const int major = file->pVersion->major;
1194     std::vector<std::string> txts;
1195     std::vector<int> values;
1196     txts.push_back(sGiga + "2"); values.push_back(2);
1197 schoenebeck 2566 txts.push_back(sGiga + "3/v4"); values.push_back(3);
1198 schoenebeck 2560 if (major != 2 && major != 3) {
1199     txts.push_back(sGiga + ToString(major)); values.push_back(major);
1200     }
1201     std::vector<const char*> texts;
1202     for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1203 persson 2579 texts.push_back(NULL); values.push_back(0);
1204 schoenebeck 2560 eFileFormat.set_choices(&texts[0], &values[0]);
1205     eFileFormat.set_value(major);
1206     }
1207    
1208     void PropDialog::onFileFormatChanged() {
1209     const int major = eFileFormat.get_value();
1210     if (m_file) m_file->pVersion->major = major;
1211     }
1212    
1213 schoenebeck 1225 void PropDialog::set_info(DLS::Info* info)
1214     {
1215 persson 2423 update(info);
1216 schoenebeck 1225 }
1217    
1218 persson 1582
1219 persson 2445 void InstrumentProps::set_Name(const gig::String& name)
1220     {
1221     m->pInfo->Name = name;
1222     }
1223    
1224     void InstrumentProps::update_name()
1225     {
1226     update_model++;
1227     eName.set_value(m->pInfo->Name);
1228     update_model--;
1229     }
1230    
1231 persson 1460 void InstrumentProps::set_IsDrum(bool value)
1232     {
1233 persson 2423 m->IsDrum = value;
1234 persson 1460 }
1235    
1236     void InstrumentProps::set_MIDIBank(uint16_t value)
1237     {
1238 persson 2423 m->MIDIBank = value;
1239 persson 1460 }
1240    
1241     void InstrumentProps::set_MIDIProgram(uint32_t value)
1242     {
1243 persson 2423 m->MIDIProgram = value;
1244 persson 1460 }
1245    
1246 persson 2423 InstrumentProps::InstrumentProps() :
1247     quitButton(Gtk::Stock::CLOSE),
1248     table(2,1),
1249     eName(_("Name")),
1250     eIsDrum(_("Is drum")),
1251     eMIDIBank(_("MIDI bank"), 0, 16383),
1252     eMIDIProgram(_("MIDI program")),
1253     eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1254     eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1255     eEffectSend(_("Effect send"), 0, 65535),
1256     eFineTune(_("Fine tune"), -8400, 8400),
1257     ePitchbendRange(_("Pitchbend range"), 0, 12),
1258     ePianoReleaseMode(_("Piano release mode")),
1259     eDimensionKeyRangeLow(_("Keyswitching range low")),
1260     eDimensionKeyRangeHigh(_("Keyswitching range high"))
1261 persson 1460 {
1262 persson 1831 set_title(_("Instrument Properties"));
1263 schoenebeck 1225
1264 schoenebeck 1656 eDimensionKeyRangeLow.set_tip(
1265     _("start of the keyboard area which should switch the "
1266     "\"keyswitching\" dimension")
1267     );
1268     eDimensionKeyRangeHigh.set_tip(
1269     _("end of the keyboard area which should switch the "
1270     "\"keyswitching\" dimension")
1271     );
1272    
1273 persson 2445 connect(eName, &InstrumentProps::set_Name);
1274 persson 1460 connect(eIsDrum, &InstrumentProps::set_IsDrum);
1275     connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1276     connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
1277     connect(eAttenuation, &gig::Instrument::Attenuation);
1278     connect(eGainPlus6, &gig::Instrument::Attenuation);
1279     connect(eEffectSend, &gig::Instrument::EffectSend);
1280     connect(eFineTune, &gig::Instrument::FineTune);
1281     connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1282     connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1283 persson 2423 connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1284     &gig::Instrument::DimensionKeyRange);
1285 persson 1460
1286 persson 2445 eName.signal_value_changed().connect(sig_name_changed.make_slot());
1287    
1288 schoenebeck 1225 table.set_col_spacings(5);
1289    
1290 persson 1582 table.add(eName);
1291     table.add(eIsDrum);
1292     table.add(eMIDIBank);
1293     table.add(eMIDIProgram);
1294     table.add(eAttenuation);
1295     table.add(eGainPlus6);
1296     table.add(eEffectSend);
1297     table.add(eFineTune);
1298     table.add(ePitchbendRange);
1299     table.add(ePianoReleaseMode);
1300     table.add(eDimensionKeyRangeLow);
1301     table.add(eDimensionKeyRangeHigh);
1302 schoenebeck 1225
1303     add(vbox);
1304     table.set_border_width(5);
1305     vbox.pack_start(table);
1306     table.show();
1307     vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
1308     buttonBox.set_layout(Gtk::BUTTONBOX_END);
1309     buttonBox.set_border_width(5);
1310     buttonBox.show();
1311     buttonBox.pack_start(quitButton);
1312 persson 2151 quitButton.set_can_default();
1313 schoenebeck 1225 quitButton.grab_focus();
1314    
1315     quitButton.signal_clicked().connect(
1316     sigc::mem_fun(*this, &InstrumentProps::hide));
1317    
1318     quitButton.show();
1319     vbox.show();
1320     show_all_children();
1321     }
1322    
1323     void InstrumentProps::set_instrument(gig::Instrument* instrument)
1324     {
1325 persson 2423 update(instrument);
1326 persson 1460
1327     update_model++;
1328 persson 2445 eName.set_value(instrument->pInfo->Name);
1329 persson 1460 eIsDrum.set_value(instrument->IsDrum);
1330     eMIDIBank.set_value(instrument->MIDIBank);
1331     eMIDIProgram.set_value(instrument->MIDIProgram);
1332     update_model--;
1333 schoenebeck 1225 }
1334    
1335    
1336 persson 1261 void MainWindow::file_changed()
1337     {
1338     if (file && !file_is_changed) {
1339     set_title("*" + get_title());
1340     file_is_changed = true;
1341 schoenebeck 1225 }
1342 persson 1261 }
1343 schoenebeck 1225
1344 schoenebeck 1382 void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1345 persson 1261 {
1346     file = 0;
1347 schoenebeck 1411 set_file_is_shared(isSharedInstrument);
1348 persson 1261
1349     this->filename = filename ? filename : _("Unsaved Gig File");
1350     set_title(Glib::filename_display_basename(this->filename));
1351     file_has_name = filename;
1352     file_is_changed = false;
1353    
1354 schoenebeck 2560 propDialog.set_file(gig);
1355 schoenebeck 1225 propDialog.set_info(gig->pInfo);
1356    
1357 persson 2442 instrument_name_connection.block();
1358 schoenebeck 1225 for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1359     instrument = gig->GetNextInstrument()) {
1360 persson 2446 Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1361 persson 2442
1362 schoenebeck 1225 Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1363     Gtk::TreeModel::Row row = *iter;
1364 persson 2442 row[m_Columns.m_col_name] = name;
1365 schoenebeck 1225 row[m_Columns.m_col_instr] = instrument;
1366 persson 2442
1367     add_instrument_to_menu(name);
1368 schoenebeck 1225 }
1369 persson 2442 instrument_name_connection.unblock();
1370     uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1371 schoenebeck 1225
1372     for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1373     if (group->Name != "") {
1374     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1375     Gtk::TreeModel::Row rowGroup = *iterGroup;
1376 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1377 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_group] = group;
1378     rowGroup[m_SamplesModel.m_col_sample] = NULL;
1379     for (gig::Sample* sample = group->GetFirstSample();
1380     sample; sample = group->GetNextSample()) {
1381     Gtk::TreeModel::iterator iterSample =
1382     m_refSamplesTreeModel->append(rowGroup.children());
1383     Gtk::TreeModel::Row rowSample = *iterSample;
1384 persson 2446 rowSample[m_SamplesModel.m_col_name] =
1385     gig_to_utf8(sample->pInfo->Name);
1386 schoenebeck 1225 rowSample[m_SamplesModel.m_col_sample] = sample;
1387     rowSample[m_SamplesModel.m_col_group] = NULL;
1388     }
1389     }
1390     }
1391 schoenebeck 2604
1392     for (int i = 0; gig->GetScriptGroup(i); ++i) {
1393     gig::ScriptGroup* group = gig->GetScriptGroup(i);
1394 schoenebeck 1225
1395 schoenebeck 2604 Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1396     Gtk::TreeModel::Row rowGroup = *iterGroup;
1397     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1398     rowGroup[m_ScriptsModel.m_col_group] = group;
1399     rowGroup[m_ScriptsModel.m_col_script] = NULL;
1400     for (int s = 0; group->GetScript(s); ++s) {
1401     gig::Script* script = group->GetScript(s);
1402    
1403     Gtk::TreeModel::iterator iterScript =
1404     m_refScriptsTreeModel->append(rowGroup.children());
1405     Gtk::TreeModel::Row rowScript = *iterScript;
1406     rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1407     rowScript[m_ScriptsModel.m_col_script] = script;
1408     rowScript[m_ScriptsModel.m_col_group] = NULL;
1409     }
1410     }
1411     // unfold all script groups by default
1412     m_TreeViewScripts.expand_all();
1413    
1414 persson 1261 file = gig;
1415    
1416 schoenebeck 1225 // select the first instrument
1417 persson 2442 m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1418 persson 2423
1419 persson 2445 instr_props_set_instrument();
1420 persson 2507 gig::Instrument* instrument = get_instrument();
1421     if (instrument) {
1422     midiRules.set_instrument(instrument);
1423     }
1424 persson 2445 }
1425    
1426     bool MainWindow::instr_props_set_instrument()
1427     {
1428     instrumentProps.signal_name_changed().clear();
1429    
1430     Gtk::TreeModel::const_iterator it =
1431     m_TreeView.get_selection()->get_selected();
1432     if (it) {
1433     Gtk::TreeModel::Row row = *it;
1434     gig::Instrument* instrument = row[m_Columns.m_col_instr];
1435    
1436 persson 2423 instrumentProps.set_instrument(instrument);
1437 persson 2445
1438     // make sure instrument tree is updated when user changes the
1439     // instrument name in instrument properties window
1440     instrumentProps.signal_name_changed().connect(
1441     sigc::bind(
1442     sigc::mem_fun(*this,
1443     &MainWindow::instr_name_changed_by_instr_props),
1444     it));
1445     } else {
1446     instrumentProps.hide();
1447 persson 2423 }
1448 persson 2445 return it;
1449 schoenebeck 1225 }
1450    
1451     void MainWindow::show_instr_props()
1452     {
1453 persson 2445 if (instr_props_set_instrument()) {
1454 persson 1533 instrumentProps.show();
1455     instrumentProps.deiconify();
1456 schoenebeck 1225 }
1457     }
1458    
1459 persson 2445 void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1460     {
1461     Gtk::TreeModel::Row row = *it;
1462     Glib::ustring name = row[m_Columns.m_col_name];
1463    
1464     gig::Instrument* instrument = row[m_Columns.m_col_instr];
1465 persson 2446 Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1466     if (gigname != name) {
1467     row[m_Columns.m_col_name] = gigname;
1468 persson 2445 }
1469     }
1470    
1471 persson 2507 void MainWindow::show_midi_rules()
1472     {
1473     if (gig::Instrument* instrument = get_instrument())
1474     {
1475     midiRules.set_instrument(instrument);
1476     midiRules.show();
1477     midiRules.deiconify();
1478     }
1479     }
1480    
1481 schoenebeck 1415 void MainWindow::on_action_view_status_bar() {
1482     Gtk::CheckMenuItem* item =
1483     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
1484     if (!item) {
1485     std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n";
1486     return;
1487     }
1488     if (item->get_active()) m_StatusBar.show();
1489     else m_StatusBar.hide();
1490     }
1491    
1492 schoenebeck 2464 bool MainWindow::is_copy_samples_unity_note_enabled() const {
1493     Gtk::CheckMenuItem* item =
1494     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1495     if (!item) {
1496     std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1497     return true;
1498     }
1499     return item->get_active();
1500     }
1501    
1502     bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1503     Gtk::CheckMenuItem* item =
1504     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1505     if (!item) {
1506     std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1507     return true;
1508     }
1509     return item->get_active();
1510     }
1511    
1512     bool MainWindow::is_copy_samples_loop_enabled() const {
1513     Gtk::CheckMenuItem* item =
1514     dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1515     if (!item) {
1516     std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1517     return true;
1518     }
1519     return item->get_active();
1520     }
1521    
1522 schoenebeck 1225 void MainWindow::on_button_release(GdkEventButton* button)
1523     {
1524     if (button->type == GDK_2BUTTON_PRESS) {
1525     show_instr_props();
1526     } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1527 persson 2507 // gig v2 files have no midi rules
1528     static_cast<Gtk::MenuItem*>(
1529     uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1530     !(file->pVersion && file->pVersion->major == 2));
1531 schoenebeck 1225 popup_menu->popup(button->button, button->time);
1532     }
1533     }
1534    
1535 persson 2442 void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1536     if (item->get_active()) {
1537     const std::vector<Gtk::Widget*> children =
1538     instrument_menu->get_children();
1539     std::vector<Gtk::Widget*>::const_iterator it =
1540     find(children.begin(), children.end(), item);
1541     if (it != children.end()) {
1542     int index = it - children.begin();
1543     m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1544    
1545     m_RegionChooser.set_instrument(file->GetInstrument(index));
1546     }
1547     }
1548 schoenebeck 1225 }
1549    
1550     void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1551     if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1552     Gtk::Menu* sample_popup =
1553     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
1554     // update enabled/disabled state of sample popup items
1555     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1556     Gtk::TreeModel::iterator it = sel->get_selected();
1557     bool group_selected = false;
1558     bool sample_selected = false;
1559     if (it) {
1560     Gtk::TreeModel::Row row = *it;
1561     group_selected = row[m_SamplesModel.m_col_group];
1562     sample_selected = row[m_SamplesModel.m_col_sample];
1563     }
1564     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1565     set_sensitive(group_selected || sample_selected);
1566     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1567     set_sensitive(group_selected || sample_selected);
1568     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1569     set_sensitive(file);
1570     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1571     set_sensitive(group_selected || sample_selected);
1572     // show sample popup
1573     sample_popup->popup(button->button, button->time);
1574     }
1575     }
1576    
1577 schoenebeck 2604 void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1578     if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1579     Gtk::Menu* script_popup =
1580     dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1581     // update enabled/disabled state of sample popup items
1582     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1583     Gtk::TreeModel::iterator it = sel->get_selected();
1584     bool group_selected = false;
1585     bool script_selected = false;
1586     if (it) {
1587     Gtk::TreeModel::Row row = *it;
1588     group_selected = row[m_ScriptsModel.m_col_group];
1589     script_selected = row[m_ScriptsModel.m_col_script];
1590     }
1591     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1592     set_sensitive(group_selected || script_selected);
1593     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1594     set_sensitive(file);
1595     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1596     set_sensitive(script_selected);
1597     dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1598     set_sensitive(group_selected || script_selected);
1599     // show sample popup
1600     script_popup->popup(button->button, button->time);
1601     }
1602     }
1603 persson 2442
1604     Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1605     const Glib::ustring& name, int position) {
1606    
1607     Gtk::RadioMenuItem::Group instrument_group;
1608     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1609     if (!children.empty()) {
1610     instrument_group =
1611     static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1612     }
1613     Gtk::RadioMenuItem* item =
1614     new Gtk::RadioMenuItem(instrument_group, name);
1615     if (position < 0) {
1616     instrument_menu->append(*item);
1617     } else {
1618     instrument_menu->insert(*item, position);
1619     }
1620     item->show();
1621     item->signal_activate().connect(
1622     sigc::bind(
1623     sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1624     item));
1625     return item;
1626     }
1627    
1628     void MainWindow::remove_instrument_from_menu(int index) {
1629     const std::vector<Gtk::Widget*> children =
1630     instrument_menu->get_children();
1631     Gtk::Widget* child = children[index];
1632     instrument_menu->remove(*child);
1633     delete child;
1634     }
1635    
1636     void MainWindow::add_instrument(gig::Instrument* instrument) {
1637 persson 2446 const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1638 persson 2442
1639     // update instrument tree view
1640     instrument_name_connection.block();
1641     Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1642     Gtk::TreeModel::Row rowInstr = *iterInstr;
1643     rowInstr[m_Columns.m_col_name] = name;
1644     rowInstr[m_Columns.m_col_instr] = instrument;
1645     instrument_name_connection.unblock();
1646    
1647     add_instrument_to_menu(name);
1648    
1649     m_TreeView.get_selection()->select(iterInstr);
1650    
1651     file_changed();
1652     }
1653    
1654 schoenebeck 1225 void MainWindow::on_action_add_instrument() {
1655     static int __instrument_indexer = 0;
1656     if (!file) return;
1657     gig::Instrument* instrument = file->AddInstrument();
1658     __instrument_indexer++;
1659 persson 2446 instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1660     ToString(__instrument_indexer));
1661 persson 2442
1662     add_instrument(instrument);
1663 schoenebeck 1225 }
1664    
1665 schoenebeck 2395 void MainWindow::on_action_duplicate_instrument() {
1666     if (!file) return;
1667 persson 2442
1668 schoenebeck 2395 // retrieve the currently selected instrument
1669     // (being the original instrument to be duplicated)
1670     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1671     Gtk::TreeModel::iterator itSelection = sel->get_selected();
1672     if (!itSelection) return;
1673     Gtk::TreeModel::Row row = *itSelection;
1674     gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1675     if (!instrOrig) return;
1676 persson 2442
1677 schoenebeck 2395 // duplicate the orginal instrument
1678     gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1679     instrNew->pInfo->Name =
1680 persson 2446 instrOrig->pInfo->Name +
1681     gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1682 persson 2442
1683     add_instrument(instrNew);
1684 schoenebeck 2395 }
1685    
1686 schoenebeck 1225 void MainWindow::on_action_remove_instrument() {
1687     if (!file) return;
1688 schoenebeck 1382 if (file_is_shared) {
1689     Gtk::MessageDialog msg(
1690     *this,
1691     _("You cannot delete an instrument from this file, since it's "
1692     "currently used by the sampler."),
1693     false, Gtk::MESSAGE_INFO
1694     );
1695     msg.run();
1696     return;
1697     }
1698    
1699 schoenebeck 1225 Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1700     Gtk::TreeModel::iterator it = sel->get_selected();
1701     if (it) {
1702     Gtk::TreeModel::Row row = *it;
1703     gig::Instrument* instr = row[m_Columns.m_col_instr];
1704     try {
1705 persson 2442 Gtk::TreePath path(it);
1706     int index = path[0];
1707    
1708 schoenebeck 1225 // remove instrument from the gig file
1709     if (instr) file->DeleteInstrument(instr);
1710 persson 1261 file_changed();
1711 persson 2423
1712 persson 2442 remove_instrument_from_menu(index);
1713    
1714     // remove row from instruments tree view
1715     m_refTreeModel->erase(it);
1716    
1717     #if GTKMM_MAJOR_VERSION < 3
1718     // select another instrument (in gtk3 this is done
1719     // automatically)
1720     if (!m_refTreeModel->children().empty()) {
1721     if (index == m_refTreeModel->children().size()) {
1722     index--;
1723     }
1724     m_TreeView.get_selection()->select(
1725     Gtk::TreePath(ToString(index)));
1726     }
1727     #endif
1728 persson 2445 instr_props_set_instrument();
1729 persson 2507 instr = get_instrument();
1730     if (instr) {
1731     midiRules.set_instrument(instr);
1732     } else {
1733     midiRules.hide();
1734     }
1735 schoenebeck 1225 } catch (RIFF::Exception e) {
1736     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1737     msg.run();
1738     }
1739     }
1740     }
1741    
1742     void MainWindow::on_action_sample_properties() {
1743     //TODO: show a dialog where the selected sample's properties can be edited
1744     Gtk::MessageDialog msg(
1745 persson 1831 *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1746 schoenebeck 1225 );
1747     msg.run();
1748     }
1749    
1750 schoenebeck 2604 void MainWindow::on_action_add_script_group() {
1751     static int __script_indexer = 0;
1752     if (!file) return;
1753     gig::ScriptGroup* group = file->AddScriptGroup();
1754     group->Name = gig_from_utf8(_("Unnamed Group"));
1755     if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1756     __script_indexer++;
1757     // update sample tree view
1758     Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1759     Gtk::TreeModel::Row rowGroup = *iterGroup;
1760     rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1761     rowGroup[m_ScriptsModel.m_col_script] = NULL;
1762     rowGroup[m_ScriptsModel.m_col_group] = group;
1763     file_changed();
1764     }
1765    
1766     void MainWindow::on_action_add_script() {
1767     if (!file) return;
1768     // get selected group
1769     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1770     Gtk::TreeModel::iterator it = sel->get_selected();
1771     if (!it) return;
1772     Gtk::TreeModel::Row row = *it;
1773     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1774     if (!group) { // not a group, but a script is selected (probably)
1775     gig::Script* script = row[m_ScriptsModel.m_col_script];
1776     if (!script) return;
1777     it = row.parent(); // resolve parent (that is the script's group)
1778     if (!it) return;
1779     row = *it;
1780     group = row[m_ScriptsModel.m_col_group];
1781     if (!group) return;
1782     }
1783    
1784     // add a new script to the .gig file
1785     gig::Script* script = group->AddScript();
1786     Glib::ustring name = _("Unnamed Script");
1787     script->Name = gig_from_utf8(name);
1788    
1789     // add script to the tree view
1790     Gtk::TreeModel::iterator iterScript =
1791     m_refScriptsTreeModel->append(row.children());
1792     Gtk::TreeModel::Row rowScript = *iterScript;
1793     rowScript[m_ScriptsModel.m_col_name] = name;
1794     rowScript[m_ScriptsModel.m_col_script] = script;
1795     rowScript[m_ScriptsModel.m_col_group] = NULL;
1796    
1797     // unfold group of new script item in treeview
1798     Gtk::TreeModel::Path path(iterScript);
1799     m_TreeViewScripts.expand_to_path(path);
1800     }
1801    
1802     void MainWindow::on_action_edit_script() {
1803     if (!file) return;
1804     // get selected script
1805     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1806     Gtk::TreeModel::iterator it = sel->get_selected();
1807     if (!it) return;
1808     Gtk::TreeModel::Row row = *it;
1809     gig::Script* script = row[m_ScriptsModel.m_col_script];
1810     if (!script) return;
1811    
1812     ScriptEditor* editor = new ScriptEditor;
1813     editor->setScript(script);
1814     //editor->reparent(*this);
1815     editor->show();
1816     }
1817    
1818     void MainWindow::on_action_remove_script() {
1819     if (!file) return;
1820     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1821     Gtk::TreeModel::iterator it = sel->get_selected();
1822     if (it) {
1823     Gtk::TreeModel::Row row = *it;
1824     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1825     gig::Script* script = row[m_ScriptsModel.m_col_script];
1826     Glib::ustring name = row[m_ScriptsModel.m_col_name];
1827     try {
1828     // remove script group or script from the gig file
1829     if (group) {
1830     // notify everybody that we're going to remove these samples
1831     //TODO: scripts_to_be_removed_signal.emit(members);
1832     // delete the group in the .gig file including the
1833     // samples that belong to the group
1834     file->DeleteScriptGroup(group);
1835     // notify that we're done with removal
1836     //TODO: scripts_removed_signal.emit();
1837     file_changed();
1838     } else if (script) {
1839     // notify everybody that we're going to remove this sample
1840     //TODO: std::list<gig::Script*> lscripts;
1841     //TODO: lscripts.push_back(script);
1842     //TODO: scripts_to_be_removed_signal.emit(lscripts);
1843     // remove sample from the .gig file
1844     script->GetGroup()->DeleteScript(script);
1845     // notify that we're done with removal
1846     //TODO: scripts_removed_signal.emit();
1847     dimreg_changed();
1848     file_changed();
1849     }
1850     // remove respective row(s) from samples tree view
1851     m_refScriptsTreeModel->erase(it);
1852     } catch (RIFF::Exception e) {
1853     // pretend we're done with removal (i.e. to avoid dead locks)
1854     //TODO: scripts_removed_signal.emit();
1855     // show error message
1856     Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1857     msg.run();
1858     }
1859     }
1860     }
1861    
1862 schoenebeck 1225 void MainWindow::on_action_add_group() {
1863     static int __sample_indexer = 0;
1864     if (!file) return;
1865     gig::Group* group = file->AddGroup();
1866 persson 2446 group->Name = gig_from_utf8(_("Unnamed Group"));
1867 schoenebeck 1225 if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1868     __sample_indexer++;
1869     // update sample tree view
1870     Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1871     Gtk::TreeModel::Row rowGroup = *iterGroup;
1872 persson 2446 rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1873 schoenebeck 1225 rowGroup[m_SamplesModel.m_col_sample] = NULL;
1874     rowGroup[m_SamplesModel.m_col_group] = group;
1875 persson 1261 file_changed();
1876 schoenebeck 1225 }
1877    
1878     void MainWindow::on_action_add_sample() {
1879     if (!file) return;
1880     // get selected group
1881     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1882     Gtk::TreeModel::iterator it = sel->get_selected();
1883     if (!it) return;
1884     Gtk::TreeModel::Row row = *it;
1885     gig::Group* group = row[m_SamplesModel.m_col_group];
1886     if (!group) { // not a group, but a sample is selected (probably)
1887     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1888     if (!sample) return;
1889     it = row.parent(); // resolve parent (that is the sample's group)
1890     if (!it) return;
1891     row = *it;
1892     group = row[m_SamplesModel.m_col_group];
1893     if (!group) return;
1894     }
1895     // show 'browse for file' dialog
1896     Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));
1897     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1898     dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1899     dialog.set_select_multiple(true);
1900 persson 2169
1901     // matches all file types supported by libsndfile
1902     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1903     Gtk::FileFilter soundfilter;
1904     #else
1905     Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1906     #endif
1907 persson 1262 const char* const supportedFileTypes[] = {
1908 schoenebeck 1225 "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1909     "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
1910     "*.svx", "*.SVX", "*.sf", "*.SF", "*.voc", "*.VOC", "*.w64",
1911     "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1912     "*.caf", "*.CAF", NULL
1913     };
1914 persson 2169 const char* soundfiles = _("Sound Files");
1915     const char* allfiles = _("All Files");
1916     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1917 schoenebeck 1225 for (int i = 0; supportedFileTypes[i]; i++)
1918     soundfilter.add_pattern(supportedFileTypes[i]);
1919 persson 2169 soundfilter.set_name(soundfiles);
1920    
1921     // matches every file
1922     Gtk::FileFilter allpassfilter;
1923 schoenebeck 1225 allpassfilter.add_pattern("*.*");
1924 persson 2169 allpassfilter.set_name(allfiles);
1925     #else
1926     for (int i = 0; supportedFileTypes[i]; i++)
1927     soundfilter->add_pattern(supportedFileTypes[i]);
1928     soundfilter->set_name(soundfiles);
1929    
1930     // matches every file
1931     Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1932     allpassfilter->add_pattern("*.*");
1933     allpassfilter->set_name(allfiles);
1934     #endif
1935 schoenebeck 1225 dialog.add_filter(soundfilter);
1936     dialog.add_filter(allpassfilter);
1937 persson 1725 if (current_sample_dir != "") {
1938     dialog.set_current_folder(current_sample_dir);
1939     }
1940 schoenebeck 1225 if (dialog.run() == Gtk::RESPONSE_OK) {
1941 persson 1725 current_sample_dir = dialog.get_current_folder();
1942 schoenebeck 1225 Glib::ustring error_files;
1943 persson 2169 std::vector<std::string> filenames = dialog.get_filenames();
1944     for (std::vector<std::string>::iterator iter = filenames.begin();
1945 schoenebeck 1225 iter != filenames.end(); ++iter) {
1946     printf("Adding sample %s\n",(*iter).c_str());
1947     // use libsndfile to retrieve file informations
1948     SF_INFO info;
1949     info.format = 0;
1950     SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1951     try {
1952 persson 1831 if (!hFile) throw std::string(_("could not open file"));
1953 schoenebeck 1225 int bitdepth;
1954     switch (info.format & 0xff) {
1955     case SF_FORMAT_PCM_S8:
1956     case SF_FORMAT_PCM_16:
1957 persson 1265 case SF_FORMAT_PCM_U8:
1958 schoenebeck 1225 bitdepth = 16;
1959     break;
1960     case SF_FORMAT_PCM_24:
1961     case SF_FORMAT_PCM_32:
1962     case SF_FORMAT_FLOAT:
1963     case SF_FORMAT_DOUBLE:
1964 persson 1265 bitdepth = 24;
1965 schoenebeck 1225 break;
1966     default:
1967     sf_close(hFile); // close sound file
1968 persson 1831 throw std::string(_("format not supported")); // unsupported subformat (yet?)
1969 schoenebeck 1225 }
1970     // add a new sample to the .gig file
1971     gig::Sample* sample = file->AddSample();
1972     // file name without path
1973 persson 1262 Glib::ustring filename = Glib::filename_display_basename(*iter);
1974     // remove file extension if there is one
1975     for (int i = 0; supportedFileTypes[i]; i++) {
1976     if (Glib::str_has_suffix(filename, supportedFileTypes[i] + 1)) {
1977     filename.erase(filename.length() - strlen(supportedFileTypes[i] + 1));
1978     break;
1979     }
1980     }
1981 persson 2446 sample->pInfo->Name = gig_from_utf8(filename);
1982 schoenebeck 1225 sample->Channels = info.channels;
1983     sample->BitDepth = bitdepth;
1984     sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
1985     sample->SamplesPerSecond = info.samplerate;
1986 persson 1265 sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond;
1987     sample->BlockAlign = sample->FrameSize;
1988     sample->SamplesTotal = info.frames;
1989    
1990     SF_INSTRUMENT instrument;
1991     if (sf_command(hFile, SFC_GET_INSTRUMENT,
1992     &instrument, sizeof(instrument)) != SF_FALSE)
1993     {
1994     sample->MIDIUnityNote = instrument.basenote;
1995 schoenebeck 2466 sample->FineTune = instrument.detune;
1996 persson 1265
1997     if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1998     sample->Loops = 1;
1999    
2000     switch (instrument.loops[0].mode) {
2001     case SF_LOOP_FORWARD:
2002     sample->LoopType = gig::loop_type_normal;
2003     break;
2004     case SF_LOOP_BACKWARD:
2005     sample->LoopType = gig::loop_type_backward;
2006     break;
2007     case SF_LOOP_ALTERNATING:
2008     sample->LoopType = gig::loop_type_bidirectional;
2009     break;
2010     }
2011     sample->LoopStart = instrument.loops[0].start;
2012     sample->LoopEnd = instrument.loops[0].end;
2013     sample->LoopPlayCount = instrument.loops[0].count;
2014     sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
2015     }
2016     }
2017    
2018 schoenebeck 1225 // schedule resizing the sample (which will be done
2019     // physically when File::Save() is called)
2020     sample->Resize(info.frames);
2021     // make sure sample is part of the selected group
2022     group->AddSample(sample);
2023     // schedule that physical resize and sample import
2024     // (data copying), performed when "Save" is requested
2025     SampleImportItem sched_item;
2026     sched_item.gig_sample = sample;
2027     sched_item.sample_path = *iter;
2028     m_SampleImportQueue.push_back(sched_item);
2029     // add sample to the tree view
2030     Gtk::TreeModel::iterator iterSample =
2031     m_refSamplesTreeModel->append(row.children());
2032     Gtk::TreeModel::Row rowSample = *iterSample;
2033 persson 2446 rowSample[m_SamplesModel.m_col_name] =
2034     gig_to_utf8(sample->pInfo->Name);
2035 schoenebeck 1225 rowSample[m_SamplesModel.m_col_sample] = sample;
2036     rowSample[m_SamplesModel.m_col_group] = NULL;
2037     // close sound file
2038     sf_close(hFile);
2039 persson 1261 file_changed();
2040 schoenebeck 1225 } catch (std::string what) { // remember the files that made trouble (and their cause)
2041 persson 2442 if (!error_files.empty()) error_files += "\n";
2042 schoenebeck 1225 error_files += *iter += " (" + what + ")";
2043     }
2044     }
2045     // show error message box when some file(s) could not be opened / added
2046 persson 2442 if (!error_files.empty()) {
2047 schoenebeck 1382 Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
2048 schoenebeck 1225 Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2049     msg.run();
2050     }
2051     }
2052     }
2053    
2054 schoenebeck 1673 void MainWindow::on_action_replace_all_samples_in_all_groups()
2055     {
2056     if (!file) return;
2057     Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
2058     Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
2059 persson 2442 const char* str =
2060 schoenebeck 1673 _("This is a very specific function. It tries to replace all samples "
2061 persson 1799 "in the current gig file by samples located in the chosen "
2062     "directory.\n\n"
2063     "It works like this: For each sample in the gig file, it tries to "
2064 schoenebeck 1673 "find a sample file in the selected directory with the same name as "
2065 persson 1799 "the sample in the gig file. Optionally, you can add a filename "
2066     "extension below, which will be added to the filename expected to be "
2067 schoenebeck 1673 "found. That is, assume you have a gig file with a sample called "
2068     "'Snare', if you enter '.wav' below (like it's done by default), it "
2069 persson 1799 "expects to find a sample file called 'Snare.wav' and will replace "
2070     "the sample in the gig file accordingly. If you don't need an "
2071     "extension, blank the field below. Any gig sample where no "
2072     "appropriate sample file could be found will be reported and left "
2073 persson 2344 "untouched.\n");
2074     #if GTKMM_MAJOR_VERSION < 3
2075     view::WrapLabel description(str);
2076     #else
2077     Gtk::Label description(str);
2078     description.set_line_wrap();
2079     #endif
2080 schoenebeck 1673 Gtk::HBox entryArea;
2081 persson 2169 Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
2082 schoenebeck 1673 Gtk::Entry postfixEntryBox;
2083     postfixEntryBox.set_text(".wav");
2084     entryArea.pack_start(entryLabel);
2085     entryArea.pack_start(postfixEntryBox);
2086     dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
2087     dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
2088     description.show();
2089 persson 1799 entryArea.show_all();
2090 schoenebeck 1673 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2091     dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
2092     dialog.set_select_multiple(false);
2093 persson 1725 if (current_sample_dir != "") {
2094     dialog.set_current_folder(current_sample_dir);
2095     }
2096 schoenebeck 1673 if (dialog.run() == Gtk::RESPONSE_OK)
2097     {
2098 persson 1725 current_sample_dir = dialog.get_current_folder();
2099 schoenebeck 1673 Glib::ustring error_files;
2100 persson 2169 std::string folder = dialog.get_filename();
2101 schoenebeck 1673 for (gig::Sample* sample = file->GetFirstSample();
2102     sample; sample = file->GetNextSample())
2103     {
2104     std::string filename =
2105 persson 2446 folder + G_DIR_SEPARATOR_S +
2106     Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
2107     postfixEntryBox.get_text());
2108 schoenebeck 1673 SF_INFO info;
2109     info.format = 0;
2110     SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
2111     try
2112     {
2113 persson 1831 if (!hFile) throw std::string(_("could not open file"));
2114 schoenebeck 1673 int bitdepth;
2115     switch (info.format & 0xff) {
2116     case SF_FORMAT_PCM_S8:
2117     case SF_FORMAT_PCM_16:
2118     case SF_FORMAT_PCM_U8:
2119     bitdepth = 16;
2120     break;
2121     case SF_FORMAT_PCM_24:
2122     case SF_FORMAT_PCM_32:
2123     case SF_FORMAT_FLOAT:
2124     case SF_FORMAT_DOUBLE:
2125     bitdepth = 24;
2126     break;
2127     default:
2128     sf_close(hFile);
2129 persson 1831 throw std::string(_("format not supported"));
2130 schoenebeck 1673 }
2131     SampleImportItem sched_item;
2132     sched_item.gig_sample = sample;
2133     sched_item.sample_path = filename;
2134     m_SampleImportQueue.push_back(sched_item);
2135     sf_close(hFile);
2136     file_changed();
2137     }
2138     catch (std::string what)
2139     {
2140 persson 2442 if (!error_files.empty()) error_files += "\n";
2141 persson 2446 error_files += Glib::filename_to_utf8(filename) +
2142     " (" + what + ")";
2143 schoenebeck 1673 }
2144     }
2145     // show error message box when some file(s) could not be opened / added
2146 persson 2442 if (!error_files.empty()) {
2147 schoenebeck 1673 Glib::ustring txt =
2148     _("Could not replace the following sample(s):\n") + error_files;
2149     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2150     msg.run();
2151     }
2152     }
2153     }
2154    
2155 schoenebeck 1225 void MainWindow::on_action_remove_sample() {
2156     if (!file) return;
2157     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2158     Gtk::TreeModel::iterator it = sel->get_selected();
2159     if (it) {
2160     Gtk::TreeModel::Row row = *it;
2161     gig::Group* group = row[m_SamplesModel.m_col_group];
2162     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2163     Glib::ustring name = row[m_SamplesModel.m_col_name];
2164     try {
2165     // remove group or sample from the gig file
2166     if (group) {
2167 persson 2446 // temporarily remember the samples that belong to
2168 schoenebeck 1225 // that group (we need that to clean the queue)
2169     std::list<gig::Sample*> members;
2170     for (gig::Sample* pSample = group->GetFirstSample();
2171     pSample; pSample = group->GetNextSample()) {
2172     members.push_back(pSample);
2173     }
2174 schoenebeck 1322 // notify everybody that we're going to remove these samples
2175     samples_to_be_removed_signal.emit(members);
2176 schoenebeck 1225 // delete the group in the .gig file including the
2177     // samples that belong to the group
2178     file->DeleteGroup(group);
2179 schoenebeck 1322 // notify that we're done with removal
2180     samples_removed_signal.emit();
2181 schoenebeck 1225 // if sample(s) were just previously added, remove
2182     // them from the import queue
2183     for (std::list<gig::Sample*>::iterator member = members.begin();
2184     member != members.end(); ++member) {
2185     for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2186     iter != m_SampleImportQueue.end(); ++iter) {
2187     if ((*iter).gig_sample == *member) {
2188     printf("Removing previously added sample '%s' from group '%s'\n",
2189     (*iter).sample_path.c_str(), name.c_str());
2190     m_SampleImportQueue.erase(iter);
2191     break;
2192     }
2193     }
2194     }
2195 persson 1261 file_changed();
2196 schoenebeck 1225 } else if (sample) {
2197 schoenebeck 1322 // notify everybody that we're going to remove this sample
2198     std::list<gig::Sample*> lsamples;
2199     lsamples.push_back(sample);
2200     samples_to_be_removed_signal.emit(lsamples);
2201 schoenebeck 1225 // remove sample from the .gig file
2202     file->DeleteSample(sample);
2203 schoenebeck 1322 // notify that we're done with removal
2204     samples_removed_signal.emit();
2205 schoenebeck 1225 // if sample was just previously added, remove it from
2206     // the import queue
2207     for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2208     iter != m_SampleImportQueue.end(); ++iter) {
2209     if ((*iter).gig_sample == sample) {
2210     printf("Removing previously added sample '%s'\n",
2211     (*iter).sample_path.c_str());
2212     m_SampleImportQueue.erase(iter);
2213     break;
2214     }
2215     }
2216 persson 1303 dimreg_changed();
2217 persson 1261 file_changed();
2218 schoenebeck 1225 }
2219     // remove respective row(s) from samples tree view
2220     m_refSamplesTreeModel->erase(it);
2221     } catch (RIFF::Exception e) {
2222 schoenebeck 1322 // pretend we're done with removal (i.e. to avoid dead locks)
2223     samples_removed_signal.emit();
2224     // show error message
2225 schoenebeck 1225 Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2226     msg.run();
2227     }
2228     }
2229     }
2230    
2231 persson 1303 // For some reason drag_data_get gets called two times for each
2232     // drag'n'drop (at least when target is an Entry). This work-around
2233     // makes sure the code in drag_data_get and drop_drag_data_received is
2234     // only executed once, as drag_begin only gets called once.
2235     void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2236     {
2237     first_call_to_drag_data_get = true;
2238     }
2239    
2240 schoenebeck 1225 void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2241     Gtk::SelectionData& selection_data, guint, guint)
2242     {
2243 persson 1303 if (!first_call_to_drag_data_get) return;
2244     first_call_to_drag_data_get = false;
2245    
2246 schoenebeck 1225 // get selected sample
2247     gig::Sample* sample = NULL;
2248     Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2249     Gtk::TreeModel::iterator it = sel->get_selected();
2250     if (it) {
2251     Gtk::TreeModel::Row row = *it;
2252     sample = row[m_SamplesModel.m_col_sample];
2253     }
2254     // pass the gig::Sample as pointer
2255     selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
2256     sizeof(sample)/*length of data in bytes*/);
2257     }
2258    
2259     void MainWindow::on_sample_label_drop_drag_data_received(
2260     const Glib::RefPtr<Gdk::DragContext>& context, int, int,
2261     const Gtk::SelectionData& selection_data, guint, guint time)
2262     {
2263     gig::Sample* sample = *((gig::Sample**) selection_data.get_data());
2264    
2265 persson 1265 if (sample && selection_data.get_length() == sizeof(gig::Sample*)) {
2266 persson 1303 std::cout << "Drop received sample \"" <<
2267     sample->pInfo->Name << "\"" << std::endl;
2268     // drop success
2269     context->drop_reply(true, time);
2270    
2271 schoenebeck 1322 //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
2272    
2273     // notify everybody that we're going to alter the region
2274     gig::Region* region = m_RegionChooser.get_region();
2275     region_to_be_changed_signal.emit(region);
2276    
2277 persson 1303 // find the samplechannel dimension
2278     gig::dimension_def_t* stereo_dimension = 0;
2279     for (int i = 0 ; i < region->Dimensions ; i++) {
2280     if (region->pDimensionDefinitions[i].dimension ==
2281     gig::dimension_samplechannel) {
2282     stereo_dimension = &region->pDimensionDefinitions[i];
2283     break;
2284     }
2285 schoenebeck 1225 }
2286 persson 1303 bool channels_changed = false;
2287     if (sample->Channels == 1 && stereo_dimension) {
2288     // remove the samplechannel dimension
2289 schoenebeck 2550 /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2290 persson 1303 region->DeleteDimension(stereo_dimension);
2291     channels_changed = true;
2292     region_changed();
2293 schoenebeck 2550 */
2294 persson 1303 }
2295 schoenebeck 2464 dimreg_edit.set_sample(
2296     sample,
2297     is_copy_samples_unity_note_enabled(),
2298     is_copy_samples_fine_tune_enabled(),
2299     is_copy_samples_loop_enabled()
2300     );
2301 persson 1303
2302     if (sample->Channels == 2 && !stereo_dimension) {
2303     // add samplechannel dimension
2304     gig::dimension_def_t dim;
2305     dim.dimension = gig::dimension_samplechannel;
2306     dim.bits = 1;
2307     dim.zones = 2;
2308     region->AddDimension(&dim);
2309     channels_changed = true;
2310     region_changed();
2311     }
2312     if (channels_changed) {
2313     // unmap all samples with wrong number of channels
2314     // TODO: maybe there should be a warning dialog for this
2315     for (int i = 0 ; i < region->DimensionRegions ; i++) {
2316     gig::DimensionRegion* d = region->pDimensionRegions[i];
2317     if (d->pSample && d->pSample->Channels != sample->Channels) {
2318 schoenebeck 1322 gig::Sample* oldref = d->pSample;
2319     d->pSample = NULL;
2320     sample_ref_changed_signal.emit(oldref, NULL);
2321 persson 1303 }
2322     }
2323     }
2324    
2325 schoenebeck 1322 // notify we're done with altering
2326     region_changed_signal.emit(region);
2327    
2328 persson 1460 file_changed();
2329    
2330 persson 1303 return;
2331 schoenebeck 1225 }
2332     // drop failed
2333     context->drop_reply(false, time);
2334     }
2335    
2336     void MainWindow::sample_name_changed(const Gtk::TreeModel::Path& path,
2337     const Gtk::TreeModel::iterator& iter) {
2338     if (!iter) return;
2339     Gtk::TreeModel::Row row = *iter;
2340     Glib::ustring name = row[m_SamplesModel.m_col_name];
2341     gig::Group* group = row[m_SamplesModel.m_col_group];
2342     gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2343 persson 2446 gig::String gigname(gig_from_utf8(name));
2344 schoenebeck 1225 if (group) {
2345 persson 2446 if (group->Name != gigname) {
2346     group->Name = gigname;
2347 persson 1261 printf("group name changed\n");
2348     file_changed();
2349     }
2350 schoenebeck 1225 } else if (sample) {
2351 persson 2446 if (sample->pInfo->Name != gigname) {
2352     sample->pInfo->Name = gigname;
2353 persson 1261 printf("sample name changed\n");
2354     file_changed();
2355     }
2356 schoenebeck 1225 }
2357     }
2358    
2359 schoenebeck 2604 void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2360     const Gtk::TreeModel::iterator& iter) {
2361     if (!iter) return;
2362     Gtk::TreeModel::Row row = *iter;
2363     Glib::ustring name = row[m_ScriptsModel.m_col_name];
2364     gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2365     gig::Script* script = row[m_ScriptsModel.m_col_script];
2366     gig::String gigname(gig_from_utf8(name));
2367     if (group) {
2368     if (group->Name != gigname) {
2369     group->Name = gigname;
2370     printf("script group name changed\n");
2371     file_changed();
2372     }
2373     } else if (script) {
2374     if (script->Name != gigname) {
2375     script->Name = gigname;
2376     printf("script name changed\n");
2377     file_changed();
2378     }
2379     }
2380     }
2381    
2382 schoenebeck 1225 void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2383     const Gtk::TreeModel::iterator& iter) {
2384     if (!iter) return;
2385     Gtk::TreeModel::Row row = *iter;
2386     Glib::ustring name = row[m_Columns.m_col_name];
2387 persson 2442
2388     // change name in instrument menu
2389     int index = path[0];
2390     const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2391     if (index < children.size()) {
2392     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2393     static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2394     #else
2395     remove_instrument_from_menu(index);
2396     Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2397     item->set_active();
2398     #endif
2399     }
2400    
2401     // change name in gig
2402 schoenebeck 1225 gig::Instrument* instrument = row[m_Columns.m_col_instr];
2403 persson 2446 gig::String gigname(gig_from_utf8(name));
2404     if (instrument && instrument->pInfo->Name != gigname) {
2405     instrument->pInfo->Name = gigname;
2406 persson 2445
2407     // change name in the instrument properties window
2408     if (instrumentProps.get_instrument() == instrument) {
2409     instrumentProps.update_name();
2410     }
2411    
2412 persson 1261 file_changed();
2413     }
2414 schoenebeck 1225 }
2415 schoenebeck 1322
2416 schoenebeck 2548 void MainWindow::on_action_combine_instruments() {
2417     CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2418     d->show_all();
2419     d->resize(500, 400);
2420     d->run();
2421     if (d->fileWasChanged()) {
2422     // update GUI with new instrument just created
2423     add_instrument(d->newCombinedInstrument());
2424     }
2425     delete d;
2426     }
2427    
2428 schoenebeck 2553 void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2429     struct _Source {
2430     std::vector<RIFF::File*> riffs;
2431     std::vector<gig::File*> gigs;
2432    
2433     ~_Source() {
2434     for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2435     for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2436     riffs.clear();
2437     gigs.clear();
2438     }
2439     } sources;
2440    
2441     if (filenames.empty())
2442     throw RIFF::Exception(_("No files selected, so nothing done."));
2443    
2444     // first open all input files (to avoid output file corruption)
2445     int i;
2446     try {
2447     for (i = 0; i < filenames.size(); ++i) {
2448     const std::string& filename = filenames[i];
2449     printf("opening file=%s\n", filename.c_str());
2450    
2451     RIFF::File* riff = new RIFF::File(filename);
2452     sources.riffs.push_back(riff);
2453    
2454     gig::File* gig = new gig::File(riff);
2455     sources.gigs.push_back(gig);
2456     }
2457     } catch (RIFF::Exception e) {
2458     throw RIFF::Exception(
2459     _("Error occurred while opening '") +
2460     filenames[i] +
2461     "': " +
2462     e.Message
2463     );
2464     } catch (...) {
2465     throw RIFF::Exception(
2466     _("Unknown exception occurred while opening '") +
2467     filenames[i] + "'"
2468     );
2469     }
2470    
2471     // now merge the opened .gig files to the main .gig file currently being
2472     // open in gigedit
2473     try {
2474     for (i = 0; i < filenames.size(); ++i) {
2475     const std::string& filename = filenames[i];
2476     printf("merging file=%s\n", filename.c_str());
2477     assert(i < sources.gigs.size());
2478    
2479     this->file->AddContentOf(sources.gigs[i]);
2480     }
2481     } catch (RIFF::Exception e) {
2482     throw RIFF::Exception(
2483     _("Error occurred while merging '") +
2484     filenames[i] +
2485     "': " +
2486     e.Message
2487     );
2488     } catch (...) {
2489     throw RIFF::Exception(
2490     _("Unknown exception occurred while merging '") +
2491     filenames[i] + "'"
2492     );
2493     }
2494    
2495     // Note: requires that this file already has a filename !
2496     this->file->Save();
2497     }
2498    
2499     void MainWindow::on_action_merge_files() {
2500     if (this->file->GetFileName().empty()) {
2501     Glib::ustring txt = _(
2502     "You seem to have a new .gig file open that has not been saved "
2503     "yet. You must save it somewhere before starting to merge it with "
2504     "other .gig files though, because during the merge operation the "
2505     "other files' sample data must be written on file level to the "
2506     "target .gig file."
2507     );
2508     Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2509     msg.run();
2510     return;
2511     }
2512    
2513     Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2514     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2515     dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2516     dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2517     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2518     Gtk::FileFilter filter;
2519     filter.add_pattern("*.gig");
2520     #else
2521     Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2522     filter->add_pattern("*.gig");
2523     #endif
2524     dialog.set_filter(filter);
2525     if (current_gig_dir != "") {
2526     dialog.set_current_folder(current_gig_dir);
2527     }
2528     dialog.set_select_multiple(true);
2529    
2530     // show warning in the file picker dialog
2531     Gtk::HBox descriptionArea;
2532     descriptionArea.set_spacing(15);
2533     Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2534     descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2535     #if GTKMM_MAJOR_VERSION < 3
2536     view::WrapLabel description;
2537     #else
2538     Gtk::Label description;
2539     description.set_line_wrap();
2540     #endif
2541     description.set_markup(_(
2542     "\nSelect at least one .gig file that shall be merged to the .gig file "
2543     "currently being open in gigedit.\n\n"
2544     "<b>Please Note:</b> Merging with other files will modify your "
2545     "currently open .gig file on file level! And be aware that the current "
2546     "merge algorithm does not detect duplicate samples yet. So if you are "
2547     "merging files which are using equivalent sample data, those "
2548     "equivalent samples will currently be treated as separate samples and "
2549     "will accordingly be stored separately in the target .gig file!"
2550     ));
2551     descriptionArea.pack_start(description);
2552     dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2553     descriptionArea.show_all();
2554    
2555     if (dialog.run() == Gtk::RESPONSE_OK) {
2556     printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2557     std::vector<std::string> filenames = dialog.get_filenames();
2558    
2559     // merge the selected files to the currently open .gig file
2560     try {
2561     mergeFiles(filenames);
2562     } catch (RIFF::Exception e) {
2563     Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2564     msg.run();
2565     }
2566    
2567     // update GUI
2568     __refreshEntireGUI();
2569     }
2570     }
2571    
2572 schoenebeck 1411 void MainWindow::set_file_is_shared(bool b) {
2573     this->file_is_shared = b;
2574    
2575     if (file_is_shared) {
2576     m_AttachedStateLabel.set_label(_("live-mode"));
2577     m_AttachedStateImage.set(
2578     Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
2579     );
2580     } else {
2581     m_AttachedStateLabel.set_label(_("stand-alone"));
2582     m_AttachedStateImage.set(
2583     Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
2584     );
2585     }
2586     }
2587    
2588 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2589 schoenebeck 1322 return file_structure_to_be_changed_signal;
2590     }
2591    
2592 schoenebeck 1339 sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
2593 schoenebeck 1322 return file_structure_changed_signal;
2594     }
2595    
2596 schoenebeck 1339 sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
2597 schoenebeck 1322 return samples_to_be_removed_signal;
2598     }
2599    
2600 schoenebeck 1339 sigc::signal<void>& MainWindow::signal_samples_removed() {
2601 schoenebeck 1322 return samples_removed_signal;
2602     }
2603    
2604 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
2605 schoenebeck 1322 return region_to_be_changed_signal;
2606     }
2607    
2608 schoenebeck 1339 sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
2609 schoenebeck 1322 return region_changed_signal;
2610     }
2611    
2612 schoenebeck 1853 sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2613     return sample_changed_signal;
2614     }
2615    
2616 schoenebeck 1339 sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2617 schoenebeck 1322 return sample_ref_changed_signal;
2618     }
2619    
2620 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
2621 schoenebeck 1322 return dimreg_to_be_changed_signal;
2622     }
2623    
2624 schoenebeck 1339 sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
2625 schoenebeck 1322 return dimreg_changed_signal;
2626     }
2627 schoenebeck 1654
2628     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
2629     return note_on_signal;
2630     }
2631    
2632     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
2633     return note_off_signal;
2634     }
2635 schoenebeck 1660
2636     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
2637     return m_RegionChooser.signal_keyboard_key_hit();
2638     }
2639    
2640     sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
2641     return m_RegionChooser.signal_keyboard_key_released();
2642     }

  ViewVC Help
Powered by ViewVC