45 |
#include "mainwindow.h" |
#include "mainwindow.h" |
46 |
#include "Settings.h" |
#include "Settings.h" |
47 |
#include "CombineInstrumentsDialog.h" |
#include "CombineInstrumentsDialog.h" |
48 |
|
#include "scripteditor.h" |
49 |
|
#include "scriptslots.h" |
50 |
|
#include "ReferencesView.h" |
51 |
#include "../../gfx/status_attached.xpm" |
#include "../../gfx/status_attached.xpm" |
52 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
53 |
|
|
54 |
|
|
55 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
56 |
|
m_DimRegionChooser(*this), |
57 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
58 |
dimreg_all_regions(_("all regions")), |
dimreg_all_regions(_("all regions")), |
59 |
dimreg_all_dimregs(_("all dimension splits")), |
dimreg_all_dimregs(_("all dimension splits")), |
82 |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
m_ScrolledWindowSamples.add(m_TreeViewSamples); |
83 |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
84 |
|
|
85 |
|
m_ScrolledWindowScripts.add(m_TreeViewScripts); |
86 |
|
m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
87 |
|
|
88 |
|
|
89 |
m_TreeViewNotebook.set_size_request(300); |
m_TreeViewNotebook.set_size_request(300); |
90 |
|
|
105 |
|
|
106 |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); |
107 |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); |
108 |
|
m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); |
109 |
|
|
110 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
111 |
|
|
137 |
sigc::mem_fun( |
sigc::mem_fun( |
138 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
139 |
actionGroup->add(Gtk::Action::create("MidiRules", |
actionGroup->add(Gtk::Action::create("MidiRules", |
140 |
_("_Midi Rules")), |
_("_Midi Rules...")), |
141 |
sigc::mem_fun( |
sigc::mem_fun( |
142 |
*this, &MainWindow::show_midi_rules)); |
*this, &MainWindow::show_midi_rules)); |
143 |
|
actionGroup->add(Gtk::Action::create("ScriptSlots", |
144 |
|
_("_Script Slots...")), |
145 |
|
sigc::mem_fun( |
146 |
|
*this, &MainWindow::show_script_slots)); |
147 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
148 |
sigc::mem_fun( |
sigc::mem_fun( |
149 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
150 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add( |
151 |
|
Gtk::Action::create("MenuSample", _("_Sample")), |
152 |
|
sigc::mem_fun(*this, &MainWindow::show_samples_tab) |
153 |
|
); |
154 |
|
actionGroup->add( |
155 |
|
Gtk::Action::create("MenuInstrument", _("_Instrument")), |
156 |
|
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
157 |
|
); |
158 |
|
actionGroup->add( |
159 |
|
Gtk::Action::create("MenuScript", _("S_cript")), |
160 |
|
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
161 |
|
); |
162 |
|
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
163 |
|
|
164 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
165 |
|
|
249 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
250 |
); |
); |
251 |
actionGroup->add( |
actionGroup->add( |
252 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
253 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
254 |
|
); |
255 |
|
actionGroup->add( |
256 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
257 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
258 |
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) |
259 |
); |
); |
260 |
|
|
261 |
|
// script right-click popup actions |
262 |
|
actionGroup->add( |
263 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
264 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
265 |
|
); |
266 |
|
actionGroup->add( |
267 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
268 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
269 |
|
); |
270 |
|
actionGroup->add( |
271 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
272 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
273 |
|
); |
274 |
|
actionGroup->add( |
275 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
276 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
277 |
|
); |
278 |
|
|
279 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
280 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
299 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
300 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
301 |
" </menu>" |
" </menu>" |
302 |
|
" <menu action='MenuSample'>" |
303 |
|
" <menuitem action='SampleProperties'/>" |
304 |
|
" <menuitem action='AddGroup'/>" |
305 |
|
" <menuitem action='AddSample'/>" |
306 |
|
" <menuitem action='ShowSampleRefs'/>" |
307 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
308 |
|
" <separator/>" |
309 |
|
" <menuitem action='RemoveSample'/>" |
310 |
|
" </menu>" |
311 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
312 |
|
" <menu action='AllInstruments'>" |
313 |
|
" </menu>" |
314 |
|
" <separator/>" |
315 |
|
" <menuitem action='InstrProperties'/>" |
316 |
|
" <menuitem action='MidiRules'/>" |
317 |
|
" <menuitem action='ScriptSlots'/>" |
318 |
|
" <menuitem action='AddInstrument'/>" |
319 |
|
" <menuitem action='DupInstrument'/>" |
320 |
|
" <separator/>" |
321 |
|
" <menuitem action='RemoveInstrument'/>" |
322 |
|
" </menu>" |
323 |
|
" <menu action='MenuScript'>" |
324 |
|
" <menuitem action='AddScriptGroup'/>" |
325 |
|
" <menuitem action='AddScript'/>" |
326 |
|
" <menuitem action='EditScript'/>" |
327 |
|
" <separator/>" |
328 |
|
" <menuitem action='RemoveScript'/>" |
329 |
" </menu>" |
" </menu>" |
330 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
331 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
344 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
345 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
346 |
" <menuitem action='MidiRules'/>" |
" <menuitem action='MidiRules'/>" |
347 |
|
" <menuitem action='ScriptSlots'/>" |
348 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
349 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
350 |
" <separator/>" |
" <separator/>" |
354 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
355 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
356 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
357 |
|
" <menuitem action='ShowSampleRefs'/>" |
358 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
359 |
" <separator/>" |
" <separator/>" |
360 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
361 |
" </popup>" |
" </popup>" |
362 |
|
" <popup name='ScriptPopupMenu'>" |
363 |
|
" <menuitem action='AddScriptGroup'/>" |
364 |
|
" <menuitem action='AddScript'/>" |
365 |
|
" <menuitem action='EditScript'/>" |
366 |
|
" <separator/>" |
367 |
|
" <menuitem action='RemoveScript'/>" |
368 |
|
" </popup>" |
369 |
"</ui>"; |
"</ui>"; |
370 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
371 |
|
|
408 |
|
|
409 |
|
|
410 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
411 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
412 |
|
|
413 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
414 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
448 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
449 |
m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples.")); |
m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples.")); |
450 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
451 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
452 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
453 |
|
{ |
454 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
455 |
|
Gtk::CellRendererText* cellrenderer = |
456 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
457 |
|
column->add_attribute( |
458 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
459 |
|
); |
460 |
|
} |
461 |
|
{ |
462 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
463 |
|
Gtk::CellRendererText* cellrenderer = |
464 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
465 |
|
column->add_attribute( |
466 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
467 |
|
); |
468 |
|
} |
469 |
|
m_TreeViewSamples.set_headers_visible(true); |
470 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
471 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
472 |
); |
); |
474 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
475 |
); |
); |
476 |
|
|
477 |
|
// create scripts treeview (including its data model) |
478 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
479 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
480 |
|
m_TreeViewScripts.set_tooltip_text(_( |
481 |
|
"Use CTRL + double click for editing a script." |
482 |
|
"\n\n" |
483 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
484 |
|
"format. This feature will not work with the GigaStudio software!" |
485 |
|
)); |
486 |
|
// m_TreeViewScripts.set_reorderable(); |
487 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
488 |
|
m_TreeViewScripts.set_headers_visible(false); |
489 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
490 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
491 |
|
); |
492 |
|
//FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? |
493 |
|
m_TreeViewScripts.signal_row_activated().connect( |
494 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
495 |
|
); |
496 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
497 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
498 |
|
); |
499 |
|
|
500 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
501 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
502 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
503 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
504 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
505 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
506 |
|
); |
507 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
508 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
509 |
|
); |
510 |
|
|
511 |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
// establish drag&drop between samples tree view and dimension region 'Sample' text entry |
512 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
513 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
541 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
542 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
543 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
544 |
|
sample_ref_changed_signal.connect( |
545 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
546 |
|
); |
547 |
|
samples_to_be_removed_signal.connect( |
548 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
549 |
|
); |
550 |
|
|
551 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
552 |
sigc::hide( |
sigc::hide( |
672 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
673 |
{ |
{ |
674 |
update_dimregs(); |
update_dimregs(); |
675 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
676 |
} |
} |
677 |
|
|
678 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
708 |
void Loader::thread_function() |
void Loader::thread_function() |
709 |
{ |
{ |
710 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
711 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename.c_str()); |
712 |
RIFF::File* riff = new RIFF::File(filename); |
try { |
713 |
gig = new gig::File(riff); |
RIFF::File* riff = new RIFF::File(filename); |
714 |
gig::progress_t progress; |
gig = new gig::File(riff); |
715 |
progress.callback = loader_progress_callback; |
gig::progress_t progress; |
716 |
progress.custom = this; |
progress.callback = loader_progress_callback; |
717 |
|
progress.custom = this; |
718 |
gig->GetInstrument(0, &progress); |
|
719 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
720 |
finished_dispatcher(); |
printf("End\n"); |
721 |
|
finished_dispatcher(); |
722 |
|
} catch (RIFF::Exception e) { |
723 |
|
error_message = e.Message; |
724 |
|
error_dispatcher.emit(); |
725 |
|
} catch (...) { |
726 |
|
error_message = _("Unknown exception occurred"); |
727 |
|
error_dispatcher.emit(); |
728 |
|
} |
729 |
} |
} |
730 |
|
|
731 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
732 |
: filename(filename), thread(0) |
: filename(filename), thread(0), progress(0.f) |
733 |
{ |
{ |
734 |
} |
} |
735 |
|
|
763 |
return finished_dispatcher; |
return finished_dispatcher; |
764 |
} |
} |
765 |
|
|
766 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
767 |
|
{ |
768 |
|
return error_dispatcher; |
769 |
|
} |
770 |
|
|
771 |
|
void saver_progress_callback(gig::progress_t* progress) |
772 |
|
{ |
773 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
774 |
|
saver->progress_callback(progress->factor); |
775 |
|
} |
776 |
|
|
777 |
|
void Saver::progress_callback(float fraction) |
778 |
|
{ |
779 |
|
{ |
780 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
781 |
|
progress = fraction; |
782 |
|
} |
783 |
|
progress_dispatcher.emit(); |
784 |
|
} |
785 |
|
|
786 |
|
void Saver::thread_function() |
787 |
|
{ |
788 |
|
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
789 |
|
printf("Start %s\n", filename.c_str()); |
790 |
|
try { |
791 |
|
gig::progress_t progress; |
792 |
|
progress.callback = saver_progress_callback; |
793 |
|
progress.custom = this; |
794 |
|
|
795 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
796 |
|
if (filename.empty()) { |
797 |
|
gig->Save(&progress); |
798 |
|
} else { |
799 |
|
gig->Save(filename, &progress); |
800 |
|
} |
801 |
|
|
802 |
|
printf("End\n"); |
803 |
|
finished_dispatcher.emit(); |
804 |
|
} catch (RIFF::Exception e) { |
805 |
|
error_message = e.Message; |
806 |
|
error_dispatcher.emit(); |
807 |
|
} catch (...) { |
808 |
|
error_message = _("Unknown exception occurred"); |
809 |
|
error_dispatcher.emit(); |
810 |
|
} |
811 |
|
} |
812 |
|
|
813 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
814 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
815 |
|
{ |
816 |
|
} |
817 |
|
|
818 |
|
void Saver::launch() |
819 |
|
{ |
820 |
|
#ifdef OLD_THREADS |
821 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
822 |
|
#else |
823 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
824 |
|
#endif |
825 |
|
printf("launch thread=%x\n", thread); |
826 |
|
} |
827 |
|
|
828 |
|
float Saver::get_progress() |
829 |
|
{ |
830 |
|
float res; |
831 |
|
{ |
832 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
833 |
|
res = progress; |
834 |
|
} |
835 |
|
return res; |
836 |
|
} |
837 |
|
|
838 |
|
Glib::Dispatcher& Saver::signal_progress() |
839 |
|
{ |
840 |
|
return progress_dispatcher; |
841 |
|
} |
842 |
|
|
843 |
|
Glib::Dispatcher& Saver::signal_finished() |
844 |
|
{ |
845 |
|
return finished_dispatcher; |
846 |
|
} |
847 |
|
|
848 |
|
Glib::Dispatcher& Saver::signal_error() |
849 |
|
{ |
850 |
|
return error_dispatcher; |
851 |
|
} |
852 |
|
|
853 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
854 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
855 |
{ |
{ |
856 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
857 |
show_all_children(); |
show_all_children(); |
858 |
|
resize(600,50); |
859 |
} |
} |
860 |
|
|
861 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
866 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
867 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
868 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
869 |
|
m_refScriptsTreeModel->clear(); |
870 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
871 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
872 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
881 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
882 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
883 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
884 |
|
m_refScriptsTreeModel->clear(); |
885 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
886 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
887 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
924 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
925 |
int response = dialog.run(); |
int response = dialog.run(); |
926 |
dialog.hide(); |
dialog.hide(); |
927 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
928 |
return response != Gtk::RESPONSE_CANCEL; |
// TODO: the following return valid is disabled and hard coded instead for |
929 |
|
// now, due to the fact that saving with progress bar is now implemented |
930 |
|
// asynchronously, as a result the app does not close automatically anymore |
931 |
|
// after saving the file has completed |
932 |
|
// |
933 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
934 |
|
// return response != Gtk::RESPONSE_CANCEL; |
935 |
|
// |
936 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
937 |
|
return false; // always prevent closing the app for now (see comment above) |
938 |
} |
} |
939 |
|
|
940 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
985 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
986 |
{ |
{ |
987 |
__clear(); |
__clear(); |
988 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
989 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
990 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
991 |
|
Glib::filename_display_basename(name) + "' ...", |
992 |
|
*this |
993 |
|
); |
994 |
|
progress_dialog->show_all(); |
995 |
|
loader = new Loader(name); //FIXME: memory leak! |
996 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
997 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
998 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
999 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1000 |
|
loader->signal_error().connect( |
1001 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1002 |
loader->launch(); |
loader->launch(); |
1003 |
} |
} |
1004 |
|
|
1014 |
// load the instrument |
// load the instrument |
1015 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1016 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1017 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1018 |
|
int i = 0; |
1019 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1020 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1021 |
|
{ |
1022 |
|
if (instrument == instr) { |
1023 |
|
// select item in "instruments" tree view |
1024 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1025 |
|
// make sure the selected item in the "instruments" tree view is |
1026 |
|
// visible (scroll to it) |
1027 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1028 |
|
// select item in instrument menu |
1029 |
|
{ |
1030 |
|
const std::vector<Gtk::Widget*> children = |
1031 |
|
instrument_menu->get_children(); |
1032 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1033 |
|
} |
1034 |
|
// update region chooser and dimension region chooser |
1035 |
|
m_RegionChooser.set_instrument(instr); |
1036 |
|
break; |
1037 |
|
} |
1038 |
|
} |
1039 |
} |
} |
1040 |
|
|
1041 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1042 |
{ |
{ |
1043 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1044 |
} |
} |
1045 |
|
|
1046 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1047 |
{ |
{ |
1048 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1049 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
1050 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename.c_str()); |
1051 |
load_dialog->hide(); |
progress_dialog->hide(); |
1052 |
|
} |
1053 |
|
|
1054 |
|
void MainWindow::on_loader_error() |
1055 |
|
{ |
1056 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1057 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1058 |
|
msg.run(); |
1059 |
|
progress_dialog->hide(); |
1060 |
} |
} |
1061 |
|
|
1062 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1095 |
|
|
1096 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1097 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1098 |
try { |
|
1099 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1100 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1101 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1102 |
file_is_changed = false; |
*this |
1103 |
} |
); |
1104 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1105 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1106 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1107 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1108 |
msg.run(); |
saver->signal_finished().connect( |
1109 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1110 |
} |
saver->signal_error().connect( |
1111 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1112 |
|
saver->launch(); |
1113 |
|
|
1114 |
|
return true; |
1115 |
|
} |
1116 |
|
|
1117 |
|
void MainWindow::on_saver_progress() |
1118 |
|
{ |
1119 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1120 |
|
} |
1121 |
|
|
1122 |
|
void MainWindow::on_saver_error() |
1123 |
|
{ |
1124 |
|
file_structure_changed_signal.emit(this->file); |
1125 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1126 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1127 |
|
msg.run(); |
1128 |
|
} |
1129 |
|
|
1130 |
|
void MainWindow::on_saver_finished() |
1131 |
|
{ |
1132 |
|
this->file = saver->gig; |
1133 |
|
this->filename = saver->filename; |
1134 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1135 |
|
set_title(Glib::filename_display_basename(filename)); |
1136 |
|
file_has_name = true; |
1137 |
|
file_is_changed = false; |
1138 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1139 |
__import_queued_samples(); |
__import_queued_samples(); |
1140 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1141 |
|
|
1142 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1143 |
return true; |
|
1144 |
|
load_gig(this->file, this->filename.c_str()); |
1145 |
|
progress_dialog->hide(); |
1146 |
} |
} |
1147 |
|
|
1148 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1207 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1208 |
|
|
1209 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1210 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1211 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1212 |
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; |
|
1213 |
} |
} |
1214 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1215 |
file_structure_changed_signal.emit(this->file); |
|
1216 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1217 |
|
_("Saving") + Glib::ustring(" '") + |
1218 |
|
Glib::filename_display_basename(filename) + "' ...", |
1219 |
|
*this |
1220 |
|
); |
1221 |
|
progress_dialog->show_all(); |
1222 |
|
|
1223 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1224 |
|
saver->signal_progress().connect( |
1225 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1226 |
|
saver->signal_finished().connect( |
1227 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1228 |
|
saver->signal_error().connect( |
1229 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1230 |
|
saver->launch(); |
1231 |
|
|
1232 |
return true; |
return true; |
1233 |
} |
} |
1234 |
return false; |
return false; |
1355 |
_( |
_( |
1356 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1357 |
"\n" |
"\n" |
1358 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1359 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1360 |
"this application.\n" |
"this application.\n" |
1361 |
"\n" |
"\n" |
1362 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1605 |
} |
} |
1606 |
} |
} |
1607 |
|
|
1608 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1609 |
|
sample_ref_count.clear(); |
1610 |
|
|
1611 |
|
if (!gig) return; |
1612 |
|
|
1613 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1614 |
|
instrument = gig->GetNextInstrument()) |
1615 |
|
{ |
1616 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1617 |
|
rgn = instrument->GetNextRegion()) |
1618 |
|
{ |
1619 |
|
for (int i = 0; i < 256; ++i) { |
1620 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1621 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1622 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1623 |
|
} |
1624 |
|
} |
1625 |
|
} |
1626 |
|
} |
1627 |
|
} |
1628 |
|
|
1629 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1630 |
{ |
{ |
1631 |
file = 0; |
file = 0; |
1652 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1653 |
} |
} |
1654 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1655 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1656 |
|
|
1657 |
|
updateSampleRefCountMap(gig); |
1658 |
|
|
1659 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1660 |
if (group->Name != "") { |
if (group->Name != "") { |
1672 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1673 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1674 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1675 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1676 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1677 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1678 |
} |
} |
1679 |
} |
} |
1680 |
} |
} |
1681 |
|
|
1682 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1683 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1684 |
|
|
1685 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1686 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1687 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1688 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1689 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1690 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1691 |
|
gig::Script* script = group->GetScript(s); |
1692 |
|
|
1693 |
|
Gtk::TreeModel::iterator iterScript = |
1694 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1695 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1696 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1697 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1698 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1699 |
|
} |
1700 |
|
} |
1701 |
|
// unfold all sample groups & script groups by default |
1702 |
|
m_TreeViewSamples.expand_all(); |
1703 |
|
m_TreeViewScripts.expand_all(); |
1704 |
|
|
1705 |
file = gig; |
file = gig; |
1706 |
|
|
1769 |
} |
} |
1770 |
} |
} |
1771 |
|
|
1772 |
|
void MainWindow::show_script_slots() { |
1773 |
|
if (!file) return; |
1774 |
|
// get selected instrument |
1775 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1776 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1777 |
|
if (!it) return; |
1778 |
|
Gtk::TreeModel::Row row = *it; |
1779 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1780 |
|
if (!instrument) return; |
1781 |
|
|
1782 |
|
ScriptSlots* window = new ScriptSlots; |
1783 |
|
window->setInstrument(instrument); |
1784 |
|
//window->reparent(*this); |
1785 |
|
window->show(); |
1786 |
|
} |
1787 |
|
|
1788 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1789 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1790 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1832 |
show_instr_props(); |
show_instr_props(); |
1833 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1834 |
// gig v2 files have no midi rules |
// gig v2 files have no midi rules |
1835 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1836 |
|
static_cast<Gtk::MenuItem*>( |
1837 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1838 |
|
bEnabled |
1839 |
|
); |
1840 |
static_cast<Gtk::MenuItem*>( |
static_cast<Gtk::MenuItem*>( |
1841 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1842 |
!(file->pVersion && file->pVersion->major == 2)); |
bEnabled |
1843 |
|
); |
1844 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1845 |
} |
} |
1846 |
} |
} |
1874 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
1875 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
1876 |
} |
} |
1877 |
|
|
1878 |
|
|
1879 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
1880 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1881 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
1882 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1883 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
1884 |
set_sensitive(file); |
set_sensitive(file); |
1885 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
1886 |
|
set_sensitive(sample_selected); |
1887 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
1888 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
1889 |
// show sample popup |
// show sample popup |
1890 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
1891 |
|
|
1892 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
1893 |
|
set_sensitive(group_selected || sample_selected); |
1894 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
1895 |
|
set_sensitive(group_selected || sample_selected); |
1896 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
1897 |
|
set_sensitive(file); |
1898 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
1899 |
|
set_sensitive(sample_selected); |
1900 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
1901 |
|
set_sensitive(group_selected || sample_selected); |
1902 |
} |
} |
1903 |
} |
} |
1904 |
|
|
1905 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
1906 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1907 |
|
Gtk::Menu* script_popup = |
1908 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
1909 |
|
// update enabled/disabled state of sample popup items |
1910 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
1911 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1912 |
|
bool group_selected = false; |
1913 |
|
bool script_selected = false; |
1914 |
|
if (it) { |
1915 |
|
Gtk::TreeModel::Row row = *it; |
1916 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
1917 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
1918 |
|
} |
1919 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
1920 |
|
set_sensitive(group_selected || script_selected); |
1921 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
1922 |
|
set_sensitive(file); |
1923 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
1924 |
|
set_sensitive(script_selected); |
1925 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
1926 |
|
set_sensitive(group_selected || script_selected); |
1927 |
|
// show sample popup |
1928 |
|
script_popup->popup(button->button, button->time); |
1929 |
|
|
1930 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
1931 |
|
set_sensitive(group_selected || script_selected); |
1932 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
1933 |
|
set_sensitive(file); |
1934 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
1935 |
|
set_sensitive(script_selected); |
1936 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
1937 |
|
set_sensitive(group_selected || script_selected); |
1938 |
|
} |
1939 |
|
} |
1940 |
|
|
1941 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
1942 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
2084 |
msg.run(); |
msg.run(); |
2085 |
} |
} |
2086 |
|
|
2087 |
|
void MainWindow::on_action_add_script_group() { |
2088 |
|
static int __script_indexer = 0; |
2089 |
|
if (!file) return; |
2090 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
2091 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
2092 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
2093 |
|
__script_indexer++; |
2094 |
|
// update sample tree view |
2095 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
2096 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
2097 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
2098 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
2099 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
2100 |
|
file_changed(); |
2101 |
|
} |
2102 |
|
|
2103 |
|
void MainWindow::on_action_add_script() { |
2104 |
|
if (!file) return; |
2105 |
|
// get selected group |
2106 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2107 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2108 |
|
if (!it) return; |
2109 |
|
Gtk::TreeModel::Row row = *it; |
2110 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2111 |
|
if (!group) { // not a group, but a script is selected (probably) |
2112 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2113 |
|
if (!script) return; |
2114 |
|
it = row.parent(); // resolve parent (that is the script's group) |
2115 |
|
if (!it) return; |
2116 |
|
row = *it; |
2117 |
|
group = row[m_ScriptsModel.m_col_group]; |
2118 |
|
if (!group) return; |
2119 |
|
} |
2120 |
|
|
2121 |
|
// add a new script to the .gig file |
2122 |
|
gig::Script* script = group->AddScript(); |
2123 |
|
Glib::ustring name = _("Unnamed Script"); |
2124 |
|
script->Name = gig_from_utf8(name); |
2125 |
|
|
2126 |
|
// add script to the tree view |
2127 |
|
Gtk::TreeModel::iterator iterScript = |
2128 |
|
m_refScriptsTreeModel->append(row.children()); |
2129 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
2130 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
2131 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
2132 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
2133 |
|
|
2134 |
|
// unfold group of new script item in treeview |
2135 |
|
Gtk::TreeModel::Path path(iterScript); |
2136 |
|
m_TreeViewScripts.expand_to_path(path); |
2137 |
|
} |
2138 |
|
|
2139 |
|
void MainWindow::on_action_edit_script() { |
2140 |
|
if (!file) return; |
2141 |
|
// get selected script |
2142 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2143 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2144 |
|
if (!it) return; |
2145 |
|
Gtk::TreeModel::Row row = *it; |
2146 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2147 |
|
if (!script) return; |
2148 |
|
|
2149 |
|
ScriptEditor* editor = new ScriptEditor; |
2150 |
|
editor->setScript(script); |
2151 |
|
//editor->reparent(*this); |
2152 |
|
editor->show(); |
2153 |
|
} |
2154 |
|
|
2155 |
|
void MainWindow::on_action_remove_script() { |
2156 |
|
if (!file) return; |
2157 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2158 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2159 |
|
if (it) { |
2160 |
|
Gtk::TreeModel::Row row = *it; |
2161 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2162 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2163 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2164 |
|
try { |
2165 |
|
// remove script group or script from the gig file |
2166 |
|
if (group) { |
2167 |
|
// notify everybody that we're going to remove these samples |
2168 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
2169 |
|
// delete the group in the .gig file including the |
2170 |
|
// samples that belong to the group |
2171 |
|
file->DeleteScriptGroup(group); |
2172 |
|
// notify that we're done with removal |
2173 |
|
//TODO: scripts_removed_signal.emit(); |
2174 |
|
file_changed(); |
2175 |
|
} else if (script) { |
2176 |
|
// notify everybody that we're going to remove this sample |
2177 |
|
//TODO: std::list<gig::Script*> lscripts; |
2178 |
|
//TODO: lscripts.push_back(script); |
2179 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
2180 |
|
// remove sample from the .gig file |
2181 |
|
script->GetGroup()->DeleteScript(script); |
2182 |
|
// notify that we're done with removal |
2183 |
|
//TODO: scripts_removed_signal.emit(); |
2184 |
|
dimreg_changed(); |
2185 |
|
file_changed(); |
2186 |
|
} |
2187 |
|
// remove respective row(s) from samples tree view |
2188 |
|
m_refScriptsTreeModel->erase(it); |
2189 |
|
} catch (RIFF::Exception e) { |
2190 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2191 |
|
//TODO: scripts_removed_signal.emit(); |
2192 |
|
// show error message |
2193 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2194 |
|
msg.run(); |
2195 |
|
} |
2196 |
|
} |
2197 |
|
} |
2198 |
|
|
2199 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
2200 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
2201 |
if (!file) return; |
if (!file) return; |
2565 |
} |
} |
2566 |
} |
} |
2567 |
|
|
2568 |
|
// see comment on on_sample_treeview_drag_begin() |
2569 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2570 |
|
{ |
2571 |
|
first_call_to_drag_data_get = true; |
2572 |
|
} |
2573 |
|
|
2574 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2575 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2576 |
|
{ |
2577 |
|
if (!first_call_to_drag_data_get) return; |
2578 |
|
first_call_to_drag_data_get = false; |
2579 |
|
|
2580 |
|
// get selected script |
2581 |
|
gig::Script* script = NULL; |
2582 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2583 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2584 |
|
if (it) { |
2585 |
|
Gtk::TreeModel::Row row = *it; |
2586 |
|
script = row[m_ScriptsModel.m_col_script]; |
2587 |
|
} |
2588 |
|
// pass the gig::Script as pointer |
2589 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2590 |
|
(const guchar*)&script, |
2591 |
|
sizeof(script)/*length of data in bytes*/); |
2592 |
|
} |
2593 |
|
|
2594 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2595 |
// 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 |
2596 |
// 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 |
2719 |
} |
} |
2720 |
} |
} |
2721 |
|
|
2722 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2723 |
|
const Gtk::TreeModel::iterator& iter) { |
2724 |
|
if (!iter) return; |
2725 |
|
Gtk::TreeModel::Row row = *iter; |
2726 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2727 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2728 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2729 |
|
gig::String gigname(gig_from_utf8(name)); |
2730 |
|
if (group) { |
2731 |
|
if (group->Name != gigname) { |
2732 |
|
group->Name = gigname; |
2733 |
|
printf("script group name changed\n"); |
2734 |
|
file_changed(); |
2735 |
|
} |
2736 |
|
} else if (script) { |
2737 |
|
if (script->Name != gigname) { |
2738 |
|
script->Name = gigname; |
2739 |
|
printf("script name changed\n"); |
2740 |
|
file_changed(); |
2741 |
|
} |
2742 |
|
} |
2743 |
|
} |
2744 |
|
|
2745 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
2746 |
|
Gtk::TreeViewColumn* column) |
2747 |
|
{ |
2748 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
2749 |
|
if (!iter) return; |
2750 |
|
Gtk::TreeModel::Row row = *iter; |
2751 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2752 |
|
if (!script) return; |
2753 |
|
|
2754 |
|
ScriptEditor* editor = new ScriptEditor; |
2755 |
|
editor->setScript(script); |
2756 |
|
//editor->reparent(*this); |
2757 |
|
editor->show(); |
2758 |
|
} |
2759 |
|
|
2760 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2761 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2762 |
if (!iter) return; |
if (!iter) return; |
2803 |
delete d; |
delete d; |
2804 |
} |
} |
2805 |
|
|
2806 |
|
void MainWindow::on_action_view_references() { |
2807 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2808 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2809 |
|
if (!it) return; |
2810 |
|
Gtk::TreeModel::Row row = *it; |
2811 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2812 |
|
if (!sample) return; |
2813 |
|
|
2814 |
|
ReferencesView* d = new ReferencesView(*this); |
2815 |
|
d->setSample(sample); |
2816 |
|
d->show_all(); |
2817 |
|
d->resize(500, 400); |
2818 |
|
d->run(); |
2819 |
|
delete d; |
2820 |
|
} |
2821 |
|
|
2822 |
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
2823 |
struct _Source { |
struct _Source { |
2824 |
std::vector<RIFF::File*> riffs; |
std::vector<RIFF::File*> riffs; |
2886 |
); |
); |
2887 |
} |
} |
2888 |
|
|
2889 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
2890 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
2891 |
|
{ |
2892 |
|
std::cout << "Saving file\n" << std::flush; |
2893 |
|
file_structure_to_be_changed_signal.emit(this->file); |
2894 |
|
|
2895 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
2896 |
|
_("Saving") + Glib::ustring(" '") + |
2897 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
2898 |
|
*this |
2899 |
|
); |
2900 |
|
progress_dialog->show_all(); |
2901 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
2902 |
|
saver->signal_progress().connect( |
2903 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
2904 |
|
saver->signal_finished().connect( |
2905 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
2906 |
|
saver->signal_error().connect( |
2907 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
2908 |
|
saver->launch(); |
2909 |
|
} |
2910 |
} |
} |
2911 |
|
|
2912 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
2998 |
} |
} |
2999 |
} |
} |
3000 |
|
|
3001 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3002 |
|
if (!sample) return; |
3003 |
|
sample_ref_count[sample] += offset; |
3004 |
|
const int refcount = sample_ref_count[sample]; |
3005 |
|
|
3006 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
3007 |
|
for (int g = 0; g < model->children().size(); ++g) { |
3008 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
3009 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
3010 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
3011 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
3012 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
3013 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
3014 |
|
} |
3015 |
|
} |
3016 |
|
} |
3017 |
|
|
3018 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
3019 |
|
on_sample_ref_count_incremented(oldSample, -1); |
3020 |
|
on_sample_ref_count_incremented(newSample, +1); |
3021 |
|
} |
3022 |
|
|
3023 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
3024 |
|
// just in case a new sample is added later with exactly the same memory |
3025 |
|
// address, which would lead to incorrect refcount if not deleted here |
3026 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3027 |
|
it != samples.end(); ++it) |
3028 |
|
{ |
3029 |
|
sample_ref_count.erase(*it); |
3030 |
|
} |
3031 |
|
} |
3032 |
|
|
3033 |
|
void MainWindow::show_samples_tab() { |
3034 |
|
m_TreeViewNotebook.set_current_page(0); |
3035 |
|
} |
3036 |
|
|
3037 |
|
void MainWindow::show_intruments_tab() { |
3038 |
|
m_TreeViewNotebook.set_current_page(1); |
3039 |
|
} |
3040 |
|
|
3041 |
|
void MainWindow::show_scripts_tab() { |
3042 |
|
m_TreeViewNotebook.set_current_page(2); |
3043 |
|
} |
3044 |
|
|
3045 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3046 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
3047 |
} |
} |