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> |
35 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
36 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
37 |
#include <gtkmm/messagedialog.h> |
#include <gtkmm/messagedialog.h> |
|
#include <gtkmm/stock.h> |
|
38 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
39 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
40 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
60 |
|
|
61 |
|
|
62 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
63 |
|
m_DimRegionChooser(*this), |
64 |
dimreg_label(_("Changes apply to:")), |
dimreg_label(_("Changes apply to:")), |
65 |
dimreg_all_regions(_("all regions")), |
dimreg_all_regions(_("all regions")), |
66 |
dimreg_all_dimregs(_("all dimension splits")), |
dimreg_all_dimregs(_("all dimension splits")), |
117 |
actionGroup = Gtk::ActionGroup::create(); |
actionGroup = Gtk::ActionGroup::create(); |
118 |
|
|
119 |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); |
120 |
actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), |
actionGroup->add(Gtk::Action::create("New", _("_New")), |
121 |
|
Gtk::AccelKey("<control>n"), |
122 |
sigc::mem_fun( |
sigc::mem_fun( |
123 |
*this, &MainWindow::on_action_file_new)); |
*this, &MainWindow::on_action_file_new)); |
124 |
Glib::RefPtr<Gtk::Action> action = |
actionGroup->add(Gtk::Action::create("Open", _("_Open...")), |
125 |
Gtk::Action::create("Open", Gtk::Stock::OPEN); |
Gtk::AccelKey("<control>o"), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
126 |
sigc::mem_fun( |
sigc::mem_fun( |
127 |
*this, &MainWindow::on_action_file_open)); |
*this, &MainWindow::on_action_file_open)); |
128 |
actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), |
actionGroup->add(Gtk::Action::create("Save", _("_Save")), |
129 |
|
Gtk::AccelKey("<control>s"), |
130 |
sigc::mem_fun( |
sigc::mem_fun( |
131 |
*this, &MainWindow::on_action_file_save)); |
*this, &MainWindow::on_action_file_save)); |
132 |
action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); |
actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")), |
|
action->property_label() = action->property_label() + "..."; |
|
|
actionGroup->add(action, |
|
133 |
Gtk::AccelKey("<shift><control>s"), |
Gtk::AccelKey("<shift><control>s"), |
134 |
sigc::mem_fun( |
sigc::mem_fun( |
135 |
*this, &MainWindow::on_action_file_save_as)); |
*this, &MainWindow::on_action_file_save_as)); |
136 |
actionGroup->add(Gtk::Action::create("Properties", |
actionGroup->add(Gtk::Action::create("Properties", |
137 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
138 |
sigc::mem_fun( |
sigc::mem_fun( |
139 |
*this, &MainWindow::on_action_file_properties)); |
*this, &MainWindow::on_action_file_properties)); |
140 |
actionGroup->add(Gtk::Action::create("InstrProperties", |
actionGroup->add(Gtk::Action::create("InstrProperties", |
141 |
Gtk::Stock::PROPERTIES), |
_("_Properties")), |
142 |
sigc::mem_fun( |
sigc::mem_fun( |
143 |
*this, &MainWindow::show_instr_props)); |
*this, &MainWindow::show_instr_props)); |
144 |
actionGroup->add(Gtk::Action::create("MidiRules", |
actionGroup->add(Gtk::Action::create("MidiRules", |
149 |
_("_Script Slots...")), |
_("_Script Slots...")), |
150 |
sigc::mem_fun( |
sigc::mem_fun( |
151 |
*this, &MainWindow::show_script_slots)); |
*this, &MainWindow::show_script_slots)); |
152 |
actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), |
actionGroup->add(Gtk::Action::create("Quit", _("_Quit")), |
153 |
|
Gtk::AccelKey("<control>q"), |
154 |
sigc::mem_fun( |
sigc::mem_fun( |
155 |
*this, &MainWindow::on_action_quit)); |
*this, &MainWindow::on_action_quit)); |
156 |
actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); |
actionGroup->add( |
157 |
|
Gtk::Action::create("MenuSample", _("_Sample")), |
158 |
|
sigc::mem_fun(*this, &MainWindow::show_samples_tab) |
159 |
|
); |
160 |
|
actionGroup->add( |
161 |
|
Gtk::Action::create("MenuInstrument", _("_Instrument")), |
162 |
|
sigc::mem_fun(*this, &MainWindow::show_intruments_tab) |
163 |
|
); |
164 |
|
actionGroup->add( |
165 |
|
Gtk::Action::create("MenuScript", _("S_cript")), |
166 |
|
sigc::mem_fun(*this, &MainWindow::show_scripts_tab) |
167 |
|
); |
168 |
|
actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); |
169 |
|
|
170 |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); |
171 |
|
|
192 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
193 |
sigc::mem_fun( |
sigc::mem_fun( |
194 |
*this, &MainWindow::on_action_view_status_bar)); |
*this, &MainWindow::on_action_view_status_bar)); |
195 |
|
actionGroup->add( |
196 |
|
Gtk::Action::create("RefreshAll", _("_Refresh All")), |
197 |
|
sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) |
198 |
|
); |
199 |
|
|
200 |
action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); |
actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help"))); |
201 |
actionGroup->add(Gtk::Action::create("MenuHelp", |
actionGroup->add(Gtk::Action::create("About", _("_About")), |
|
action->property_label())); |
|
|
actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), |
|
202 |
sigc::mem_fun( |
sigc::mem_fun( |
203 |
*this, &MainWindow::on_action_help_about)); |
*this, &MainWindow::on_action_help_about)); |
204 |
actionGroup->add( |
actionGroup->add( |
210 |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) |
211 |
); |
); |
212 |
actionGroup->add( |
actionGroup->add( |
213 |
Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveInstrument", _("_Remove")), |
214 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
215 |
); |
); |
216 |
|
|
225 |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
226 |
); |
); |
227 |
|
|
228 |
|
toggle_action = |
229 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
230 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
231 |
|
actionGroup->add( |
232 |
|
toggle_action, |
233 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
234 |
|
); |
235 |
|
|
236 |
|
toggle_action = |
237 |
|
Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); |
238 |
|
toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); |
239 |
|
actionGroup->add( |
240 |
|
toggle_action, |
241 |
|
sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) |
242 |
|
); |
243 |
|
|
244 |
|
|
245 |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
246 |
|
|
257 |
|
|
258 |
// sample right-click popup actions |
// sample right-click popup actions |
259 |
actionGroup->add( |
actionGroup->add( |
260 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", _("_Properties")), |
261 |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) |
262 |
); |
); |
263 |
actionGroup->add( |
actionGroup->add( |
269 |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_add_sample) |
270 |
); |
); |
271 |
actionGroup->add( |
actionGroup->add( |
272 |
Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveSample", _("_Remove")), |
273 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
274 |
); |
); |
275 |
actionGroup->add( |
actionGroup->add( |
276 |
|
Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), |
277 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) |
278 |
|
); |
279 |
|
actionGroup->add( |
280 |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
281 |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
282 |
); |
); |
283 |
actionGroup->add( |
actionGroup->add( |
284 |
|
Gtk::Action::create("ReplaceSample", |
285 |
|
_("Replace Sample...")), |
286 |
|
sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) |
287 |
|
); |
288 |
|
actionGroup->add( |
289 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
290 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
291 |
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) |
305 |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
306 |
); |
); |
307 |
actionGroup->add( |
actionGroup->add( |
308 |
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
Gtk::Action::create("RemoveScript", _("_Remove")), |
309 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
310 |
); |
); |
311 |
|
|
332 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
333 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
334 |
" </menu>" |
" </menu>" |
335 |
|
" <menu action='MenuSample'>" |
336 |
|
" <menuitem action='SampleProperties'/>" |
337 |
|
" <menuitem action='AddGroup'/>" |
338 |
|
" <menuitem action='AddSample'/>" |
339 |
|
" <menuitem action='ShowSampleRefs'/>" |
340 |
|
" <menuitem action='ReplaceSample' />" |
341 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
342 |
|
" <separator/>" |
343 |
|
" <menuitem action='RemoveSample'/>" |
344 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
345 |
|
" </menu>" |
346 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
347 |
|
" <menu action='AllInstruments'>" |
348 |
|
" </menu>" |
349 |
|
" <separator/>" |
350 |
|
" <menuitem action='InstrProperties'/>" |
351 |
|
" <menuitem action='MidiRules'/>" |
352 |
|
" <menuitem action='ScriptSlots'/>" |
353 |
|
" <menuitem action='AddInstrument'/>" |
354 |
|
" <menuitem action='DupInstrument'/>" |
355 |
|
" <separator/>" |
356 |
|
" <menuitem action='RemoveInstrument'/>" |
357 |
|
" </menu>" |
358 |
|
" <menu action='MenuScript'>" |
359 |
|
" <menuitem action='AddScriptGroup'/>" |
360 |
|
" <menuitem action='AddScript'/>" |
361 |
|
" <menuitem action='EditScript'/>" |
362 |
|
" <separator/>" |
363 |
|
" <menuitem action='RemoveScript'/>" |
364 |
" </menu>" |
" </menu>" |
365 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
366 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
367 |
|
" <separator/>" |
368 |
|
" <menuitem action='RefreshAll'/>" |
369 |
" </menu>" |
" </menu>" |
370 |
" <menu action='MenuTools'>" |
" <menu action='MenuTools'>" |
371 |
" <menuitem action='CombineInstruments'/>" |
" <menuitem action='CombineInstruments'/>" |
373 |
" </menu>" |
" </menu>" |
374 |
" <menu action='MenuSettings'>" |
" <menu action='MenuSettings'>" |
375 |
" <menuitem action='WarnUserOnExtensions'/>" |
" <menuitem action='WarnUserOnExtensions'/>" |
376 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
377 |
|
" <menuitem action='MoveRootNoteWithRegionMoved'/>" |
378 |
" </menu>" |
" </menu>" |
379 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
380 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
394 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
395 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
396 |
" <menuitem action='ShowSampleRefs'/>" |
" <menuitem action='ShowSampleRefs'/>" |
397 |
|
" <menuitem action='ReplaceSample' />" |
398 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
399 |
" <separator/>" |
" <separator/>" |
400 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
401 |
|
" <menuitem action='RemoveUnusedSamples'/>" |
402 |
" </popup>" |
" </popup>" |
403 |
" <popup name='ScriptPopupMenu'>" |
" <popup name='ScriptPopupMenu'>" |
404 |
" <menuitem action='AddScriptGroup'/>" |
" <menuitem action='AddScriptGroup'/>" |
438 |
} |
} |
439 |
{ |
{ |
440 |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
441 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
442 |
|
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).")); |
443 |
|
} |
444 |
|
{ |
445 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
446 |
|
uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); |
447 |
|
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.")); |
448 |
|
} |
449 |
|
{ |
450 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
451 |
|
uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); |
452 |
|
item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); |
453 |
|
// copy tooltip to popup menu |
454 |
|
Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>( |
455 |
|
uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); |
456 |
|
item2->set_tooltip_text(item->get_tooltip_text()); |
457 |
|
} |
458 |
|
{ |
459 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
460 |
|
uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); |
461 |
|
item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); |
462 |
|
} |
463 |
|
{ |
464 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
465 |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
466 |
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.")); |
467 |
} |
} |
473 |
|
|
474 |
|
|
475 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
476 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
477 |
|
|
478 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
479 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
499 |
// Create the Tree model: |
// Create the Tree model: |
500 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
501 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
502 |
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.")); |
503 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
504 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
505 |
); |
); |
507 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
508 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
509 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
510 |
|
|
511 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
512 |
|
// the sequence of instruments within the gig file |
513 |
|
{ |
514 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
515 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
516 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
517 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
518 |
|
m_TreeView.signal_drag_begin().connect( |
519 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
520 |
|
); |
521 |
|
m_TreeView.signal_drag_data_get().connect( |
522 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
523 |
|
); |
524 |
|
m_TreeView.signal_drag_data_received().connect( |
525 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
526 |
|
); |
527 |
|
} |
528 |
|
|
529 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
530 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
536 |
{ |
{ |
537 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
538 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
539 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
540 |
column->add_attribute( |
column->add_attribute( |
541 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
542 |
); |
); |
544 |
{ |
{ |
545 |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
546 |
Gtk::CellRendererText* cellrenderer = |
Gtk::CellRendererText* cellrenderer = |
547 |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer()); |
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
548 |
column->add_attribute( |
column->add_attribute( |
549 |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
cellrenderer->property_foreground(), m_SamplesModel.m_color |
550 |
); |
); |
561 |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
562 |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
563 |
m_TreeViewScripts.set_tooltip_text(_( |
m_TreeViewScripts.set_tooltip_text(_( |
564 |
|
"Use CTRL + double click for editing a script." |
565 |
|
"\n\n" |
566 |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
"Note: instrument scripts are a LinuxSampler extension of the gig " |
567 |
"format. This feature will not work with the GigaStudio software!" |
"format. This feature will not work with the GigaStudio software!" |
568 |
)); |
)); |
572 |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
m_TreeViewScripts.signal_button_press_event().connect_notify( |
573 |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
574 |
); |
); |
575 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
576 |
|
m_TreeViewScripts.signal_row_activated().connect( |
577 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
578 |
|
); |
579 |
m_refScriptsTreeModel->signal_row_changed().connect( |
m_refScriptsTreeModel->signal_row_changed().connect( |
580 |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
581 |
); |
); |
609 |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
610 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
611 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
612 |
|
m_RegionChooser.signal_instrument_changed().connect( |
613 |
|
sigc::mem_fun(*this, &MainWindow::region_changed)); |
614 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
615 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
616 |
instrumentProps.signal_changed().connect( |
instrumentProps.signal_changed().connect( |
633 |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
634 |
); |
); |
635 |
|
|
636 |
|
dimreg_edit.signal_select_sample().connect( |
637 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
638 |
|
); |
639 |
|
|
640 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
641 |
sigc::hide( |
sigc::hide( |
642 |
sigc::bind( |
sigc::bind( |
761 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
762 |
{ |
{ |
763 |
update_dimregs(); |
update_dimregs(); |
764 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
765 |
} |
} |
766 |
|
|
767 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
777 |
} |
} |
778 |
|
|
779 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
780 |
|
|
781 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
782 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
783 |
|
} |
784 |
} |
} |
785 |
|
|
786 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
800 |
|
|
801 |
void Loader::thread_function() |
void Loader::thread_function() |
802 |
{ |
{ |
803 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%p\n", |
804 |
printf("Start %s\n", filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
805 |
RIFF::File* riff = new RIFF::File(filename); |
printf("Start %s\n", filename.c_str()); |
806 |
gig = new gig::File(riff); |
try { |
807 |
gig::progress_t progress; |
RIFF::File* riff = new RIFF::File(filename); |
808 |
progress.callback = loader_progress_callback; |
gig = new gig::File(riff); |
809 |
progress.custom = this; |
gig::progress_t progress; |
810 |
|
progress.callback = loader_progress_callback; |
811 |
gig->GetInstrument(0, &progress); |
progress.custom = this; |
812 |
printf("End\n"); |
|
813 |
finished_dispatcher(); |
gig->GetInstrument(0, &progress); |
814 |
|
printf("End\n"); |
815 |
|
finished_dispatcher(); |
816 |
|
} catch (RIFF::Exception e) { |
817 |
|
error_message = e.Message; |
818 |
|
error_dispatcher.emit(); |
819 |
|
} catch (...) { |
820 |
|
error_message = _("Unknown exception occurred"); |
821 |
|
error_dispatcher.emit(); |
822 |
|
} |
823 |
} |
} |
824 |
|
|
825 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
826 |
: filename(filename), thread(0) |
: filename(filename), gig(0), thread(0), progress(0.f) |
827 |
{ |
{ |
828 |
} |
} |
829 |
|
|
834 |
#else |
#else |
835 |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); |
836 |
#endif |
#endif |
837 |
printf("launch thread=%x\n", thread); |
printf("launch thread=%p\n", static_cast<void*>(thread)); |
838 |
} |
} |
839 |
|
|
840 |
float Loader::get_progress() |
float Loader::get_progress() |
857 |
return finished_dispatcher; |
return finished_dispatcher; |
858 |
} |
} |
859 |
|
|
860 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
861 |
|
{ |
862 |
|
return error_dispatcher; |
863 |
|
} |
864 |
|
|
865 |
|
void saver_progress_callback(gig::progress_t* progress) |
866 |
|
{ |
867 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
868 |
|
saver->progress_callback(progress->factor); |
869 |
|
} |
870 |
|
|
871 |
|
void Saver::progress_callback(float fraction) |
872 |
|
{ |
873 |
|
{ |
874 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
875 |
|
progress = fraction; |
876 |
|
} |
877 |
|
progress_dispatcher.emit(); |
878 |
|
} |
879 |
|
|
880 |
|
void Saver::thread_function() |
881 |
|
{ |
882 |
|
printf("thread_function self=%p\n", |
883 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
884 |
|
printf("Start %s\n", filename.c_str()); |
885 |
|
try { |
886 |
|
gig::progress_t progress; |
887 |
|
progress.callback = saver_progress_callback; |
888 |
|
progress.custom = this; |
889 |
|
|
890 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
891 |
|
if (filename.empty()) { |
892 |
|
gig->Save(&progress); |
893 |
|
} else { |
894 |
|
gig->Save(filename, &progress); |
895 |
|
} |
896 |
|
|
897 |
|
printf("End\n"); |
898 |
|
finished_dispatcher.emit(); |
899 |
|
} catch (RIFF::Exception e) { |
900 |
|
error_message = e.Message; |
901 |
|
error_dispatcher.emit(); |
902 |
|
} catch (...) { |
903 |
|
error_message = _("Unknown exception occurred"); |
904 |
|
error_dispatcher.emit(); |
905 |
|
} |
906 |
|
} |
907 |
|
|
908 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
909 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
910 |
|
{ |
911 |
|
} |
912 |
|
|
913 |
|
void Saver::launch() |
914 |
|
{ |
915 |
|
#ifdef OLD_THREADS |
916 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
917 |
|
#else |
918 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
919 |
|
#endif |
920 |
|
printf("launch thread=%p\n", static_cast<void*>(thread)); |
921 |
|
} |
922 |
|
|
923 |
|
float Saver::get_progress() |
924 |
|
{ |
925 |
|
float res; |
926 |
|
{ |
927 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
928 |
|
res = progress; |
929 |
|
} |
930 |
|
return res; |
931 |
|
} |
932 |
|
|
933 |
|
Glib::Dispatcher& Saver::signal_progress() |
934 |
|
{ |
935 |
|
return progress_dispatcher; |
936 |
|
} |
937 |
|
|
938 |
|
Glib::Dispatcher& Saver::signal_finished() |
939 |
|
{ |
940 |
|
return finished_dispatcher; |
941 |
|
} |
942 |
|
|
943 |
|
Glib::Dispatcher& Saver::signal_error() |
944 |
|
{ |
945 |
|
return error_dispatcher; |
946 |
|
} |
947 |
|
|
948 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
949 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
950 |
{ |
{ |
951 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
952 |
show_all_children(); |
show_all_children(); |
953 |
|
resize(600,50); |
954 |
} |
} |
955 |
|
|
956 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
1014 |
g_free(msg); |
g_free(msg); |
1015 |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); |
1016 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
1017 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1018 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES); |
1019 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
1020 |
int response = dialog.run(); |
int response = dialog.run(); |
1021 |
dialog.hide(); |
dialog.hide(); |
1022 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
1023 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
1024 |
|
if (response == Gtk::RESPONSE_NO) return true; |
1025 |
|
|
1026 |
|
// user cancelled dialog, thus don't close app |
1027 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
1028 |
|
|
1029 |
|
// TODO: the following return valid is disabled and hard coded instead for |
1030 |
|
// now, due to the fact that saving with progress bar is now implemented |
1031 |
|
// asynchronously, as a result the app does not close automatically anymore |
1032 |
|
// after saving the file has completed |
1033 |
|
// |
1034 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
1035 |
|
// return response != Gtk::RESPONSE_CANCEL; |
1036 |
|
// |
1037 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
1038 |
|
return false; // always prevent closing the app for now (see comment above) |
1039 |
} |
} |
1040 |
|
|
1041 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1046 |
"used by the sampler until you tell the sampler explicitly to " |
"used by the sampler until you tell the sampler explicitly to " |
1047 |
"load it.")); |
"load it.")); |
1048 |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
1049 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1050 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
1051 |
int response = dialog.run(); |
int response = dialog.run(); |
1052 |
dialog.hide(); |
dialog.hide(); |
1060 |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
1061 |
|
|
1062 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
1063 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1064 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
1065 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1066 |
#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 |
1067 |
Gtk::FileFilter filter; |
Gtk::FileFilter filter; |
1077 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1078 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
1079 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
1080 |
printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); |
printf("on_action_file_open self=%p\n", |
1081 |
|
static_cast<void*>(Glib::Threads::Thread::self())); |
1082 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
1083 |
current_gig_dir = Glib::path_get_dirname(filename); |
current_gig_dir = Glib::path_get_dirname(filename); |
1084 |
} |
} |
1087 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1088 |
{ |
{ |
1089 |
__clear(); |
__clear(); |
1090 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1091 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1092 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1093 |
|
Glib::filename_display_basename(name) + "' ...", |
1094 |
|
*this |
1095 |
|
); |
1096 |
|
progress_dialog->show_all(); |
1097 |
|
loader = new Loader(name); //FIXME: memory leak! |
1098 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1099 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1100 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1101 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1102 |
|
loader->signal_error().connect( |
1103 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1104 |
loader->launch(); |
loader->launch(); |
1105 |
} |
} |
1106 |
|
|
1116 |
// load the instrument |
// load the instrument |
1117 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1118 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1119 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1120 |
|
int i = 0; |
1121 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1122 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1123 |
|
{ |
1124 |
|
if (instrument == instr) { |
1125 |
|
// select item in "instruments" tree view |
1126 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1127 |
|
// make sure the selected item in the "instruments" tree view is |
1128 |
|
// visible (scroll to it) |
1129 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1130 |
|
// select item in instrument menu |
1131 |
|
{ |
1132 |
|
const std::vector<Gtk::Widget*> children = |
1133 |
|
instrument_menu->get_children(); |
1134 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1135 |
|
} |
1136 |
|
// update region chooser and dimension region chooser |
1137 |
|
m_RegionChooser.set_instrument(instr); |
1138 |
|
break; |
1139 |
|
} |
1140 |
|
} |
1141 |
} |
} |
1142 |
|
|
1143 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1144 |
{ |
{ |
1145 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1146 |
} |
} |
1147 |
|
|
1148 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1149 |
{ |
{ |
1150 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1151 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%p\n", |
1152 |
load_gig(loader->gig, loader->filename); |
static_cast<void*>(Glib::Threads::Thread::self())); |
1153 |
load_dialog->hide(); |
load_gig(loader->gig, loader->filename.c_str()); |
1154 |
|
progress_dialog->hide(); |
1155 |
|
} |
1156 |
|
|
1157 |
|
void MainWindow::on_loader_error() |
1158 |
|
{ |
1159 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1160 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1161 |
|
msg.run(); |
1162 |
|
progress_dialog->hide(); |
1163 |
} |
} |
1164 |
|
|
1165 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1198 |
|
|
1199 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1200 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1201 |
try { |
|
1202 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1203 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1204 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1205 |
file_is_changed = false; |
*this |
1206 |
} |
); |
1207 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1208 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1209 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1210 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1211 |
msg.run(); |
saver->signal_finished().connect( |
1212 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1213 |
} |
saver->signal_error().connect( |
1214 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1215 |
|
saver->launch(); |
1216 |
|
|
1217 |
|
return true; |
1218 |
|
} |
1219 |
|
|
1220 |
|
void MainWindow::on_saver_progress() |
1221 |
|
{ |
1222 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1223 |
|
} |
1224 |
|
|
1225 |
|
void MainWindow::on_saver_error() |
1226 |
|
{ |
1227 |
|
file_structure_changed_signal.emit(this->file); |
1228 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1229 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1230 |
|
msg.run(); |
1231 |
|
} |
1232 |
|
|
1233 |
|
void MainWindow::on_saver_finished() |
1234 |
|
{ |
1235 |
|
this->file = saver->gig; |
1236 |
|
this->filename = saver->filename; |
1237 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1238 |
|
set_title(Glib::filename_display_basename(filename)); |
1239 |
|
file_has_name = true; |
1240 |
|
file_is_changed = false; |
1241 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1242 |
__import_queued_samples(); |
__import_queued_samples(); |
1243 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1244 |
|
|
1245 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1246 |
return true; |
|
1247 |
|
__refreshEntireGUI(); |
1248 |
|
progress_dialog->hide(); |
1249 |
} |
} |
1250 |
|
|
1251 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1256 |
|
|
1257 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
1258 |
{ |
{ |
1259 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
1260 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
1261 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); |
1262 |
dialog.set_default_response(Gtk::RESPONSE_OK); |
dialog.set_default_response(Gtk::RESPONSE_OK); |
1263 |
dialog.set_do_overwrite_confirmation(); |
dialog.set_do_overwrite_confirmation(); |
1264 |
|
|
1289 |
// show warning in the dialog |
// show warning in the dialog |
1290 |
Gtk::HBox descriptionArea; |
Gtk::HBox descriptionArea; |
1291 |
descriptionArea.set_spacing(15); |
descriptionArea.set_spacing(15); |
1292 |
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
Gtk::Image warningIcon; |
1293 |
|
warningIcon.set_from_icon_name("dialog-warning", |
1294 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
1295 |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
1296 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
1297 |
view::WrapLabel description; |
view::WrapLabel description; |
1312 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1313 |
|
|
1314 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1315 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1316 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1317 |
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; |
|
1318 |
} |
} |
1319 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1320 |
file_structure_changed_signal.emit(this->file); |
|
1321 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1322 |
|
_("Saving") + Glib::ustring(" '") + |
1323 |
|
Glib::filename_display_basename(filename) + "' ...", |
1324 |
|
*this |
1325 |
|
); |
1326 |
|
progress_dialog->show_all(); |
1327 |
|
|
1328 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1329 |
|
saver->signal_progress().connect( |
1330 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1331 |
|
saver->signal_finished().connect( |
1332 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1333 |
|
saver->signal_error().connect( |
1334 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1335 |
|
saver->launch(); |
1336 |
|
|
1337 |
return true; |
return true; |
1338 |
} |
} |
1339 |
return false; |
return false; |
1343 |
void MainWindow::__import_queued_samples() { |
void MainWindow::__import_queued_samples() { |
1344 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1345 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1346 |
printf("Samples to import: %d\n", m_SampleImportQueue.size()); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1347 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1348 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1349 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
1444 |
!Settings::singleton()->warnUserOnExtensions; |
!Settings::singleton()->warnUserOnExtensions; |
1445 |
} |
} |
1446 |
|
|
1447 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1448 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1449 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1450 |
|
} |
1451 |
|
|
1452 |
|
void MainWindow::on_action_move_root_note_with_region_moved() { |
1453 |
|
Settings::singleton()->moveRootNoteWithRegionMoved = |
1454 |
|
!Settings::singleton()->moveRootNoteWithRegionMoved; |
1455 |
|
} |
1456 |
|
|
1457 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1458 |
{ |
{ |
1459 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1463 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1464 |
#endif |
#endif |
1465 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1466 |
dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1467 |
const std::string sComment = |
const std::string sComment = |
1468 |
_("Built " __DATE__ "\nUsing ") + |
_("Built " __DATE__ "\nUsing ") + |
1469 |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1470 |
_( |
_( |
1471 |
"Gigedit is released under the GNU General Public License.\n" |
"Gigedit is released under the GNU General Public License.\n" |
1472 |
"\n" |
"\n" |
1473 |
"Please notice that this is still a very young instrument editor. " |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1474 |
"So better backup your Gigasampler files before editing them with " |
"backup your Gigasampler/GigaStudio files before editing them with " |
1475 |
"this application.\n" |
"this application.\n" |
1476 |
"\n" |
"\n" |
1477 |
"Please report bugs to: http://bugs.linuxsampler.org" |
"Please report bugs to: http://bugs.linuxsampler.org" |
1500 |
eSourceForm(_("Source form")), |
eSourceForm(_("Source form")), |
1501 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1502 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1503 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(_("_Close"), true), |
1504 |
table(2, 1), |
table(2, 1), |
1505 |
m_file(NULL) |
m_file(NULL) |
1506 |
{ |
{ |
1623 |
} |
} |
1624 |
|
|
1625 |
InstrumentProps::InstrumentProps() : |
InstrumentProps::InstrumentProps() : |
1626 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(_("_Close"), true), |
1627 |
table(2,1), |
table(2,1), |
1628 |
eName(_("Name")), |
eName(_("Name")), |
1629 |
eIsDrum(_("Is drum")), |
eIsDrum(_("Is drum")), |
1746 |
file = 0; |
file = 0; |
1747 |
set_file_is_shared(isSharedInstrument); |
set_file_is_shared(isSharedInstrument); |
1748 |
|
|
1749 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = |
1750 |
|
(filename && strlen(filename) > 0) ? |
1751 |
|
filename : (!gig->GetFileName().empty()) ? |
1752 |
|
gig->GetFileName() : _("Unsaved Gig File"); |
1753 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1754 |
file_has_name = filename; |
file_has_name = filename; |
1755 |
file_is_changed = false; |
file_is_changed = false; |
1770 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1771 |
} |
} |
1772 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1773 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1774 |
|
|
1775 |
updateSampleRefCountMap(gig); |
updateSampleRefCountMap(gig); |
1776 |
|
|
1792 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1793 |
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1794 |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1795 |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; |
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1796 |
} |
} |
1797 |
} |
} |
1798 |
} |
} |
1903 |
window->show(); |
window->show(); |
1904 |
} |
} |
1905 |
|
|
1906 |
|
void MainWindow::on_action_refresh_all() { |
1907 |
|
__refreshEntireGUI(); |
1908 |
|
} |
1909 |
|
|
1910 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1911 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1912 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1954 |
show_instr_props(); |
show_instr_props(); |
1955 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1956 |
// gig v2 files have no midi rules |
// gig v2 files have no midi rules |
1957 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1958 |
|
static_cast<Gtk::MenuItem*>( |
1959 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1960 |
|
bEnabled |
1961 |
|
); |
1962 |
static_cast<Gtk::MenuItem*>( |
static_cast<Gtk::MenuItem*>( |
1963 |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1964 |
!(file->pVersion && file->pVersion->major == 2)); |
bEnabled |
1965 |
|
); |
1966 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1967 |
} |
} |
1968 |
} |
} |
1982 |
} |
} |
1983 |
} |
} |
1984 |
|
|
1985 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1986 |
|
if (!instrument) return; |
1987 |
|
|
1988 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1989 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1990 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1991 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1992 |
|
// select and show the respective instrument in the list view |
1993 |
|
show_intruments_tab(); |
1994 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1995 |
|
Gtk::TreePath path( |
1996 |
|
m_TreeView.get_selection()->get_selected() |
1997 |
|
); |
1998 |
|
m_TreeView.scroll_to_row(path); |
1999 |
|
on_sel_change(); // the regular instrument selection change callback |
2000 |
|
} |
2001 |
|
} |
2002 |
|
} |
2003 |
|
|
2004 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
2005 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
2006 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
2007 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
2008 |
|
|
2009 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
2010 |
|
for (int i = 0; i < model->children().size(); ++i) { |
2011 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
2012 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
2013 |
|
// select and show the respective instrument in the list view |
2014 |
|
show_intruments_tab(); |
2015 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
2016 |
|
Gtk::TreePath path( |
2017 |
|
m_TreeView.get_selection()->get_selected() |
2018 |
|
); |
2019 |
|
m_TreeView.scroll_to_row(path); |
2020 |
|
on_sel_change(); // the regular instrument selection change callback |
2021 |
|
|
2022 |
|
// select respective region in the region selector |
2023 |
|
m_RegionChooser.set_region(pRegion); |
2024 |
|
|
2025 |
|
// select and show the respective dimension region in the editor |
2026 |
|
//update_dimregs(); |
2027 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
2028 |
|
//dimreg_edit.set_dim_region(dimRgn); |
2029 |
|
|
2030 |
|
return true; |
2031 |
|
} |
2032 |
|
} |
2033 |
|
|
2034 |
|
return false; |
2035 |
|
} |
2036 |
|
|
2037 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
2038 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
2039 |
|
for (int g = 0; g < model->children().size(); ++g) { |
2040 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
2041 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
2042 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
2043 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
2044 |
|
show_samples_tab(); |
2045 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
2046 |
|
Gtk::TreePath path( |
2047 |
|
m_TreeViewSamples.get_selection()->get_selected() |
2048 |
|
); |
2049 |
|
m_TreeViewSamples.scroll_to_row(path); |
2050 |
|
return; |
2051 |
|
} |
2052 |
|
} |
2053 |
|
} |
2054 |
|
} |
2055 |
|
|
2056 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
2057 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2058 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
2067 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
2068 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
2069 |
} |
} |
2070 |
|
|
2071 |
|
|
2072 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
2073 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2074 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
2081 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2082 |
// show sample popup |
// show sample popup |
2083 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
2084 |
|
|
2085 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
2086 |
|
set_sensitive(group_selected || sample_selected); |
2087 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
2088 |
|
set_sensitive(group_selected || sample_selected); |
2089 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
2090 |
|
set_sensitive(file); |
2091 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
2092 |
|
set_sensitive(sample_selected); |
2093 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
2094 |
|
set_sensitive(group_selected || sample_selected); |
2095 |
} |
} |
2096 |
} |
} |
2097 |
|
|
2119 |
set_sensitive(group_selected || script_selected); |
set_sensitive(group_selected || script_selected); |
2120 |
// show sample popup |
// show sample popup |
2121 |
script_popup->popup(button->button, button->time); |
script_popup->popup(button->button, button->time); |
2122 |
|
|
2123 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
2124 |
|
set_sensitive(group_selected || script_selected); |
2125 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
2126 |
|
set_sensitive(file); |
2127 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
2128 |
|
set_sensitive(script_selected); |
2129 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
2130 |
|
set_sensitive(group_selected || script_selected); |
2131 |
} |
} |
2132 |
} |
} |
2133 |
|
|
2405 |
file_changed(); |
file_changed(); |
2406 |
} |
} |
2407 |
|
|
2408 |
|
void MainWindow::on_action_replace_sample() { |
2409 |
|
add_or_replace_sample(true); |
2410 |
|
} |
2411 |
|
|
2412 |
void MainWindow::on_action_add_sample() { |
void MainWindow::on_action_add_sample() { |
2413 |
|
add_or_replace_sample(false); |
2414 |
|
} |
2415 |
|
|
2416 |
|
void MainWindow::add_or_replace_sample(bool replace) { |
2417 |
if (!file) return; |
if (!file) return; |
2418 |
// get selected group |
|
2419 |
|
// get selected group (and probably selected sample) |
2420 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2421 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
2422 |
if (!it) return; |
if (!it) return; |
2423 |
Gtk::TreeModel::Row row = *it; |
Gtk::TreeModel::Row row = *it; |
2424 |
|
gig::Sample* sample = NULL; |
2425 |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
gig::Group* group = row[m_SamplesModel.m_col_group]; |
2426 |
if (!group) { // not a group, but a sample is selected (probably) |
if (!group) { // not a group, but a sample is selected (probably) |
2427 |
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
if (replace) sample = row[m_SamplesModel.m_col_sample]; |
2428 |
if (!sample) return; |
if (!row[m_SamplesModel.m_col_sample]) return; |
2429 |
it = row.parent(); // resolve parent (that is the sample's group) |
it = row.parent(); // resolve parent (that is the sample's group) |
2430 |
if (!it) return; |
if (!it) return; |
2431 |
row = *it; |
if (!replace) row = *it; |
2432 |
group = row[m_SamplesModel.m_col_group]; |
group = (*it)[m_SamplesModel.m_col_group]; |
2433 |
if (!group) return; |
if (!group) return; |
2434 |
} |
} |
2435 |
|
if (replace && !sample) return; |
2436 |
|
|
2437 |
// show 'browse for file' dialog |
// show 'browse for file' dialog |
2438 |
Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); |
Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); |
2439 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2440 |
dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); |
dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); |
2441 |
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 |
2442 |
|
|
2443 |
// matches all file types supported by libsndfile |
// matches all file types supported by libsndfile |
2444 |
#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 |
2509 |
sf_close(hFile); // close sound file |
sf_close(hFile); // close sound file |
2510 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
2511 |
} |
} |
2512 |
// add a new sample to the .gig file |
// add a new sample to the .gig file (if adding is requested actually) |
2513 |
gig::Sample* sample = file->AddSample(); |
if (!replace) sample = file->AddSample(); |
2514 |
// file name without path |
// file name without path |
2515 |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
Glib::ustring filename = Glib::filename_display_basename(*iter); |
2516 |
// remove file extension if there is one |
// remove file extension if there is one |
2561 |
// physically when File::Save() is called) |
// physically when File::Save() is called) |
2562 |
sample->Resize(info.frames); |
sample->Resize(info.frames); |
2563 |
// make sure sample is part of the selected group |
// make sure sample is part of the selected group |
2564 |
group->AddSample(sample); |
if (!replace) group->AddSample(sample); |
2565 |
// schedule that physical resize and sample import |
// schedule that physical resize and sample import |
2566 |
// (data copying), performed when "Save" is requested |
// (data copying), performed when "Save" is requested |
2567 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2569 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2570 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue.push_back(sched_item); |
2571 |
// add sample to the tree view |
// add sample to the tree view |
2572 |
Gtk::TreeModel::iterator iterSample = |
if (replace) { |
2573 |
m_refSamplesTreeModel->append(row.children()); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2574 |
Gtk::TreeModel::Row rowSample = *iterSample; |
} else { |
2575 |
rowSample[m_SamplesModel.m_col_name] = |
Gtk::TreeModel::iterator iterSample = |
2576 |
gig_to_utf8(sample->pInfo->Name); |
m_refSamplesTreeModel->append(row.children()); |
2577 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
Gtk::TreeModel::Row rowSample = *iterSample; |
2578 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_name] = |
2579 |
|
gig_to_utf8(sample->pInfo->Name); |
2580 |
|
rowSample[m_SamplesModel.m_col_sample] = sample; |
2581 |
|
rowSample[m_SamplesModel.m_col_group] = NULL; |
2582 |
|
} |
2583 |
// close sound file |
// close sound file |
2584 |
sf_close(hFile); |
sf_close(hFile); |
2585 |
file_changed(); |
file_changed(); |
2590 |
} |
} |
2591 |
// 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 |
2592 |
if (!error_files.empty()) { |
if (!error_files.empty()) { |
2593 |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
Glib::ustring txt = |
2594 |
|
(replace |
2595 |
|
? _("Failed to replace sample with:\n") |
2596 |
|
: _("Could not add the following sample(s):\n")) |
2597 |
|
+ error_files; |
2598 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
2599 |
msg.run(); |
msg.run(); |
2600 |
} |
} |
2637 |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); |
2638 |
description.show(); |
description.show(); |
2639 |
entryArea.show_all(); |
entryArea.show_all(); |
2640 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
2641 |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Select"), Gtk::RESPONSE_OK); |
2642 |
dialog.set_select_multiple(false); |
dialog.set_select_multiple(false); |
2643 |
if (current_sample_dir != "") { |
if (current_sample_dir != "") { |
2661 |
try |
try |
2662 |
{ |
{ |
2663 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
|
int bitdepth; |
|
2664 |
switch (info.format & 0xff) { |
switch (info.format & 0xff) { |
2665 |
case SF_FORMAT_PCM_S8: |
case SF_FORMAT_PCM_S8: |
2666 |
case SF_FORMAT_PCM_16: |
case SF_FORMAT_PCM_16: |
2667 |
case SF_FORMAT_PCM_U8: |
case SF_FORMAT_PCM_U8: |
|
bitdepth = 16; |
|
|
break; |
|
2668 |
case SF_FORMAT_PCM_24: |
case SF_FORMAT_PCM_24: |
2669 |
case SF_FORMAT_PCM_32: |
case SF_FORMAT_PCM_32: |
2670 |
case SF_FORMAT_FLOAT: |
case SF_FORMAT_FLOAT: |
2671 |
case SF_FORMAT_DOUBLE: |
case SF_FORMAT_DOUBLE: |
|
bitdepth = 24; |
|
2672 |
break; |
break; |
2673 |
default: |
default: |
2674 |
sf_close(hFile); |
sf_close(hFile); |
2774 |
} |
} |
2775 |
} |
} |
2776 |
|
|
2777 |
|
void MainWindow::on_action_remove_unused_samples() { |
2778 |
|
if (!file) return; |
2779 |
|
|
2780 |
|
// collect all samples that are not referenced by any instrument |
2781 |
|
std::list<gig::Sample*> lsamples; |
2782 |
|
for (int iSample = 0; file->GetSample(iSample); ++iSample) { |
2783 |
|
gig::Sample* sample = file->GetSample(iSample); |
2784 |
|
bool isUsed = false; |
2785 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; |
2786 |
|
instrument = file->GetNextInstrument()) |
2787 |
|
{ |
2788 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
2789 |
|
rgn = instrument->GetNextRegion()) |
2790 |
|
{ |
2791 |
|
for (int i = 0; i < 256; ++i) { |
2792 |
|
if (!rgn->pDimensionRegions[i]) continue; |
2793 |
|
if (rgn->pDimensionRegions[i]->pSample != sample) continue; |
2794 |
|
isUsed = true; |
2795 |
|
goto endOfRefSearch; |
2796 |
|
} |
2797 |
|
} |
2798 |
|
} |
2799 |
|
endOfRefSearch: |
2800 |
|
if (!isUsed) lsamples.push_back(sample); |
2801 |
|
} |
2802 |
|
|
2803 |
|
if (lsamples.empty()) return; |
2804 |
|
|
2805 |
|
// notify everybody that we're going to remove these samples |
2806 |
|
samples_to_be_removed_signal.emit(lsamples); |
2807 |
|
|
2808 |
|
// remove collected samples |
2809 |
|
try { |
2810 |
|
for (std::list<gig::Sample*>::iterator itSample = lsamples.begin(); |
2811 |
|
itSample != lsamples.end(); ++itSample) |
2812 |
|
{ |
2813 |
|
gig::Sample* sample = *itSample; |
2814 |
|
// remove sample from the .gig file |
2815 |
|
file->DeleteSample(sample); |
2816 |
|
// if sample was just previously added, remove it fro the import queue |
2817 |
|
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
2818 |
|
iter != m_SampleImportQueue.end(); ++iter) |
2819 |
|
{ |
2820 |
|
if ((*iter).gig_sample == sample) { |
2821 |
|
printf("Removing previously added sample '%s'\n", |
2822 |
|
(*iter).sample_path.c_str()); |
2823 |
|
m_SampleImportQueue.erase(iter); |
2824 |
|
break; |
2825 |
|
} |
2826 |
|
} |
2827 |
|
} |
2828 |
|
} catch (RIFF::Exception e) { |
2829 |
|
// show error message |
2830 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2831 |
|
msg.run(); |
2832 |
|
} |
2833 |
|
|
2834 |
|
// notify everybody that we're done with removal |
2835 |
|
samples_removed_signal.emit(); |
2836 |
|
|
2837 |
|
dimreg_changed(); |
2838 |
|
file_changed(); |
2839 |
|
__refreshEntireGUI(); |
2840 |
|
} |
2841 |
|
|
2842 |
// see comment on on_sample_treeview_drag_begin() |
// see comment on on_sample_treeview_drag_begin() |
2843 |
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) |
2844 |
{ |
{ |
2865 |
sizeof(script)/*length of data in bytes*/); |
sizeof(script)/*length of data in bytes*/); |
2866 |
} |
} |
2867 |
|
|
2868 |
|
// see comment on on_sample_treeview_drag_begin() |
2869 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2870 |
|
{ |
2871 |
|
first_call_to_drag_data_get = true; |
2872 |
|
} |
2873 |
|
|
2874 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2875 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2876 |
|
{ |
2877 |
|
if (!first_call_to_drag_data_get) return; |
2878 |
|
first_call_to_drag_data_get = false; |
2879 |
|
|
2880 |
|
// get selected source instrument |
2881 |
|
gig::Instrument* src = NULL; |
2882 |
|
{ |
2883 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2884 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2885 |
|
if (it) { |
2886 |
|
Gtk::TreeModel::Row row = *it; |
2887 |
|
src = row[m_Columns.m_col_instr]; |
2888 |
|
} |
2889 |
|
} |
2890 |
|
if (!src) return; |
2891 |
|
|
2892 |
|
// pass the source gig::Instrument as pointer |
2893 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2894 |
|
sizeof(src)/*length of data in bytes*/); |
2895 |
|
} |
2896 |
|
|
2897 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2898 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2899 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2900 |
|
{ |
2901 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2902 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2903 |
|
return; |
2904 |
|
|
2905 |
|
gig::Instrument* dst = NULL; |
2906 |
|
{ |
2907 |
|
Gtk::TreeModel::Path path; |
2908 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2909 |
|
if (!found) return; |
2910 |
|
|
2911 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2912 |
|
if (!iter) return; |
2913 |
|
Gtk::TreeModel::Row row = *iter; |
2914 |
|
dst = row[m_Columns.m_col_instr]; |
2915 |
|
} |
2916 |
|
if (!dst) return; |
2917 |
|
|
2918 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2919 |
|
src->MoveTo(dst); |
2920 |
|
__refreshEntireGUI(); |
2921 |
|
select_instrument(src); |
2922 |
|
} |
2923 |
|
|
2924 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2925 |
// 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 |
2926 |
// 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 |
3072 |
} |
} |
3073 |
} |
} |
3074 |
|
|
3075 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
3076 |
|
Gtk::TreeViewColumn* column) |
3077 |
|
{ |
3078 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
3079 |
|
if (!iter) return; |
3080 |
|
Gtk::TreeModel::Row row = *iter; |
3081 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
3082 |
|
if (!script) return; |
3083 |
|
|
3084 |
|
ScriptEditor* editor = new ScriptEditor; |
3085 |
|
editor->setScript(script); |
3086 |
|
//editor->reparent(*this); |
3087 |
|
editor->show(); |
3088 |
|
} |
3089 |
|
|
3090 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
3091 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
3092 |
if (!iter) return; |
if (!iter) return; |
3143 |
|
|
3144 |
ReferencesView* d = new ReferencesView(*this); |
ReferencesView* d = new ReferencesView(*this); |
3145 |
d->setSample(sample); |
d->setSample(sample); |
3146 |
|
d->dimension_region_selected.connect( |
3147 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
3148 |
|
); |
3149 |
d->show_all(); |
d->show_all(); |
3150 |
d->resize(500, 400); |
d->resize(500, 400); |
3151 |
d->run(); |
d->run(); |
3219 |
); |
); |
3220 |
} |
} |
3221 |
|
|
3222 |
// Note: requires that this file already has a filename ! |
// Finally save gig file persistently to disk ... |
3223 |
this->file->Save(); |
//NOTE: requires that this gig file already has a filename ! |
3224 |
|
{ |
3225 |
|
std::cout << "Saving file\n" << std::flush; |
3226 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3227 |
|
|
3228 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3229 |
|
_("Saving") + Glib::ustring(" '") + |
3230 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3231 |
|
*this |
3232 |
|
); |
3233 |
|
progress_dialog->show_all(); |
3234 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3235 |
|
saver->signal_progress().connect( |
3236 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3237 |
|
saver->signal_finished().connect( |
3238 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3239 |
|
saver->signal_error().connect( |
3240 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3241 |
|
saver->launch(); |
3242 |
|
} |
3243 |
} |
} |
3244 |
|
|
3245 |
void MainWindow::on_action_merge_files() { |
void MainWindow::on_action_merge_files() { |
3257 |
} |
} |
3258 |
|
|
3259 |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
3260 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); |
3261 |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
3262 |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
3263 |
#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 |
3276 |
// show warning in the file picker dialog |
// show warning in the file picker dialog |
3277 |
Gtk::HBox descriptionArea; |
Gtk::HBox descriptionArea; |
3278 |
descriptionArea.set_spacing(15); |
descriptionArea.set_spacing(15); |
3279 |
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
Gtk::Image warningIcon; |
3280 |
|
warningIcon.set_from_icon_name("dialog-warning", |
3281 |
|
Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
3282 |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
3283 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
3284 |
view::WrapLabel description; |
view::WrapLabel description; |
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 |
|
} |