/[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 2548 - (hide annotations) (download)
Tue May 13 12:17:43 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 82744 byte(s)
* Combine instruments: a new feature that allows to merge a selection of
  instruments to one new single instrument. It uses the 'layer' dimension
  to stack up the instruments. This feature is available from the main menu
  under 'Tools' -> 'Combine Instruments'.

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

  ViewVC Help
Powered by ViewVC