/[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 2615 - (hide annotations) (download)
Tue Jun 10 19:14:01 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 102619 byte(s)
* Fixed refresh of script tree view on main window.
* Updated German translation.

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

  ViewVC Help
Powered by ViewVC