1 |
/* |
/* |
2 |
* Copyright (C) 2006-2014 Andreas Persson |
* Copyright (C) 2006-2015 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> |
55 |
#include "CombineInstrumentsDialog.h" |
#include "CombineInstrumentsDialog.h" |
56 |
#include "scripteditor.h" |
#include "scripteditor.h" |
57 |
#include "scriptslots.h" |
#include "scriptslots.h" |
58 |
|
#include "ReferencesView.h" |
59 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
60 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
61 |
|
|
62 |
|
|
63 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
64 |
|
m_DimRegionChooser(*this), |
65 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
66 |
dimreg_all_regions(_("all regions")), |
dimreg_all_regions(_("all regions")), |
67 |
dimreg_all_dimregs(_("all dimension splits")), |
dimreg_all_dimregs(_("all dimension splits")), |
155 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
156 |
sigc::mem_fun( |
sigc::mem_fun( |
157 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
158 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add( |
159 |
|
Gtk::Action::create("MenuSample", _("_Sample")), |
160 |
|
sigc::mem_fun(*this, &MainWindow::show_samples_tab) |
161 |
|
); |
162 |
|
actionGroup->add( |
163 |
|
Gtk::Action::create("MenuInstrument", _("_Instrument")), |
164 |
|
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
165 |
|
); |
166 |
|
actionGroup->add( |
167 |
|
Gtk::Action::create("MenuScript", _("S_cript")), |
168 |
|
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
169 |
|
); |
170 |
|
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
171 |
|
|
172 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
173 |
|
|
194 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
195 |
sigc::mem_fun( |
sigc::mem_fun( |
196 |
*this, &MainWindow::on_action_view_status_bar)); |
*this, &MainWindow::on_action_view_status_bar)); |
197 |
|
actionGroup->add( |
198 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
199 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
200 |
|
); |
201 |
|
|
202 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
203 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("MenuHelp", |
229 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
230 |
); |
); |
231 |
|
|
232 |
|
toggle_action = |
233 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
234 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
235 |
|
actionGroup->add( |
236 |
|
toggle_action, |
237 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
238 |
|
); |
239 |
|
|
240 |
|
toggle_action = |
241 |
|
Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); |
242 |
|
toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); |
243 |
|
actionGroup->add( |
244 |
|
toggle_action, |
245 |
|
sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) |
246 |
|
); |
247 |
|
|
248 |
|
|
249 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
250 |
|
|
277 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
278 |
); |
); |
279 |
actionGroup->add( |
actionGroup->add( |
280 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
281 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
282 |
|
); |
283 |
|
actionGroup->add( |
284 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
285 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
286 |
|
); |
287 |
|
actionGroup->add( |
288 |
|
Gtk::Action::create("ReplaceSample", |
289 |
|
_("Replace Sample...")), |
290 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) |
291 |
|
); |
292 |
|
actionGroup->add( |
293 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
294 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
295 |
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) |
336 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
337 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
338 |
" </menu>" |
" </menu>" |
339 |
|
" <menu action='MenuSample'>" |
340 |
|
" <menuitem action='SampleProperties'/>" |
341 |
|
" <menuitem action='AddGroup'/>" |
342 |
|
" <menuitem action='AddSample'/>" |
343 |
|
" <menuitem action='ShowSampleRefs'/>" |
344 |
|
" <menuitem action='ReplaceSample' />" |
345 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
346 |
|
" <separator/>" |
347 |
|
" <menuitem action='RemoveSample'/>" |
348 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
349 |
|
" </menu>" |
350 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
351 |
|
" <menu action='AllInstruments'>" |
352 |
|
" </menu>" |
353 |
|
" <separator/>" |
354 |
|
" <menuitem action='InstrProperties'/>" |
355 |
|
" <menuitem action='MidiRules'/>" |
356 |
|
" <menuitem action='ScriptSlots'/>" |
357 |
|
" <menuitem action='AddInstrument'/>" |
358 |
|
" <menuitem action='DupInstrument'/>" |
359 |
|
" <separator/>" |
360 |
|
" <menuitem action='RemoveInstrument'/>" |
361 |
|
" </menu>" |
362 |
|
" <menu action='MenuScript'>" |
363 |
|
" <menuitem action='AddScriptGroup'/>" |
364 |
|
" <menuitem action='AddScript'/>" |
365 |
|
" <menuitem action='EditScript'/>" |
366 |
|
" <separator/>" |
367 |
|
" <menuitem action='RemoveScript'/>" |
368 |
" </menu>" |
" </menu>" |
369 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
370 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
371 |
|
" <separator/>" |
372 |
|
" <menuitem action='RefreshAll'/>" |
373 |
" </menu>" |
" </menu>" |
374 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
375 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
377 |
" </menu>" |
" </menu>" |
378 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
379 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
380 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
381 |
|
" <menuitem action='MoveRootNoteWithRegionMoved'/>" |
382 |
" </menu>" |
" </menu>" |
383 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
384 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
397 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
398 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
399 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
400 |
|
" <menuitem action='ShowSampleRefs'/>" |
401 |
|
" <menuitem action='ReplaceSample' />" |
402 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
403 |
" <separator/>" |
" <separator/>" |
404 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
405 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
406 |
" </popup>" |
" </popup>" |
407 |
" <popup name='ScriptPopupMenu'>" |
" <popup name='ScriptPopupMenu'>" |
408 |
" <menuitem action='AddScriptGroup'/>" |
" <menuitem action='AddScriptGroup'/>" |
442 |
} |
} |
443 |
{ |
{ |
444 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
445 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
446 |
|
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).")); |
447 |
|
} |
448 |
|
{ |
449 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
450 |
|
uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); |
451 |
|
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.")); |
452 |
|
} |
453 |
|
{ |
454 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
455 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
456 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
457 |
|
// copy tooltip to popup menu |
458 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
459 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
460 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
461 |
|
} |
462 |
|
{ |
463 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
464 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
465 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
466 |
|
} |
467 |
|
{ |
468 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
469 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
470 |
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.")); |
471 |
} |
} |
477 |
|
|
478 |
|
|
479 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
480 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
481 |
|
|
482 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
483 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
503 |
// Create the Tree model: |
// Create the Tree model: |
504 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
505 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
506 |
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.")); |
507 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
508 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
509 |
); |
); |
511 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
512 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
513 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
514 |
|
|
515 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
516 |
|
// the sequence of instruments within the gig file |
517 |
|
{ |
518 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
519 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
520 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
521 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
522 |
|
m_TreeView.signal_drag_begin().connect( |
523 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
524 |
|
); |
525 |
|
m_TreeView.signal_drag_data_get().connect( |
526 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
527 |
|
); |
528 |
|
m_TreeView.signal_drag_data_received().connect( |
529 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
530 |
|
); |
531 |
|
} |
532 |
|
|
533 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
534 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
540 |
{ |
{ |
541 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
542 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
543 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
544 |
column->add_attribute( |
column->add_attribute( |
545 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
546 |
); |
); |
548 |
{ |
{ |
549 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
550 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
551 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
552 |
column->add_attribute( |
column->add_attribute( |
553 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
554 |
); |
); |
565 |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
566 |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
567 |
m_TreeViewScripts.set_tooltip_text(_( |
m_TreeViewScripts.set_tooltip_text(_( |
568 |
|
"Use CTRL + double click for editing a script." |
569 |
|
"\n\n" |
570 |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
571 |
"format. This feature will not work with the GigaStudio software!" |
"format. This feature will not work with the GigaStudio software!" |
572 |
)); |
)); |
576 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
577 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
578 |
); |
); |
579 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
580 |
|
m_TreeViewScripts.signal_row_activated().connect( |
581 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
582 |
|
); |
583 |
m_refScriptsTreeModel->signal_row_changed().connect( |
m_refScriptsTreeModel->signal_row_changed().connect( |
584 |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
585 |
); |
); |
613 |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
614 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
615 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
616 |
|
m_RegionChooser.signal_instrument_changed().connect( |
617 |
|
sigc::mem_fun(*this, &MainWindow::region_changed)); |
618 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
619 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
620 |
instrumentProps.signal_changed().connect( |
instrumentProps.signal_changed().connect( |
637 |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
638 |
); |
); |
639 |
|
|
640 |
|
dimreg_edit.signal_select_sample().connect( |
641 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
642 |
|
); |
643 |
|
|
644 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
645 |
sigc::hide( |
sigc::hide( |
646 |
sigc::bind( |
sigc::bind( |
765 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
766 |
{ |
{ |
767 |
update_dimregs(); |
update_dimregs(); |
768 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
769 |
} |
} |
770 |
|
|
771 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
781 |
} |
} |
782 |
|
|
783 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
784 |
|
|
785 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
786 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
787 |
|
} |
788 |
} |
} |
789 |
|
|
790 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
804 |
|
|
805 |
void Loader::thread_function() |
void Loader::thread_function() |
806 |
{ |
{ |
807 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%p\n", |
808 |
printf("Start %s\n", filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
809 |
RIFF::File* riff = new RIFF::File(filename); |
printf("Start %s\n", filename.c_str()); |
810 |
gig = new gig::File(riff); |
try { |
811 |
gig::progress_t progress; |
RIFF::File* riff = new RIFF::File(filename); |
812 |
progress.callback = loader_progress_callback; |
gig = new gig::File(riff); |
813 |
progress.custom = this; |
gig::progress_t progress; |
814 |
|
progress.callback = loader_progress_callback; |
815 |
gig->GetInstrument(0, &progress); |
progress.custom = this; |
816 |
printf("End\n"); |
|
817 |
finished_dispatcher(); |
gig->GetInstrument(0, &progress); |
818 |
|
printf("End\n"); |
819 |
|
finished_dispatcher(); |
820 |
|
} catch (RIFF::Exception e) { |
821 |
|
error_message = e.Message; |
822 |
|
error_dispatcher.emit(); |
823 |
|
} catch (...) { |
824 |
|
error_message = _("Unknown exception occurred"); |
825 |
|
error_dispatcher.emit(); |
826 |
|
} |
827 |
} |
} |
828 |
|
|
829 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
830 |
: filename(filename), thread(0) |
: filename(filename), gig(0), thread(0), progress(0.f) |
831 |
{ |
{ |
832 |
} |
} |
833 |
|
|
838 |
#else |
#else |
839 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
840 |
#endif |
#endif |
841 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
842 |
} |
} |
843 |
|
|
844 |
float Loader::get_progress() |
float Loader::get_progress() |
861 |
return finished_dispatcher; |
return finished_dispatcher; |
862 |
} |
} |
863 |
|
|
864 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
865 |
|
{ |
866 |
|
return error_dispatcher; |
867 |
|
} |
868 |
|
|
869 |
|
void saver_progress_callback(gig::progress_t* progress) |
870 |
|
{ |
871 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
872 |
|
saver->progress_callback(progress->factor); |
873 |
|
} |
874 |
|
|
875 |
|
void Saver::progress_callback(float fraction) |
876 |
|
{ |
877 |
|
{ |
878 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
879 |
|
progress = fraction; |
880 |
|
} |
881 |
|
progress_dispatcher.emit(); |
882 |
|
} |
883 |
|
|
884 |
|
void Saver::thread_function() |
885 |
|
{ |
886 |
|
printf("thread_function self=%p\n", |
887 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
888 |
|
printf("Start %s\n", filename.c_str()); |
889 |
|
try { |
890 |
|
gig::progress_t progress; |
891 |
|
progress.callback = saver_progress_callback; |
892 |
|
progress.custom = this; |
893 |
|
|
894 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
895 |
|
if (filename.empty()) { |
896 |
|
gig->Save(&progress); |
897 |
|
} else { |
898 |
|
gig->Save(filename, &progress); |
899 |
|
} |
900 |
|
|
901 |
|
printf("End\n"); |
902 |
|
finished_dispatcher.emit(); |
903 |
|
} catch (RIFF::Exception e) { |
904 |
|
error_message = e.Message; |
905 |
|
error_dispatcher.emit(); |
906 |
|
} catch (...) { |
907 |
|
error_message = _("Unknown exception occurred"); |
908 |
|
error_dispatcher.emit(); |
909 |
|
} |
910 |
|
} |
911 |
|
|
912 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
913 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
914 |
|
{ |
915 |
|
} |
916 |
|
|
917 |
|
void Saver::launch() |
918 |
|
{ |
919 |
|
#ifdef OLD_THREADS |
920 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
921 |
|
#else |
922 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
923 |
|
#endif |
924 |
|
printf("launch thread=%p\n", static_cast<void*>(thread)); |
925 |
|
} |
926 |
|
|
927 |
|
float Saver::get_progress() |
928 |
|
{ |
929 |
|
float res; |
930 |
|
{ |
931 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
932 |
|
res = progress; |
933 |
|
} |
934 |
|
return res; |
935 |
|
} |
936 |
|
|
937 |
|
Glib::Dispatcher& Saver::signal_progress() |
938 |
|
{ |
939 |
|
return progress_dispatcher; |
940 |
|
} |
941 |
|
|
942 |
|
Glib::Dispatcher& Saver::signal_finished() |
943 |
|
{ |
944 |
|
return finished_dispatcher; |
945 |
|
} |
946 |
|
|
947 |
|
Glib::Dispatcher& Saver::signal_error() |
948 |
|
{ |
949 |
|
return error_dispatcher; |
950 |
|
} |
951 |
|
|
952 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
953 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
954 |
{ |
{ |
955 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
956 |
show_all_children(); |
show_all_children(); |
957 |
|
resize(600,50); |
958 |
} |
} |
959 |
|
|
960 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
1023 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
1024 |
int response = dialog.run(); |
int response = dialog.run(); |
1025 |
dialog.hide(); |
dialog.hide(); |
1026 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
1027 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
1028 |
|
if (response == Gtk::RESPONSE_NO) return true; |
1029 |
|
|
1030 |
|
// user cancelled dialog, thus don't close app |
1031 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
1032 |
|
|
1033 |
|
// TODO: the following return valid is disabled and hard coded instead for |
1034 |
|
// now, due to the fact that saving with progress bar is now implemented |
1035 |
|
// asynchronously, as a result the app does not close automatically anymore |
1036 |
|
// after saving the file has completed |
1037 |
|
// |
1038 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
1039 |
|
// return response != Gtk::RESPONSE_CANCEL; |
1040 |
|
// |
1041 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
1042 |
|
return false; // always prevent closing the app for now (see comment above) |
1043 |
} |
} |
1044 |
|
|
1045 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1081 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1082 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
1083 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
1084 |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_file_open self=%p\n", |
1085 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
1086 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
1087 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
1088 |
} |
} |
1091 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1092 |
{ |
{ |
1093 |
__clear(); |
__clear(); |
1094 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1095 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1096 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1097 |
|
Glib::filename_display_basename(name) + "' ...", |
1098 |
|
*this |
1099 |
|
); |
1100 |
|
progress_dialog->show_all(); |
1101 |
|
loader = new Loader(name); //FIXME: memory leak! |
1102 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1103 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1104 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1105 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1106 |
|
loader->signal_error().connect( |
1107 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1108 |
loader->launch(); |
loader->launch(); |
1109 |
} |
} |
1110 |
|
|
1120 |
// load the instrument |
// load the instrument |
1121 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1122 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1123 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1124 |
|
int i = 0; |
1125 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1126 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1127 |
|
{ |
1128 |
|
if (instrument == instr) { |
1129 |
|
// select item in "instruments" tree view |
1130 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1131 |
|
// make sure the selected item in the "instruments" tree view is |
1132 |
|
// visible (scroll to it) |
1133 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1134 |
|
// select item in instrument menu |
1135 |
|
{ |
1136 |
|
const std::vector<Gtk::Widget*> children = |
1137 |
|
instrument_menu->get_children(); |
1138 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1139 |
|
} |
1140 |
|
// update region chooser and dimension region chooser |
1141 |
|
m_RegionChooser.set_instrument(instr); |
1142 |
|
break; |
1143 |
|
} |
1144 |
|
} |
1145 |
} |
} |
1146 |
|
|
1147 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1148 |
{ |
{ |
1149 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1150 |
} |
} |
1151 |
|
|
1152 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1153 |
{ |
{ |
1154 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1155 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%p\n", |
1156 |
load_gig(loader->gig, loader->filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1157 |
load_dialog->hide(); |
load_gig(loader->gig, loader->filename.c_str()); |
1158 |
|
progress_dialog->hide(); |
1159 |
|
} |
1160 |
|
|
1161 |
|
void MainWindow::on_loader_error() |
1162 |
|
{ |
1163 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1164 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1165 |
|
msg.run(); |
1166 |
|
progress_dialog->hide(); |
1167 |
} |
} |
1168 |
|
|
1169 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1202 |
|
|
1203 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1204 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1205 |
try { |
|
1206 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1207 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1208 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1209 |
file_is_changed = false; |
*this |
1210 |
} |
); |
1211 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1212 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1213 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1214 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1215 |
msg.run(); |
saver->signal_finished().connect( |
1216 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1217 |
} |
saver->signal_error().connect( |
1218 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1219 |
|
saver->launch(); |
1220 |
|
|
1221 |
|
return true; |
1222 |
|
} |
1223 |
|
|
1224 |
|
void MainWindow::on_saver_progress() |
1225 |
|
{ |
1226 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1227 |
|
} |
1228 |
|
|
1229 |
|
void MainWindow::on_saver_error() |
1230 |
|
{ |
1231 |
|
file_structure_changed_signal.emit(this->file); |
1232 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1233 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1234 |
|
msg.run(); |
1235 |
|
} |
1236 |
|
|
1237 |
|
void MainWindow::on_saver_finished() |
1238 |
|
{ |
1239 |
|
this->file = saver->gig; |
1240 |
|
this->filename = saver->filename; |
1241 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1242 |
|
set_title(Glib::filename_display_basename(filename)); |
1243 |
|
file_has_name = true; |
1244 |
|
file_is_changed = false; |
1245 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1246 |
__import_queued_samples(); |
__import_queued_samples(); |
1247 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1248 |
|
|
1249 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1250 |
return true; |
|
1251 |
|
__refreshEntireGUI(); |
1252 |
|
progress_dialog->hide(); |
1253 |
} |
} |
1254 |
|
|
1255 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1314 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1315 |
|
|
1316 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1317 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1318 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1319 |
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; |
|
1320 |
} |
} |
1321 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1322 |
file_structure_changed_signal.emit(this->file); |
|
1323 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1324 |
|
_("Saving") + Glib::ustring(" '") + |
1325 |
|
Glib::filename_display_basename(filename) + "' ...", |
1326 |
|
*this |
1327 |
|
); |
1328 |
|
progress_dialog->show_all(); |
1329 |
|
|
1330 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1331 |
|
saver->signal_progress().connect( |
1332 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1333 |
|
saver->signal_finished().connect( |
1334 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1335 |
|
saver->signal_error().connect( |
1336 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1337 |
|
saver->launch(); |
1338 |
|
|
1339 |
return true; |
return true; |
1340 |
} |
} |
1341 |
return false; |
return false; |
1345 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1346 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1347 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1348 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1349 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1350 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1351 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1446 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1447 |
} |
} |
1448 |
|
|
1449 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1450 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1451 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1452 |
|
} |
1453 |
|
|
1454 |
|
void MainWindow::on_action_move_root_note_with_region_moved() { |
1455 |
|
Settings::singleton()->moveRootNoteWithRegionMoved = |
1456 |
|
!Settings::singleton()->moveRootNoteWithRegionMoved; |
1457 |
|
} |
1458 |
|
|
1459 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1460 |
{ |
{ |
1461 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1465 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1466 |
#endif |
#endif |
1467 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1468 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1469 |
const std::string sComment = |
const std::string sComment = |
1470 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1471 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1472 |
_( |
_( |
1473 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1474 |
"\n" |
"\n" |
1475 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1476 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1477 |
"this application.\n" |
"this application.\n" |
1478 |
"\n" |
"\n" |
1479 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1748 |
file = 0; |
file = 0; |
1749 |
set_file_is_shared(isSharedInstrument); |
set_file_is_shared(isSharedInstrument); |
1750 |
|
|
1751 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1752 |
|
(filename && strlen(filename) > 0) ? |
1753 |
|
filename : (!gig->GetFileName().empty()) ? |
1754 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1755 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1756 |
file_has_name = filename; |
file_has_name = filename; |
1757 |
file_is_changed = false; |
file_is_changed = false; |
1772 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1773 |
} |
} |
1774 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1775 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1776 |
|
|
1777 |
updateSampleRefCountMap(gig); |
updateSampleRefCountMap(gig); |
1778 |
|
|
1794 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1795 |
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1796 |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1797 |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1798 |
} |
} |
1799 |
} |
} |
1800 |
} |
} |
1818 |
rowScript[m_ScriptsModel.m_col_group] = NULL; |
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1819 |
} |
} |
1820 |
} |
} |
1821 |
// unfold all script groups by default |
// unfold all sample groups & script groups by default |
1822 |
|
m_TreeViewSamples.expand_all(); |
1823 |
m_TreeViewScripts.expand_all(); |
m_TreeViewScripts.expand_all(); |
1824 |
|
|
1825 |
file = gig; |
file = gig; |
1905 |
window->show(); |
window->show(); |
1906 |
} |
} |
1907 |
|
|
1908 |
|
void MainWindow::on_action_refresh_all() { |
1909 |
|
__refreshEntireGUI(); |
1910 |
|
} |
1911 |
|
|
1912 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1913 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1914 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1956 |
show_instr_props(); |
show_instr_props(); |
1957 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1958 |
// gig v2 files have no midi rules |
// gig v2 files have no midi rules |
1959 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1960 |
|
static_cast<Gtk::MenuItem*>( |
1961 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1962 |
|
bEnabled |
1963 |
|
); |
1964 |
static_cast<Gtk::MenuItem*>( |
static_cast<Gtk::MenuItem*>( |
1965 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1966 |
!(file->pVersion && file->pVersion->major == 2)); |
bEnabled |
1967 |
|
); |
1968 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1969 |
} |
} |
1970 |
} |
} |
1984 |
} |
} |
1985 |
} |
} |
1986 |
|
|
1987 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1988 |
|
if (!instrument) return; |
1989 |
|
|
1990 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1991 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1992 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1993 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1994 |
|
// select and show the respective instrument in the list view |
1995 |
|
show_intruments_tab(); |
1996 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1997 |
|
Gtk::TreePath path( |
1998 |
|
m_TreeView.get_selection()->get_selected() |
1999 |
|
); |
2000 |
|
m_TreeView.scroll_to_row(path); |
2001 |
|
on_sel_change(); // the regular instrument selection change callback |
2002 |
|
} |
2003 |
|
} |
2004 |
|
} |
2005 |
|
|
2006 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
2007 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
2008 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
2009 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
2010 |
|
|
2011 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2012 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2013 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2014 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
2015 |
|
// select and show the respective instrument in the list view |
2016 |
|
show_intruments_tab(); |
2017 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2018 |
|
Gtk::TreePath path( |
2019 |
|
m_TreeView.get_selection()->get_selected() |
2020 |
|
); |
2021 |
|
m_TreeView.scroll_to_row(path); |
2022 |
|
on_sel_change(); // the regular instrument selection change callback |
2023 |
|
|
2024 |
|
// select respective region in the region selector |
2025 |
|
m_RegionChooser.set_region(pRegion); |
2026 |
|
|
2027 |
|
// select and show the respective dimension region in the editor |
2028 |
|
//update_dimregs(); |
2029 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
2030 |
|
//dimreg_edit.set_dim_region(dimRgn); |
2031 |
|
|
2032 |
|
return true; |
2033 |
|
} |
2034 |
|
} |
2035 |
|
|
2036 |
|
return false; |
2037 |
|
} |
2038 |
|
|
2039 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
2040 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2041 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2042 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2043 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2044 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2045 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2046 |
|
show_samples_tab(); |
2047 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2048 |
|
Gtk::TreePath path( |
2049 |
|
m_TreeViewSamples.get_selection()->get_selected() |
2050 |
|
); |
2051 |
|
m_TreeViewSamples.scroll_to_row(path); |
2052 |
|
return; |
2053 |
|
} |
2054 |
|
} |
2055 |
|
} |
2056 |
|
} |
2057 |
|
|
2058 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2059 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2060 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2069 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
2070 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
2071 |
} |
} |
2072 |
|
|
2073 |
|
|
2074 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
2075 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2076 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
2077 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2078 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
2079 |
set_sensitive(file); |
set_sensitive(file); |
2080 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
2081 |
|
set_sensitive(sample_selected); |
2082 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
2083 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2084 |
// show sample popup |
// show sample popup |
2085 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
2086 |
|
|
2087 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
2088 |
|
set_sensitive(group_selected || sample_selected); |
2089 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
2090 |
|
set_sensitive(group_selected || sample_selected); |
2091 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
2092 |
|
set_sensitive(file); |
2093 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
2094 |
|
set_sensitive(sample_selected); |
2095 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
2096 |
|
set_sensitive(group_selected || sample_selected); |
2097 |
} |
} |
2098 |
} |
} |
2099 |
|
|
2121 |
set_sensitive(group_selected || script_selected); |
set_sensitive(group_selected || script_selected); |
2122 |
// show sample popup |
// show sample popup |
2123 |
script_popup->popup(button->button, button->time); |
script_popup->popup(button->button, button->time); |
2124 |
|
|
2125 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
2126 |
|
set_sensitive(group_selected || script_selected); |
2127 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
2128 |
|
set_sensitive(file); |
2129 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
2130 |
|
set_sensitive(script_selected); |
2131 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
2132 |
|
set_sensitive(group_selected || script_selected); |
2133 |
} |
} |
2134 |
} |
} |
2135 |
|
|
2407 |
file_changed(); |
file_changed(); |
2408 |
} |
} |
2409 |
|
|
2410 |
|
void MainWindow::on_action_replace_sample() { |
2411 |
|
add_or_replace_sample(true); |
2412 |
|
} |
2413 |
|
|
2414 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
2415 |
|
add_or_replace_sample(false); |
2416 |
|
} |
2417 |
|
|
2418 |
|
void MainWindow::add_or_replace_sample(bool replace) { |
2419 |
if (!file) return; |
if (!file) return; |
2420 |
// get selected group |
|
2421 |
|
// get selected group (and probably selected sample) |
2422 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2423 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
2424 |
if (!it) return; |
if (!it) return; |
2425 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2426 |
|
gig::Sample* sample = NULL; |
2427 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2428 |
if (!group) { // not a group, but a sample is selected (probably) |
if (!group) { // not a group, but a sample is selected (probably) |
2429 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
if (replace) sample = row[m_SamplesModel.m_col_sample]; |
2430 |
if (!sample) return; |
if (!row[m_SamplesModel.m_col_sample]) return; |
2431 |
it = row.parent(); // resolve parent (that is the sample's group) |
it = row.parent(); // resolve parent (that is the sample's group) |
2432 |
if (!it) return; |
if (!it) return; |
2433 |
row = *it; |
if (!replace) row = *it; |
2434 |
group = row[m_SamplesModel.m_col_group]; |
group = (*it)[m_SamplesModel.m_col_group]; |
2435 |
if (!group) return; |
if (!group) return; |
2436 |
} |
} |
2437 |
|
if (replace && !sample) return; |
2438 |
|
|
2439 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
2440 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
2441 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
2442 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
2443 |
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 |
2444 |
|
|
2445 |
// matches all file types supported by libsndfile |
// matches all file types supported by libsndfile |
2446 |
#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 |
2511 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
2512 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
2513 |
} |
} |
2514 |
// add a new sample to the .gig file |
// add a new sample to the .gig file (if adding is requested actually) |
2515 |
gig::Sample* sample = file->AddSample(); |
if (!replace) sample = file->AddSample(); |
2516 |
// file name without path |
// file name without path |
2517 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
2518 |
// remove file extension if there is one |
// remove file extension if there is one |
2563 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
2564 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
2565 |
// make sure sample is part of the selected group |
// make sure sample is part of the selected group |
2566 |
group->AddSample(sample); |
if (!replace) group->AddSample(sample); |
2567 |
// schedule that physical resize and sample import |
// schedule that physical resize and sample import |
2568 |
// (data copying), performed when "Save" is requested |
// (data copying), performed when "Save" is requested |
2569 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2571 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2572 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue.push_back(sched_item); |
2573 |
// add sample to the tree view |
// add sample to the tree view |
2574 |
Gtk::TreeModel::iterator iterSample = |
if (replace) { |
2575 |
m_refSamplesTreeModel->append(row.children()); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2576 |
Gtk::TreeModel::Row rowSample = *iterSample; |
} else { |
2577 |
rowSample[m_SamplesModel.m_col_name] = |
Gtk::TreeModel::iterator iterSample = |
2578 |
gig_to_utf8(sample->pInfo->Name); |
m_refSamplesTreeModel->append(row.children()); |
2579 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
2580 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_name] = |
2581 |
|
gig_to_utf8(sample->pInfo->Name); |
2582 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
2583 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
2584 |
|
} |
2585 |
// close sound file |
// close sound file |
2586 |
sf_close(hFile); |
sf_close(hFile); |
2587 |
file_changed(); |
file_changed(); |
2592 |
} |
} |
2593 |
// 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 |
2594 |
if (!error_files.empty()) { |
if (!error_files.empty()) { |
2595 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = |
2596 |
|
(replace |
2597 |
|
? _("Failed to replace sample with:\n") |
2598 |
|
: _("Could not add the following sample(s):\n")) |
2599 |
|
+ error_files; |
2600 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2601 |
msg.run(); |
msg.run(); |
2602 |
} |
} |
2663 |
try |
try |
2664 |
{ |
{ |
2665 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
|
int bitdepth; |
|
2666 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
2667 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
2668 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
2669 |
case SF_FORMAT_PCM_U8: |
case SF_FORMAT_PCM_U8: |
|
bitdepth = 16; |
|
|
break; |
|
2670 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
2671 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
2672 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
2673 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
|
bitdepth = 24; |
|
2674 |
break; |
break; |
2675 |
default: |
default: |
2676 |
sf_close(hFile); |
sf_close(hFile); |
2776 |
} |
} |
2777 |
} |
} |
2778 |
|
|
2779 |
|
void MainWindow::on_action_remove_unused_samples() { |
2780 |
|
if (!file) return; |
2781 |
|
|
2782 |
|
// collect all samples that are not referenced by any instrument |
2783 |
|
std::list<gig::Sample*> lsamples; |
2784 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2785 |
|
gig::Sample* sample = file->GetSample(iSample); |
2786 |
|
bool isUsed = false; |
2787 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2788 |
|
instrument = file->GetNextInstrument()) |
2789 |
|
{ |
2790 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2791 |
|
rgn = instrument->GetNextRegion()) |
2792 |
|
{ |
2793 |
|
for (int i = 0; i < 256; ++i) { |
2794 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2795 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2796 |
|
isUsed = true; |
2797 |
|
goto endOfRefSearch; |
2798 |
|
} |
2799 |
|
} |
2800 |
|
} |
2801 |
|
endOfRefSearch: |
2802 |
|
if (!isUsed) lsamples.push_back(sample); |
2803 |
|
} |
2804 |
|
|
2805 |
|
if (lsamples.empty()) return; |
2806 |
|
|
2807 |
|
// notify everybody that we're going to remove these samples |
2808 |
|
samples_to_be_removed_signal.emit(lsamples); |
2809 |
|
|
2810 |
|
// remove collected samples |
2811 |
|
try { |
2812 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2813 |
|
itSample != lsamples.end(); ++itSample) |
2814 |
|
{ |
2815 |
|
gig::Sample* sample = *itSample; |
2816 |
|
// remove sample from the .gig file |
2817 |
|
file->DeleteSample(sample); |
2818 |
|
// if sample was just previously added, remove it fro the import queue |
2819 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2820 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2821 |
|
{ |
2822 |
|
if ((*iter).gig_sample == sample) { |
2823 |
|
printf("Removing previously added sample '%s'\n", |
2824 |
|
(*iter).sample_path.c_str()); |
2825 |
|
m_SampleImportQueue.erase(iter); |
2826 |
|
break; |
2827 |
|
} |
2828 |
|
} |
2829 |
|
} |
2830 |
|
} catch (RIFF::Exception e) { |
2831 |
|
// show error message |
2832 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2833 |
|
msg.run(); |
2834 |
|
} |
2835 |
|
|
2836 |
|
// notify everybody that we're done with removal |
2837 |
|
samples_removed_signal.emit(); |
2838 |
|
|
2839 |
|
dimreg_changed(); |
2840 |
|
file_changed(); |
2841 |
|
__refreshEntireGUI(); |
2842 |
|
} |
2843 |
|
|
2844 |
// see comment on on_sample_treeview_drag_begin() |
// see comment on on_sample_treeview_drag_begin() |
2845 |
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) |
2846 |
{ |
{ |
2867 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2868 |
} |
} |
2869 |
|
|
2870 |
|
// see comment on on_sample_treeview_drag_begin() |
2871 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2872 |
|
{ |
2873 |
|
first_call_to_drag_data_get = true; |
2874 |
|
} |
2875 |
|
|
2876 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2877 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2878 |
|
{ |
2879 |
|
if (!first_call_to_drag_data_get) return; |
2880 |
|
first_call_to_drag_data_get = false; |
2881 |
|
|
2882 |
|
// get selected source instrument |
2883 |
|
gig::Instrument* src = NULL; |
2884 |
|
{ |
2885 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2886 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2887 |
|
if (it) { |
2888 |
|
Gtk::TreeModel::Row row = *it; |
2889 |
|
src = row[m_Columns.m_col_instr]; |
2890 |
|
} |
2891 |
|
} |
2892 |
|
if (!src) return; |
2893 |
|
|
2894 |
|
// pass the source gig::Instrument as pointer |
2895 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2896 |
|
sizeof(src)/*length of data in bytes*/); |
2897 |
|
} |
2898 |
|
|
2899 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2900 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2901 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2902 |
|
{ |
2903 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2904 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2905 |
|
return; |
2906 |
|
|
2907 |
|
gig::Instrument* dst = NULL; |
2908 |
|
{ |
2909 |
|
Gtk::TreeModel::Path path; |
2910 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2911 |
|
if (!found) return; |
2912 |
|
|
2913 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2914 |
|
if (!iter) return; |
2915 |
|
Gtk::TreeModel::Row row = *iter; |
2916 |
|
dst = row[m_Columns.m_col_instr]; |
2917 |
|
} |
2918 |
|
if (!dst) return; |
2919 |
|
|
2920 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2921 |
|
src->MoveTo(dst); |
2922 |
|
__refreshEntireGUI(); |
2923 |
|
select_instrument(src); |
2924 |
|
} |
2925 |
|
|
2926 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2927 |
// 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 |
2928 |
// 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 |
3074 |
} |
} |
3075 |
} |
} |
3076 |
|
|
3077 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
3078 |
|
Gtk::TreeViewColumn* column) |
3079 |
|
{ |
3080 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
3081 |
|
if (!iter) return; |
3082 |
|
Gtk::TreeModel::Row row = *iter; |
3083 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
3084 |
|
if (!script) return; |
3085 |
|
|
3086 |
|
ScriptEditor* editor = new ScriptEditor; |
3087 |
|
editor->setScript(script); |
3088 |
|
//editor->reparent(*this); |
3089 |
|
editor->show(); |
3090 |
|
} |
3091 |
|
|
3092 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
3093 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
3094 |
if (!iter) return; |
if (!iter) return; |
3135 |
delete d; |
delete d; |
3136 |
} |
} |
3137 |
|
|
3138 |
|
void MainWindow::on_action_view_references() { |
3139 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
3140 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
3141 |
|
if (!it) return; |
3142 |
|
Gtk::TreeModel::Row row = *it; |
3143 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
3144 |
|
if (!sample) return; |
3145 |
|
|
3146 |
|
ReferencesView* d = new ReferencesView(*this); |
3147 |
|
d->setSample(sample); |
3148 |
|
d->dimension_region_selected.connect( |
3149 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
3150 |
|
); |
3151 |
|
d->show_all(); |
3152 |
|
d->resize(500, 400); |
3153 |
|
d->run(); |
3154 |
|
delete d; |
3155 |
|
} |
3156 |
|
|
3157 |
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
3158 |
struct _Source { |
struct _Source { |
3159 |
std::vector<RIFF::File*> riffs; |
std::vector<RIFF::File*> riffs; |
3221 |
); |
); |
3222 |
} |
} |
3223 |
|
|
3224 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
3225 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
3226 |
|
{ |
3227 |
|
std::cout << "Saving file\n" << std::flush; |
3228 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3229 |
|
|
3230 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3231 |
|
_("Saving") + Glib::ustring(" '") + |
3232 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3233 |
|
*this |
3234 |
|
); |
3235 |
|
progress_dialog->show_all(); |
3236 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3237 |
|
saver->signal_progress().connect( |
3238 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3239 |
|
saver->signal_finished().connect( |
3240 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3241 |
|
saver->signal_error().connect( |
3242 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3243 |
|
saver->launch(); |
3244 |
|
} |
3245 |
} |
} |
3246 |
|
|
3247 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
3301 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
3302 |
|
|
3303 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
3304 |
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_merge_files self=%p\n", |
3305 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
3306 |
std::vector<std::string> filenames = dialog.get_filenames(); |
std::vector<std::string> filenames = dialog.get_filenames(); |
3307 |
|
|
3308 |
// merge the selected files to the currently open .gig file |
// merge the selected files to the currently open .gig file |
3314 |
} |
} |
3315 |
|
|
3316 |
// update GUI |
// update GUI |
3317 |
__refreshEntireGUI(); |
__refreshEntireGUI(); |
3318 |
} |
} |
3319 |
} |
} |
3320 |
|
|
3332 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3333 |
); |
); |
3334 |
} |
} |
3335 |
|
|
3336 |
|
{ |
3337 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3338 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3339 |
|
if (item) item->set_sensitive(b); |
3340 |
|
} |
3341 |
} |
} |
3342 |
|
|
3343 |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3352 |
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
3353 |
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
3354 |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
3355 |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
3356 |
} |
} |
3357 |
} |
} |
3358 |
} |
} |
3366 |
// 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 |
3367 |
// address, which would lead to incorrect refcount if not deleted here |
// address, which would lead to incorrect refcount if not deleted here |
3368 |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3369 |
it != samples.end(); it != samples.end()) |
it != samples.end(); ++it) |
3370 |
{ |
{ |
3371 |
sample_ref_count.erase(*it); |
sample_ref_count.erase(*it); |
3372 |
} |
} |
3373 |
} |
} |
3374 |
|
|
3375 |
|
void MainWindow::show_samples_tab() { |
3376 |
|
m_TreeViewNotebook.set_current_page(0); |
3377 |
|
} |
3378 |
|
|
3379 |
|
void MainWindow::show_intruments_tab() { |
3380 |
|
m_TreeViewNotebook.set_current_page(1); |
3381 |
|
} |
3382 |
|
|
3383 |
|
void MainWindow::show_scripts_tab() { |
3384 |
|
m_TreeViewNotebook.set_current_page(2); |
3385 |
|
} |
3386 |
|
|
3387 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3388 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
3389 |
} |
} |
3439 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3440 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3441 |
} |
} |
3442 |
|
|
3443 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3444 |
|
return switch_sampler_instrument_signal; |
3445 |
|
} |