1 |
/* |
/* |
2 |
* Copyright (C) 2006-2014 Andreas Persson |
* Copyright (C) 2006-2016 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 |
20 |
#include <iostream> |
#include <iostream> |
21 |
#include <cstring> |
#include <cstring> |
22 |
|
|
23 |
|
#include <glibmmconfig.h> |
24 |
|
// threads.h must be included first to be able to build with |
25 |
|
// G_DISABLE_DEPRECATED |
26 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
27 |
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
28 |
|
#include <glibmm/threads.h> |
29 |
|
#endif |
30 |
|
|
31 |
#include <glibmm/convert.h> |
#include <glibmm/convert.h> |
32 |
#include <glibmm/dispatcher.h> |
#include <glibmm/dispatcher.h> |
33 |
#include <glibmm/miscutils.h> |
#include <glibmm/miscutils.h> |
35 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
36 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
37 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
|
#include <gtkmm/stock.h> |
|
38 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
39 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
40 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
117 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
118 |
|
|
119 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
120 |
actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), |
actionGroup->add(Gtk::Action::create("New", _("_New")), |
121 |
|
Gtk::AccelKey("<control>n"), |
122 |
sigc::mem_fun( |
sigc::mem_fun( |
123 |
*this, &MainWindow::on_action_file_new)); |
*this, &MainWindow::on_action_file_new)); |
124 |
Glib::RefPtr<Gtk::Action> action = |
actionGroup->add(Gtk::Action::create("Open", _("_Open...")), |
125 |
Gtk::Action::create("Open", Gtk::Stock::OPEN); |
Gtk::AccelKey("<control>o"), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
126 |
sigc::mem_fun( |
sigc::mem_fun( |
127 |
*this, &MainWindow::on_action_file_open)); |
*this, &MainWindow::on_action_file_open)); |
128 |
actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), |
actionGroup->add(Gtk::Action::create("Save", _("_Save")), |
129 |
|
Gtk::AccelKey("<control>s"), |
130 |
sigc::mem_fun( |
sigc::mem_fun( |
131 |
*this, &MainWindow::on_action_file_save)); |
*this, &MainWindow::on_action_file_save)); |
132 |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
133 |
Gtk::AccelKey("<shift><control>s"), |
Gtk::AccelKey("<shift><control>s"), |
134 |
sigc::mem_fun( |
sigc::mem_fun( |
135 |
*this, &MainWindow::on_action_file_save_as)); |
*this, &MainWindow::on_action_file_save_as)); |
136 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
137 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
138 |
sigc::mem_fun( |
sigc::mem_fun( |
139 |
*this, &MainWindow::on_action_file_properties)); |
*this, &MainWindow::on_action_file_properties)); |
140 |
actionGroup->add(Gtk::Action::create("InstrProperties", |
actionGroup->add(Gtk::Action::create("InstrProperties", |
141 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
142 |
sigc::mem_fun( |
sigc::mem_fun( |
143 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
144 |
actionGroup->add(Gtk::Action::create("MidiRules", |
actionGroup->add(Gtk::Action::create("MidiRules", |
149 |
_("_Script Slots...")), |
_("_Script Slots...")), |
150 |
sigc::mem_fun( |
sigc::mem_fun( |
151 |
*this, &MainWindow::show_script_slots)); |
*this, &MainWindow::show_script_slots)); |
152 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", _("_Quit")), |
153 |
|
Gtk::AccelKey("<control>q"), |
154 |
sigc::mem_fun( |
sigc::mem_fun( |
155 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
156 |
actionGroup->add( |
actionGroup->add( |
193 |
sigc::mem_fun( |
sigc::mem_fun( |
194 |
*this, &MainWindow::on_action_view_status_bar)); |
*this, &MainWindow::on_action_view_status_bar)); |
195 |
|
|
196 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
toggle_action = |
197 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension")); |
198 |
action->property_label())); |
toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension); |
199 |
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
actionGroup->add(toggle_action, |
200 |
|
sigc::mem_fun( |
201 |
|
*this, &MainWindow::on_auto_restore_win_dim)); |
202 |
|
|
203 |
|
toggle_action = |
204 |
|
Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file")); |
205 |
|
toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile); |
206 |
|
actionGroup->add(toggle_action, |
207 |
|
sigc::mem_fun( |
208 |
|
*this, &MainWindow::on_save_with_temporary_file)); |
209 |
|
|
210 |
|
actionGroup->add( |
211 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
212 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
213 |
|
); |
214 |
|
|
215 |
|
actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help"))); |
216 |
|
actionGroup->add(Gtk::Action::create("About", _("_About")), |
217 |
sigc::mem_fun( |
sigc::mem_fun( |
218 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
219 |
actionGroup->add( |
actionGroup->add( |
225 |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
226 |
); |
); |
227 |
actionGroup->add( |
actionGroup->add( |
228 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveInstrument", _("_Remove")), |
229 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
230 |
); |
); |
231 |
|
|
240 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
241 |
); |
); |
242 |
|
|
243 |
|
toggle_action = |
244 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
245 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
246 |
|
actionGroup->add( |
247 |
|
toggle_action, |
248 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
249 |
|
); |
250 |
|
|
251 |
|
toggle_action = |
252 |
|
Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); |
253 |
|
toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); |
254 |
|
actionGroup->add( |
255 |
|
toggle_action, |
256 |
|
sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) |
257 |
|
); |
258 |
|
|
259 |
|
|
260 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
261 |
|
|
272 |
|
|
273 |
// sample right-click popup actions |
// sample right-click popup actions |
274 |
actionGroup->add( |
actionGroup->add( |
275 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", _("_Properties")), |
276 |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
277 |
); |
); |
278 |
actionGroup->add( |
actionGroup->add( |
284 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
285 |
); |
); |
286 |
actionGroup->add( |
actionGroup->add( |
287 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveSample", _("_Remove")), |
288 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
289 |
); |
); |
290 |
actionGroup->add( |
actionGroup->add( |
291 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
292 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
293 |
|
); |
294 |
|
actionGroup->add( |
295 |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
296 |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
297 |
); |
); |
298 |
actionGroup->add( |
actionGroup->add( |
299 |
|
Gtk::Action::create("ReplaceSample", |
300 |
|
_("Replace Sample...")), |
301 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) |
302 |
|
); |
303 |
|
actionGroup->add( |
304 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
305 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
306 |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) |
320 |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
321 |
); |
); |
322 |
actionGroup->add( |
actionGroup->add( |
323 |
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveScript", _("_Remove")), |
324 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
325 |
); |
); |
326 |
|
|
352 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
353 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
354 |
" <menuitem action='ShowSampleRefs'/>" |
" <menuitem action='ShowSampleRefs'/>" |
355 |
|
" <menuitem action='ReplaceSample' />" |
356 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
357 |
" <separator/>" |
" <separator/>" |
358 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
359 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
360 |
" </menu>" |
" </menu>" |
361 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
362 |
" <menu action='AllInstruments'>" |
" <menu action='AllInstruments'>" |
379 |
" </menu>" |
" </menu>" |
380 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
381 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
382 |
|
" <menuitem action='AutoRestoreWinDim'/>" |
383 |
|
" <separator/>" |
384 |
|
" <menuitem action='RefreshAll'/>" |
385 |
" </menu>" |
" </menu>" |
386 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
387 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
389 |
" </menu>" |
" </menu>" |
390 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
391 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
392 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
393 |
|
" <menuitem action='MoveRootNoteWithRegionMoved'/>" |
394 |
|
" <menuitem action='SaveWithTemporaryFile'/>" |
395 |
" </menu>" |
" </menu>" |
396 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
397 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
411 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
412 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
413 |
" <menuitem action='ShowSampleRefs'/>" |
" <menuitem action='ShowSampleRefs'/>" |
414 |
|
" <menuitem action='ReplaceSample' />" |
415 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
416 |
" <separator/>" |
" <separator/>" |
417 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
418 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
419 |
" </popup>" |
" </popup>" |
420 |
" <popup name='ScriptPopupMenu'>" |
" <popup name='ScriptPopupMenu'>" |
421 |
" <menuitem action='AddScriptGroup'/>" |
" <menuitem action='AddScriptGroup'/>" |
455 |
} |
} |
456 |
{ |
{ |
457 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
458 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
459 |
|
item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode).")); |
460 |
|
} |
461 |
|
{ |
462 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
463 |
|
uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); |
464 |
|
item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around.")); |
465 |
|
} |
466 |
|
{ |
467 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
468 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
469 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
470 |
|
// copy tooltip to popup menu |
471 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
472 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
473 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
474 |
|
} |
475 |
|
{ |
476 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
477 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
478 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
479 |
|
} |
480 |
|
{ |
481 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
482 |
|
uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); |
483 |
|
item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time.")); |
484 |
|
} |
485 |
|
{ |
486 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
487 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
488 |
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
489 |
} |
} |
521 |
// Create the Tree model: |
// Create the Tree model: |
522 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
523 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
524 |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); |
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
525 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
526 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
527 |
); |
); |
529 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
530 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
531 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
532 |
|
|
533 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
534 |
|
// the sequence of instruments within the gig file |
535 |
|
{ |
536 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
537 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
538 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
539 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
540 |
|
m_TreeView.signal_drag_begin().connect( |
541 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
542 |
|
); |
543 |
|
m_TreeView.signal_drag_data_get().connect( |
544 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
545 |
|
); |
546 |
|
m_TreeView.signal_drag_data_received().connect( |
547 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
548 |
|
); |
549 |
|
} |
550 |
|
|
551 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
552 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
594 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
595 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
596 |
); |
); |
597 |
//FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? |
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
598 |
m_TreeViewScripts.signal_row_activated().connect( |
m_TreeViewScripts.signal_row_activated().connect( |
599 |
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
600 |
); |
); |
631 |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
632 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
633 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
634 |
|
m_RegionChooser.signal_instrument_changed().connect( |
635 |
|
sigc::mem_fun(*this, &MainWindow::region_changed)); |
636 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
637 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
638 |
instrumentProps.signal_changed().connect( |
instrumentProps.signal_changed().connect( |
655 |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
656 |
); |
); |
657 |
|
|
658 |
|
dimreg_edit.signal_select_sample().connect( |
659 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
660 |
|
); |
661 |
|
|
662 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
663 |
sigc::hide( |
sigc::hide( |
664 |
sigc::bind( |
sigc::bind( |
799 |
} |
} |
800 |
|
|
801 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
802 |
|
|
803 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
804 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
805 |
|
} |
806 |
} |
} |
807 |
|
|
808 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
822 |
|
|
823 |
void Loader::thread_function() |
void Loader::thread_function() |
824 |
{ |
{ |
825 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%p\n", |
826 |
printf("Start %s\n", filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
827 |
RIFF::File* riff = new RIFF::File(filename); |
printf("Start %s\n", filename.c_str()); |
828 |
gig = new gig::File(riff); |
try { |
829 |
gig::progress_t progress; |
RIFF::File* riff = new RIFF::File(filename); |
830 |
progress.callback = loader_progress_callback; |
gig = new gig::File(riff); |
831 |
progress.custom = this; |
gig::progress_t progress; |
832 |
|
progress.callback = loader_progress_callback; |
833 |
gig->GetInstrument(0, &progress); |
progress.custom = this; |
834 |
printf("End\n"); |
|
835 |
finished_dispatcher(); |
gig->GetInstrument(0, &progress); |
836 |
|
printf("End\n"); |
837 |
|
finished_dispatcher(); |
838 |
|
} catch (RIFF::Exception e) { |
839 |
|
error_message = e.Message; |
840 |
|
error_dispatcher.emit(); |
841 |
|
} catch (...) { |
842 |
|
error_message = _("Unknown exception occurred"); |
843 |
|
error_dispatcher.emit(); |
844 |
|
} |
845 |
} |
} |
846 |
|
|
847 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
848 |
: filename(filename), thread(0) |
: filename(filename), gig(0), thread(0), progress(0.f) |
849 |
{ |
{ |
850 |
} |
} |
851 |
|
|
856 |
#else |
#else |
857 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
858 |
#endif |
#endif |
859 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
860 |
} |
} |
861 |
|
|
862 |
float Loader::get_progress() |
float Loader::get_progress() |
879 |
return finished_dispatcher; |
return finished_dispatcher; |
880 |
} |
} |
881 |
|
|
882 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
883 |
|
{ |
884 |
|
return error_dispatcher; |
885 |
|
} |
886 |
|
|
887 |
|
void saver_progress_callback(gig::progress_t* progress) |
888 |
|
{ |
889 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
890 |
|
saver->progress_callback(progress->factor); |
891 |
|
} |
892 |
|
|
893 |
|
void Saver::progress_callback(float fraction) |
894 |
|
{ |
895 |
|
{ |
896 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
897 |
|
progress = fraction; |
898 |
|
} |
899 |
|
progress_dispatcher.emit(); |
900 |
|
} |
901 |
|
|
902 |
|
void Saver::thread_function() |
903 |
|
{ |
904 |
|
printf("thread_function self=%p\n", |
905 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
906 |
|
printf("Start %s\n", filename.c_str()); |
907 |
|
try { |
908 |
|
gig::progress_t progress; |
909 |
|
progress.callback = saver_progress_callback; |
910 |
|
progress.custom = this; |
911 |
|
|
912 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
913 |
|
if (filename.empty()) { |
914 |
|
if (!Settings::singleton()->saveWithTemporaryFile) { |
915 |
|
// save directly over the existing .gig file |
916 |
|
// (requires less disk space than solution below |
917 |
|
// but may be slower) |
918 |
|
gig->Save(&progress); |
919 |
|
} else { |
920 |
|
// save the file as separate temporary file first, |
921 |
|
// then move the saved file over the old file |
922 |
|
// (may result in performance speedup during save) |
923 |
|
String tmpname = filename + ".TMP"; |
924 |
|
gig->Save(tmpname, &progress); |
925 |
|
#if defined(WIN32) |
926 |
|
if (!DeleteFile(filename.c_str()) { |
927 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file)."); |
928 |
|
} |
929 |
|
#else // POSIX ... |
930 |
|
if (unlink(filename.c_str())) { |
931 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno))); |
932 |
|
} |
933 |
|
#endif |
934 |
|
if (rename(tmpname.c_str(), filename.c_str())) { |
935 |
|
#if defined(WIN32) |
936 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); |
937 |
|
#else |
938 |
|
throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno))); |
939 |
|
#endif |
940 |
|
} |
941 |
|
} |
942 |
|
} else { |
943 |
|
gig->Save(filename, &progress); |
944 |
|
} |
945 |
|
|
946 |
|
printf("End\n"); |
947 |
|
finished_dispatcher.emit(); |
948 |
|
} catch (RIFF::Exception e) { |
949 |
|
error_message = e.Message; |
950 |
|
error_dispatcher.emit(); |
951 |
|
} catch (...) { |
952 |
|
error_message = _("Unknown exception occurred"); |
953 |
|
error_dispatcher.emit(); |
954 |
|
} |
955 |
|
} |
956 |
|
|
957 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
958 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
959 |
|
{ |
960 |
|
} |
961 |
|
|
962 |
|
void Saver::launch() |
963 |
|
{ |
964 |
|
#ifdef OLD_THREADS |
965 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
966 |
|
#else |
967 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
968 |
|
#endif |
969 |
|
printf("launch thread=%p\n", static_cast<void*>(thread)); |
970 |
|
} |
971 |
|
|
972 |
|
float Saver::get_progress() |
973 |
|
{ |
974 |
|
float res; |
975 |
|
{ |
976 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
977 |
|
res = progress; |
978 |
|
} |
979 |
|
return res; |
980 |
|
} |
981 |
|
|
982 |
|
Glib::Dispatcher& Saver::signal_progress() |
983 |
|
{ |
984 |
|
return progress_dispatcher; |
985 |
|
} |
986 |
|
|
987 |
|
Glib::Dispatcher& Saver::signal_finished() |
988 |
|
{ |
989 |
|
return finished_dispatcher; |
990 |
|
} |
991 |
|
|
992 |
|
Glib::Dispatcher& Saver::signal_error() |
993 |
|
{ |
994 |
|
return error_dispatcher; |
995 |
|
} |
996 |
|
|
997 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
998 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
999 |
{ |
{ |
1000 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
1001 |
show_all_children(); |
show_all_children(); |
1002 |
|
resize(600,50); |
1003 |
} |
} |
1004 |
|
|
1005 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
1063 |
g_free(msg); |
g_free(msg); |
1064 |
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.")); |
1065 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
1066 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1067 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES); |
1068 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
1069 |
int response = dialog.run(); |
int response = dialog.run(); |
1070 |
dialog.hide(); |
dialog.hide(); |
1071 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
1072 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
1073 |
|
if (response == Gtk::RESPONSE_NO) return true; |
1074 |
|
|
1075 |
|
// user cancelled dialog, thus don't close app |
1076 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
1077 |
|
|
1078 |
|
// TODO: the following return valid is disabled and hard coded instead for |
1079 |
|
// now, due to the fact that saving with progress bar is now implemented |
1080 |
|
// asynchronously, as a result the app does not close automatically anymore |
1081 |
|
// after saving the file has completed |
1082 |
|
// |
1083 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
1084 |
|
// return response != Gtk::RESPONSE_CANCEL; |
1085 |
|
// |
1086 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
1087 |
|
return false; // always prevent closing the app for now (see comment above) |
1088 |
} |
} |
1089 |
|
|
1090 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1095 |
"used by the sampler until you tell the sampler explicitly to " |
"used by the sampler until you tell the sampler explicitly to " |
1096 |
"load it.")); |
"load it.")); |
1097 |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
1098 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1099 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
1100 |
int response = dialog.run(); |
int response = dialog.run(); |
1101 |
dialog.hide(); |
dialog.hide(); |
1109 |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
1110 |
|
|
1111 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
1112 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1113 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
1114 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1115 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
1116 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
1126 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1127 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
1128 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
1129 |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_file_open self=%p\n", |
1130 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
1131 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
1132 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
1133 |
} |
} |
1136 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1137 |
{ |
{ |
1138 |
__clear(); |
__clear(); |
1139 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1140 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1141 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1142 |
|
Glib::filename_display_basename(name) + "' ...", |
1143 |
|
*this |
1144 |
|
); |
1145 |
|
progress_dialog->show_all(); |
1146 |
|
loader = new Loader(name); //FIXME: memory leak! |
1147 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1148 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1149 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1150 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1151 |
|
loader->signal_error().connect( |
1152 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1153 |
loader->launch(); |
loader->launch(); |
1154 |
} |
} |
1155 |
|
|
1191 |
|
|
1192 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1193 |
{ |
{ |
1194 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1195 |
} |
} |
1196 |
|
|
1197 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1198 |
{ |
{ |
1199 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1200 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%p\n", |
1201 |
load_gig(loader->gig, loader->filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1202 |
load_dialog->hide(); |
load_gig(loader->gig, loader->filename.c_str()); |
1203 |
|
progress_dialog->hide(); |
1204 |
|
} |
1205 |
|
|
1206 |
|
void MainWindow::on_loader_error() |
1207 |
|
{ |
1208 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1209 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1210 |
|
msg.run(); |
1211 |
|
progress_dialog->hide(); |
1212 |
} |
} |
1213 |
|
|
1214 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1247 |
|
|
1248 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1249 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1250 |
try { |
|
1251 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1252 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1253 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1254 |
file_is_changed = false; |
*this |
1255 |
} |
); |
1256 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1257 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1258 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1259 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1260 |
msg.run(); |
saver->signal_finished().connect( |
1261 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1262 |
} |
saver->signal_error().connect( |
1263 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1264 |
|
saver->launch(); |
1265 |
|
|
1266 |
|
return true; |
1267 |
|
} |
1268 |
|
|
1269 |
|
void MainWindow::on_saver_progress() |
1270 |
|
{ |
1271 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1272 |
|
} |
1273 |
|
|
1274 |
|
void MainWindow::on_saver_error() |
1275 |
|
{ |
1276 |
|
file_structure_changed_signal.emit(this->file); |
1277 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1278 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1279 |
|
msg.run(); |
1280 |
|
} |
1281 |
|
|
1282 |
|
void MainWindow::on_saver_finished() |
1283 |
|
{ |
1284 |
|
this->file = saver->gig; |
1285 |
|
this->filename = saver->filename; |
1286 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1287 |
|
set_title(Glib::filename_display_basename(filename)); |
1288 |
|
file_has_name = true; |
1289 |
|
file_is_changed = false; |
1290 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1291 |
__import_queued_samples(); |
__import_queued_samples(); |
1292 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1293 |
|
|
1294 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1295 |
return true; |
|
1296 |
|
__refreshEntireGUI(); |
1297 |
|
progress_dialog->hide(); |
1298 |
} |
} |
1299 |
|
|
1300 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1305 |
|
|
1306 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
1307 |
{ |
{ |
1308 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
1309 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1310 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); |
1311 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1312 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
1313 |
|
|
1338 |
// show warning in the dialog |
// show warning in the dialog |
1339 |
Gtk::HBox descriptionArea; |
Gtk::HBox descriptionArea; |
1340 |
descriptionArea.set_spacing(15); |
descriptionArea.set_spacing(15); |
1341 |
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
Gtk::Image warningIcon; |
1342 |
|
warningIcon.set_from_icon_name("dialog-warning", |
1343 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
1344 |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
1345 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
1346 |
view::WrapLabel description; |
view::WrapLabel description; |
1361 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1362 |
|
|
1363 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1364 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1365 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1366 |
std::string filename = dialog.get_filename(); |
filename += ".gig"; |
|
if (!Glib::str_has_suffix(filename, ".gig")) { |
|
|
filename += ".gig"; |
|
|
} |
|
|
printf("filename=%s\n", filename.c_str()); |
|
|
file->Save(filename); |
|
|
this->filename = filename; |
|
|
current_gig_dir = Glib::path_get_dirname(filename); |
|
|
set_title(Glib::filename_display_basename(filename)); |
|
|
file_has_name = true; |
|
|
file_is_changed = false; |
|
|
} catch (RIFF::Exception e) { |
|
|
file_structure_changed_signal.emit(this->file); |
|
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
|
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
|
|
msg.run(); |
|
|
return false; |
|
1367 |
} |
} |
1368 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1369 |
file_structure_changed_signal.emit(this->file); |
|
1370 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1371 |
|
_("Saving") + Glib::ustring(" '") + |
1372 |
|
Glib::filename_display_basename(filename) + "' ...", |
1373 |
|
*this |
1374 |
|
); |
1375 |
|
progress_dialog->show_all(); |
1376 |
|
|
1377 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1378 |
|
saver->signal_progress().connect( |
1379 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1380 |
|
saver->signal_finished().connect( |
1381 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1382 |
|
saver->signal_error().connect( |
1383 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1384 |
|
saver->launch(); |
1385 |
|
|
1386 |
return true; |
return true; |
1387 |
} |
} |
1388 |
return false; |
return false; |
1392 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1393 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1394 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1395 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1396 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1397 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1398 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1493 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1494 |
} |
} |
1495 |
|
|
1496 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1497 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1498 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1499 |
|
} |
1500 |
|
|
1501 |
|
void MainWindow::on_action_move_root_note_with_region_moved() { |
1502 |
|
Settings::singleton()->moveRootNoteWithRegionMoved = |
1503 |
|
!Settings::singleton()->moveRootNoteWithRegionMoved; |
1504 |
|
} |
1505 |
|
|
1506 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1507 |
{ |
{ |
1508 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1512 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1513 |
#endif |
#endif |
1514 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1515 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson"); |
1516 |
const std::string sComment = |
const std::string sComment = |
1517 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1518 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1549 |
eSourceForm(_("Source form")), |
eSourceForm(_("Source form")), |
1550 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1551 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1552 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(_("_Close"), true), |
1553 |
table(2, 1), |
table(2, 1), |
1554 |
m_file(NULL) |
m_file(NULL) |
1555 |
{ |
{ |
1672 |
} |
} |
1673 |
|
|
1674 |
InstrumentProps::InstrumentProps() : |
InstrumentProps::InstrumentProps() : |
1675 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(_("_Close"), true), |
1676 |
table(2,1), |
table(2,1), |
1677 |
eName(_("Name")), |
eName(_("Name")), |
1678 |
eIsDrum(_("Is drum")), |
eIsDrum(_("Is drum")), |
1795 |
file = 0; |
file = 0; |
1796 |
set_file_is_shared(isSharedInstrument); |
set_file_is_shared(isSharedInstrument); |
1797 |
|
|
1798 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1799 |
|
(filename && strlen(filename) > 0) ? |
1800 |
|
filename : (!gig->GetFileName().empty()) ? |
1801 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1802 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1803 |
file_has_name = filename; |
file_has_name = filename; |
1804 |
file_is_changed = false; |
file_is_changed = false; |
1952 |
window->show(); |
window->show(); |
1953 |
} |
} |
1954 |
|
|
1955 |
|
void MainWindow::on_action_refresh_all() { |
1956 |
|
__refreshEntireGUI(); |
1957 |
|
} |
1958 |
|
|
1959 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1960 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1961 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1967 |
else m_StatusBar.hide(); |
else m_StatusBar.hide(); |
1968 |
} |
} |
1969 |
|
|
1970 |
|
void MainWindow::on_auto_restore_win_dim() { |
1971 |
|
Gtk::CheckMenuItem* item = |
1972 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); |
1973 |
|
if (!item) { |
1974 |
|
std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n"; |
1975 |
|
return; |
1976 |
|
} |
1977 |
|
Settings::singleton()->autoRestoreWindowDimension = item->get_active(); |
1978 |
|
} |
1979 |
|
|
1980 |
|
void MainWindow::on_save_with_temporary_file() { |
1981 |
|
Gtk::CheckMenuItem* item = |
1982 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile")); |
1983 |
|
if (!item) { |
1984 |
|
std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n"; |
1985 |
|
return; |
1986 |
|
} |
1987 |
|
Settings::singleton()->saveWithTemporaryFile = item->get_active(); |
1988 |
|
} |
1989 |
|
|
1990 |
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
1991 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1992 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
2051 |
} |
} |
2052 |
} |
} |
2053 |
|
|
2054 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
2055 |
|
if (!instrument) return; |
2056 |
|
|
2057 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2058 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2059 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2060 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
2061 |
|
// select and show the respective instrument in the list view |
2062 |
|
show_intruments_tab(); |
2063 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2064 |
|
Gtk::TreePath path( |
2065 |
|
m_TreeView.get_selection()->get_selected() |
2066 |
|
); |
2067 |
|
m_TreeView.scroll_to_row(path); |
2068 |
|
on_sel_change(); // the regular instrument selection change callback |
2069 |
|
} |
2070 |
|
} |
2071 |
|
} |
2072 |
|
|
2073 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
2074 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
2075 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
2076 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
2077 |
|
|
2078 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2079 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2080 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2081 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
2082 |
|
// select and show the respective instrument in the list view |
2083 |
|
show_intruments_tab(); |
2084 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2085 |
|
Gtk::TreePath path( |
2086 |
|
m_TreeView.get_selection()->get_selected() |
2087 |
|
); |
2088 |
|
m_TreeView.scroll_to_row(path); |
2089 |
|
on_sel_change(); // the regular instrument selection change callback |
2090 |
|
|
2091 |
|
// select respective region in the region selector |
2092 |
|
m_RegionChooser.set_region(pRegion); |
2093 |
|
|
2094 |
|
// select and show the respective dimension region in the editor |
2095 |
|
//update_dimregs(); |
2096 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
2097 |
|
//dimreg_edit.set_dim_region(dimRgn); |
2098 |
|
|
2099 |
|
return true; |
2100 |
|
} |
2101 |
|
} |
2102 |
|
|
2103 |
|
return false; |
2104 |
|
} |
2105 |
|
|
2106 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
2107 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2108 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2109 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2110 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2111 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2112 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2113 |
|
show_samples_tab(); |
2114 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2115 |
|
Gtk::TreePath path( |
2116 |
|
m_TreeViewSamples.get_selection()->get_selected() |
2117 |
|
); |
2118 |
|
m_TreeViewSamples.scroll_to_row(path); |
2119 |
|
return; |
2120 |
|
} |
2121 |
|
} |
2122 |
|
} |
2123 |
|
} |
2124 |
|
|
2125 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2126 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2127 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2409 |
if (!script) return; |
if (!script) return; |
2410 |
|
|
2411 |
ScriptEditor* editor = new ScriptEditor; |
ScriptEditor* editor = new ScriptEditor; |
2412 |
|
editor->signal_script_to_be_changed.connect( |
2413 |
|
signal_script_to_be_changed.make_slot() |
2414 |
|
); |
2415 |
|
editor->signal_script_changed.connect( |
2416 |
|
signal_script_changed.make_slot() |
2417 |
|
); |
2418 |
editor->setScript(script); |
editor->setScript(script); |
2419 |
//editor->reparent(*this); |
//editor->reparent(*this); |
2420 |
editor->show(); |
editor->show(); |
2480 |
file_changed(); |
file_changed(); |
2481 |
} |
} |
2482 |
|
|
2483 |
|
void MainWindow::on_action_replace_sample() { |
2484 |
|
add_or_replace_sample(true); |
2485 |
|
} |
2486 |
|
|
2487 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
2488 |
|
add_or_replace_sample(false); |
2489 |
|
} |
2490 |
|
|
2491 |
|
void MainWindow::add_or_replace_sample(bool replace) { |
2492 |
if (!file) return; |
if (!file) return; |
2493 |
// get selected group |
|
2494 |
|
// get selected group (and probably selected sample) |
2495 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2496 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
2497 |
if (!it) return; |
if (!it) return; |
2498 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2499 |
|
gig::Sample* sample = NULL; |
2500 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2501 |
if (!group) { // not a group, but a sample is selected (probably) |
if (!group) { // not a group, but a sample is selected (probably) |
2502 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
if (replace) sample = row[m_SamplesModel.m_col_sample]; |
2503 |
if (!sample) return; |
if (!row[m_SamplesModel.m_col_sample]) return; |
2504 |
it = row.parent(); // resolve parent (that is the sample's group) |
it = row.parent(); // resolve parent (that is the sample's group) |
2505 |
if (!it) return; |
if (!it) return; |
2506 |
row = *it; |
if (!replace) row = *it; |
2507 |
group = row[m_SamplesModel.m_col_group]; |
group = (*it)[m_SamplesModel.m_col_group]; |
2508 |
if (!group) return; |
if (!group) return; |
2509 |
} |
} |
2510 |
|
if (replace && !sample) return; |
2511 |
|
|
2512 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
2513 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
2514 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2515 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
2516 |
dialog.set_select_multiple(true); |
dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample |
2517 |
|
|
2518 |
// matches all file types supported by libsndfile |
// matches all file types supported by libsndfile |
2519 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
2584 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
2585 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
2586 |
} |
} |
2587 |
// add a new sample to the .gig file |
// add a new sample to the .gig file (if adding is requested actually) |
2588 |
gig::Sample* sample = file->AddSample(); |
if (!replace) sample = file->AddSample(); |
2589 |
// file name without path |
// file name without path |
2590 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
2591 |
// remove file extension if there is one |
// remove file extension if there is one |
2636 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
2637 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
2638 |
// make sure sample is part of the selected group |
// make sure sample is part of the selected group |
2639 |
group->AddSample(sample); |
if (!replace) group->AddSample(sample); |
2640 |
// schedule that physical resize and sample import |
// schedule that physical resize and sample import |
2641 |
// (data copying), performed when "Save" is requested |
// (data copying), performed when "Save" is requested |
2642 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2644 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2645 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue.push_back(sched_item); |
2646 |
// add sample to the tree view |
// add sample to the tree view |
2647 |
Gtk::TreeModel::iterator iterSample = |
if (replace) { |
2648 |
m_refSamplesTreeModel->append(row.children()); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2649 |
Gtk::TreeModel::Row rowSample = *iterSample; |
} else { |
2650 |
rowSample[m_SamplesModel.m_col_name] = |
Gtk::TreeModel::iterator iterSample = |
2651 |
gig_to_utf8(sample->pInfo->Name); |
m_refSamplesTreeModel->append(row.children()); |
2652 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
2653 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_name] = |
2654 |
|
gig_to_utf8(sample->pInfo->Name); |
2655 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
2656 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
2657 |
|
} |
2658 |
// close sound file |
// close sound file |
2659 |
sf_close(hFile); |
sf_close(hFile); |
2660 |
file_changed(); |
file_changed(); |
2665 |
} |
} |
2666 |
// 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 |
2667 |
if (!error_files.empty()) { |
if (!error_files.empty()) { |
2668 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = |
2669 |
|
(replace |
2670 |
|
? _("Failed to replace sample with:\n") |
2671 |
|
: _("Could not add the following sample(s):\n")) |
2672 |
|
+ error_files; |
2673 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2674 |
msg.run(); |
msg.run(); |
2675 |
} |
} |
2712 |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
2713 |
description.show(); |
description.show(); |
2714 |
entryArea.show_all(); |
entryArea.show_all(); |
2715 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2716 |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
2717 |
dialog.set_select_multiple(false); |
dialog.set_select_multiple(false); |
2718 |
if (current_sample_dir != "") { |
if (current_sample_dir != "") { |
2736 |
try |
try |
2737 |
{ |
{ |
2738 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
|
int bitdepth; |
|
2739 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
2740 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
2741 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
2742 |
case SF_FORMAT_PCM_U8: |
case SF_FORMAT_PCM_U8: |
|
bitdepth = 16; |
|
|
break; |
|
2743 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
2744 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
2745 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
2746 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
|
bitdepth = 24; |
|
2747 |
break; |
break; |
2748 |
default: |
default: |
2749 |
sf_close(hFile); |
sf_close(hFile); |
2849 |
} |
} |
2850 |
} |
} |
2851 |
|
|
2852 |
|
void MainWindow::on_action_remove_unused_samples() { |
2853 |
|
if (!file) return; |
2854 |
|
|
2855 |
|
// collect all samples that are not referenced by any instrument |
2856 |
|
std::list<gig::Sample*> lsamples; |
2857 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2858 |
|
gig::Sample* sample = file->GetSample(iSample); |
2859 |
|
bool isUsed = false; |
2860 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2861 |
|
instrument = file->GetNextInstrument()) |
2862 |
|
{ |
2863 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2864 |
|
rgn = instrument->GetNextRegion()) |
2865 |
|
{ |
2866 |
|
for (int i = 0; i < 256; ++i) { |
2867 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2868 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2869 |
|
isUsed = true; |
2870 |
|
goto endOfRefSearch; |
2871 |
|
} |
2872 |
|
} |
2873 |
|
} |
2874 |
|
endOfRefSearch: |
2875 |
|
if (!isUsed) lsamples.push_back(sample); |
2876 |
|
} |
2877 |
|
|
2878 |
|
if (lsamples.empty()) return; |
2879 |
|
|
2880 |
|
// notify everybody that we're going to remove these samples |
2881 |
|
samples_to_be_removed_signal.emit(lsamples); |
2882 |
|
|
2883 |
|
// remove collected samples |
2884 |
|
try { |
2885 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2886 |
|
itSample != lsamples.end(); ++itSample) |
2887 |
|
{ |
2888 |
|
gig::Sample* sample = *itSample; |
2889 |
|
// remove sample from the .gig file |
2890 |
|
file->DeleteSample(sample); |
2891 |
|
// if sample was just previously added, remove it fro the import queue |
2892 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2893 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2894 |
|
{ |
2895 |
|
if ((*iter).gig_sample == sample) { |
2896 |
|
printf("Removing previously added sample '%s'\n", |
2897 |
|
(*iter).sample_path.c_str()); |
2898 |
|
m_SampleImportQueue.erase(iter); |
2899 |
|
break; |
2900 |
|
} |
2901 |
|
} |
2902 |
|
} |
2903 |
|
} catch (RIFF::Exception e) { |
2904 |
|
// show error message |
2905 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2906 |
|
msg.run(); |
2907 |
|
} |
2908 |
|
|
2909 |
|
// notify everybody that we're done with removal |
2910 |
|
samples_removed_signal.emit(); |
2911 |
|
|
2912 |
|
dimreg_changed(); |
2913 |
|
file_changed(); |
2914 |
|
__refreshEntireGUI(); |
2915 |
|
} |
2916 |
|
|
2917 |
// see comment on on_sample_treeview_drag_begin() |
// see comment on on_sample_treeview_drag_begin() |
2918 |
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2919 |
{ |
{ |
2940 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2941 |
} |
} |
2942 |
|
|
2943 |
|
// see comment on on_sample_treeview_drag_begin() |
2944 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2945 |
|
{ |
2946 |
|
first_call_to_drag_data_get = true; |
2947 |
|
} |
2948 |
|
|
2949 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2950 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2951 |
|
{ |
2952 |
|
if (!first_call_to_drag_data_get) return; |
2953 |
|
first_call_to_drag_data_get = false; |
2954 |
|
|
2955 |
|
// get selected source instrument |
2956 |
|
gig::Instrument* src = NULL; |
2957 |
|
{ |
2958 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2959 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2960 |
|
if (it) { |
2961 |
|
Gtk::TreeModel::Row row = *it; |
2962 |
|
src = row[m_Columns.m_col_instr]; |
2963 |
|
} |
2964 |
|
} |
2965 |
|
if (!src) return; |
2966 |
|
|
2967 |
|
// pass the source gig::Instrument as pointer |
2968 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2969 |
|
sizeof(src)/*length of data in bytes*/); |
2970 |
|
} |
2971 |
|
|
2972 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2973 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2974 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2975 |
|
{ |
2976 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2977 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2978 |
|
return; |
2979 |
|
|
2980 |
|
gig::Instrument* dst = NULL; |
2981 |
|
{ |
2982 |
|
Gtk::TreeModel::Path path; |
2983 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2984 |
|
if (!found) return; |
2985 |
|
|
2986 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2987 |
|
if (!iter) return; |
2988 |
|
Gtk::TreeModel::Row row = *iter; |
2989 |
|
dst = row[m_Columns.m_col_instr]; |
2990 |
|
} |
2991 |
|
if (!dst) return; |
2992 |
|
|
2993 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2994 |
|
src->MoveTo(dst); |
2995 |
|
__refreshEntireGUI(); |
2996 |
|
select_instrument(src); |
2997 |
|
} |
2998 |
|
|
2999 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
3000 |
// drag'n'drop (at least when target is an Entry). This work-around |
// drag'n'drop (at least when target is an Entry). This work-around |
3001 |
// makes sure the code in drag_data_get and drop_drag_data_received is |
// makes sure the code in drag_data_get and drop_drag_data_received is |
3157 |
if (!script) return; |
if (!script) return; |
3158 |
|
|
3159 |
ScriptEditor* editor = new ScriptEditor; |
ScriptEditor* editor = new ScriptEditor; |
3160 |
|
editor->signal_script_to_be_changed.connect( |
3161 |
|
signal_script_to_be_changed.make_slot() |
3162 |
|
); |
3163 |
|
editor->signal_script_changed.connect( |
3164 |
|
signal_script_changed.make_slot() |
3165 |
|
); |
3166 |
editor->setScript(script); |
editor->setScript(script); |
3167 |
//editor->reparent(*this); |
//editor->reparent(*this); |
3168 |
editor->show(); |
editor->show(); |
3224 |
|
|
3225 |
ReferencesView* d = new ReferencesView(*this); |
ReferencesView* d = new ReferencesView(*this); |
3226 |
d->setSample(sample); |
d->setSample(sample); |
3227 |
|
d->dimension_region_selected.connect( |
3228 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
3229 |
|
); |
3230 |
d->show_all(); |
d->show_all(); |
3231 |
d->resize(500, 400); |
d->resize(500, 400); |
3232 |
d->run(); |
d->run(); |
3300 |
); |
); |
3301 |
} |
} |
3302 |
|
|
3303 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
3304 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
3305 |
|
{ |
3306 |
|
std::cout << "Saving file\n" << std::flush; |
3307 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3308 |
|
|
3309 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3310 |
|
_("Saving") + Glib::ustring(" '") + |
3311 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3312 |
|
*this |
3313 |
|
); |
3314 |
|
progress_dialog->show_all(); |
3315 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3316 |
|
saver->signal_progress().connect( |
3317 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3318 |
|
saver->signal_finished().connect( |
3319 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3320 |
|
saver->signal_error().connect( |
3321 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3322 |
|
saver->launch(); |
3323 |
|
} |
3324 |
} |
} |
3325 |
|
|
3326 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
3338 |
} |
} |
3339 |
|
|
3340 |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
3341 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
3342 |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
3343 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
3344 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
3357 |
// show warning in the file picker dialog |
// show warning in the file picker dialog |
3358 |
Gtk::HBox descriptionArea; |
Gtk::HBox descriptionArea; |
3359 |
descriptionArea.set_spacing(15); |
descriptionArea.set_spacing(15); |
3360 |
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
Gtk::Image warningIcon; |
3361 |
|
warningIcon.set_from_icon_name("dialog-warning", |
3362 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
3363 |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
3364 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
3365 |
view::WrapLabel description; |
view::WrapLabel description; |
3382 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
3383 |
|
|
3384 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
3385 |
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_merge_files self=%p\n", |
3386 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
3387 |
std::vector<std::string> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
3388 |
|
|
3389 |
// merge the selected files to the currently open .gig file |
// merge the selected files to the currently open .gig file |
3395 |
} |
} |
3396 |
|
|
3397 |
// update GUI |
// update GUI |
3398 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
3399 |
} |
} |
3400 |
} |
} |
3401 |
|
|
3413 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3414 |
); |
); |
3415 |
} |
} |
3416 |
|
|
3417 |
|
{ |
3418 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3419 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3420 |
|
if (item) item->set_sensitive(b); |
3421 |
|
} |
3422 |
} |
} |
3423 |
|
|
3424 |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3447 |
// just in case a new sample is added later with exactly the same memory |
// just in case a new sample is added later with exactly the same memory |
3448 |
// address, which would lead to incorrect refcount if not deleted here |
// address, which would lead to incorrect refcount if not deleted here |
3449 |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3450 |
it != samples.end(); it != samples.end()) |
it != samples.end(); ++it) |
3451 |
{ |
{ |
3452 |
sample_ref_count.erase(*it); |
sample_ref_count.erase(*it); |
3453 |
} |
} |
3520 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3521 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3522 |
} |
} |
3523 |
|
|
3524 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3525 |
|
return switch_sampler_instrument_signal; |
3526 |
|
} |