1 |
/* |
/* |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2014 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
18 |
*/ |
*/ |
19 |
|
|
20 |
#include <iostream> |
#include <iostream> |
21 |
|
#include <cstring> |
22 |
|
|
23 |
|
#include <glibmm/convert.h> |
24 |
|
#include <glibmm/dispatcher.h> |
25 |
|
#include <glibmm/miscutils.h> |
26 |
|
#include <glibmm/stringutils.h> |
27 |
|
#include <gtkmm/aboutdialog.h> |
28 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
29 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
30 |
#include <gtkmm/stock.h> |
#include <gtkmm/stock.h> |
31 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
32 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
33 |
|
#include <gtkmm/toggleaction.h> |
34 |
#include "global.h" |
#if GTKMM_MAJOR_VERSION < 3 |
35 |
|
#include "wrapLabel.hh" |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
|
|
#define ABOUT_DIALOG |
|
|
#include <gtkmm/aboutdialog.h> |
|
36 |
#endif |
#endif |
37 |
|
|
38 |
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2 |
#include "global.h" |
39 |
namespace Glib { |
#include "compat.h" |
|
Glib::ustring filename_display_basename(const std::string& filename) |
|
|
{ |
|
|
gchar* gstr = g_path_get_basename(filename.c_str()); |
|
|
Glib::ustring str(gstr); |
|
|
g_free(gstr); |
|
|
return Glib::filename_to_utf8(str); |
|
|
} |
|
|
} |
|
|
#endif |
|
40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
42 |
#include <sndfile.h> |
#include <sndfile.h> |
43 |
|
|
44 |
#include "mainwindow.h" |
#include "mainwindow.h" |
45 |
|
#include "Settings.h" |
46 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
47 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
48 |
|
|
|
template<class T> inline std::string ToString(T o) { |
|
|
std::stringstream ss; |
|
|
ss << o; |
|
|
return ss.str(); |
|
|
} |
|
49 |
|
|
50 |
MainWindow::MainWindow() |
MainWindow::MainWindow() : |
51 |
|
dimreg_label(_("Changes apply to:")), |
52 |
|
dimreg_all_regions(_("all regions")), |
53 |
|
dimreg_all_dimregs(_("all dimension splits")), |
54 |
|
dimreg_stereo(_("both channels")) |
55 |
{ |
{ |
56 |
// set_border_width(5); |
// set_border_width(5); |
57 |
// set_default_size(400, 200); |
// set_default_size(400, 200); |
60 |
add(m_VBox); |
add(m_VBox); |
61 |
|
|
62 |
// Handle selection |
// Handle selection |
63 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->signal_changed().connect( |
|
tree_sel_ref->signal_changed().connect( |
|
64 |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
sigc::mem_fun(*this, &MainWindow::on_sel_change)); |
65 |
|
|
66 |
// m_TreeView.set_reorderable(); |
// m_TreeView.set_reorderable(); |
80 |
m_TreeViewNotebook.set_size_request(300); |
m_TreeViewNotebook.set_size_request(300); |
81 |
|
|
82 |
m_HPaned.add1(m_TreeViewNotebook); |
m_HPaned.add1(m_TreeViewNotebook); |
83 |
m_HPaned.add2(dimreg_edit); |
dimreg_hbox.add(dimreg_label); |
84 |
|
dimreg_hbox.add(dimreg_all_regions); |
85 |
|
dimreg_hbox.add(dimreg_all_dimregs); |
86 |
|
dimreg_stereo.set_active(); |
87 |
|
dimreg_hbox.add(dimreg_stereo); |
88 |
|
dimreg_vbox.add(dimreg_edit); |
89 |
|
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
90 |
|
m_HPaned.add2(dimreg_vbox); |
91 |
|
|
92 |
|
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
93 |
|
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.")); |
94 |
|
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.")); |
95 |
|
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).")); |
96 |
|
|
97 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
98 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments"); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
99 |
|
|
100 |
|
|
101 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
127 |
Gtk::Stock::PROPERTIES), |
Gtk::Stock::PROPERTIES), |
128 |
sigc::mem_fun( |
sigc::mem_fun( |
129 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
130 |
|
actionGroup->add(Gtk::Action::create("MidiRules", |
131 |
|
_("_Midi Rules")), |
132 |
|
sigc::mem_fun( |
133 |
|
*this, &MainWindow::show_midi_rules)); |
134 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
135 |
sigc::mem_fun( |
sigc::mem_fun( |
136 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
137 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
138 |
|
|
139 |
|
|
140 |
|
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
141 |
|
|
142 |
|
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
143 |
|
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
144 |
|
toggle_action->set_active(true); |
145 |
|
actionGroup->add(toggle_action); |
146 |
|
|
147 |
|
toggle_action = |
148 |
|
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
149 |
|
toggle_action->set_active(true); |
150 |
|
actionGroup->add(toggle_action); |
151 |
|
|
152 |
|
toggle_action = |
153 |
|
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
154 |
|
toggle_action->set_active(true); |
155 |
|
actionGroup->add(toggle_action); |
156 |
|
|
157 |
|
|
158 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
159 |
|
toggle_action = |
160 |
|
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
161 |
|
toggle_action->set_active(true); |
162 |
|
actionGroup->add(toggle_action, |
163 |
|
sigc::mem_fun( |
164 |
|
*this, &MainWindow::on_action_view_status_bar)); |
165 |
|
|
166 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
167 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("MenuHelp", |
168 |
action->property_label())); |
action->property_label())); |
|
#ifdef ABOUT_DIALOG |
|
169 |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
170 |
sigc::mem_fun( |
sigc::mem_fun( |
171 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
|
#endif |
|
172 |
actionGroup->add( |
actionGroup->add( |
173 |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
174 |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
175 |
); |
); |
176 |
actionGroup->add( |
actionGroup->add( |
177 |
|
Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")), |
178 |
|
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
179 |
|
); |
180 |
|
actionGroup->add( |
181 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
182 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
183 |
); |
); |
184 |
|
|
185 |
|
|
186 |
|
actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); |
187 |
|
|
188 |
|
toggle_action = |
189 |
|
Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions")); |
190 |
|
toggle_action->set_active(Settings::singleton()->warnUserOnExtensions); |
191 |
|
actionGroup->add( |
192 |
|
toggle_action, |
193 |
|
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
194 |
|
); |
195 |
|
|
196 |
|
|
197 |
// sample right-click popup actions |
// sample right-click popup actions |
198 |
actionGroup->add( |
actionGroup->add( |
199 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
204 |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
205 |
); |
); |
206 |
actionGroup->add( |
actionGroup->add( |
207 |
Gtk::Action::create("AddSample", _("Add _Sample(s)")), |
Gtk::Action::create("AddSample", _("Add _Sample(s)...")), |
208 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
209 |
); |
); |
210 |
actionGroup->add( |
actionGroup->add( |
211 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
212 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
213 |
); |
); |
214 |
|
actionGroup->add( |
215 |
|
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
216 |
|
_("Replace All Samples in All Groups...")), |
217 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
218 |
|
); |
219 |
|
|
220 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
221 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
235 |
" <separator/>" |
" <separator/>" |
236 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
237 |
" </menu>" |
" </menu>" |
238 |
|
" <menu action='MenuEdit'>" |
239 |
|
" <menuitem action='CopySampleUnity'/>" |
240 |
|
" <menuitem action='CopySampleTune'/>" |
241 |
|
" <menuitem action='CopySampleLoop'/>" |
242 |
|
" </menu>" |
243 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
244 |
" </menu>" |
" </menu>" |
245 |
#ifdef ABOUT_DIALOG |
" <menu action='MenuView'>" |
246 |
|
" <menuitem action='Statusbar'/>" |
247 |
|
" </menu>" |
248 |
|
" <menu action='MenuSettings'>" |
249 |
|
" <menuitem action='WarnUserOnExtensions'/>" |
250 |
|
" </menu>" |
251 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
252 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
253 |
" </menu>" |
" </menu>" |
|
#endif |
|
254 |
" </menubar>" |
" </menubar>" |
255 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
256 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
257 |
|
" <menuitem action='MidiRules'/>" |
258 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
259 |
|
" <menuitem action='DupInstrument'/>" |
260 |
" <separator/>" |
" <separator/>" |
261 |
" <menuitem action='RemoveInstrument'/>" |
" <menuitem action='RemoveInstrument'/>" |
262 |
" </popup>" |
" </popup>" |
264 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
265 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
266 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
267 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
268 |
" <separator/>" |
" <separator/>" |
269 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
270 |
" </popup>" |
" </popup>" |
272 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
273 |
|
|
274 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
275 |
|
|
276 |
|
// Set tooltips for menu items (for some reason, setting a tooltip on the |
277 |
|
// respective Gtk::Action objects above will simply be ignored, no matter |
278 |
|
// if using Gtk::Action::set_tooltip() or passing the tooltip string on |
279 |
|
// Gtk::Action::create()). |
280 |
|
{ |
281 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
282 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
283 |
|
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.")); |
284 |
|
} |
285 |
|
{ |
286 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
287 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
288 |
|
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.")); |
289 |
|
} |
290 |
|
{ |
291 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
292 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
293 |
|
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.")); |
294 |
|
} |
295 |
|
{ |
296 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
297 |
|
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
298 |
|
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.")); |
299 |
|
} |
300 |
|
|
301 |
|
instrument_menu = static_cast<Gtk::MenuItem*>( |
302 |
|
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
303 |
|
|
304 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
305 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
306 |
m_VBox.pack_start(m_HPaned); |
m_VBox.pack_start(m_HPaned); |
307 |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
308 |
|
m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK); |
309 |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
310 |
m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); |
311 |
|
|
312 |
|
set_file_is_shared(false); |
313 |
|
|
314 |
// Status Bar: |
// Status Bar: |
315 |
m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); |
m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); |
316 |
m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); |
m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); |
325 |
// Create the Tree model: |
// Create the Tree model: |
326 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
327 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
328 |
m_refTreeModel->signal_row_changed().connect( |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); |
329 |
|
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
330 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
331 |
); |
); |
332 |
|
|
337 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
338 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
339 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
340 |
|
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.")); |
341 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
342 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
343 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.set_headers_visible(false); |
349 |
); |
); |
350 |
|
|
351 |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
352 |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
353 |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
354 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
355 |
m_TreeViewSamples.signal_drag_begin().connect( |
m_TreeViewSamples.signal_drag_begin().connect( |
356 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
368 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
369 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
370 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
371 |
instrumentProps.signal_instrument_changed().connect( |
instrumentProps.signal_changed().connect( |
372 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
373 |
|
propDialog.signal_changed().connect( |
374 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
375 |
|
midiRules.signal_changed().connect( |
376 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
377 |
|
|
378 |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
403 |
m_RegionChooser.signal_region_changed_signal().connect( |
m_RegionChooser.signal_region_changed_signal().connect( |
404 |
region_changed_signal.make_slot()); |
region_changed_signal.make_slot()); |
405 |
|
|
406 |
|
note_on_signal.connect( |
407 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event)); |
408 |
|
note_off_signal.connect( |
409 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event)); |
410 |
|
|
411 |
|
dimreg_all_regions.signal_toggled().connect( |
412 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
413 |
|
dimreg_all_dimregs.signal_toggled().connect( |
414 |
|
sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled)); |
415 |
|
dimreg_stereo.signal_toggled().connect( |
416 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
417 |
|
|
418 |
file = 0; |
file = 0; |
419 |
file_is_changed = false; |
file_is_changed = false; |
|
set_file_is_shared(false); |
|
420 |
|
|
421 |
show_all_children(); |
show_all_children(); |
422 |
|
|
444 |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
445 |
} |
} |
446 |
|
|
447 |
|
gig::Instrument* MainWindow::get_instrument() |
448 |
|
{ |
449 |
|
gig::Instrument* instrument = 0; |
450 |
|
Gtk::TreeModel::const_iterator it = |
451 |
|
m_TreeView.get_selection()->get_selected(); |
452 |
|
if (it) { |
453 |
|
Gtk::TreeModel::Row row = *it; |
454 |
|
instrument = row[m_Columns.m_col_instr]; |
455 |
|
} |
456 |
|
return instrument; |
457 |
|
} |
458 |
|
|
459 |
|
void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs) |
460 |
|
{ |
461 |
|
if (all_dimregs) { |
462 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
463 |
|
if (region->pDimensionRegions[i]) { |
464 |
|
dimreg_edit.dimregs.insert(region->pDimensionRegions[i]); |
465 |
|
} |
466 |
|
} |
467 |
|
} else { |
468 |
|
m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs); |
469 |
|
} |
470 |
|
} |
471 |
|
|
472 |
|
void MainWindow::update_dimregs() |
473 |
|
{ |
474 |
|
dimreg_edit.dimregs.clear(); |
475 |
|
bool all_regions = dimreg_all_regions.get_active(); |
476 |
|
bool stereo = dimreg_stereo.get_active(); |
477 |
|
bool all_dimregs = dimreg_all_dimregs.get_active(); |
478 |
|
|
479 |
|
if (all_regions) { |
480 |
|
gig::Instrument* instrument = get_instrument(); |
481 |
|
if (instrument) { |
482 |
|
for (gig::Region* region = instrument->GetFirstRegion() ; |
483 |
|
region ; |
484 |
|
region = instrument->GetNextRegion()) { |
485 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
486 |
|
} |
487 |
|
} |
488 |
|
} else { |
489 |
|
gig::Region* region = m_RegionChooser.get_region(); |
490 |
|
if (region) { |
491 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
492 |
|
} |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
|
void MainWindow::dimreg_all_dimregs_toggled() |
497 |
|
{ |
498 |
|
dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active()); |
499 |
|
update_dimregs(); |
500 |
|
} |
501 |
|
|
502 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
503 |
{ |
{ |
504 |
|
update_dimregs(); |
505 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
506 |
} |
} |
507 |
|
|
508 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
509 |
{ |
{ |
510 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
// select item in instrument menu |
511 |
|
Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); |
|
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
|
512 |
if (it) { |
if (it) { |
513 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreePath path(it); |
514 |
std::cout << row[m_Columns.m_col_name] << std::endl; |
int index = path[0]; |
515 |
|
const std::vector<Gtk::Widget*> children = |
516 |
m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]); |
instrument_menu->get_children(); |
517 |
} else { |
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
|
m_RegionChooser.set_instrument(0); |
|
518 |
} |
} |
519 |
|
|
520 |
|
m_RegionChooser.set_instrument(get_instrument()); |
521 |
} |
} |
522 |
|
|
523 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
529 |
void Loader::progress_callback(float fraction) |
void Loader::progress_callback(float fraction) |
530 |
{ |
{ |
531 |
{ |
{ |
532 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
533 |
progress = fraction; |
progress = fraction; |
534 |
} |
} |
535 |
progress_dispatcher(); |
progress_dispatcher(); |
537 |
|
|
538 |
void Loader::thread_function() |
void Loader::thread_function() |
539 |
{ |
{ |
540 |
printf("thread_function self=%x\n", Glib::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
541 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename); |
542 |
RIFF::File* riff = new RIFF::File(filename); |
RIFF::File* riff = new RIFF::File(filename); |
543 |
gig = new gig::File(riff); |
gig = new gig::File(riff); |
551 |
} |
} |
552 |
|
|
553 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
554 |
: thread(0), filename(filename) |
: filename(filename), thread(0) |
555 |
{ |
{ |
556 |
} |
} |
557 |
|
|
558 |
void Loader::launch() |
void Loader::launch() |
559 |
{ |
{ |
560 |
|
#ifdef OLD_THREADS |
561 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
562 |
|
#else |
563 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
564 |
|
#endif |
565 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%x\n", thread); |
566 |
} |
} |
567 |
|
|
569 |
{ |
{ |
570 |
float res; |
float res; |
571 |
{ |
{ |
572 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
573 |
res = progress; |
res = progress; |
574 |
} |
} |
575 |
return res; |
return res; |
595 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
596 |
// before a new .gig file is to be created or to be loaded. |
// before a new .gig file is to be created or to be loaded. |
597 |
void MainWindow::__clear() { |
void MainWindow::__clear() { |
|
// remove all entries from "Instrument" menu |
|
|
Gtk::MenuItem* instrument_menu = |
|
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
instrument_menu->hide(); |
|
|
for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) { |
|
|
delete &instrument_menu->get_submenu()->items()[i]; |
|
|
} |
|
|
instrument_menu->get_submenu()->items().clear(); |
|
598 |
// forget all samples that ought to be imported |
// forget all samples that ought to be imported |
599 |
m_SampleImportQueue.clear(); |
m_SampleImportQueue.clear(); |
600 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
601 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
602 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
603 |
|
// remove all entries from "Instrument" menu |
604 |
|
while (!instrument_menu->get_children().empty()) { |
605 |
|
remove_instrument_from_menu(0); |
606 |
|
} |
607 |
// free libgig's gig::File instance |
// free libgig's gig::File instance |
608 |
if (file && !file_is_shared) delete file; |
if (file && !file_is_shared) delete file; |
609 |
file = NULL; |
file = NULL; |
622 |
gig::File* pFile = new gig::File; |
gig::File* pFile = new gig::File; |
623 |
// already add one new instrument by default |
// already add one new instrument by default |
624 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
625 |
pInstrument->pInfo->Name = "Unnamed Instrument"; |
pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument")); |
626 |
// update GUI with that new gig::File |
// update GUI with that new gig::File |
627 |
load_gig(pFile, 0 /*no file name yet*/); |
load_gig(pFile, 0 /*no file name yet*/); |
628 |
} |
} |
633 |
Glib::filename_display_basename(filename).c_str()); |
Glib::filename_display_basename(filename).c_str()); |
634 |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
635 |
g_free(msg); |
g_free(msg); |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
|
636 |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
|
#endif |
|
637 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
638 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
639 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
647 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
648 |
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
649 |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
|
650 |
dialog.set_secondary_text( |
dialog.set_secondary_text( |
651 |
_("If you proceed to work on another instrument file, it won't be " |
_("If you proceed to work on another instrument file, it won't be " |
652 |
"used by the sampler until you tell the sampler explicitly to " |
"used by the sampler until you tell the sampler explicitly to " |
653 |
"load it.") |
"load it.")); |
|
); |
|
|
#endif |
|
654 |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
655 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
656 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
669 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
670 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
671 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
672 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
673 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
674 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
675 |
|
#else |
676 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
677 |
|
filter->add_pattern("*.gig"); |
678 |
|
#endif |
679 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
680 |
if (current_dir != "") { |
if (current_gig_dir != "") { |
681 |
dialog.set_current_folder(current_dir); |
dialog.set_current_folder(current_gig_dir); |
682 |
} |
} |
683 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
684 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
685 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
686 |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
687 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
688 |
current_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
689 |
} |
} |
690 |
} |
} |
691 |
|
|
692 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
693 |
{ |
{ |
694 |
__clear(); |
__clear(); |
695 |
load_dialog = new LoadDialog("Loading...", *this); |
load_dialog = new LoadDialog(_("Loading..."), *this); |
696 |
load_dialog->show_all(); |
load_dialog->show_all(); |
697 |
loader = new Loader(strdup(name)); |
loader = new Loader(strdup(name)); |
698 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
725 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
726 |
{ |
{ |
727 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
728 |
printf("on_loader_finished self=%x\n", Glib::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
729 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename); |
730 |
load_dialog->hide(); |
load_dialog->hide(); |
731 |
} |
} |
797 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
798 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
799 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
|
|
|
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2 |
|
800 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
801 |
// TODO: an overwrite dialog for gtkmm < 2.8 |
|
802 |
#endif |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
803 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
804 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
805 |
|
#else |
806 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
807 |
|
filter->add_pattern("*.gig"); |
808 |
|
#endif |
809 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
810 |
|
|
811 |
if (Glib::path_is_absolute(filename)) { |
// set initial dir and filename of the Save As dialog |
812 |
dialog.set_filename(filename); |
// and prepare that initial filename as a copy of the gig |
813 |
} else if (current_dir != "") { |
{ |
814 |
dialog.set_current_folder(current_dir); |
std::string basename = Glib::path_get_basename(filename); |
815 |
|
std::string dir = Glib::path_get_dirname(filename); |
816 |
|
basename = std::string(_("copy_of_")) + basename; |
817 |
|
Glib::ustring copyFileName = Glib::build_filename(dir, basename); |
818 |
|
if (Glib::path_is_absolute(filename)) { |
819 |
|
dialog.set_filename(copyFileName); |
820 |
|
} else { |
821 |
|
if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir); |
822 |
|
} |
823 |
|
dialog.set_current_name(Glib::filename_display_basename(copyFileName)); |
824 |
} |
} |
825 |
dialog.set_current_name(Glib::filename_display_basename(filename)); |
|
826 |
|
// show warning in the dialog |
827 |
|
Gtk::HBox descriptionArea; |
828 |
|
descriptionArea.set_spacing(15); |
829 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
830 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
831 |
|
#if GTKMM_MAJOR_VERSION < 3 |
832 |
|
view::WrapLabel description; |
833 |
|
#else |
834 |
|
Gtk::Label description; |
835 |
|
description.set_line_wrap(); |
836 |
|
#endif |
837 |
|
description.set_markup( |
838 |
|
_("\n<b>CAUTION:</b> You <b>MUST</b> use the " |
839 |
|
"<span style=\"italic\">\"Save\"</span> dialog instead of " |
840 |
|
"<span style=\"italic\">\"Save As...\"</span> if you want to save " |
841 |
|
"to the same .gig file. Using " |
842 |
|
"<span style=\"italic\">\"Save As...\"</span> for writing to the " |
843 |
|
"same .gig file will end up in corrupted sample wave data!\n") |
844 |
|
); |
845 |
|
descriptionArea.pack_start(description); |
846 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
847 |
|
descriptionArea.show_all(); |
848 |
|
|
849 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
850 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
856 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
857 |
file->Save(filename); |
file->Save(filename); |
858 |
this->filename = filename; |
this->filename = filename; |
859 |
current_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
860 |
set_title(Glib::filename_display_basename(filename)); |
set_title(Glib::filename_display_basename(filename)); |
861 |
file_has_name = true; |
file_has_name = true; |
862 |
file_is_changed = false; |
file_is_changed = false; |
885 |
SF_INFO info; |
SF_INFO info; |
886 |
info.format = 0; |
info.format = 0; |
887 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
888 |
|
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
889 |
try { |
try { |
890 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
891 |
// determine sample's bit depth |
// determine sample's bit depth |
892 |
int bitdepth; |
int bitdepth; |
893 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
904 |
break; |
break; |
905 |
default: |
default: |
906 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
907 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
908 |
} |
} |
909 |
|
|
910 |
const int bufsize = 10000; |
const int bufsize = 10000; |
946 |
} |
} |
947 |
// cleanup |
// cleanup |
948 |
sf_close(hFile); |
sf_close(hFile); |
949 |
|
// let the sampler re-cache the sample if needed |
950 |
|
sample_changed_signal.emit(iter->gig_sample); |
951 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
952 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
953 |
std::list<SampleImportItem>::iterator cur = iter; |
std::list<SampleImportItem>::iterator cur = iter; |
955 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
956 |
} catch (std::string what) { |
} catch (std::string what) { |
957 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
958 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
959 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += (*iter).sample_path += " (" + what + ")"; |
960 |
++iter; |
++iter; |
961 |
} |
} |
962 |
} |
} |
963 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
964 |
if (error_files.size()) { |
if (!error_files.empty()) { |
965 |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
966 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
967 |
msg.run(); |
msg.run(); |
974 |
propDialog.deiconify(); |
propDialog.deiconify(); |
975 |
} |
} |
976 |
|
|
977 |
|
void MainWindow::on_action_warn_user_on_extensions() { |
978 |
|
Settings::singleton()->warnUserOnExtensions = |
979 |
|
!Settings::singleton()->warnUserOnExtensions; |
980 |
|
} |
981 |
|
|
982 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
983 |
{ |
{ |
|
#ifdef ABOUT_DIALOG |
|
984 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
985 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2 |
986 |
|
dialog.set_program_name("Gigedit"); |
987 |
|
#else |
988 |
|
dialog.set_name("Gigedit"); |
989 |
|
#endif |
990 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
991 |
|
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
992 |
|
const std::string sComment = |
993 |
|
_("Built " __DATE__ "\nUsing ") + |
994 |
|
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
995 |
|
_( |
996 |
|
"Gigedit is released under the GNU General Public License.\n" |
997 |
|
"\n" |
998 |
|
"Please notice that this is still a very young instrument editor. " |
999 |
|
"So better backup your Gigasampler files before editing them with " |
1000 |
|
"this application.\n" |
1001 |
|
"\n" |
1002 |
|
"Please report bugs to: http://bugs.linuxsampler.org" |
1003 |
|
); |
1004 |
|
dialog.set_comments(sComment.c_str()); |
1005 |
|
dialog.set_website("http://www.linuxsampler.org"); |
1006 |
|
dialog.set_website_label("http://www.linuxsampler.org"); |
1007 |
dialog.run(); |
dialog.run(); |
|
#endif |
|
1008 |
} |
} |
1009 |
|
|
1010 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1011 |
: table(2,1) |
: eName(_("Name")), |
1012 |
|
eCreationDate(_("Creation date")), |
1013 |
|
eComments(_("Comments")), |
1014 |
|
eProduct(_("Product")), |
1015 |
|
eCopyright(_("Copyright")), |
1016 |
|
eArtists(_("Artists")), |
1017 |
|
eGenre(_("Genre")), |
1018 |
|
eKeywords(_("Keywords")), |
1019 |
|
eEngineer(_("Engineer")), |
1020 |
|
eTechnician(_("Technician")), |
1021 |
|
eSoftware(_("Software")), |
1022 |
|
eMedium(_("Medium")), |
1023 |
|
eSource(_("Source")), |
1024 |
|
eSourceForm(_("Source form")), |
1025 |
|
eCommissioned(_("Commissioned")), |
1026 |
|
eSubject(_("Subject")), |
1027 |
|
quitButton(Gtk::Stock::CLOSE), |
1028 |
|
table(2, 1) |
1029 |
{ |
{ |
1030 |
|
set_title(_("File Properties")); |
1031 |
|
eName.set_width_chars(50); |
1032 |
|
|
1033 |
|
connect(eName, &DLS::Info::Name); |
1034 |
|
connect(eCreationDate, &DLS::Info::CreationDate); |
1035 |
|
connect(eComments, &DLS::Info::Comments); |
1036 |
|
connect(eProduct, &DLS::Info::Product); |
1037 |
|
connect(eCopyright, &DLS::Info::Copyright); |
1038 |
|
connect(eArtists, &DLS::Info::Artists); |
1039 |
|
connect(eGenre, &DLS::Info::Genre); |
1040 |
|
connect(eKeywords, &DLS::Info::Keywords); |
1041 |
|
connect(eEngineer, &DLS::Info::Engineer); |
1042 |
|
connect(eTechnician, &DLS::Info::Technician); |
1043 |
|
connect(eSoftware, &DLS::Info::Software); |
1044 |
|
connect(eMedium, &DLS::Info::Medium); |
1045 |
|
connect(eSource, &DLS::Info::Source); |
1046 |
|
connect(eSourceForm, &DLS::Info::SourceForm); |
1047 |
|
connect(eCommissioned, &DLS::Info::Commissioned); |
1048 |
|
connect(eSubject, &DLS::Info::Subject); |
1049 |
|
|
1050 |
|
table.add(eName); |
1051 |
|
table.add(eCreationDate); |
1052 |
|
table.add(eComments); |
1053 |
|
table.add(eProduct); |
1054 |
|
table.add(eCopyright); |
1055 |
|
table.add(eArtists); |
1056 |
|
table.add(eGenre); |
1057 |
|
table.add(eKeywords); |
1058 |
|
table.add(eEngineer); |
1059 |
|
table.add(eTechnician); |
1060 |
|
table.add(eSoftware); |
1061 |
|
table.add(eMedium); |
1062 |
|
table.add(eSource); |
1063 |
|
table.add(eSourceForm); |
1064 |
|
table.add(eCommissioned); |
1065 |
|
table.add(eSubject); |
1066 |
|
|
1067 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1068 |
const char* propLabels[] = { |
add(vbox); |
1069 |
"Name:", |
table.set_border_width(5); |
1070 |
"CreationDate:", |
vbox.add(table); |
1071 |
"Comments:", // TODO: multiline |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
1072 |
"Product:", |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
1073 |
"Copyright:", |
buttonBox.set_border_width(5); |
1074 |
"Artists:", |
buttonBox.show(); |
1075 |
"Genre:", |
buttonBox.pack_start(quitButton); |
1076 |
"Keywords:", |
quitButton.set_can_default(); |
1077 |
"Engineer:", |
quitButton.grab_focus(); |
1078 |
"Technician:", |
quitButton.signal_clicked().connect( |
1079 |
"Software:", // TODO: readonly |
sigc::mem_fun(*this, &PropDialog::hide)); |
|
"Medium:", |
|
|
"Source:", |
|
|
"SourceForm:", |
|
|
"Commissioned:", |
|
|
"Subject:" |
|
|
}; |
|
|
for (int i = 0 ; i < sizeof(propLabels) / sizeof(char*) ; i++) { |
|
|
label[i].set_text(propLabels[i]); |
|
|
label[i].set_alignment(Gtk::ALIGN_LEFT); |
|
|
table.attach(label[i], 0, 1, i, i + 1, Gtk::FILL, Gtk::SHRINK); |
|
|
table.attach(entry[i], 1, 2, i, i + 1, Gtk::FILL | Gtk::EXPAND, |
|
|
Gtk::SHRINK); |
|
|
} |
|
1080 |
|
|
1081 |
add(table); |
quitButton.show(); |
1082 |
// add_button(Gtk::Stock::CANCEL, 0); |
vbox.show(); |
|
// add_button(Gtk::Stock::OK, 1); |
|
1083 |
show_all_children(); |
show_all_children(); |
1084 |
} |
} |
1085 |
|
|
1086 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1087 |
{ |
{ |
1088 |
entry[0].set_text(info->Name); |
update(info); |
|
entry[1].set_text(info->CreationDate); |
|
|
entry[2].set_text(Glib::convert(info->Comments, "UTF-8", "ISO-8859-1")); |
|
|
entry[3].set_text(info->Product); |
|
|
entry[4].set_text(info->Copyright); |
|
|
entry[5].set_text(info->Artists); |
|
|
entry[6].set_text(info->Genre); |
|
|
entry[7].set_text(info->Keywords); |
|
|
entry[8].set_text(info->Engineer); |
|
|
entry[9].set_text(info->Technician); |
|
|
entry[10].set_text(info->Software); |
|
|
entry[11].set_text(info->Medium); |
|
|
entry[12].set_text(info->Source); |
|
|
entry[13].set_text(info->SourceForm); |
|
|
entry[14].set_text(info->Commissioned); |
|
|
entry[15].set_text(info->Subject); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(BoolEntry& boolentry) |
|
|
{ |
|
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
rowno++; |
|
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(BoolEntryPlus6& boolentry) |
|
|
{ |
|
|
table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
rowno++; |
|
|
boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
|
} |
|
|
|
|
|
void InstrumentProps::add_prop(LabelWidget& prop) |
|
|
{ |
|
|
table.attach(prop.label, 0, 1, rowno, rowno + 1, |
|
|
Gtk::FILL, Gtk::SHRINK); |
|
|
table.attach(prop.widget, 1, 2, rowno, rowno + 1, |
|
|
Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); |
|
|
rowno++; |
|
|
prop.signal_changed_by_user().connect(instrument_changed.make_slot()); |
|
1089 |
} |
} |
1090 |
|
|
1091 |
InstrumentProps::InstrumentProps() |
|
1092 |
: table(2,1), |
void InstrumentProps::set_Name(const gig::String& name) |
1093 |
quitButton(Gtk::Stock::CLOSE), |
{ |
1094 |
eName("Name"), |
m->pInfo->Name = name; |
1095 |
eIsDrum("Is drum"), |
} |
1096 |
eMIDIBank("MIDI bank", 0, 16383), |
|
1097 |
eMIDIProgram("MIDI program"), |
void InstrumentProps::update_name() |
|
eAttenuation("Attenuation", 0, 96, 0, 1), |
|
|
eGainPlus6("Gain +6dB", eAttenuation, -6), |
|
|
eEffectSend("Effect send", 0, 65535), |
|
|
eFineTune("Fine tune", -8400, 8400), |
|
|
ePitchbendRange("Pitchbend range", 0, 12), |
|
|
ePianoReleaseMode("Piano release mode"), |
|
|
eDimensionKeyRangeLow("Dimension key range low"), |
|
|
eDimensionKeyRangeHigh("Dimension key range high") |
|
1098 |
{ |
{ |
1099 |
set_title("Instrument properties"); |
update_model++; |
1100 |
|
eName.set_value(m->pInfo->Name); |
1101 |
|
update_model--; |
1102 |
|
} |
1103 |
|
|
1104 |
|
void InstrumentProps::set_IsDrum(bool value) |
1105 |
|
{ |
1106 |
|
m->IsDrum = value; |
1107 |
|
} |
1108 |
|
|
1109 |
|
void InstrumentProps::set_MIDIBank(uint16_t value) |
1110 |
|
{ |
1111 |
|
m->MIDIBank = value; |
1112 |
|
} |
1113 |
|
|
1114 |
|
void InstrumentProps::set_MIDIProgram(uint32_t value) |
1115 |
|
{ |
1116 |
|
m->MIDIProgram = value; |
1117 |
|
} |
1118 |
|
|
1119 |
|
InstrumentProps::InstrumentProps() : |
1120 |
|
quitButton(Gtk::Stock::CLOSE), |
1121 |
|
table(2,1), |
1122 |
|
eName(_("Name")), |
1123 |
|
eIsDrum(_("Is drum")), |
1124 |
|
eMIDIBank(_("MIDI bank"), 0, 16383), |
1125 |
|
eMIDIProgram(_("MIDI program")), |
1126 |
|
eAttenuation(_("Attenuation"), 0, 96, 0, 1), |
1127 |
|
eGainPlus6(_("Gain +6dB"), eAttenuation, -6), |
1128 |
|
eEffectSend(_("Effect send"), 0, 65535), |
1129 |
|
eFineTune(_("Fine tune"), -8400, 8400), |
1130 |
|
ePitchbendRange(_("Pitchbend range"), 0, 12), |
1131 |
|
ePianoReleaseMode(_("Piano release mode")), |
1132 |
|
eDimensionKeyRangeLow(_("Keyswitching range low")), |
1133 |
|
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
1134 |
|
{ |
1135 |
|
set_title(_("Instrument Properties")); |
1136 |
|
|
1137 |
|
eDimensionKeyRangeLow.set_tip( |
1138 |
|
_("start of the keyboard area which should switch the " |
1139 |
|
"\"keyswitching\" dimension") |
1140 |
|
); |
1141 |
|
eDimensionKeyRangeHigh.set_tip( |
1142 |
|
_("end of the keyboard area which should switch the " |
1143 |
|
"\"keyswitching\" dimension") |
1144 |
|
); |
1145 |
|
|
1146 |
|
connect(eName, &InstrumentProps::set_Name); |
1147 |
|
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
1148 |
|
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
1149 |
|
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
1150 |
|
connect(eAttenuation, &gig::Instrument::Attenuation); |
1151 |
|
connect(eGainPlus6, &gig::Instrument::Attenuation); |
1152 |
|
connect(eEffectSend, &gig::Instrument::EffectSend); |
1153 |
|
connect(eFineTune, &gig::Instrument::FineTune); |
1154 |
|
connect(ePitchbendRange, &gig::Instrument::PitchbendRange); |
1155 |
|
connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); |
1156 |
|
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
1157 |
|
&gig::Instrument::DimensionKeyRange); |
1158 |
|
|
1159 |
|
eName.signal_value_changed().connect(sig_name_changed.make_slot()); |
1160 |
|
|
|
rowno = 0; |
|
1161 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1162 |
|
|
1163 |
add_prop(eName); |
table.add(eName); |
1164 |
add_prop(eIsDrum); |
table.add(eIsDrum); |
1165 |
add_prop(eMIDIBank); |
table.add(eMIDIBank); |
1166 |
add_prop(eMIDIProgram); |
table.add(eMIDIProgram); |
1167 |
add_prop(eAttenuation); |
table.add(eAttenuation); |
1168 |
add_prop(eGainPlus6); |
table.add(eGainPlus6); |
1169 |
add_prop(eEffectSend); |
table.add(eEffectSend); |
1170 |
add_prop(eFineTune); |
table.add(eFineTune); |
1171 |
add_prop(ePitchbendRange); |
table.add(ePitchbendRange); |
1172 |
add_prop(ePianoReleaseMode); |
table.add(ePianoReleaseMode); |
1173 |
add_prop(eDimensionKeyRangeLow); |
table.add(eDimensionKeyRangeLow); |
1174 |
add_prop(eDimensionKeyRangeHigh); |
table.add(eDimensionKeyRangeHigh); |
|
|
|
|
eDimensionKeyRangeLow.signal_changed_by_user().connect( |
|
|
sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed)); |
|
|
eDimensionKeyRangeHigh.signal_changed_by_user().connect( |
|
|
sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed)); |
|
1175 |
|
|
1176 |
add(vbox); |
add(vbox); |
1177 |
table.set_border_width(5); |
table.set_border_width(5); |
1182 |
buttonBox.set_border_width(5); |
buttonBox.set_border_width(5); |
1183 |
buttonBox.show(); |
buttonBox.show(); |
1184 |
buttonBox.pack_start(quitButton); |
buttonBox.pack_start(quitButton); |
1185 |
quitButton.set_flags(Gtk::CAN_DEFAULT); |
quitButton.set_can_default(); |
1186 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1187 |
|
|
1188 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1195 |
|
|
1196 |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
1197 |
{ |
{ |
1198 |
eName.set_ptr(&instrument->pInfo->Name); |
update(instrument); |
|
eIsDrum.set_ptr(&instrument->IsDrum); |
|
|
eMIDIBank.set_ptr(&instrument->MIDIBank); |
|
|
eMIDIProgram.set_ptr(&instrument->MIDIProgram); |
|
|
eAttenuation.set_ptr(&instrument->Attenuation); |
|
|
eGainPlus6.set_ptr(&instrument->Attenuation); |
|
|
eEffectSend.set_ptr(&instrument->EffectSend); |
|
|
eFineTune.set_ptr(&instrument->FineTune); |
|
|
ePitchbendRange.set_ptr(&instrument->PitchbendRange); |
|
|
ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode); |
|
|
eDimensionKeyRangeLow.set_ptr(0); |
|
|
eDimensionKeyRangeHigh.set_ptr(0); |
|
|
eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low); |
|
|
eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high); |
|
|
} |
|
|
|
|
|
void InstrumentProps::key_range_low_changed() |
|
|
{ |
|
|
double l = eDimensionKeyRangeLow.get_value(); |
|
|
double h = eDimensionKeyRangeHigh.get_value(); |
|
|
if (h < l) eDimensionKeyRangeHigh.set_value(l); |
|
|
} |
|
1199 |
|
|
1200 |
void InstrumentProps::key_range_high_changed() |
update_model++; |
1201 |
{ |
eName.set_value(instrument->pInfo->Name); |
1202 |
double l = eDimensionKeyRangeLow.get_value(); |
eIsDrum.set_value(instrument->IsDrum); |
1203 |
double h = eDimensionKeyRangeHigh.get_value(); |
eMIDIBank.set_value(instrument->MIDIBank); |
1204 |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
eMIDIProgram.set_value(instrument->MIDIProgram); |
1205 |
|
update_model--; |
1206 |
} |
} |
1207 |
|
|
|
sigc::signal<void>& InstrumentProps::signal_instrument_changed() |
|
|
{ |
|
|
return instrument_changed; |
|
|
} |
|
1208 |
|
|
1209 |
void MainWindow::file_changed() |
void MainWindow::file_changed() |
1210 |
{ |
{ |
1226 |
|
|
1227 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1228 |
|
|
1229 |
Gtk::MenuItem* instrument_menu = |
instrument_name_connection.block(); |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument")); |
|
|
|
|
|
int instrument_index = 0; |
|
|
Gtk::RadioMenuItem::Group instrument_group; |
|
1230 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1231 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument()) { |
1232 |
|
Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1233 |
|
|
1234 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1235 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1236 |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
row[m_Columns.m_col_name] = name; |
1237 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1238 |
// create a menu item for this instrument |
|
1239 |
Gtk::RadioMenuItem* item = |
add_instrument_to_menu(name); |
|
new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str()); |
|
|
instrument_menu->get_submenu()->append(*item); |
|
|
item->signal_activate().connect( |
|
|
sigc::bind( |
|
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
|
|
instrument_index |
|
|
) |
|
|
); |
|
|
instrument_index++; |
|
1240 |
} |
} |
1241 |
instrument_menu->show(); |
instrument_name_connection.unblock(); |
1242 |
instrument_menu->get_submenu()->show_all_children(); |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1243 |
|
|
1244 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1245 |
if (group->Name != "") { |
if (group->Name != "") { |
1246 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1247 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1248 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1249 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1250 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1251 |
for (gig::Sample* sample = group->GetFirstSample(); |
for (gig::Sample* sample = group->GetFirstSample(); |
1253 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1254 |
m_refSamplesTreeModel->append(rowGroup.children()); |
m_refSamplesTreeModel->append(rowGroup.children()); |
1255 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1256 |
rowSample[m_SamplesModel.m_col_name] = sample->pInfo->Name.c_str(); |
rowSample[m_SamplesModel.m_col_name] = |
1257 |
|
gig_to_utf8(sample->pInfo->Name); |
1258 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1259 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1260 |
} |
} |
1264 |
file = gig; |
file = gig; |
1265 |
|
|
1266 |
// select the first instrument |
// select the first instrument |
1267 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1268 |
tree_sel_ref->select(Gtk::TreePath("0")); |
|
1269 |
|
instr_props_set_instrument(); |
1270 |
|
gig::Instrument* instrument = get_instrument(); |
1271 |
|
if (instrument) { |
1272 |
|
midiRules.set_instrument(instrument); |
1273 |
|
} |
1274 |
|
} |
1275 |
|
|
1276 |
|
bool MainWindow::instr_props_set_instrument() |
1277 |
|
{ |
1278 |
|
instrumentProps.signal_name_changed().clear(); |
1279 |
|
|
1280 |
|
Gtk::TreeModel::const_iterator it = |
1281 |
|
m_TreeView.get_selection()->get_selected(); |
1282 |
|
if (it) { |
1283 |
|
Gtk::TreeModel::Row row = *it; |
1284 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1285 |
|
|
1286 |
|
instrumentProps.set_instrument(instrument); |
1287 |
|
|
1288 |
|
// make sure instrument tree is updated when user changes the |
1289 |
|
// instrument name in instrument properties window |
1290 |
|
instrumentProps.signal_name_changed().connect( |
1291 |
|
sigc::bind( |
1292 |
|
sigc::mem_fun(*this, |
1293 |
|
&MainWindow::instr_name_changed_by_instr_props), |
1294 |
|
it)); |
1295 |
|
} else { |
1296 |
|
instrumentProps.hide(); |
1297 |
|
} |
1298 |
|
return it; |
1299 |
} |
} |
1300 |
|
|
1301 |
void MainWindow::show_instr_props() |
void MainWindow::show_instr_props() |
1302 |
{ |
{ |
1303 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
if (instr_props_set_instrument()) { |
1304 |
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
instrumentProps.show(); |
1305 |
if (it) |
instrumentProps.deiconify(); |
1306 |
|
} |
1307 |
|
} |
1308 |
|
|
1309 |
|
void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it) |
1310 |
|
{ |
1311 |
|
Gtk::TreeModel::Row row = *it; |
1312 |
|
Glib::ustring name = row[m_Columns.m_col_name]; |
1313 |
|
|
1314 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1315 |
|
Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); |
1316 |
|
if (gigname != name) { |
1317 |
|
row[m_Columns.m_col_name] = gigname; |
1318 |
|
} |
1319 |
|
} |
1320 |
|
|
1321 |
|
void MainWindow::show_midi_rules() |
1322 |
|
{ |
1323 |
|
if (gig::Instrument* instrument = get_instrument()) |
1324 |
{ |
{ |
1325 |
Gtk::TreeModel::Row row = *it; |
midiRules.set_instrument(instrument); |
1326 |
if (row[m_Columns.m_col_instr]) |
midiRules.show(); |
1327 |
{ |
midiRules.deiconify(); |
1328 |
instrumentProps.set_instrument(row[m_Columns.m_col_instr]); |
} |
1329 |
instrumentProps.show(); |
} |
1330 |
instrumentProps.deiconify(); |
|
1331 |
} |
void MainWindow::on_action_view_status_bar() { |
1332 |
|
Gtk::CheckMenuItem* item = |
1333 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1334 |
|
if (!item) { |
1335 |
|
std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n"; |
1336 |
|
return; |
1337 |
|
} |
1338 |
|
if (item->get_active()) m_StatusBar.show(); |
1339 |
|
else m_StatusBar.hide(); |
1340 |
|
} |
1341 |
|
|
1342 |
|
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
1343 |
|
Gtk::CheckMenuItem* item = |
1344 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
1345 |
|
if (!item) { |
1346 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; |
1347 |
|
return true; |
1348 |
|
} |
1349 |
|
return item->get_active(); |
1350 |
|
} |
1351 |
|
|
1352 |
|
bool MainWindow::is_copy_samples_fine_tune_enabled() const { |
1353 |
|
Gtk::CheckMenuItem* item = |
1354 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
1355 |
|
if (!item) { |
1356 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; |
1357 |
|
return true; |
1358 |
} |
} |
1359 |
|
return item->get_active(); |
1360 |
|
} |
1361 |
|
|
1362 |
|
bool MainWindow::is_copy_samples_loop_enabled() const { |
1363 |
|
Gtk::CheckMenuItem* item = |
1364 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
1365 |
|
if (!item) { |
1366 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; |
1367 |
|
return true; |
1368 |
|
} |
1369 |
|
return item->get_active(); |
1370 |
} |
} |
1371 |
|
|
1372 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
1374 |
if (button->type == GDK_2BUTTON_PRESS) { |
if (button->type == GDK_2BUTTON_PRESS) { |
1375 |
show_instr_props(); |
show_instr_props(); |
1376 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1377 |
|
// gig v2 files have no midi rules |
1378 |
|
static_cast<Gtk::MenuItem*>( |
1379 |
|
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1380 |
|
!(file->pVersion && file->pVersion->major == 2)); |
1381 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1382 |
} |
} |
1383 |
} |
} |
1384 |
|
|
1385 |
void MainWindow::on_instrument_selection_change(int index) { |
void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { |
1386 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
if (item->get_active()) { |
1387 |
|
const std::vector<Gtk::Widget*> children = |
1388 |
|
instrument_menu->get_children(); |
1389 |
|
std::vector<Gtk::Widget*>::const_iterator it = |
1390 |
|
find(children.begin(), children.end(), item); |
1391 |
|
if (it != children.end()) { |
1392 |
|
int index = it - children.begin(); |
1393 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); |
1394 |
|
|
1395 |
|
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
1396 |
|
} |
1397 |
|
} |
1398 |
} |
} |
1399 |
|
|
1400 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1424 |
} |
} |
1425 |
} |
} |
1426 |
|
|
1427 |
void MainWindow::on_action_add_instrument() { |
|
1428 |
static int __instrument_indexer = 0; |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1429 |
if (!file) return; |
const Glib::ustring& name, int position) { |
1430 |
gig::Instrument* instrument = file->AddInstrument(); |
|
1431 |
__instrument_indexer++; |
Gtk::RadioMenuItem::Group instrument_group; |
1432 |
instrument->pInfo->Name = |
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1433 |
"Unnamed Instrument " + ToString(__instrument_indexer); |
if (!children.empty()) { |
1434 |
|
instrument_group = |
1435 |
|
static_cast<Gtk::RadioMenuItem*>(children[0])->get_group(); |
1436 |
|
} |
1437 |
|
Gtk::RadioMenuItem* item = |
1438 |
|
new Gtk::RadioMenuItem(instrument_group, name); |
1439 |
|
if (position < 0) { |
1440 |
|
instrument_menu->append(*item); |
1441 |
|
} else { |
1442 |
|
instrument_menu->insert(*item, position); |
1443 |
|
} |
1444 |
|
item->show(); |
1445 |
|
item->signal_activate().connect( |
1446 |
|
sigc::bind( |
1447 |
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
1448 |
|
item)); |
1449 |
|
return item; |
1450 |
|
} |
1451 |
|
|
1452 |
|
void MainWindow::remove_instrument_from_menu(int index) { |
1453 |
|
const std::vector<Gtk::Widget*> children = |
1454 |
|
instrument_menu->get_children(); |
1455 |
|
Gtk::Widget* child = children[index]; |
1456 |
|
instrument_menu->remove(*child); |
1457 |
|
delete child; |
1458 |
|
} |
1459 |
|
|
1460 |
|
void MainWindow::add_instrument(gig::Instrument* instrument) { |
1461 |
|
const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); |
1462 |
|
|
1463 |
// update instrument tree view |
// update instrument tree view |
1464 |
|
instrument_name_connection.block(); |
1465 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
1466 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
1467 |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
rowInstr[m_Columns.m_col_name] = name; |
1468 |
rowInstr[m_Columns.m_col_instr] = instrument; |
rowInstr[m_Columns.m_col_instr] = instrument; |
1469 |
|
instrument_name_connection.unblock(); |
1470 |
|
|
1471 |
|
add_instrument_to_menu(name); |
1472 |
|
|
1473 |
|
m_TreeView.get_selection()->select(iterInstr); |
1474 |
|
|
1475 |
file_changed(); |
file_changed(); |
1476 |
} |
} |
1477 |
|
|
1478 |
|
void MainWindow::on_action_add_instrument() { |
1479 |
|
static int __instrument_indexer = 0; |
1480 |
|
if (!file) return; |
1481 |
|
gig::Instrument* instrument = file->AddInstrument(); |
1482 |
|
__instrument_indexer++; |
1483 |
|
instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") + |
1484 |
|
ToString(__instrument_indexer)); |
1485 |
|
|
1486 |
|
add_instrument(instrument); |
1487 |
|
} |
1488 |
|
|
1489 |
|
void MainWindow::on_action_duplicate_instrument() { |
1490 |
|
if (!file) return; |
1491 |
|
|
1492 |
|
// retrieve the currently selected instrument |
1493 |
|
// (being the original instrument to be duplicated) |
1494 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1495 |
|
Gtk::TreeModel::iterator itSelection = sel->get_selected(); |
1496 |
|
if (!itSelection) return; |
1497 |
|
Gtk::TreeModel::Row row = *itSelection; |
1498 |
|
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
1499 |
|
if (!instrOrig) return; |
1500 |
|
|
1501 |
|
// duplicate the orginal instrument |
1502 |
|
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
1503 |
|
instrNew->pInfo->Name = |
1504 |
|
instrOrig->pInfo->Name + |
1505 |
|
gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); |
1506 |
|
|
1507 |
|
add_instrument(instrNew); |
1508 |
|
} |
1509 |
|
|
1510 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
1511 |
if (!file) return; |
if (!file) return; |
1512 |
if (file_is_shared) { |
if (file_is_shared) { |
1526 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
1527 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
1528 |
try { |
try { |
1529 |
|
Gtk::TreePath path(it); |
1530 |
|
int index = path[0]; |
1531 |
|
|
1532 |
// remove instrument from the gig file |
// remove instrument from the gig file |
1533 |
if (instr) file->DeleteInstrument(instr); |
if (instr) file->DeleteInstrument(instr); |
|
// remove respective row from instruments tree view |
|
|
m_refTreeModel->erase(it); |
|
1534 |
file_changed(); |
file_changed(); |
1535 |
|
|
1536 |
|
remove_instrument_from_menu(index); |
1537 |
|
|
1538 |
|
// remove row from instruments tree view |
1539 |
|
m_refTreeModel->erase(it); |
1540 |
|
|
1541 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1542 |
|
// select another instrument (in gtk3 this is done |
1543 |
|
// automatically) |
1544 |
|
if (!m_refTreeModel->children().empty()) { |
1545 |
|
if (index == m_refTreeModel->children().size()) { |
1546 |
|
index--; |
1547 |
|
} |
1548 |
|
m_TreeView.get_selection()->select( |
1549 |
|
Gtk::TreePath(ToString(index))); |
1550 |
|
} |
1551 |
|
#endif |
1552 |
|
instr_props_set_instrument(); |
1553 |
|
instr = get_instrument(); |
1554 |
|
if (instr) { |
1555 |
|
midiRules.set_instrument(instr); |
1556 |
|
} else { |
1557 |
|
midiRules.hide(); |
1558 |
|
} |
1559 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1560 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1561 |
msg.run(); |
msg.run(); |
1566 |
void MainWindow::on_action_sample_properties() { |
void MainWindow::on_action_sample_properties() { |
1567 |
//TODO: show a dialog where the selected sample's properties can be edited |
//TODO: show a dialog where the selected sample's properties can be edited |
1568 |
Gtk::MessageDialog msg( |
Gtk::MessageDialog msg( |
1569 |
*this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO |
*this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO |
1570 |
); |
); |
1571 |
msg.run(); |
msg.run(); |
1572 |
} |
} |
1575 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
1576 |
if (!file) return; |
if (!file) return; |
1577 |
gig::Group* group = file->AddGroup(); |
gig::Group* group = file->AddGroup(); |
1578 |
group->Name = "Unnamed Group"; |
group->Name = gig_from_utf8(_("Unnamed Group")); |
1579 |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
1580 |
__sample_indexer++; |
__sample_indexer++; |
1581 |
// update sample tree view |
// update sample tree view |
1582 |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append(); |
1583 |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1584 |
rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str(); |
rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name); |
1585 |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
rowGroup[m_SamplesModel.m_col_sample] = NULL; |
1586 |
rowGroup[m_SamplesModel.m_col_group] = group; |
rowGroup[m_SamplesModel.m_col_group] = group; |
1587 |
file_changed(); |
file_changed(); |
1609 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1610 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1611 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(true); |
1612 |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
|
1613 |
|
// matches all file types supported by libsndfile |
1614 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1615 |
|
Gtk::FileFilter soundfilter; |
1616 |
|
#else |
1617 |
|
Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create(); |
1618 |
|
#endif |
1619 |
const char* const supportedFileTypes[] = { |
const char* const supportedFileTypes[] = { |
1620 |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
1621 |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
1623 |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
1624 |
"*.caf", "*.CAF", NULL |
"*.caf", "*.CAF", NULL |
1625 |
}; |
}; |
1626 |
|
const char* soundfiles = _("Sound Files"); |
1627 |
|
const char* allfiles = _("All Files"); |
1628 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1629 |
for (int i = 0; supportedFileTypes[i]; i++) |
for (int i = 0; supportedFileTypes[i]; i++) |
1630 |
soundfilter.add_pattern(supportedFileTypes[i]); |
soundfilter.add_pattern(supportedFileTypes[i]); |
1631 |
soundfilter.set_name("Sound Files"); |
soundfilter.set_name(soundfiles); |
1632 |
Gtk::FileFilter allpassfilter; // matches every file |
|
1633 |
|
// matches every file |
1634 |
|
Gtk::FileFilter allpassfilter; |
1635 |
allpassfilter.add_pattern("*.*"); |
allpassfilter.add_pattern("*.*"); |
1636 |
allpassfilter.set_name("All Files"); |
allpassfilter.set_name(allfiles); |
1637 |
|
#else |
1638 |
|
for (int i = 0; supportedFileTypes[i]; i++) |
1639 |
|
soundfilter->add_pattern(supportedFileTypes[i]); |
1640 |
|
soundfilter->set_name(soundfiles); |
1641 |
|
|
1642 |
|
// matches every file |
1643 |
|
Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create(); |
1644 |
|
allpassfilter->add_pattern("*.*"); |
1645 |
|
allpassfilter->set_name(allfiles); |
1646 |
|
#endif |
1647 |
dialog.add_filter(soundfilter); |
dialog.add_filter(soundfilter); |
1648 |
dialog.add_filter(allpassfilter); |
dialog.add_filter(allpassfilter); |
1649 |
|
if (current_sample_dir != "") { |
1650 |
|
dialog.set_current_folder(current_sample_dir); |
1651 |
|
} |
1652 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1653 |
|
current_sample_dir = dialog.get_current_folder(); |
1654 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1655 |
Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
1656 |
for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin(); |
for (std::vector<std::string>::iterator iter = filenames.begin(); |
1657 |
iter != filenames.end(); ++iter) { |
iter != filenames.end(); ++iter) { |
1658 |
printf("Adding sample %s\n",(*iter).c_str()); |
printf("Adding sample %s\n",(*iter).c_str()); |
1659 |
// use libsndfile to retrieve file informations |
// use libsndfile to retrieve file informations |
1661 |
info.format = 0; |
info.format = 0; |
1662 |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
1663 |
try { |
try { |
1664 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
1665 |
int bitdepth; |
int bitdepth; |
1666 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
1667 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
1677 |
break; |
break; |
1678 |
default: |
default: |
1679 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
1680 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1681 |
} |
} |
1682 |
// add a new sample to the .gig file |
// add a new sample to the .gig file |
1683 |
gig::Sample* sample = file->AddSample(); |
gig::Sample* sample = file->AddSample(); |
1690 |
break; |
break; |
1691 |
} |
} |
1692 |
} |
} |
1693 |
sample->pInfo->Name = filename; |
sample->pInfo->Name = gig_from_utf8(filename); |
1694 |
sample->Channels = info.channels; |
sample->Channels = info.channels; |
1695 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1696 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1704 |
&instrument, sizeof(instrument)) != SF_FALSE) |
&instrument, sizeof(instrument)) != SF_FALSE) |
1705 |
{ |
{ |
1706 |
sample->MIDIUnityNote = instrument.basenote; |
sample->MIDIUnityNote = instrument.basenote; |
1707 |
|
sample->FineTune = instrument.detune; |
1708 |
|
|
|
#if HAVE_SF_INSTRUMENT_LOOPS |
|
1709 |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
1710 |
sample->Loops = 1; |
sample->Loops = 1; |
1711 |
|
|
1725 |
sample->LoopPlayCount = instrument.loops[0].count; |
sample->LoopPlayCount = instrument.loops[0].count; |
1726 |
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
1727 |
} |
} |
|
#endif |
|
1728 |
} |
} |
1729 |
|
|
1730 |
// schedule resizing the sample (which will be done |
// schedule resizing the sample (which will be done |
1742 |
Gtk::TreeModel::iterator iterSample = |
Gtk::TreeModel::iterator iterSample = |
1743 |
m_refSamplesTreeModel->append(row.children()); |
m_refSamplesTreeModel->append(row.children()); |
1744 |
Gtk::TreeModel::Row rowSample = *iterSample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
1745 |
rowSample[m_SamplesModel.m_col_name] = filename; |
rowSample[m_SamplesModel.m_col_name] = |
1746 |
|
gig_to_utf8(sample->pInfo->Name); |
1747 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1748 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1749 |
// close sound file |
// close sound file |
1750 |
sf_close(hFile); |
sf_close(hFile); |
1751 |
file_changed(); |
file_changed(); |
1752 |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
} catch (std::string what) { // remember the files that made trouble (and their cause) |
1753 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1754 |
error_files += *iter += " (" + what + ")"; |
error_files += *iter += " (" + what + ")"; |
1755 |
} |
} |
1756 |
} |
} |
1757 |
// show error message box when some file(s) could not be opened / added |
// show error message box when some file(s) could not be opened / added |
1758 |
if (error_files.size()) { |
if (!error_files.empty()) { |
1759 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
1760 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1761 |
msg.run(); |
msg.run(); |
1763 |
} |
} |
1764 |
} |
} |
1765 |
|
|
1766 |
|
void MainWindow::on_action_replace_all_samples_in_all_groups() |
1767 |
|
{ |
1768 |
|
if (!file) return; |
1769 |
|
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
1770 |
|
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
1771 |
|
const char* str = |
1772 |
|
_("This is a very specific function. It tries to replace all samples " |
1773 |
|
"in the current gig file by samples located in the chosen " |
1774 |
|
"directory.\n\n" |
1775 |
|
"It works like this: For each sample in the gig file, it tries to " |
1776 |
|
"find a sample file in the selected directory with the same name as " |
1777 |
|
"the sample in the gig file. Optionally, you can add a filename " |
1778 |
|
"extension below, which will be added to the filename expected to be " |
1779 |
|
"found. That is, assume you have a gig file with a sample called " |
1780 |
|
"'Snare', if you enter '.wav' below (like it's done by default), it " |
1781 |
|
"expects to find a sample file called 'Snare.wav' and will replace " |
1782 |
|
"the sample in the gig file accordingly. If you don't need an " |
1783 |
|
"extension, blank the field below. Any gig sample where no " |
1784 |
|
"appropriate sample file could be found will be reported and left " |
1785 |
|
"untouched.\n"); |
1786 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1787 |
|
view::WrapLabel description(str); |
1788 |
|
#else |
1789 |
|
Gtk::Label description(str); |
1790 |
|
description.set_line_wrap(); |
1791 |
|
#endif |
1792 |
|
Gtk::HBox entryArea; |
1793 |
|
Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); |
1794 |
|
Gtk::Entry postfixEntryBox; |
1795 |
|
postfixEntryBox.set_text(".wav"); |
1796 |
|
entryArea.pack_start(entryLabel); |
1797 |
|
entryArea.pack_start(postfixEntryBox); |
1798 |
|
dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); |
1799 |
|
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
1800 |
|
description.show(); |
1801 |
|
entryArea.show_all(); |
1802 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1803 |
|
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
1804 |
|
dialog.set_select_multiple(false); |
1805 |
|
if (current_sample_dir != "") { |
1806 |
|
dialog.set_current_folder(current_sample_dir); |
1807 |
|
} |
1808 |
|
if (dialog.run() == Gtk::RESPONSE_OK) |
1809 |
|
{ |
1810 |
|
current_sample_dir = dialog.get_current_folder(); |
1811 |
|
Glib::ustring error_files; |
1812 |
|
std::string folder = dialog.get_filename(); |
1813 |
|
for (gig::Sample* sample = file->GetFirstSample(); |
1814 |
|
sample; sample = file->GetNextSample()) |
1815 |
|
{ |
1816 |
|
std::string filename = |
1817 |
|
folder + G_DIR_SEPARATOR_S + |
1818 |
|
Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) + |
1819 |
|
postfixEntryBox.get_text()); |
1820 |
|
SF_INFO info; |
1821 |
|
info.format = 0; |
1822 |
|
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
1823 |
|
try |
1824 |
|
{ |
1825 |
|
if (!hFile) throw std::string(_("could not open file")); |
1826 |
|
int bitdepth; |
1827 |
|
switch (info.format & 0xff) { |
1828 |
|
case SF_FORMAT_PCM_S8: |
1829 |
|
case SF_FORMAT_PCM_16: |
1830 |
|
case SF_FORMAT_PCM_U8: |
1831 |
|
bitdepth = 16; |
1832 |
|
break; |
1833 |
|
case SF_FORMAT_PCM_24: |
1834 |
|
case SF_FORMAT_PCM_32: |
1835 |
|
case SF_FORMAT_FLOAT: |
1836 |
|
case SF_FORMAT_DOUBLE: |
1837 |
|
bitdepth = 24; |
1838 |
|
break; |
1839 |
|
default: |
1840 |
|
sf_close(hFile); |
1841 |
|
throw std::string(_("format not supported")); |
1842 |
|
} |
1843 |
|
SampleImportItem sched_item; |
1844 |
|
sched_item.gig_sample = sample; |
1845 |
|
sched_item.sample_path = filename; |
1846 |
|
m_SampleImportQueue.push_back(sched_item); |
1847 |
|
sf_close(hFile); |
1848 |
|
file_changed(); |
1849 |
|
} |
1850 |
|
catch (std::string what) |
1851 |
|
{ |
1852 |
|
if (!error_files.empty()) error_files += "\n"; |
1853 |
|
error_files += Glib::filename_to_utf8(filename) + |
1854 |
|
" (" + what + ")"; |
1855 |
|
} |
1856 |
|
} |
1857 |
|
// show error message box when some file(s) could not be opened / added |
1858 |
|
if (!error_files.empty()) { |
1859 |
|
Glib::ustring txt = |
1860 |
|
_("Could not replace the following sample(s):\n") + error_files; |
1861 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1862 |
|
msg.run(); |
1863 |
|
} |
1864 |
|
} |
1865 |
|
} |
1866 |
|
|
1867 |
void MainWindow::on_action_remove_sample() { |
void MainWindow::on_action_remove_sample() { |
1868 |
if (!file) return; |
if (!file) return; |
1869 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1876 |
try { |
try { |
1877 |
// remove group or sample from the gig file |
// remove group or sample from the gig file |
1878 |
if (group) { |
if (group) { |
1879 |
// temporarily remember the samples that bolong to |
// temporarily remember the samples that belong to |
1880 |
// that group (we need that to clean the queue) |
// that group (we need that to clean the queue) |
1881 |
std::list<gig::Sample*> members; |
std::list<gig::Sample*> members; |
1882 |
for (gig::Sample* pSample = group->GetFirstSample(); |
for (gig::Sample* pSample = group->GetFirstSample(); |
2002 |
channels_changed = true; |
channels_changed = true; |
2003 |
region_changed(); |
region_changed(); |
2004 |
} |
} |
2005 |
dimreg_edit.set_sample(sample); |
dimreg_edit.set_sample( |
2006 |
|
sample, |
2007 |
|
is_copy_samples_unity_note_enabled(), |
2008 |
|
is_copy_samples_fine_tune_enabled(), |
2009 |
|
is_copy_samples_loop_enabled() |
2010 |
|
); |
2011 |
|
|
2012 |
if (sample->Channels == 2 && !stereo_dimension) { |
if (sample->Channels == 2 && !stereo_dimension) { |
2013 |
// add samplechannel dimension |
// add samplechannel dimension |
2035 |
// notify we're done with altering |
// notify we're done with altering |
2036 |
region_changed_signal.emit(region); |
region_changed_signal.emit(region); |
2037 |
|
|
2038 |
|
file_changed(); |
2039 |
|
|
2040 |
return; |
return; |
2041 |
} |
} |
2042 |
// drop failed |
// drop failed |
2050 |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
Glib::ustring name = row[m_SamplesModel.m_col_name]; |
2051 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2052 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2053 |
|
gig::String gigname(gig_from_utf8(name)); |
2054 |
if (group) { |
if (group) { |
2055 |
if (group->Name != name) { |
if (group->Name != gigname) { |
2056 |
group->Name = name; |
group->Name = gigname; |
2057 |
printf("group name changed\n"); |
printf("group name changed\n"); |
2058 |
file_changed(); |
file_changed(); |
2059 |
} |
} |
2060 |
} else if (sample) { |
} else if (sample) { |
2061 |
if (sample->pInfo->Name != name.raw()) { |
if (sample->pInfo->Name != gigname) { |
2062 |
sample->pInfo->Name = name.raw(); |
sample->pInfo->Name = gigname; |
2063 |
printf("sample name changed\n"); |
printf("sample name changed\n"); |
2064 |
file_changed(); |
file_changed(); |
2065 |
} |
} |
2071 |
if (!iter) return; |
if (!iter) return; |
2072 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
2073 |
Glib::ustring name = row[m_Columns.m_col_name]; |
Glib::ustring name = row[m_Columns.m_col_name]; |
2074 |
|
|
2075 |
|
// change name in instrument menu |
2076 |
|
int index = path[0]; |
2077 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
2078 |
|
if (index < children.size()) { |
2079 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 |
2080 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name); |
2081 |
|
#else |
2082 |
|
remove_instrument_from_menu(index); |
2083 |
|
Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); |
2084 |
|
item->set_active(); |
2085 |
|
#endif |
2086 |
|
} |
2087 |
|
|
2088 |
|
// change name in gig |
2089 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
2090 |
if (instrument && instrument->pInfo->Name != name.raw()) { |
gig::String gigname(gig_from_utf8(name)); |
2091 |
instrument->pInfo->Name = name.raw(); |
if (instrument && instrument->pInfo->Name != gigname) { |
2092 |
|
instrument->pInfo->Name = gigname; |
2093 |
|
|
2094 |
|
// change name in the instrument properties window |
2095 |
|
if (instrumentProps.get_instrument() == instrument) { |
2096 |
|
instrumentProps.update_name(); |
2097 |
|
} |
2098 |
|
|
2099 |
file_changed(); |
file_changed(); |
2100 |
} |
} |
2101 |
} |
} |
2140 |
return region_changed_signal; |
return region_changed_signal; |
2141 |
} |
} |
2142 |
|
|
2143 |
|
sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() { |
2144 |
|
return sample_changed_signal; |
2145 |
|
} |
2146 |
|
|
2147 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
2148 |
return sample_ref_changed_signal; |
return sample_ref_changed_signal; |
2149 |
} |
} |
2155 |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
2156 |
return dimreg_changed_signal; |
return dimreg_changed_signal; |
2157 |
} |
} |
2158 |
|
|
2159 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() { |
2160 |
|
return note_on_signal; |
2161 |
|
} |
2162 |
|
|
2163 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() { |
2164 |
|
return note_off_signal; |
2165 |
|
} |
2166 |
|
|
2167 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() { |
2168 |
|
return m_RegionChooser.signal_keyboard_key_hit(); |
2169 |
|
} |
2170 |
|
|
2171 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
2172 |
|
return m_RegionChooser.signal_keyboard_key_released(); |
2173 |
|
} |