1 |
/* |
/* |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2013 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 |
17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
|
#include <libintl.h> |
|
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 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
#if GTKMM_MAJOR_VERSION < 3 |
35 |
#define ABOUT_DIALOG |
#include "wrapLabel.hh" |
|
#include <gtkmm/aboutdialog.h> |
|
36 |
#endif |
#endif |
37 |
|
|
38 |
|
#include "global.h" |
39 |
|
#include "compat.h" |
40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
42 |
#include <sndfile.h> |
#include <sndfile.h> |
43 |
|
|
44 |
#include "mainwindow.h" |
#include "mainwindow.h" |
45 |
|
|
46 |
#define _(String) gettext(String) |
#include "../../gfx/status_attached.xpm" |
47 |
|
#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 |
|
|
93 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
94 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments"); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
95 |
|
|
96 |
|
|
97 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
128 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
129 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
130 |
|
|
131 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
132 |
|
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
133 |
|
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
134 |
|
toggle_action->set_active(true); |
135 |
|
actionGroup->add(toggle_action, |
136 |
|
sigc::mem_fun( |
137 |
|
*this, &MainWindow::on_action_view_status_bar)); |
138 |
|
|
139 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
140 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("MenuHelp", |
141 |
action->property_label())); |
action->property_label())); |
|
#ifdef ABOUT_DIALOG |
|
142 |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
143 |
sigc::mem_fun( |
sigc::mem_fun( |
144 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
|
#endif |
|
145 |
actionGroup->add( |
actionGroup->add( |
146 |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
Gtk::Action::create("AddInstrument", _("Add _Instrument")), |
147 |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) |
148 |
); |
); |
149 |
actionGroup->add( |
actionGroup->add( |
150 |
|
Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")), |
151 |
|
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
152 |
|
); |
153 |
|
actionGroup->add( |
154 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
155 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
156 |
); |
); |
165 |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
sigc::mem_fun(*this, &MainWindow::on_action_add_group) |
166 |
); |
); |
167 |
actionGroup->add( |
actionGroup->add( |
168 |
Gtk::Action::create("AddSample", _("Add _Sample(s)")), |
Gtk::Action::create("AddSample", _("Add _Sample(s)...")), |
169 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
170 |
); |
); |
171 |
actionGroup->add( |
actionGroup->add( |
172 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
173 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
174 |
); |
); |
175 |
|
actionGroup->add( |
176 |
|
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
177 |
|
_("Replace All Samples in All Groups...")), |
178 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
179 |
|
); |
180 |
|
|
181 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
182 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
198 |
" </menu>" |
" </menu>" |
199 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
200 |
" </menu>" |
" </menu>" |
201 |
#ifdef ABOUT_DIALOG |
" <menu action='MenuView'>" |
202 |
|
" <menuitem action='Statusbar'/>" |
203 |
|
" </menu>" |
204 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
205 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
206 |
" </menu>" |
" </menu>" |
|
#endif |
|
207 |
" </menubar>" |
" </menubar>" |
208 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
209 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
210 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
211 |
|
" <menuitem action='DupInstrument'/>" |
212 |
" <separator/>" |
" <separator/>" |
213 |
" <menuitem action='RemoveInstrument'/>" |
" <menuitem action='RemoveInstrument'/>" |
214 |
" </popup>" |
" </popup>" |
216 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
217 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
218 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
219 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
220 |
" <separator/>" |
" <separator/>" |
221 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
222 |
" </popup>" |
" </popup>" |
225 |
|
|
226 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
227 |
|
|
228 |
|
instrument_menu = static_cast<Gtk::MenuItem*>( |
229 |
|
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
230 |
|
|
231 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
232 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
233 |
m_VBox.pack_start(m_HPaned); |
m_VBox.pack_start(m_HPaned); |
234 |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); |
235 |
|
m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK); |
236 |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); |
237 |
|
m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); |
238 |
|
|
239 |
|
set_file_is_shared(false); |
240 |
|
|
241 |
|
// Status Bar: |
242 |
|
m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); |
243 |
|
m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); |
244 |
|
m_StatusBar.show(); |
245 |
|
|
246 |
m_RegionChooser.signal_region_selected().connect( |
m_RegionChooser.signal_region_selected().connect( |
247 |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
sigc::mem_fun(*this, &MainWindow::region_changed) ); |
252 |
// Create the Tree model: |
// Create the Tree model: |
253 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
254 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
255 |
m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
256 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
257 |
); |
); |
258 |
|
|
274 |
); |
); |
275 |
|
|
276 |
// 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 |
277 |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
278 |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
279 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
280 |
|
m_TreeViewSamples.signal_drag_begin().connect( |
281 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
282 |
|
); |
283 |
m_TreeViewSamples.signal_drag_data_get().connect( |
m_TreeViewSamples.signal_drag_data_get().connect( |
284 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
285 |
); |
); |
288 |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
289 |
); |
); |
290 |
dimreg_edit.signal_dimreg_changed().connect( |
dimreg_edit.signal_dimreg_changed().connect( |
291 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
292 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
293 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
294 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
295 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
296 |
instrumentProps.signal_instrument_changed().connect( |
instrumentProps.signal_changed().connect( |
297 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
298 |
|
propDialog.signal_changed().connect( |
299 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
300 |
|
|
301 |
|
dimreg_edit.signal_dimreg_to_be_changed().connect( |
302 |
|
dimreg_to_be_changed_signal.make_slot()); |
303 |
|
dimreg_edit.signal_dimreg_changed().connect( |
304 |
|
dimreg_changed_signal.make_slot()); |
305 |
|
dimreg_edit.signal_sample_ref_changed().connect( |
306 |
|
sample_ref_changed_signal.make_slot()); |
307 |
|
|
308 |
|
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
309 |
|
sigc::hide( |
310 |
|
sigc::bind( |
311 |
|
file_structure_to_be_changed_signal.make_slot(), |
312 |
|
sigc::ref(this->file) |
313 |
|
) |
314 |
|
) |
315 |
|
); |
316 |
|
m_RegionChooser.signal_instrument_struct_changed().connect( |
317 |
|
sigc::hide( |
318 |
|
sigc::bind( |
319 |
|
file_structure_changed_signal.make_slot(), |
320 |
|
sigc::ref(this->file) |
321 |
|
) |
322 |
|
) |
323 |
|
); |
324 |
|
m_RegionChooser.signal_region_to_be_changed().connect( |
325 |
|
region_to_be_changed_signal.make_slot()); |
326 |
|
m_RegionChooser.signal_region_changed_signal().connect( |
327 |
|
region_changed_signal.make_slot()); |
328 |
|
|
329 |
|
note_on_signal.connect( |
330 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event)); |
331 |
|
note_off_signal.connect( |
332 |
|
sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event)); |
333 |
|
|
334 |
|
dimreg_all_regions.signal_toggled().connect( |
335 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
336 |
|
dimreg_all_dimregs.signal_toggled().connect( |
337 |
|
sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled)); |
338 |
|
dimreg_stereo.signal_toggled().connect( |
339 |
|
sigc::mem_fun(*this, &MainWindow::update_dimregs)); |
340 |
|
|
341 |
file = 0; |
file = 0; |
342 |
file_is_changed = false; |
file_is_changed = false; |
343 |
|
|
344 |
show_all_children(); |
show_all_children(); |
345 |
|
|
346 |
|
// start with a new gig file by default |
347 |
|
on_action_file_new(); |
348 |
} |
} |
349 |
|
|
350 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
353 |
|
|
354 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
355 |
{ |
{ |
356 |
return file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
357 |
} |
} |
358 |
|
|
359 |
void MainWindow::on_action_quit() |
void MainWindow::on_action_quit() |
360 |
{ |
{ |
361 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
362 |
hide(); |
hide(); |
363 |
} |
} |
364 |
|
|
367 |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
m_DimRegionChooser.set_region(m_RegionChooser.get_region()); |
368 |
} |
} |
369 |
|
|
370 |
|
gig::Instrument* MainWindow::get_instrument() |
371 |
|
{ |
372 |
|
gig::Instrument* instrument = 0; |
373 |
|
Gtk::TreeModel::const_iterator it = |
374 |
|
m_TreeView.get_selection()->get_selected(); |
375 |
|
if (it) { |
376 |
|
Gtk::TreeModel::Row row = *it; |
377 |
|
instrument = row[m_Columns.m_col_instr]; |
378 |
|
} |
379 |
|
return instrument; |
380 |
|
} |
381 |
|
|
382 |
|
void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs) |
383 |
|
{ |
384 |
|
if (all_dimregs) { |
385 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
386 |
|
if (region->pDimensionRegions[i]) { |
387 |
|
dimreg_edit.dimregs.insert(region->pDimensionRegions[i]); |
388 |
|
} |
389 |
|
} |
390 |
|
} else { |
391 |
|
m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs); |
392 |
|
} |
393 |
|
} |
394 |
|
|
395 |
|
void MainWindow::update_dimregs() |
396 |
|
{ |
397 |
|
dimreg_edit.dimregs.clear(); |
398 |
|
bool all_regions = dimreg_all_regions.get_active(); |
399 |
|
bool stereo = dimreg_stereo.get_active(); |
400 |
|
bool all_dimregs = dimreg_all_dimregs.get_active(); |
401 |
|
|
402 |
|
if (all_regions) { |
403 |
|
gig::Instrument* instrument = get_instrument(); |
404 |
|
if (instrument) { |
405 |
|
for (gig::Region* region = instrument->GetFirstRegion() ; |
406 |
|
region ; |
407 |
|
region = instrument->GetNextRegion()) { |
408 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
409 |
|
} |
410 |
|
} |
411 |
|
} else { |
412 |
|
gig::Region* region = m_RegionChooser.get_region(); |
413 |
|
if (region) { |
414 |
|
add_region_to_dimregs(region, stereo, all_dimregs); |
415 |
|
} |
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
void MainWindow::dimreg_all_dimregs_toggled() |
420 |
|
{ |
421 |
|
dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active()); |
422 |
|
update_dimregs(); |
423 |
|
} |
424 |
|
|
425 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
426 |
{ |
{ |
427 |
|
update_dimregs(); |
428 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
429 |
} |
} |
430 |
|
|
431 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
432 |
{ |
{ |
433 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
// select item in instrument menu |
434 |
|
Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); |
|
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
|
435 |
if (it) { |
if (it) { |
436 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreePath path(it); |
437 |
std::cout << row[m_Columns.m_col_name] << std::endl; |
int index = path[0]; |
438 |
|
const std::vector<Gtk::Widget*> children = |
439 |
m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]); |
instrument_menu->get_children(); |
440 |
} else { |
static_cast<Gtk::RadioMenuItem*>(children[index])->set_active(); |
|
m_RegionChooser.set_instrument(0); |
|
441 |
} |
} |
442 |
|
|
443 |
|
m_RegionChooser.set_instrument(get_instrument()); |
444 |
} |
} |
445 |
|
|
446 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
452 |
void Loader::progress_callback(float fraction) |
void Loader::progress_callback(float fraction) |
453 |
{ |
{ |
454 |
{ |
{ |
455 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
456 |
progress = fraction; |
progress = fraction; |
457 |
} |
} |
458 |
progress_dispatcher(); |
progress_dispatcher(); |
460 |
|
|
461 |
void Loader::thread_function() |
void Loader::thread_function() |
462 |
{ |
{ |
463 |
printf("thread_function self=%x\n", Glib::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
464 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename); |
465 |
RIFF::File* riff = new RIFF::File(filename); |
RIFF::File* riff = new RIFF::File(filename); |
466 |
gig = new gig::File(riff); |
gig = new gig::File(riff); |
474 |
} |
} |
475 |
|
|
476 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
477 |
: thread(0), filename(filename) |
: filename(filename), thread(0) |
478 |
{ |
{ |
479 |
} |
} |
480 |
|
|
481 |
void Loader::launch() |
void Loader::launch() |
482 |
{ |
{ |
483 |
|
#ifdef OLD_THREADS |
484 |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); |
485 |
|
#else |
486 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
487 |
|
#endif |
488 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%x\n", thread); |
489 |
} |
} |
490 |
|
|
492 |
{ |
{ |
493 |
float res; |
float res; |
494 |
{ |
{ |
495 |
Glib::Mutex::Lock lock(progressMutex); |
Glib::Threads::Mutex::Lock lock(progressMutex); |
496 |
res = progress; |
res = progress; |
497 |
} |
} |
498 |
return res; |
return res; |
518 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
519 |
// 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. |
520 |
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(); |
|
521 |
// forget all samples that ought to be imported |
// forget all samples that ought to be imported |
522 |
m_SampleImportQueue.clear(); |
m_SampleImportQueue.clear(); |
523 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
524 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
525 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
526 |
// free libgig's gig::File instance |
// remove all entries from "Instrument" menu |
527 |
if (file) { |
while (!instrument_menu->get_children().empty()) { |
528 |
delete file; |
remove_instrument_from_menu(0); |
|
file = NULL; |
|
529 |
} |
} |
530 |
|
// free libgig's gig::File instance |
531 |
|
if (file && !file_is_shared) delete file; |
532 |
|
file = NULL; |
533 |
|
set_file_is_shared(false); |
534 |
} |
} |
535 |
|
|
536 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
537 |
{ |
{ |
538 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
539 |
|
|
540 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
541 |
|
|
542 |
// clear all GUI elements |
// clear all GUI elements |
543 |
__clear(); |
__clear(); |
545 |
gig::File* pFile = new gig::File; |
gig::File* pFile = new gig::File; |
546 |
// already add one new instrument by default |
// already add one new instrument by default |
547 |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
gig::Instrument* pInstrument = pFile->AddInstrument(); |
548 |
pInstrument->pInfo->Name = "Unnamed Instrument"; |
pInstrument->pInfo->Name = _("Unnamed Instrument"); |
549 |
// update GUI with that new gig::File |
// update GUI with that new gig::File |
550 |
load_gig(pFile, 0 /*no file name yet*/); |
load_gig(pFile, 0 /*no file name yet*/); |
551 |
} |
} |
562 |
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); |
563 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
564 |
int response = dialog.run(); |
int response = dialog.run(); |
565 |
|
dialog.hide(); |
566 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
if (response == Gtk::RESPONSE_YES) return file_save(); |
567 |
return response != Gtk::RESPONSE_CANCEL; |
return response != Gtk::RESPONSE_CANCEL; |
568 |
} |
} |
569 |
|
|
570 |
|
bool MainWindow::leaving_shared_mode_dialog() { |
571 |
|
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
572 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
573 |
|
dialog.set_secondary_text( |
574 |
|
_("If you proceed to work on another instrument file, it won't be " |
575 |
|
"used by the sampler until you tell the sampler explicitly to " |
576 |
|
"load it.")); |
577 |
|
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
578 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
579 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
580 |
|
int response = dialog.run(); |
581 |
|
dialog.hide(); |
582 |
|
return response == Gtk::RESPONSE_YES; |
583 |
|
} |
584 |
|
|
585 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
586 |
{ |
{ |
587 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
588 |
|
|
589 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
590 |
|
|
591 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
592 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
593 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
594 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
595 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
596 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
597 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
598 |
|
#else |
599 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
600 |
|
filter->add_pattern("*.gig"); |
601 |
|
#endif |
602 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
603 |
if (current_dir != "") { |
if (current_gig_dir != "") { |
604 |
dialog.set_current_folder(current_dir); |
dialog.set_current_folder(current_gig_dir); |
605 |
} |
} |
606 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
607 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
608 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
609 |
__clear(); |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
|
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
|
610 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
611 |
current_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
612 |
} |
} |
613 |
} |
} |
614 |
|
|
615 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
616 |
{ |
{ |
617 |
load_dialog = new LoadDialog("Loading...", *this); |
__clear(); |
618 |
|
load_dialog = new LoadDialog(_("Loading..."), *this); |
619 |
load_dialog->show_all(); |
load_dialog->show_all(); |
620 |
loader = new Loader(strdup(name)); |
loader = new Loader(strdup(name)); |
621 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
632 |
msg.run(); |
msg.run(); |
633 |
Gtk::Main::quit(); |
Gtk::Main::quit(); |
634 |
} |
} |
635 |
|
// clear all GUI elements |
636 |
|
__clear(); |
637 |
|
// load the instrument |
638 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
639 |
load_gig(pFile, 0 /*file name*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
640 |
//TODO: automatically select the given instrument |
//TODO: automatically select the given instrument |
641 |
} |
} |
642 |
|
|
648 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
649 |
{ |
{ |
650 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
651 |
printf("on_loader_finished self=%x\n", Glib::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
652 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename); |
653 |
load_dialog->hide(); |
load_dialog->hide(); |
654 |
} |
} |
658 |
file_save(); |
file_save(); |
659 |
} |
} |
660 |
|
|
661 |
bool MainWindow::file_save() |
bool MainWindow::check_if_savable() |
662 |
{ |
{ |
663 |
if (!file) return false; |
if (!file) return false; |
664 |
if (!file_has_name) return file_save_as(); |
|
665 |
|
if (!file->GetFirstSample()) { |
666 |
|
Gtk::MessageDialog(*this, _("The file could not be saved " |
667 |
|
"because it contains no samples"), |
668 |
|
false, Gtk::MESSAGE_ERROR).run(); |
669 |
|
return false; |
670 |
|
} |
671 |
|
|
672 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ; |
673 |
|
instrument = file->GetNextInstrument()) { |
674 |
|
if (!instrument->GetFirstRegion()) { |
675 |
|
Gtk::MessageDialog(*this, _("The file could not be saved " |
676 |
|
"because there are instruments " |
677 |
|
"that have no regions"), |
678 |
|
false, Gtk::MESSAGE_ERROR).run(); |
679 |
|
return false; |
680 |
|
} |
681 |
|
} |
682 |
|
return true; |
683 |
|
} |
684 |
|
|
685 |
|
bool MainWindow::file_save() |
686 |
|
{ |
687 |
|
if (!check_if_savable()) return false; |
688 |
|
if (!file_is_shared && !file_has_name) return file_save_as(); |
689 |
|
|
690 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
691 |
|
file_structure_to_be_changed_signal.emit(this->file); |
692 |
try { |
try { |
693 |
file->Save(); |
file->Save(); |
694 |
if (file_is_changed) { |
if (file_is_changed) { |
696 |
file_is_changed = false; |
file_is_changed = false; |
697 |
} |
} |
698 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
699 |
Glib::ustring txt = "Could not save file: " + e.Message; |
file_structure_changed_signal.emit(this->file); |
700 |
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
701 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
702 |
msg.run(); |
msg.run(); |
703 |
return false; |
return false; |
704 |
} |
} |
705 |
std::cout << "Saving file done\n" << std::flush; |
std::cout << "Saving file done\n" << std::flush; |
706 |
__import_queued_samples(); |
__import_queued_samples(); |
707 |
|
file_structure_changed_signal.emit(this->file); |
708 |
return true; |
return true; |
709 |
} |
} |
710 |
|
|
711 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
712 |
{ |
{ |
713 |
|
if (!check_if_savable()) return; |
714 |
file_save_as(); |
file_save_as(); |
715 |
} |
} |
716 |
|
|
717 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
718 |
{ |
{ |
|
if (!file) return false; |
|
719 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
720 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
721 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
722 |
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 |
|
723 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
724 |
// TODO: an overwrite dialog for gtkmm < 2.8 |
|
725 |
#endif |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
726 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
727 |
filter.add_pattern("*.gig"); |
filter.add_pattern("*.gig"); |
728 |
|
#else |
729 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
730 |
|
filter->add_pattern("*.gig"); |
731 |
|
#endif |
732 |
dialog.set_filter(filter); |
dialog.set_filter(filter); |
733 |
|
|
734 |
if (Glib::path_is_absolute(filename)) { |
// set initial dir and filename of the Save As dialog |
735 |
dialog.set_filename(filename); |
// and prepare that initial filename as a copy of the gig |
736 |
} else if (current_dir != "") { |
{ |
737 |
dialog.set_current_folder(current_dir); |
std::string basename = Glib::path_get_basename(filename); |
738 |
|
std::string dir = Glib::path_get_dirname(filename); |
739 |
|
basename = std::string(_("copy_of_")) + basename; |
740 |
|
Glib::ustring copyFileName = Glib::build_filename(dir, basename); |
741 |
|
if (Glib::path_is_absolute(filename)) { |
742 |
|
dialog.set_filename(copyFileName); |
743 |
|
} else { |
744 |
|
if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir); |
745 |
|
} |
746 |
|
dialog.set_current_name(Glib::filename_display_basename(copyFileName)); |
747 |
} |
} |
748 |
dialog.set_current_name(Glib::filename_display_basename(filename)); |
|
749 |
|
// show warning in the dialog |
750 |
|
Gtk::HBox descriptionArea; |
751 |
|
descriptionArea.set_spacing(15); |
752 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
753 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
754 |
|
#if GTKMM_MAJOR_VERSION < 3 |
755 |
|
view::WrapLabel description; |
756 |
|
#else |
757 |
|
Gtk::Label description; |
758 |
|
description.set_line_wrap(); |
759 |
|
#endif |
760 |
|
description.set_markup( |
761 |
|
_("\n<b>CAUTION:</b> You <b>MUST</b> use the " |
762 |
|
"<span style=\"italic\">\"Save\"</span> dialog instead of " |
763 |
|
"<span style=\"italic\">\"Save As...\"</span> if you want to save " |
764 |
|
"to the same .gig file. Using " |
765 |
|
"<span style=\"italic\">\"Save As...\"</span> for writing to the " |
766 |
|
"same .gig file will end up in corrupted sample wave data!\n") |
767 |
|
); |
768 |
|
descriptionArea.pack_start(description); |
769 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
770 |
|
descriptionArea.show_all(); |
771 |
|
|
772 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
773 |
|
file_structure_to_be_changed_signal.emit(this->file); |
774 |
try { |
try { |
775 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
776 |
if (!Glib::str_has_suffix(filename, ".gig")) { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
779 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
780 |
file->Save(filename); |
file->Save(filename); |
781 |
this->filename = filename; |
this->filename = filename; |
782 |
current_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
783 |
set_title(Glib::filename_display_basename(filename)); |
set_title(Glib::filename_display_basename(filename)); |
784 |
file_has_name = true; |
file_has_name = true; |
785 |
file_is_changed = false; |
file_is_changed = false; |
786 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
787 |
Glib::ustring txt = "Could not save file: " + e.Message; |
file_structure_changed_signal.emit(this->file); |
788 |
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
789 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
790 |
msg.run(); |
msg.run(); |
791 |
return false; |
return false; |
792 |
} |
} |
793 |
__import_queued_samples(); |
__import_queued_samples(); |
794 |
|
file_structure_changed_signal.emit(this->file); |
795 |
return true; |
return true; |
796 |
} |
} |
797 |
return false; |
return false; |
808 |
SF_INFO info; |
SF_INFO info; |
809 |
info.format = 0; |
info.format = 0; |
810 |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); |
811 |
|
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
812 |
try { |
try { |
813 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
814 |
// determine sample's bit depth |
// determine sample's bit depth |
815 |
int bitdepth; |
int bitdepth; |
816 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
817 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
818 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
819 |
|
case SF_FORMAT_PCM_U8: |
820 |
bitdepth = 16; |
bitdepth = 16; |
821 |
break; |
break; |
822 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
|
bitdepth = 32; // we simply convert to 32 bit for now |
|
|
break; |
|
823 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
|
bitdepth = 32; |
|
|
break; |
|
|
case SF_FORMAT_PCM_U8: |
|
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
824 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
|
bitdepth = 32; |
|
|
break; |
|
825 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
826 |
bitdepth = 32; // I guess we will always truncate this to 32 bit |
bitdepth = 24; |
827 |
break; |
break; |
828 |
default: |
default: |
829 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
830 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
831 |
} |
} |
832 |
// allocate appropriate copy buffer (TODO: for now we copy |
|
833 |
// it in one piece, might be tough for very long samples) |
const int bufsize = 10000; |
|
// and copy sample data into buffer |
|
|
int8_t* buffer = NULL; |
|
834 |
switch (bitdepth) { |
switch (bitdepth) { |
835 |
case 16: |
case 16: { |
836 |
buffer = new int8_t[2 * info.channels * info.frames]; |
short* buffer = new short[bufsize * info.channels]; |
837 |
// libsndfile does the conversion for us (if needed) |
sf_count_t cnt = info.frames; |
838 |
sf_readf_short(hFile, (short*) buffer, info.frames); |
while (cnt) { |
839 |
|
// libsndfile does the conversion for us (if needed) |
840 |
|
int n = sf_readf_short(hFile, buffer, bufsize); |
841 |
|
// write from buffer directly (physically) into .gig file |
842 |
|
iter->gig_sample->Write(buffer, n); |
843 |
|
cnt -= n; |
844 |
|
} |
845 |
|
delete[] buffer; |
846 |
break; |
break; |
847 |
case 32: |
} |
848 |
buffer = new int8_t[4 * info.channels * info.frames]; |
case 24: { |
849 |
// libsndfile does the conversion for us (if needed) |
int* srcbuf = new int[bufsize * info.channels]; |
850 |
sf_readf_int(hFile, (int*) buffer, info.frames); |
uint8_t* dstbuf = new uint8_t[bufsize * 3 * info.channels]; |
851 |
|
sf_count_t cnt = info.frames; |
852 |
|
while (cnt) { |
853 |
|
// libsndfile returns 32 bits, convert to 24 |
854 |
|
int n = sf_readf_int(hFile, srcbuf, bufsize); |
855 |
|
int j = 0; |
856 |
|
for (int i = 0 ; i < n * info.channels ; i++) { |
857 |
|
dstbuf[j++] = srcbuf[i] >> 8; |
858 |
|
dstbuf[j++] = srcbuf[i] >> 16; |
859 |
|
dstbuf[j++] = srcbuf[i] >> 24; |
860 |
|
} |
861 |
|
// write from buffer directly (physically) into .gig file |
862 |
|
iter->gig_sample->Write(dstbuf, n); |
863 |
|
cnt -= n; |
864 |
|
} |
865 |
|
delete[] srcbuf; |
866 |
|
delete[] dstbuf; |
867 |
break; |
break; |
868 |
|
} |
869 |
} |
} |
|
// write from buffer directly (physically) into .gig file |
|
|
(*iter).gig_sample->Write(buffer, info.frames); |
|
870 |
// cleanup |
// cleanup |
871 |
sf_close(hFile); |
sf_close(hFile); |
872 |
delete[] buffer; |
// let the sampler re-cache the sample if needed |
873 |
|
sample_changed_signal.emit(iter->gig_sample); |
874 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
875 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
876 |
std::list<SampleImportItem>::iterator cur = iter; |
std::list<SampleImportItem>::iterator cur = iter; |
878 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
879 |
} catch (std::string what) { |
} catch (std::string what) { |
880 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
881 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
882 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += (*iter).sample_path += " (" + what + ")"; |
883 |
++iter; |
++iter; |
884 |
} |
} |
885 |
} |
} |
886 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
887 |
if (error_files.size()) { |
if (!error_files.empty()) { |
888 |
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; |
889 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
890 |
msg.run(); |
msg.run(); |
891 |
} |
} |
899 |
|
|
900 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
901 |
{ |
{ |
|
#ifdef ABOUT_DIALOG |
|
902 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
903 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2 |
904 |
|
dialog.set_program_name("Gigedit"); |
905 |
|
#else |
906 |
|
dialog.set_name("Gigedit"); |
907 |
|
#endif |
908 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
909 |
|
dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson"); |
910 |
|
dialog.set_comments(_( |
911 |
|
"Released under the GNU General Public License.\n" |
912 |
|
"\n" |
913 |
|
"Please notice that this is still a very young instrument editor. " |
914 |
|
"So better backup your Gigasampler files before editing them with " |
915 |
|
"this application.\n" |
916 |
|
"\n" |
917 |
|
"Please report bugs to: http://bugs.linuxsampler.org") |
918 |
|
); |
919 |
|
dialog.set_website("http://www.linuxsampler.org"); |
920 |
|
dialog.set_website_label("http://www.linuxsampler.org"); |
921 |
dialog.run(); |
dialog.run(); |
|
#endif |
|
922 |
} |
} |
923 |
|
|
924 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
925 |
: table(2,1) |
: eName(_("Name")), |
926 |
|
eCreationDate(_("Creation date")), |
927 |
|
eComments(_("Comments")), |
928 |
|
eProduct(_("Product")), |
929 |
|
eCopyright(_("Copyright")), |
930 |
|
eArtists(_("Artists")), |
931 |
|
eGenre(_("Genre")), |
932 |
|
eKeywords(_("Keywords")), |
933 |
|
eEngineer(_("Engineer")), |
934 |
|
eTechnician(_("Technician")), |
935 |
|
eSoftware(_("Software")), |
936 |
|
eMedium(_("Medium")), |
937 |
|
eSource(_("Source")), |
938 |
|
eSourceForm(_("Source form")), |
939 |
|
eCommissioned(_("Commissioned")), |
940 |
|
eSubject(_("Subject")), |
941 |
|
quitButton(Gtk::Stock::CLOSE), |
942 |
|
table(2, 1) |
943 |
{ |
{ |
944 |
|
set_title(_("File Properties")); |
945 |
|
eName.set_width_chars(50); |
946 |
|
|
947 |
|
connect(eName, &DLS::Info::Name); |
948 |
|
connect(eCreationDate, &DLS::Info::CreationDate); |
949 |
|
connect(eComments, &DLS::Info::Comments); |
950 |
|
connect(eProduct, &DLS::Info::Product); |
951 |
|
connect(eCopyright, &DLS::Info::Copyright); |
952 |
|
connect(eArtists, &DLS::Info::Artists); |
953 |
|
connect(eGenre, &DLS::Info::Genre); |
954 |
|
connect(eKeywords, &DLS::Info::Keywords); |
955 |
|
connect(eEngineer, &DLS::Info::Engineer); |
956 |
|
connect(eTechnician, &DLS::Info::Technician); |
957 |
|
connect(eSoftware, &DLS::Info::Software); |
958 |
|
connect(eMedium, &DLS::Info::Medium); |
959 |
|
connect(eSource, &DLS::Info::Source); |
960 |
|
connect(eSourceForm, &DLS::Info::SourceForm); |
961 |
|
connect(eCommissioned, &DLS::Info::Commissioned); |
962 |
|
connect(eSubject, &DLS::Info::Subject); |
963 |
|
|
964 |
|
table.add(eName); |
965 |
|
table.add(eCreationDate); |
966 |
|
table.add(eComments); |
967 |
|
table.add(eProduct); |
968 |
|
table.add(eCopyright); |
969 |
|
table.add(eArtists); |
970 |
|
table.add(eGenre); |
971 |
|
table.add(eKeywords); |
972 |
|
table.add(eEngineer); |
973 |
|
table.add(eTechnician); |
974 |
|
table.add(eSoftware); |
975 |
|
table.add(eMedium); |
976 |
|
table.add(eSource); |
977 |
|
table.add(eSourceForm); |
978 |
|
table.add(eCommissioned); |
979 |
|
table.add(eSubject); |
980 |
|
|
981 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
982 |
const char* propLabels[] = { |
add(vbox); |
983 |
"Name:", |
table.set_border_width(5); |
984 |
"CreationDate:", |
vbox.add(table); |
985 |
"Comments:", // TODO: multiline |
vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); |
986 |
"Product:", |
buttonBox.set_layout(Gtk::BUTTONBOX_END); |
987 |
"Copyright:", |
buttonBox.set_border_width(5); |
988 |
"Artists:", |
buttonBox.show(); |
989 |
"Genre:", |
buttonBox.pack_start(quitButton); |
990 |
"Keywords:", |
quitButton.set_can_default(); |
991 |
"Engineer:", |
quitButton.grab_focus(); |
992 |
"Technician:", |
quitButton.signal_clicked().connect( |
993 |
"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); |
|
|
} |
|
994 |
|
|
995 |
add(table); |
quitButton.show(); |
996 |
// add_button(Gtk::Stock::CANCEL, 0); |
vbox.show(); |
|
// add_button(Gtk::Stock::OK, 1); |
|
997 |
show_all_children(); |
show_all_children(); |
998 |
} |
} |
999 |
|
|
1000 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1001 |
{ |
{ |
1002 |
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()); |
|
1003 |
} |
} |
1004 |
|
|
1005 |
InstrumentProps::InstrumentProps() |
|
1006 |
: table(2,1), |
void InstrumentProps::set_IsDrum(bool value) |
|
quitButton(Gtk::Stock::CLOSE), |
|
|
eName("Name"), |
|
|
eIsDrum("Is drum"), |
|
|
eMIDIBank("MIDI bank", 0, 16383), |
|
|
eMIDIProgram("MIDI program"), |
|
|
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") |
|
1007 |
{ |
{ |
1008 |
set_title("Instrument properties"); |
m->IsDrum = value; |
1009 |
|
} |
1010 |
|
|
1011 |
|
void InstrumentProps::set_MIDIBank(uint16_t value) |
1012 |
|
{ |
1013 |
|
m->MIDIBank = value; |
1014 |
|
} |
1015 |
|
|
1016 |
|
void InstrumentProps::set_MIDIProgram(uint32_t value) |
1017 |
|
{ |
1018 |
|
m->MIDIProgram = value; |
1019 |
|
} |
1020 |
|
|
1021 |
|
InstrumentProps::InstrumentProps() : |
1022 |
|
quitButton(Gtk::Stock::CLOSE), |
1023 |
|
table(2,1), |
1024 |
|
eName(_("Name")), |
1025 |
|
eIsDrum(_("Is drum")), |
1026 |
|
eMIDIBank(_("MIDI bank"), 0, 16383), |
1027 |
|
eMIDIProgram(_("MIDI program")), |
1028 |
|
eAttenuation(_("Attenuation"), 0, 96, 0, 1), |
1029 |
|
eGainPlus6(_("Gain +6dB"), eAttenuation, -6), |
1030 |
|
eEffectSend(_("Effect send"), 0, 65535), |
1031 |
|
eFineTune(_("Fine tune"), -8400, 8400), |
1032 |
|
ePitchbendRange(_("Pitchbend range"), 0, 12), |
1033 |
|
ePianoReleaseMode(_("Piano release mode")), |
1034 |
|
eDimensionKeyRangeLow(_("Keyswitching range low")), |
1035 |
|
eDimensionKeyRangeHigh(_("Keyswitching range high")) |
1036 |
|
{ |
1037 |
|
set_title(_("Instrument Properties")); |
1038 |
|
|
1039 |
|
eDimensionKeyRangeLow.set_tip( |
1040 |
|
_("start of the keyboard area which should switch the " |
1041 |
|
"\"keyswitching\" dimension") |
1042 |
|
); |
1043 |
|
eDimensionKeyRangeHigh.set_tip( |
1044 |
|
_("end of the keyboard area which should switch the " |
1045 |
|
"\"keyswitching\" dimension") |
1046 |
|
); |
1047 |
|
|
1048 |
|
connect(eIsDrum, &InstrumentProps::set_IsDrum); |
1049 |
|
connect(eMIDIBank, &InstrumentProps::set_MIDIBank); |
1050 |
|
connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); |
1051 |
|
connect(eAttenuation, &gig::Instrument::Attenuation); |
1052 |
|
connect(eGainPlus6, &gig::Instrument::Attenuation); |
1053 |
|
connect(eEffectSend, &gig::Instrument::EffectSend); |
1054 |
|
connect(eFineTune, &gig::Instrument::FineTune); |
1055 |
|
connect(ePitchbendRange, &gig::Instrument::PitchbendRange); |
1056 |
|
connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); |
1057 |
|
connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh, |
1058 |
|
&gig::Instrument::DimensionKeyRange); |
1059 |
|
|
|
rowno = 0; |
|
1060 |
table.set_col_spacings(5); |
table.set_col_spacings(5); |
1061 |
|
|
1062 |
add_prop(eName); |
table.add(eName); |
1063 |
add_prop(eIsDrum); |
table.add(eIsDrum); |
1064 |
add_prop(eMIDIBank); |
table.add(eMIDIBank); |
1065 |
add_prop(eMIDIProgram); |
table.add(eMIDIProgram); |
1066 |
add_prop(eAttenuation); |
table.add(eAttenuation); |
1067 |
add_prop(eGainPlus6); |
table.add(eGainPlus6); |
1068 |
add_prop(eEffectSend); |
table.add(eEffectSend); |
1069 |
add_prop(eFineTune); |
table.add(eFineTune); |
1070 |
add_prop(ePitchbendRange); |
table.add(ePitchbendRange); |
1071 |
add_prop(ePianoReleaseMode); |
table.add(ePianoReleaseMode); |
1072 |
add_prop(eDimensionKeyRangeLow); |
table.add(eDimensionKeyRangeLow); |
1073 |
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)); |
|
1074 |
|
|
1075 |
add(vbox); |
add(vbox); |
1076 |
table.set_border_width(5); |
table.set_border_width(5); |
1081 |
buttonBox.set_border_width(5); |
buttonBox.set_border_width(5); |
1082 |
buttonBox.show(); |
buttonBox.show(); |
1083 |
buttonBox.pack_start(quitButton); |
buttonBox.pack_start(quitButton); |
1084 |
quitButton.set_flags(Gtk::CAN_DEFAULT); |
quitButton.set_can_default(); |
1085 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1086 |
|
|
1087 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1094 |
|
|
1095 |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
void InstrumentProps::set_instrument(gig::Instrument* instrument) |
1096 |
{ |
{ |
1097 |
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); |
|
|
} |
|
1098 |
|
|
1099 |
void InstrumentProps::key_range_high_changed() |
update_model++; |
1100 |
{ |
eIsDrum.set_value(instrument->IsDrum); |
1101 |
double l = eDimensionKeyRangeLow.get_value(); |
eMIDIBank.set_value(instrument->MIDIBank); |
1102 |
double h = eDimensionKeyRangeHigh.get_value(); |
eMIDIProgram.set_value(instrument->MIDIProgram); |
1103 |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
update_model--; |
1104 |
} |
} |
1105 |
|
|
|
sigc::signal<void> InstrumentProps::signal_instrument_changed() |
|
|
{ |
|
|
return instrument_changed; |
|
|
} |
|
1106 |
|
|
1107 |
void MainWindow::file_changed() |
void MainWindow::file_changed() |
1108 |
{ |
{ |
1112 |
} |
} |
1113 |
} |
} |
1114 |
|
|
1115 |
void MainWindow::load_gig(gig::File* gig, const char* filename) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1116 |
{ |
{ |
1117 |
file = 0; |
file = 0; |
1118 |
|
set_file_is_shared(isSharedInstrument); |
1119 |
|
|
1120 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = filename ? filename : _("Unsaved Gig File"); |
1121 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1124 |
|
|
1125 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1126 |
|
|
1127 |
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; |
|
1128 |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; |
1129 |
instrument = gig->GetNextInstrument()) { |
instrument = gig->GetNextInstrument()) { |
1130 |
|
Glib::ustring name(instrument->pInfo->Name); |
1131 |
|
|
1132 |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
Gtk::TreeModel::iterator iter = m_refTreeModel->append(); |
1133 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1134 |
row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
row[m_Columns.m_col_name] = name; |
1135 |
row[m_Columns.m_col_instr] = instrument; |
row[m_Columns.m_col_instr] = instrument; |
1136 |
// create a menu item for this instrument |
|
1137 |
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++; |
|
1138 |
} |
} |
1139 |
instrument_menu->show(); |
instrument_name_connection.unblock(); |
1140 |
instrument_menu->get_submenu()->show_all_children(); |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
1141 |
|
|
1142 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1143 |
if (group->Name != "") { |
if (group->Name != "") { |
1161 |
file = gig; |
file = gig; |
1162 |
|
|
1163 |
// select the first instrument |
// select the first instrument |
1164 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1165 |
tree_sel_ref->select(Gtk::TreePath("0")); |
|
1166 |
|
gig::Instrument* instrument = get_instrument(); |
1167 |
|
if (instrument) { |
1168 |
|
instrumentProps.set_instrument(instrument); |
1169 |
|
} |
1170 |
} |
} |
1171 |
|
|
1172 |
void MainWindow::show_instr_props() |
void MainWindow::show_instr_props() |
1173 |
{ |
{ |
1174 |
Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection(); |
gig::Instrument* instrument = get_instrument(); |
1175 |
Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); |
if (instrument) |
|
if (it) |
|
1176 |
{ |
{ |
1177 |
Gtk::TreeModel::Row row = *it; |
instrumentProps.set_instrument(instrument); |
1178 |
if (row[m_Columns.m_col_instr]) |
instrumentProps.show(); |
1179 |
{ |
instrumentProps.deiconify(); |
1180 |
instrumentProps.set_instrument(row[m_Columns.m_col_instr]); |
} |
1181 |
instrumentProps.show(); |
} |
1182 |
instrumentProps.deiconify(); |
|
1183 |
} |
void MainWindow::on_action_view_status_bar() { |
1184 |
|
Gtk::CheckMenuItem* item = |
1185 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1186 |
|
if (!item) { |
1187 |
|
std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n"; |
1188 |
|
return; |
1189 |
} |
} |
1190 |
|
if (item->get_active()) m_StatusBar.show(); |
1191 |
|
else m_StatusBar.hide(); |
1192 |
} |
} |
1193 |
|
|
1194 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
1200 |
} |
} |
1201 |
} |
} |
1202 |
|
|
1203 |
void MainWindow::on_instrument_selection_change(int index) { |
void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { |
1204 |
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
if (item->get_active()) { |
1205 |
|
const std::vector<Gtk::Widget*> children = |
1206 |
|
instrument_menu->get_children(); |
1207 |
|
std::vector<Gtk::Widget*>::const_iterator it = |
1208 |
|
find(children.begin(), children.end(), item); |
1209 |
|
if (it != children.end()) { |
1210 |
|
int index = it - children.begin(); |
1211 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index))); |
1212 |
|
|
1213 |
|
m_RegionChooser.set_instrument(file->GetInstrument(index)); |
1214 |
|
} |
1215 |
|
} |
1216 |
} |
} |
1217 |
|
|
1218 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1242 |
} |
} |
1243 |
} |
} |
1244 |
|
|
1245 |
|
|
1246 |
|
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1247 |
|
const Glib::ustring& name, int position) { |
1248 |
|
|
1249 |
|
Gtk::RadioMenuItem::Group instrument_group; |
1250 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1251 |
|
if (!children.empty()) { |
1252 |
|
instrument_group = |
1253 |
|
static_cast<Gtk::RadioMenuItem*>(children[0])->get_group(); |
1254 |
|
} |
1255 |
|
Gtk::RadioMenuItem* item = |
1256 |
|
new Gtk::RadioMenuItem(instrument_group, name); |
1257 |
|
if (position < 0) { |
1258 |
|
instrument_menu->append(*item); |
1259 |
|
} else { |
1260 |
|
instrument_menu->insert(*item, position); |
1261 |
|
} |
1262 |
|
item->show(); |
1263 |
|
item->signal_activate().connect( |
1264 |
|
sigc::bind( |
1265 |
|
sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change), |
1266 |
|
item)); |
1267 |
|
return item; |
1268 |
|
} |
1269 |
|
|
1270 |
|
void MainWindow::remove_instrument_from_menu(int index) { |
1271 |
|
const std::vector<Gtk::Widget*> children = |
1272 |
|
instrument_menu->get_children(); |
1273 |
|
Gtk::Widget* child = children[index]; |
1274 |
|
instrument_menu->remove(*child); |
1275 |
|
delete child; |
1276 |
|
} |
1277 |
|
|
1278 |
|
void MainWindow::add_instrument(gig::Instrument* instrument) { |
1279 |
|
const char* name = instrument->pInfo->Name.c_str(); |
1280 |
|
|
1281 |
|
// update instrument tree view |
1282 |
|
instrument_name_connection.block(); |
1283 |
|
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
1284 |
|
Gtk::TreeModel::Row rowInstr = *iterInstr; |
1285 |
|
rowInstr[m_Columns.m_col_name] = name; |
1286 |
|
rowInstr[m_Columns.m_col_instr] = instrument; |
1287 |
|
instrument_name_connection.unblock(); |
1288 |
|
|
1289 |
|
add_instrument_to_menu(name); |
1290 |
|
|
1291 |
|
m_TreeView.get_selection()->select(iterInstr); |
1292 |
|
|
1293 |
|
file_changed(); |
1294 |
|
} |
1295 |
|
|
1296 |
void MainWindow::on_action_add_instrument() { |
void MainWindow::on_action_add_instrument() { |
1297 |
static int __instrument_indexer = 0; |
static int __instrument_indexer = 0; |
1298 |
if (!file) return; |
if (!file) return; |
1299 |
gig::Instrument* instrument = file->AddInstrument(); |
gig::Instrument* instrument = file->AddInstrument(); |
1300 |
__instrument_indexer++; |
__instrument_indexer++; |
1301 |
instrument->pInfo->Name = |
instrument->pInfo->Name = |
1302 |
"Unnamed Instrument " + ToString(__instrument_indexer); |
_("Unnamed Instrument ") + ToString(__instrument_indexer); |
1303 |
// update instrument tree view |
|
1304 |
Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); |
add_instrument(instrument); |
1305 |
Gtk::TreeModel::Row rowInstr = *iterInstr; |
} |
1306 |
rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str(); |
|
1307 |
rowInstr[m_Columns.m_col_instr] = instrument; |
void MainWindow::on_action_duplicate_instrument() { |
1308 |
file_changed(); |
if (!file) return; |
1309 |
|
|
1310 |
|
// retrieve the currently selected instrument |
1311 |
|
// (being the original instrument to be duplicated) |
1312 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1313 |
|
Gtk::TreeModel::iterator itSelection = sel->get_selected(); |
1314 |
|
if (!itSelection) return; |
1315 |
|
Gtk::TreeModel::Row row = *itSelection; |
1316 |
|
gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; |
1317 |
|
if (!instrOrig) return; |
1318 |
|
|
1319 |
|
// duplicate the orginal instrument |
1320 |
|
gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); |
1321 |
|
instrNew->pInfo->Name = |
1322 |
|
instrOrig->pInfo->Name + " (" + _("Copy") + ")"; |
1323 |
|
|
1324 |
|
add_instrument(instrNew); |
1325 |
} |
} |
1326 |
|
|
1327 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
1328 |
if (!file) return; |
if (!file) return; |
1329 |
|
if (file_is_shared) { |
1330 |
|
Gtk::MessageDialog msg( |
1331 |
|
*this, |
1332 |
|
_("You cannot delete an instrument from this file, since it's " |
1333 |
|
"currently used by the sampler."), |
1334 |
|
false, Gtk::MESSAGE_INFO |
1335 |
|
); |
1336 |
|
msg.run(); |
1337 |
|
return; |
1338 |
|
} |
1339 |
|
|
1340 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1341 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1342 |
if (it) { |
if (it) { |
1343 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
1344 |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
gig::Instrument* instr = row[m_Columns.m_col_instr]; |
1345 |
try { |
try { |
1346 |
|
Gtk::TreePath path(it); |
1347 |
|
int index = path[0]; |
1348 |
|
|
1349 |
// remove instrument from the gig file |
// remove instrument from the gig file |
1350 |
if (instr) file->DeleteInstrument(instr); |
if (instr) file->DeleteInstrument(instr); |
|
// remove respective row from instruments tree view |
|
|
m_refTreeModel->erase(it); |
|
1351 |
file_changed(); |
file_changed(); |
1352 |
|
|
1353 |
|
remove_instrument_from_menu(index); |
1354 |
|
|
1355 |
|
// remove row from instruments tree view |
1356 |
|
m_refTreeModel->erase(it); |
1357 |
|
|
1358 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1359 |
|
// select another instrument (in gtk3 this is done |
1360 |
|
// automatically) |
1361 |
|
if (!m_refTreeModel->children().empty()) { |
1362 |
|
if (index == m_refTreeModel->children().size()) { |
1363 |
|
index--; |
1364 |
|
} |
1365 |
|
m_TreeView.get_selection()->select( |
1366 |
|
Gtk::TreePath(ToString(index))); |
1367 |
|
} |
1368 |
|
#endif |
1369 |
|
instr = get_instrument(); |
1370 |
|
if (instr) { |
1371 |
|
instrumentProps.set_instrument(instr); |
1372 |
|
} else { |
1373 |
|
instrumentProps.hide(); |
1374 |
|
} |
1375 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1376 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1377 |
msg.run(); |
msg.run(); |
1382 |
void MainWindow::on_action_sample_properties() { |
void MainWindow::on_action_sample_properties() { |
1383 |
//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 |
1384 |
Gtk::MessageDialog msg( |
Gtk::MessageDialog msg( |
1385 |
*this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO |
*this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO |
1386 |
); |
); |
1387 |
msg.run(); |
msg.run(); |
1388 |
} |
} |
1391 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
1392 |
if (!file) return; |
if (!file) return; |
1393 |
gig::Group* group = file->AddGroup(); |
gig::Group* group = file->AddGroup(); |
1394 |
group->Name = "Unnamed Group"; |
group->Name = _("Unnamed Group"); |
1395 |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
if (__sample_indexer) group->Name += " " + ToString(__sample_indexer); |
1396 |
__sample_indexer++; |
__sample_indexer++; |
1397 |
// update sample tree view |
// update sample tree view |
1425 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1426 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
1427 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(true); |
1428 |
Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile |
|
1429 |
|
// matches all file types supported by libsndfile |
1430 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1431 |
|
Gtk::FileFilter soundfilter; |
1432 |
|
#else |
1433 |
|
Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create(); |
1434 |
|
#endif |
1435 |
const char* const supportedFileTypes[] = { |
const char* const supportedFileTypes[] = { |
1436 |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
"*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd", |
1437 |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
"*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF", |
1439 |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
"*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK", |
1440 |
"*.caf", "*.CAF", NULL |
"*.caf", "*.CAF", NULL |
1441 |
}; |
}; |
1442 |
|
const char* soundfiles = _("Sound Files"); |
1443 |
|
const char* allfiles = _("All Files"); |
1444 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1445 |
for (int i = 0; supportedFileTypes[i]; i++) |
for (int i = 0; supportedFileTypes[i]; i++) |
1446 |
soundfilter.add_pattern(supportedFileTypes[i]); |
soundfilter.add_pattern(supportedFileTypes[i]); |
1447 |
soundfilter.set_name("Sound Files"); |
soundfilter.set_name(soundfiles); |
1448 |
Gtk::FileFilter allpassfilter; // matches every file |
|
1449 |
|
// matches every file |
1450 |
|
Gtk::FileFilter allpassfilter; |
1451 |
allpassfilter.add_pattern("*.*"); |
allpassfilter.add_pattern("*.*"); |
1452 |
allpassfilter.set_name("All Files"); |
allpassfilter.set_name(allfiles); |
1453 |
|
#else |
1454 |
|
for (int i = 0; supportedFileTypes[i]; i++) |
1455 |
|
soundfilter->add_pattern(supportedFileTypes[i]); |
1456 |
|
soundfilter->set_name(soundfiles); |
1457 |
|
|
1458 |
|
// matches every file |
1459 |
|
Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create(); |
1460 |
|
allpassfilter->add_pattern("*.*"); |
1461 |
|
allpassfilter->set_name(allfiles); |
1462 |
|
#endif |
1463 |
dialog.add_filter(soundfilter); |
dialog.add_filter(soundfilter); |
1464 |
dialog.add_filter(allpassfilter); |
dialog.add_filter(allpassfilter); |
1465 |
|
if (current_sample_dir != "") { |
1466 |
|
dialog.set_current_folder(current_sample_dir); |
1467 |
|
} |
1468 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1469 |
|
current_sample_dir = dialog.get_current_folder(); |
1470 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1471 |
Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
1472 |
for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin(); |
for (std::vector<std::string>::iterator iter = filenames.begin(); |
1473 |
iter != filenames.end(); ++iter) { |
iter != filenames.end(); ++iter) { |
1474 |
printf("Adding sample %s\n",(*iter).c_str()); |
printf("Adding sample %s\n",(*iter).c_str()); |
1475 |
// use libsndfile to retrieve file informations |
// use libsndfile to retrieve file informations |
1477 |
info.format = 0; |
info.format = 0; |
1478 |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); |
1479 |
try { |
try { |
1480 |
if (!hFile) throw std::string("could not open file"); |
if (!hFile) throw std::string(_("could not open file")); |
1481 |
int bitdepth; |
int bitdepth; |
1482 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
1483 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
1484 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
1485 |
|
case SF_FORMAT_PCM_U8: |
1486 |
bitdepth = 16; |
bitdepth = 16; |
1487 |
break; |
break; |
1488 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
|
bitdepth = 32; // we simply convert to 32 bit for now |
|
|
break; |
|
1489 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
|
bitdepth = 32; |
|
|
break; |
|
|
case SF_FORMAT_PCM_U8: |
|
|
bitdepth = 16; // we simply convert to 16 bit for now |
|
|
break; |
|
1490 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
|
bitdepth = 32; |
|
|
break; |
|
1491 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
1492 |
bitdepth = 32; // I guess we will always truncate this to 32 bit |
bitdepth = 24; |
1493 |
break; |
break; |
1494 |
default: |
default: |
1495 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
1496 |
throw std::string("format not supported"); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1497 |
} |
} |
1498 |
// add a new sample to the .gig file |
// add a new sample to the .gig file |
1499 |
gig::Sample* sample = file->AddSample(); |
gig::Sample* sample = file->AddSample(); |
1511 |
sample->BitDepth = bitdepth; |
sample->BitDepth = bitdepth; |
1512 |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels; |
1513 |
sample->SamplesPerSecond = info.samplerate; |
sample->SamplesPerSecond = info.samplerate; |
1514 |
|
sample->AverageBytesPerSecond = sample->FrameSize * sample->SamplesPerSecond; |
1515 |
|
sample->BlockAlign = sample->FrameSize; |
1516 |
|
sample->SamplesTotal = info.frames; |
1517 |
|
|
1518 |
|
SF_INSTRUMENT instrument; |
1519 |
|
if (sf_command(hFile, SFC_GET_INSTRUMENT, |
1520 |
|
&instrument, sizeof(instrument)) != SF_FALSE) |
1521 |
|
{ |
1522 |
|
sample->MIDIUnityNote = instrument.basenote; |
1523 |
|
|
1524 |
|
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
1525 |
|
sample->Loops = 1; |
1526 |
|
|
1527 |
|
switch (instrument.loops[0].mode) { |
1528 |
|
case SF_LOOP_FORWARD: |
1529 |
|
sample->LoopType = gig::loop_type_normal; |
1530 |
|
break; |
1531 |
|
case SF_LOOP_BACKWARD: |
1532 |
|
sample->LoopType = gig::loop_type_backward; |
1533 |
|
break; |
1534 |
|
case SF_LOOP_ALTERNATING: |
1535 |
|
sample->LoopType = gig::loop_type_bidirectional; |
1536 |
|
break; |
1537 |
|
} |
1538 |
|
sample->LoopStart = instrument.loops[0].start; |
1539 |
|
sample->LoopEnd = instrument.loops[0].end; |
1540 |
|
sample->LoopPlayCount = instrument.loops[0].count; |
1541 |
|
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
1542 |
|
} |
1543 |
|
} |
1544 |
|
|
1545 |
// schedule resizing the sample (which will be done |
// schedule resizing the sample (which will be done |
1546 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
1547 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
1564 |
sf_close(hFile); |
sf_close(hFile); |
1565 |
file_changed(); |
file_changed(); |
1566 |
} 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) |
1567 |
if (error_files.size()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1568 |
error_files += *iter += " (" + what + ")"; |
error_files += *iter += " (" + what + ")"; |
1569 |
} |
} |
1570 |
} |
} |
1571 |
// 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 |
1572 |
if (error_files.size()) { |
if (!error_files.empty()) { |
1573 |
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; |
1574 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1575 |
|
msg.run(); |
1576 |
|
} |
1577 |
|
} |
1578 |
|
} |
1579 |
|
|
1580 |
|
void MainWindow::on_action_replace_all_samples_in_all_groups() |
1581 |
|
{ |
1582 |
|
if (!file) return; |
1583 |
|
Gtk::FileChooserDialog dialog(*this, _("Select Folder"), |
1584 |
|
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
1585 |
|
const char* str = |
1586 |
|
_("This is a very specific function. It tries to replace all samples " |
1587 |
|
"in the current gig file by samples located in the chosen " |
1588 |
|
"directory.\n\n" |
1589 |
|
"It works like this: For each sample in the gig file, it tries to " |
1590 |
|
"find a sample file in the selected directory with the same name as " |
1591 |
|
"the sample in the gig file. Optionally, you can add a filename " |
1592 |
|
"extension below, which will be added to the filename expected to be " |
1593 |
|
"found. That is, assume you have a gig file with a sample called " |
1594 |
|
"'Snare', if you enter '.wav' below (like it's done by default), it " |
1595 |
|
"expects to find a sample file called 'Snare.wav' and will replace " |
1596 |
|
"the sample in the gig file accordingly. If you don't need an " |
1597 |
|
"extension, blank the field below. Any gig sample where no " |
1598 |
|
"appropriate sample file could be found will be reported and left " |
1599 |
|
"untouched.\n"); |
1600 |
|
#if GTKMM_MAJOR_VERSION < 3 |
1601 |
|
view::WrapLabel description(str); |
1602 |
|
#else |
1603 |
|
Gtk::Label description(str); |
1604 |
|
description.set_line_wrap(); |
1605 |
|
#endif |
1606 |
|
Gtk::HBox entryArea; |
1607 |
|
Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); |
1608 |
|
Gtk::Entry postfixEntryBox; |
1609 |
|
postfixEntryBox.set_text(".wav"); |
1610 |
|
entryArea.pack_start(entryLabel); |
1611 |
|
entryArea.pack_start(postfixEntryBox); |
1612 |
|
dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); |
1613 |
|
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
1614 |
|
description.show(); |
1615 |
|
entryArea.show_all(); |
1616 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
1617 |
|
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
1618 |
|
dialog.set_select_multiple(false); |
1619 |
|
if (current_sample_dir != "") { |
1620 |
|
dialog.set_current_folder(current_sample_dir); |
1621 |
|
} |
1622 |
|
if (dialog.run() == Gtk::RESPONSE_OK) |
1623 |
|
{ |
1624 |
|
current_sample_dir = dialog.get_current_folder(); |
1625 |
|
Glib::ustring error_files; |
1626 |
|
std::string folder = dialog.get_filename(); |
1627 |
|
for (gig::Sample* sample = file->GetFirstSample(); |
1628 |
|
sample; sample = file->GetNextSample()) |
1629 |
|
{ |
1630 |
|
std::string filename = |
1631 |
|
folder + G_DIR_SEPARATOR_S + sample->pInfo->Name + |
1632 |
|
postfixEntryBox.get_text().raw(); |
1633 |
|
SF_INFO info; |
1634 |
|
info.format = 0; |
1635 |
|
SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info); |
1636 |
|
try |
1637 |
|
{ |
1638 |
|
if (!hFile) throw std::string(_("could not open file")); |
1639 |
|
int bitdepth; |
1640 |
|
switch (info.format & 0xff) { |
1641 |
|
case SF_FORMAT_PCM_S8: |
1642 |
|
case SF_FORMAT_PCM_16: |
1643 |
|
case SF_FORMAT_PCM_U8: |
1644 |
|
bitdepth = 16; |
1645 |
|
break; |
1646 |
|
case SF_FORMAT_PCM_24: |
1647 |
|
case SF_FORMAT_PCM_32: |
1648 |
|
case SF_FORMAT_FLOAT: |
1649 |
|
case SF_FORMAT_DOUBLE: |
1650 |
|
bitdepth = 24; |
1651 |
|
break; |
1652 |
|
default: |
1653 |
|
sf_close(hFile); |
1654 |
|
throw std::string(_("format not supported")); |
1655 |
|
} |
1656 |
|
SampleImportItem sched_item; |
1657 |
|
sched_item.gig_sample = sample; |
1658 |
|
sched_item.sample_path = filename; |
1659 |
|
m_SampleImportQueue.push_back(sched_item); |
1660 |
|
sf_close(hFile); |
1661 |
|
file_changed(); |
1662 |
|
} |
1663 |
|
catch (std::string what) |
1664 |
|
{ |
1665 |
|
if (!error_files.empty()) error_files += "\n"; |
1666 |
|
error_files += filename += " (" + what + ")"; |
1667 |
|
} |
1668 |
|
} |
1669 |
|
// show error message box when some file(s) could not be opened / added |
1670 |
|
if (!error_files.empty()) { |
1671 |
|
Glib::ustring txt = |
1672 |
|
_("Could not replace the following sample(s):\n") + error_files; |
1673 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1674 |
msg.run(); |
msg.run(); |
1675 |
} |
} |
1695 |
pSample; pSample = group->GetNextSample()) { |
pSample; pSample = group->GetNextSample()) { |
1696 |
members.push_back(pSample); |
members.push_back(pSample); |
1697 |
} |
} |
1698 |
|
// notify everybody that we're going to remove these samples |
1699 |
|
samples_to_be_removed_signal.emit(members); |
1700 |
// delete the group in the .gig file including the |
// delete the group in the .gig file including the |
1701 |
// samples that belong to the group |
// samples that belong to the group |
1702 |
file->DeleteGroup(group); |
file->DeleteGroup(group); |
1703 |
|
// notify that we're done with removal |
1704 |
|
samples_removed_signal.emit(); |
1705 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
1706 |
// them from the import queue |
// them from the import queue |
1707 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
1718 |
} |
} |
1719 |
file_changed(); |
file_changed(); |
1720 |
} else if (sample) { |
} else if (sample) { |
1721 |
|
// notify everybody that we're going to remove this sample |
1722 |
|
std::list<gig::Sample*> lsamples; |
1723 |
|
lsamples.push_back(sample); |
1724 |
|
samples_to_be_removed_signal.emit(lsamples); |
1725 |
// remove sample from the .gig file |
// remove sample from the .gig file |
1726 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
1727 |
|
// notify that we're done with removal |
1728 |
|
samples_removed_signal.emit(); |
1729 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
1730 |
// the import queue |
// the import queue |
1731 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1737 |
break; |
break; |
1738 |
} |
} |
1739 |
} |
} |
1740 |
|
dimreg_changed(); |
1741 |
file_changed(); |
file_changed(); |
1742 |
} |
} |
1743 |
// remove respective row(s) from samples tree view |
// remove respective row(s) from samples tree view |
1744 |
m_refSamplesTreeModel->erase(it); |
m_refSamplesTreeModel->erase(it); |
1745 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1746 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
1747 |
|
samples_removed_signal.emit(); |
1748 |
|
// show error message |
1749 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1750 |
msg.run(); |
msg.run(); |
1751 |
} |
} |
1752 |
} |
} |
1753 |
} |
} |
1754 |
|
|
1755 |
|
// For some reason drag_data_get gets called two times for each |
1756 |
|
// drag'n'drop (at least when target is an Entry). This work-around |
1757 |
|
// makes sure the code in drag_data_get and drop_drag_data_received is |
1758 |
|
// only executed once, as drag_begin only gets called once. |
1759 |
|
void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
1760 |
|
{ |
1761 |
|
first_call_to_drag_data_get = true; |
1762 |
|
} |
1763 |
|
|
1764 |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
1765 |
Gtk::SelectionData& selection_data, guint, guint) |
Gtk::SelectionData& selection_data, guint, guint) |
1766 |
{ |
{ |
1767 |
|
if (!first_call_to_drag_data_get) return; |
1768 |
|
first_call_to_drag_data_get = false; |
1769 |
|
|
1770 |
// get selected sample |
// get selected sample |
1771 |
gig::Sample* sample = NULL; |
gig::Sample* sample = NULL; |
1772 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1784 |
const Glib::RefPtr<Gdk::DragContext>& context, int, int, |
const Glib::RefPtr<Gdk::DragContext>& context, int, int, |
1785 |
const Gtk::SelectionData& selection_data, guint, guint time) |
const Gtk::SelectionData& selection_data, guint, guint time) |
1786 |
{ |
{ |
|
gig::DimensionRegion* dimregion = m_DimRegionChooser.get_dimregion(); |
|
1787 |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
1788 |
|
|
1789 |
if (sample && dimregion && selection_data.get_length() == sizeof(gig::Sample*)) { |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
1790 |
if (sample != dimregion->pSample) { |
std::cout << "Drop received sample \"" << |
1791 |
dimregion->pSample = sample; |
sample->pInfo->Name << "\"" << std::endl; |
1792 |
dimreg_edit.wSample->set_text(dimregion->pSample->pInfo->Name.c_str()); |
// drop success |
1793 |
std::cout << "Drop received sample \"" << |
context->drop_reply(true, time); |
1794 |
dimregion->pSample->pInfo->Name.c_str() << "\"" << std::endl; |
|
1795 |
// drop success |
//TODO: we should better move most of the following code to DimRegionEdit::set_sample() |
1796 |
context->drop_reply(true, time); |
|
1797 |
file_changed(); |
// notify everybody that we're going to alter the region |
1798 |
return; |
gig::Region* region = m_RegionChooser.get_region(); |
1799 |
|
region_to_be_changed_signal.emit(region); |
1800 |
|
|
1801 |
|
// find the samplechannel dimension |
1802 |
|
gig::dimension_def_t* stereo_dimension = 0; |
1803 |
|
for (int i = 0 ; i < region->Dimensions ; i++) { |
1804 |
|
if (region->pDimensionDefinitions[i].dimension == |
1805 |
|
gig::dimension_samplechannel) { |
1806 |
|
stereo_dimension = ®ion->pDimensionDefinitions[i]; |
1807 |
|
break; |
1808 |
|
} |
1809 |
|
} |
1810 |
|
bool channels_changed = false; |
1811 |
|
if (sample->Channels == 1 && stereo_dimension) { |
1812 |
|
// remove the samplechannel dimension |
1813 |
|
region->DeleteDimension(stereo_dimension); |
1814 |
|
channels_changed = true; |
1815 |
|
region_changed(); |
1816 |
|
} |
1817 |
|
dimreg_edit.set_sample(sample); |
1818 |
|
|
1819 |
|
if (sample->Channels == 2 && !stereo_dimension) { |
1820 |
|
// add samplechannel dimension |
1821 |
|
gig::dimension_def_t dim; |
1822 |
|
dim.dimension = gig::dimension_samplechannel; |
1823 |
|
dim.bits = 1; |
1824 |
|
dim.zones = 2; |
1825 |
|
region->AddDimension(&dim); |
1826 |
|
channels_changed = true; |
1827 |
|
region_changed(); |
1828 |
} |
} |
1829 |
|
if (channels_changed) { |
1830 |
|
// unmap all samples with wrong number of channels |
1831 |
|
// TODO: maybe there should be a warning dialog for this |
1832 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
1833 |
|
gig::DimensionRegion* d = region->pDimensionRegions[i]; |
1834 |
|
if (d->pSample && d->pSample->Channels != sample->Channels) { |
1835 |
|
gig::Sample* oldref = d->pSample; |
1836 |
|
d->pSample = NULL; |
1837 |
|
sample_ref_changed_signal.emit(oldref, NULL); |
1838 |
|
} |
1839 |
|
} |
1840 |
|
} |
1841 |
|
|
1842 |
|
// notify we're done with altering |
1843 |
|
region_changed_signal.emit(region); |
1844 |
|
|
1845 |
|
file_changed(); |
1846 |
|
|
1847 |
|
return; |
1848 |
} |
} |
1849 |
// drop failed |
// drop failed |
1850 |
context->drop_reply(false, time); |
context->drop_reply(false, time); |
1877 |
if (!iter) return; |
if (!iter) return; |
1878 |
Gtk::TreeModel::Row row = *iter; |
Gtk::TreeModel::Row row = *iter; |
1879 |
Glib::ustring name = row[m_Columns.m_col_name]; |
Glib::ustring name = row[m_Columns.m_col_name]; |
1880 |
|
|
1881 |
|
// change name in instrument menu |
1882 |
|
int index = path[0]; |
1883 |
|
const std::vector<Gtk::Widget*> children = instrument_menu->get_children(); |
1884 |
|
if (index < children.size()) { |
1885 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2 |
1886 |
|
static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name); |
1887 |
|
#else |
1888 |
|
remove_instrument_from_menu(index); |
1889 |
|
Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index); |
1890 |
|
item->set_active(); |
1891 |
|
#endif |
1892 |
|
} |
1893 |
|
|
1894 |
|
// change name in gig |
1895 |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1896 |
if (instrument && instrument->pInfo->Name != name.raw()) { |
if (instrument && instrument->pInfo->Name != name.raw()) { |
1897 |
instrument->pInfo->Name = name.raw(); |
instrument->pInfo->Name = name.raw(); |
1898 |
file_changed(); |
file_changed(); |
1899 |
} |
} |
1900 |
} |
} |
1901 |
|
|
1902 |
|
void MainWindow::set_file_is_shared(bool b) { |
1903 |
|
this->file_is_shared = b; |
1904 |
|
|
1905 |
|
if (file_is_shared) { |
1906 |
|
m_AttachedStateLabel.set_label(_("live-mode")); |
1907 |
|
m_AttachedStateImage.set( |
1908 |
|
Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm) |
1909 |
|
); |
1910 |
|
} else { |
1911 |
|
m_AttachedStateLabel.set_label(_("stand-alone")); |
1912 |
|
m_AttachedStateImage.set( |
1913 |
|
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
1914 |
|
); |
1915 |
|
} |
1916 |
|
} |
1917 |
|
|
1918 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
1919 |
|
return file_structure_to_be_changed_signal; |
1920 |
|
} |
1921 |
|
|
1922 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() { |
1923 |
|
return file_structure_changed_signal; |
1924 |
|
} |
1925 |
|
|
1926 |
|
sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() { |
1927 |
|
return samples_to_be_removed_signal; |
1928 |
|
} |
1929 |
|
|
1930 |
|
sigc::signal<void>& MainWindow::signal_samples_removed() { |
1931 |
|
return samples_removed_signal; |
1932 |
|
} |
1933 |
|
|
1934 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() { |
1935 |
|
return region_to_be_changed_signal; |
1936 |
|
} |
1937 |
|
|
1938 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() { |
1939 |
|
return region_changed_signal; |
1940 |
|
} |
1941 |
|
|
1942 |
|
sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() { |
1943 |
|
return sample_changed_signal; |
1944 |
|
} |
1945 |
|
|
1946 |
|
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
1947 |
|
return sample_ref_changed_signal; |
1948 |
|
} |
1949 |
|
|
1950 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() { |
1951 |
|
return dimreg_to_be_changed_signal; |
1952 |
|
} |
1953 |
|
|
1954 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
1955 |
|
return dimreg_changed_signal; |
1956 |
|
} |
1957 |
|
|
1958 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() { |
1959 |
|
return note_on_signal; |
1960 |
|
} |
1961 |
|
|
1962 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() { |
1963 |
|
return note_off_signal; |
1964 |
|
} |
1965 |
|
|
1966 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() { |
1967 |
|
return m_RegionChooser.signal_keyboard_key_hit(); |
1968 |
|
} |
1969 |
|
|
1970 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
1971 |
|
return m_RegionChooser.signal_keyboard_key_released(); |
1972 |
|
} |