/[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 2715 - (hide annotations) (download)
Tue Jan 20 18:48:15 2015 UTC (9 years, 2 months ago) by schoenebeck
File size: 125810 byte(s)
* Implemented replacing of existing samples.

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

  ViewVC Help
Powered by ViewVC