/[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 2689 - (hide annotations) (download)
Sun Jan 4 17:19:19 2015 UTC (9 years, 2 months ago) by schoenebeck
File size: 118431 byte(s)
* Automatically switch the sampler's (audible) instrument (in live-mode)
  whenever another instrument was selected in gigedit (this default
  behavior can be switched off in the settings menu of gigedit).

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

  ViewVC Help
Powered by ViewVC