1 |
/* |
/* |
2 |
* Copyright (C) 2006-2013 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 |
40 |
|
|
41 |
#include <stdio.h> |
#include <stdio.h> |
42 |
#include <sndfile.h> |
#include <sndfile.h> |
43 |
|
#include <assert.h> |
44 |
|
|
45 |
#include "mainwindow.h" |
#include "mainwindow.h" |
46 |
|
#include "Settings.h" |
47 |
|
#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 |
|
|
98 |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); |
99 |
m_HPaned.add2(dimreg_vbox); |
m_HPaned.add2(dimreg_vbox); |
100 |
|
|
101 |
|
dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); |
102 |
|
dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well.")); |
103 |
|
dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below.")); |
104 |
|
dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below).")); |
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 |
|
|
136 |
Gtk::Stock::PROPERTIES), |
Gtk::Stock::PROPERTIES), |
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", |
140 |
|
_("_Midi Rules...")), |
141 |
|
sigc::mem_fun( |
142 |
|
*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"))); |
165 |
|
|
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
|
166 |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
Glib::RefPtr<Gtk::ToggleAction> toggle_action = |
167 |
|
Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); |
168 |
|
toggle_action->set_active(true); |
169 |
|
actionGroup->add(toggle_action); |
170 |
|
|
171 |
|
toggle_action = |
172 |
|
Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune")); |
173 |
|
toggle_action->set_active(true); |
174 |
|
actionGroup->add(toggle_action); |
175 |
|
|
176 |
|
toggle_action = |
177 |
|
Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); |
178 |
|
toggle_action->set_active(true); |
179 |
|
actionGroup->add(toggle_action); |
180 |
|
|
181 |
|
|
182 |
|
actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); |
183 |
|
toggle_action = |
184 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
185 |
toggle_action->set_active(true); |
toggle_action->set_active(true); |
186 |
actionGroup->add(toggle_action, |
actionGroup->add(toggle_action, |
206 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) |
207 |
); |
); |
208 |
|
|
209 |
|
|
210 |
|
actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); |
211 |
|
|
212 |
|
toggle_action = |
213 |
|
Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions")); |
214 |
|
toggle_action->set_active(Settings::singleton()->warnUserOnExtensions); |
215 |
|
actionGroup->add( |
216 |
|
toggle_action, |
217 |
|
sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) |
218 |
|
); |
219 |
|
|
220 |
|
toggle_action = |
221 |
|
Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); |
222 |
|
toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); |
223 |
|
actionGroup->add( |
224 |
|
toggle_action, |
225 |
|
sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) |
226 |
|
); |
227 |
|
|
228 |
|
|
229 |
|
actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); |
230 |
|
|
231 |
|
actionGroup->add( |
232 |
|
Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")), |
233 |
|
sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) |
234 |
|
); |
235 |
|
|
236 |
|
actionGroup->add( |
237 |
|
Gtk::Action::create("MergeFiles", _("_Merge Files...")), |
238 |
|
sigc::mem_fun(*this, &MainWindow::on_action_merge_files) |
239 |
|
); |
240 |
|
|
241 |
|
|
242 |
// sample right-click popup actions |
// sample right-click popup actions |
243 |
actionGroup->add( |
actionGroup->add( |
244 |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), |
257 |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) |
258 |
); |
); |
259 |
actionGroup->add( |
actionGroup->add( |
260 |
|
Gtk::Action::create("ShowSampleRefs", _("Show References...")), |
261 |
|
sigc::mem_fun(*this, &MainWindow::on_action_view_references) |
262 |
|
); |
263 |
|
actionGroup->add( |
264 |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
Gtk::Action::create("ReplaceAllSamplesInAllGroups", |
265 |
_("Replace All Samples in All Groups...")), |
_("Replace All Samples in All Groups...")), |
266 |
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) |
267 |
); |
); |
268 |
|
|
269 |
|
// script right-click popup actions |
270 |
|
actionGroup->add( |
271 |
|
Gtk::Action::create("AddScriptGroup", _("Add _Group")), |
272 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) |
273 |
|
); |
274 |
|
actionGroup->add( |
275 |
|
Gtk::Action::create("AddScript", _("Add _Script")), |
276 |
|
sigc::mem_fun(*this, &MainWindow::on_action_add_script) |
277 |
|
); |
278 |
|
actionGroup->add( |
279 |
|
Gtk::Action::create("EditScript", _("_Edit Script...")), |
280 |
|
sigc::mem_fun(*this, &MainWindow::on_action_edit_script) |
281 |
|
); |
282 |
|
actionGroup->add( |
283 |
|
Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), |
284 |
|
sigc::mem_fun(*this, &MainWindow::on_action_remove_script) |
285 |
|
); |
286 |
|
|
287 |
uiManager = Gtk::UIManager::create(); |
uiManager = Gtk::UIManager::create(); |
288 |
uiManager->insert_action_group(actionGroup); |
uiManager->insert_action_group(actionGroup); |
302 |
" <separator/>" |
" <separator/>" |
303 |
" <menuitem action='Quit'/>" |
" <menuitem action='Quit'/>" |
304 |
" </menu>" |
" </menu>" |
305 |
|
" <menu action='MenuEdit'>" |
306 |
|
" <menuitem action='CopySampleUnity'/>" |
307 |
|
" <menuitem action='CopySampleTune'/>" |
308 |
|
" <menuitem action='CopySampleLoop'/>" |
309 |
|
" </menu>" |
310 |
|
" <menu action='MenuSample'>" |
311 |
|
" <menuitem action='SampleProperties'/>" |
312 |
|
" <menuitem action='AddGroup'/>" |
313 |
|
" <menuitem action='AddSample'/>" |
314 |
|
" <menuitem action='ShowSampleRefs'/>" |
315 |
|
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
316 |
|
" <separator/>" |
317 |
|
" <menuitem action='RemoveSample'/>" |
318 |
|
" </menu>" |
319 |
" <menu action='MenuInstrument'>" |
" <menu action='MenuInstrument'>" |
320 |
|
" <menu action='AllInstruments'>" |
321 |
|
" </menu>" |
322 |
|
" <separator/>" |
323 |
|
" <menuitem action='InstrProperties'/>" |
324 |
|
" <menuitem action='MidiRules'/>" |
325 |
|
" <menuitem action='ScriptSlots'/>" |
326 |
|
" <menuitem action='AddInstrument'/>" |
327 |
|
" <menuitem action='DupInstrument'/>" |
328 |
|
" <separator/>" |
329 |
|
" <menuitem action='RemoveInstrument'/>" |
330 |
|
" </menu>" |
331 |
|
" <menu action='MenuScript'>" |
332 |
|
" <menuitem action='AddScriptGroup'/>" |
333 |
|
" <menuitem action='AddScript'/>" |
334 |
|
" <menuitem action='EditScript'/>" |
335 |
|
" <separator/>" |
336 |
|
" <menuitem action='RemoveScript'/>" |
337 |
" </menu>" |
" </menu>" |
338 |
" <menu action='MenuView'>" |
" <menu action='MenuView'>" |
339 |
" <menuitem action='Statusbar'/>" |
" <menuitem action='Statusbar'/>" |
340 |
" </menu>" |
" </menu>" |
341 |
|
" <menu action='MenuTools'>" |
342 |
|
" <menuitem action='CombineInstruments'/>" |
343 |
|
" <menuitem action='MergeFiles'/>" |
344 |
|
" </menu>" |
345 |
|
" <menu action='MenuSettings'>" |
346 |
|
" <menuitem action='WarnUserOnExtensions'/>" |
347 |
|
" <menuitem action='SyncSamplerInstrumentSelection'/>" |
348 |
|
" </menu>" |
349 |
" <menu action='MenuHelp'>" |
" <menu action='MenuHelp'>" |
350 |
" <menuitem action='About'/>" |
" <menuitem action='About'/>" |
351 |
" </menu>" |
" </menu>" |
352 |
" </menubar>" |
" </menubar>" |
353 |
" <popup name='PopupMenu'>" |
" <popup name='PopupMenu'>" |
354 |
" <menuitem action='InstrProperties'/>" |
" <menuitem action='InstrProperties'/>" |
355 |
|
" <menuitem action='MidiRules'/>" |
356 |
|
" <menuitem action='ScriptSlots'/>" |
357 |
" <menuitem action='AddInstrument'/>" |
" <menuitem action='AddInstrument'/>" |
358 |
" <menuitem action='DupInstrument'/>" |
" <menuitem action='DupInstrument'/>" |
359 |
" <separator/>" |
" <separator/>" |
363 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
364 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
365 |
" <menuitem action='AddSample'/>" |
" <menuitem action='AddSample'/>" |
366 |
|
" <menuitem action='ShowSampleRefs'/>" |
367 |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
" <menuitem action='ReplaceAllSamplesInAllGroups' />" |
368 |
" <separator/>" |
" <separator/>" |
369 |
" <menuitem action='RemoveSample'/>" |
" <menuitem action='RemoveSample'/>" |
370 |
" </popup>" |
" </popup>" |
371 |
|
" <popup name='ScriptPopupMenu'>" |
372 |
|
" <menuitem action='AddScriptGroup'/>" |
373 |
|
" <menuitem action='AddScript'/>" |
374 |
|
" <menuitem action='EditScript'/>" |
375 |
|
" <separator/>" |
376 |
|
" <menuitem action='RemoveScript'/>" |
377 |
|
" </popup>" |
378 |
"</ui>"; |
"</ui>"; |
379 |
uiManager->add_ui_from_string(ui_info); |
uiManager->add_ui_from_string(ui_info); |
380 |
|
|
381 |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu")); |
382 |
|
|
383 |
|
// Set tooltips for menu items (for some reason, setting a tooltip on the |
384 |
|
// respective Gtk::Action objects above will simply be ignored, no matter |
385 |
|
// if using Gtk::Action::set_tooltip() or passing the tooltip string on |
386 |
|
// Gtk::Action::create()). |
387 |
|
{ |
388 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
389 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
390 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action.")); |
391 |
|
} |
392 |
|
{ |
393 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
394 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
395 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action.")); |
396 |
|
} |
397 |
|
{ |
398 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
399 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
400 |
|
item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action.")); |
401 |
|
} |
402 |
|
{ |
403 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
404 |
|
uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions")); |
405 |
|
item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application.")); |
406 |
|
} |
407 |
|
{ |
408 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
409 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
410 |
|
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).")); |
411 |
|
} |
412 |
|
{ |
413 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
414 |
|
uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); |
415 |
|
item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); |
416 |
|
} |
417 |
|
{ |
418 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
419 |
|
uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); |
420 |
|
item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
instrument_menu = static_cast<Gtk::MenuItem*>( |
instrument_menu = static_cast<Gtk::MenuItem*>( |
425 |
uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); |
426 |
|
|
427 |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); |
428 |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); |
448 |
// Create the Tree model: |
// Create the Tree model: |
449 |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
m_refTreeModel = Gtk::ListStore::create(m_Columns); |
450 |
m_TreeView.set_model(m_refTreeModel); |
m_TreeView.set_model(m_refTreeModel); |
451 |
|
m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); |
452 |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
instrument_name_connection = m_refTreeModel->signal_row_changed().connect( |
453 |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
sigc::mem_fun(*this, &MainWindow::instrument_name_changed) |
454 |
); |
); |
456 |
// Add the TreeView's view columns: |
// Add the TreeView's view columns: |
457 |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); |
458 |
m_TreeView.set_headers_visible(false); |
m_TreeView.set_headers_visible(false); |
459 |
|
|
460 |
|
// establish drag&drop within the instrument tree view, allowing to reorder |
461 |
|
// the sequence of instruments within the gig file |
462 |
|
{ |
463 |
|
std::vector<Gtk::TargetEntry> drag_target_instrument; |
464 |
|
drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); |
465 |
|
m_TreeView.drag_source_set(drag_target_instrument); |
466 |
|
m_TreeView.drag_dest_set(drag_target_instrument); |
467 |
|
m_TreeView.signal_drag_begin().connect( |
468 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) |
469 |
|
); |
470 |
|
m_TreeView.signal_drag_data_get().connect( |
471 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) |
472 |
|
); |
473 |
|
m_TreeView.signal_drag_data_received().connect( |
474 |
|
sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) |
475 |
|
); |
476 |
|
} |
477 |
|
|
478 |
// create samples treeview (including its data model) |
// create samples treeview (including its data model) |
479 |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); |
480 |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
m_TreeViewSamples.set_model(m_refSamplesTreeModel); |
481 |
|
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.")); |
482 |
// m_TreeViewSamples.set_reorderable(); |
// m_TreeViewSamples.set_reorderable(); |
483 |
m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); |
m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); |
484 |
m_TreeViewSamples.set_headers_visible(false); |
m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); |
485 |
|
{ |
486 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); |
487 |
|
Gtk::CellRendererText* cellrenderer = |
488 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
489 |
|
column->add_attribute( |
490 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
491 |
|
); |
492 |
|
} |
493 |
|
{ |
494 |
|
Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); |
495 |
|
Gtk::CellRendererText* cellrenderer = |
496 |
|
dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell()); |
497 |
|
column->add_attribute( |
498 |
|
cellrenderer->property_foreground(), m_SamplesModel.m_color |
499 |
|
); |
500 |
|
} |
501 |
|
m_TreeViewSamples.set_headers_visible(true); |
502 |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
m_TreeViewSamples.signal_button_press_event().connect_notify( |
503 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) |
504 |
); |
); |
506 |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
sigc::mem_fun(*this, &MainWindow::sample_name_changed) |
507 |
); |
); |
508 |
|
|
509 |
|
// create scripts treeview (including its data model) |
510 |
|
m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); |
511 |
|
m_TreeViewScripts.set_model(m_refScriptsTreeModel); |
512 |
|
m_TreeViewScripts.set_tooltip_text(_( |
513 |
|
"Use CTRL + double click for editing a script." |
514 |
|
"\n\n" |
515 |
|
"Note: instrument scripts are a LinuxSampler extension of the gig " |
516 |
|
"format. This feature will not work with the GigaStudio software!" |
517 |
|
)); |
518 |
|
// m_TreeViewScripts.set_reorderable(); |
519 |
|
m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); |
520 |
|
m_TreeViewScripts.set_headers_visible(false); |
521 |
|
m_TreeViewScripts.signal_button_press_event().connect_notify( |
522 |
|
sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) |
523 |
|
); |
524 |
|
//FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? |
525 |
|
m_TreeViewScripts.signal_row_activated().connect( |
526 |
|
sigc::mem_fun(*this, &MainWindow::script_double_clicked) |
527 |
|
); |
528 |
|
m_refScriptsTreeModel->signal_row_changed().connect( |
529 |
|
sigc::mem_fun(*this, &MainWindow::script_name_changed) |
530 |
|
); |
531 |
|
|
532 |
|
// establish drag&drop between scripts tree view and ScriptSlots window |
533 |
|
std::vector<Gtk::TargetEntry> drag_target_gig_script; |
534 |
|
drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); |
535 |
|
m_TreeViewScripts.drag_source_set(drag_target_gig_script); |
536 |
|
m_TreeViewScripts.signal_drag_begin().connect( |
537 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) |
538 |
|
); |
539 |
|
m_TreeViewScripts.signal_drag_data_get().connect( |
540 |
|
sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) |
541 |
|
); |
542 |
|
|
543 |
// 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 |
544 |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
std::vector<Gtk::TargetEntry> drag_target_gig_sample; |
545 |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); |
564 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
565 |
propDialog.signal_changed().connect( |
propDialog.signal_changed().connect( |
566 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
567 |
|
midiRules.signal_changed().connect( |
568 |
|
sigc::mem_fun(*this, &MainWindow::file_changed)); |
569 |
|
|
570 |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
dimreg_edit.signal_dimreg_to_be_changed().connect( |
571 |
dimreg_to_be_changed_signal.make_slot()); |
dimreg_to_be_changed_signal.make_slot()); |
573 |
dimreg_changed_signal.make_slot()); |
dimreg_changed_signal.make_slot()); |
574 |
dimreg_edit.signal_sample_ref_changed().connect( |
dimreg_edit.signal_sample_ref_changed().connect( |
575 |
sample_ref_changed_signal.make_slot()); |
sample_ref_changed_signal.make_slot()); |
576 |
|
sample_ref_changed_signal.connect( |
577 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) |
578 |
|
); |
579 |
|
samples_to_be_removed_signal.connect( |
580 |
|
sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) |
581 |
|
); |
582 |
|
|
583 |
|
dimreg_edit.signal_select_sample().connect( |
584 |
|
sigc::mem_fun(*this, &MainWindow::select_sample) |
585 |
|
); |
586 |
|
|
587 |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
588 |
sigc::hide( |
sigc::hide( |
624 |
|
|
625 |
// start with a new gig file by default |
// start with a new gig file by default |
626 |
on_action_file_new(); |
on_action_file_new(); |
627 |
|
|
628 |
|
// select 'Instruments' tab by default |
629 |
|
// (gtk allows this only if the tab childs are visible, thats why it's here) |
630 |
|
m_TreeViewNotebook.set_current_page(1); |
631 |
} |
} |
632 |
|
|
633 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
708 |
void MainWindow::dimreg_changed() |
void MainWindow::dimreg_changed() |
709 |
{ |
{ |
710 |
update_dimregs(); |
update_dimregs(); |
711 |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); |
dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); |
712 |
} |
} |
713 |
|
|
714 |
void MainWindow::on_sel_change() |
void MainWindow::on_sel_change() |
724 |
} |
} |
725 |
|
|
726 |
m_RegionChooser.set_instrument(get_instrument()); |
m_RegionChooser.set_instrument(get_instrument()); |
727 |
|
|
728 |
|
if (Settings::singleton()->syncSamplerInstrumentSelection) { |
729 |
|
switch_sampler_instrument_signal.emit(get_instrument()); |
730 |
|
} |
731 |
} |
} |
732 |
|
|
733 |
void loader_progress_callback(gig::progress_t* progress) |
void loader_progress_callback(gig::progress_t* progress) |
748 |
void Loader::thread_function() |
void Loader::thread_function() |
749 |
{ |
{ |
750 |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
751 |
printf("Start %s\n", filename); |
printf("Start %s\n", filename.c_str()); |
752 |
RIFF::File* riff = new RIFF::File(filename); |
try { |
753 |
gig = new gig::File(riff); |
RIFF::File* riff = new RIFF::File(filename); |
754 |
gig::progress_t progress; |
gig = new gig::File(riff); |
755 |
progress.callback = loader_progress_callback; |
gig::progress_t progress; |
756 |
progress.custom = this; |
progress.callback = loader_progress_callback; |
757 |
|
progress.custom = this; |
758 |
gig->GetInstrument(0, &progress); |
|
759 |
printf("End\n"); |
gig->GetInstrument(0, &progress); |
760 |
finished_dispatcher(); |
printf("End\n"); |
761 |
|
finished_dispatcher(); |
762 |
|
} catch (RIFF::Exception e) { |
763 |
|
error_message = e.Message; |
764 |
|
error_dispatcher.emit(); |
765 |
|
} catch (...) { |
766 |
|
error_message = _("Unknown exception occurred"); |
767 |
|
error_dispatcher.emit(); |
768 |
|
} |
769 |
} |
} |
770 |
|
|
771 |
Loader::Loader(const char* filename) |
Loader::Loader(const char* filename) |
772 |
: filename(filename), thread(0) |
: filename(filename), thread(0), progress(0.f) |
773 |
{ |
{ |
774 |
} |
} |
775 |
|
|
803 |
return finished_dispatcher; |
return finished_dispatcher; |
804 |
} |
} |
805 |
|
|
806 |
LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) |
Glib::Dispatcher& Loader::signal_error() |
807 |
|
{ |
808 |
|
return error_dispatcher; |
809 |
|
} |
810 |
|
|
811 |
|
void saver_progress_callback(gig::progress_t* progress) |
812 |
|
{ |
813 |
|
Saver* saver = static_cast<Saver*>(progress->custom); |
814 |
|
saver->progress_callback(progress->factor); |
815 |
|
} |
816 |
|
|
817 |
|
void Saver::progress_callback(float fraction) |
818 |
|
{ |
819 |
|
{ |
820 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
821 |
|
progress = fraction; |
822 |
|
} |
823 |
|
progress_dispatcher.emit(); |
824 |
|
} |
825 |
|
|
826 |
|
void Saver::thread_function() |
827 |
|
{ |
828 |
|
printf("thread_function self=%x\n", Glib::Threads::Thread::self()); |
829 |
|
printf("Start %s\n", filename.c_str()); |
830 |
|
try { |
831 |
|
gig::progress_t progress; |
832 |
|
progress.callback = saver_progress_callback; |
833 |
|
progress.custom = this; |
834 |
|
|
835 |
|
// if no filename was provided, that means "save", if filename was provided means "save as" |
836 |
|
if (filename.empty()) { |
837 |
|
gig->Save(&progress); |
838 |
|
} else { |
839 |
|
gig->Save(filename, &progress); |
840 |
|
} |
841 |
|
|
842 |
|
printf("End\n"); |
843 |
|
finished_dispatcher.emit(); |
844 |
|
} catch (RIFF::Exception e) { |
845 |
|
error_message = e.Message; |
846 |
|
error_dispatcher.emit(); |
847 |
|
} catch (...) { |
848 |
|
error_message = _("Unknown exception occurred"); |
849 |
|
error_dispatcher.emit(); |
850 |
|
} |
851 |
|
} |
852 |
|
|
853 |
|
Saver::Saver(gig::File* file, Glib::ustring filename) |
854 |
|
: gig(file), filename(filename), thread(0), progress(0.f) |
855 |
|
{ |
856 |
|
} |
857 |
|
|
858 |
|
void Saver::launch() |
859 |
|
{ |
860 |
|
#ifdef OLD_THREADS |
861 |
|
thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); |
862 |
|
#else |
863 |
|
thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); |
864 |
|
#endif |
865 |
|
printf("launch thread=%x\n", thread); |
866 |
|
} |
867 |
|
|
868 |
|
float Saver::get_progress() |
869 |
|
{ |
870 |
|
float res; |
871 |
|
{ |
872 |
|
Glib::Threads::Mutex::Lock lock(progressMutex); |
873 |
|
res = progress; |
874 |
|
} |
875 |
|
return res; |
876 |
|
} |
877 |
|
|
878 |
|
Glib::Dispatcher& Saver::signal_progress() |
879 |
|
{ |
880 |
|
return progress_dispatcher; |
881 |
|
} |
882 |
|
|
883 |
|
Glib::Dispatcher& Saver::signal_finished() |
884 |
|
{ |
885 |
|
return finished_dispatcher; |
886 |
|
} |
887 |
|
|
888 |
|
Glib::Dispatcher& Saver::signal_error() |
889 |
|
{ |
890 |
|
return error_dispatcher; |
891 |
|
} |
892 |
|
|
893 |
|
ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) |
894 |
: Gtk::Dialog(title, parent, true) |
: Gtk::Dialog(title, parent, true) |
895 |
{ |
{ |
896 |
get_vbox()->pack_start(progressBar); |
get_vbox()->pack_start(progressBar); |
897 |
show_all_children(); |
show_all_children(); |
898 |
|
resize(600,50); |
899 |
} |
} |
900 |
|
|
901 |
// Clear all GUI elements / controls. This method is typically called |
// Clear all GUI elements / controls. This method is typically called |
906 |
// clear the samples and instruments tree views |
// clear the samples and instruments tree views |
907 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
908 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
909 |
|
m_refScriptsTreeModel->clear(); |
910 |
// remove all entries from "Instrument" menu |
// remove all entries from "Instrument" menu |
911 |
while (!instrument_menu->get_children().empty()) { |
while (!instrument_menu->get_children().empty()) { |
912 |
remove_instrument_from_menu(0); |
remove_instrument_from_menu(0); |
917 |
set_file_is_shared(false); |
set_file_is_shared(false); |
918 |
} |
} |
919 |
|
|
920 |
|
void MainWindow::__refreshEntireGUI() { |
921 |
|
// clear the samples and instruments tree views |
922 |
|
m_refTreeModel->clear(); |
923 |
|
m_refSamplesTreeModel->clear(); |
924 |
|
m_refScriptsTreeModel->clear(); |
925 |
|
// remove all entries from "Instrument" menu |
926 |
|
while (!instrument_menu->get_children().empty()) { |
927 |
|
remove_instrument_from_menu(0); |
928 |
|
} |
929 |
|
|
930 |
|
if (!this->file) return; |
931 |
|
|
932 |
|
load_gig( |
933 |
|
this->file, this->file->pInfo->Name.c_str(), this->file_is_shared |
934 |
|
); |
935 |
|
} |
936 |
|
|
937 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
938 |
{ |
{ |
939 |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
964 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
965 |
int response = dialog.run(); |
int response = dialog.run(); |
966 |
dialog.hide(); |
dialog.hide(); |
967 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
|
968 |
return response != Gtk::RESPONSE_CANCEL; |
// user decided to exit app without saving |
969 |
|
if (response == Gtk::RESPONSE_NO) return true; |
970 |
|
|
971 |
|
// user cancelled dialog, thus don't close app |
972 |
|
if (response == Gtk::RESPONSE_CANCEL) return false; |
973 |
|
|
974 |
|
// TODO: the following return valid is disabled and hard coded instead for |
975 |
|
// now, due to the fact that saving with progress bar is now implemented |
976 |
|
// asynchronously, as a result the app does not close automatically anymore |
977 |
|
// after saving the file has completed |
978 |
|
// |
979 |
|
// if (response == Gtk::RESPONSE_YES) return file_save(); |
980 |
|
// return response != Gtk::RESPONSE_CANCEL; |
981 |
|
// |
982 |
|
if (response == Gtk::RESPONSE_YES) file_save(); |
983 |
|
return false; // always prevent closing the app for now (see comment above) |
984 |
} |
} |
985 |
|
|
986 |
bool MainWindow::leaving_shared_mode_dialog() { |
bool MainWindow::leaving_shared_mode_dialog() { |
1031 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
1032 |
{ |
{ |
1033 |
__clear(); |
__clear(); |
1034 |
load_dialog = new LoadDialog(_("Loading..."), *this); |
|
1035 |
load_dialog->show_all(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1036 |
loader = new Loader(strdup(name)); |
_("Loading") + Glib::ustring(" '") + |
1037 |
|
Glib::filename_display_basename(name) + "' ...", |
1038 |
|
*this |
1039 |
|
); |
1040 |
|
progress_dialog->show_all(); |
1041 |
|
loader = new Loader(name); //FIXME: memory leak! |
1042 |
loader->signal_progress().connect( |
loader->signal_progress().connect( |
1043 |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
sigc::mem_fun(*this, &MainWindow::on_loader_progress)); |
1044 |
loader->signal_finished().connect( |
loader->signal_finished().connect( |
1045 |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
sigc::mem_fun(*this, &MainWindow::on_loader_finished)); |
1046 |
|
loader->signal_error().connect( |
1047 |
|
sigc::mem_fun(*this, &MainWindow::on_loader_error)); |
1048 |
loader->launch(); |
loader->launch(); |
1049 |
} |
} |
1050 |
|
|
1060 |
// load the instrument |
// load the instrument |
1061 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
1062 |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
1063 |
//TODO: automatically select the given instrument |
// automatically select the given instrument |
1064 |
|
int i = 0; |
1065 |
|
for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; |
1066 |
|
instrument = pFile->GetNextInstrument(), ++i) |
1067 |
|
{ |
1068 |
|
if (instrument == instr) { |
1069 |
|
// select item in "instruments" tree view |
1070 |
|
m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); |
1071 |
|
// make sure the selected item in the "instruments" tree view is |
1072 |
|
// visible (scroll to it) |
1073 |
|
m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); |
1074 |
|
// select item in instrument menu |
1075 |
|
{ |
1076 |
|
const std::vector<Gtk::Widget*> children = |
1077 |
|
instrument_menu->get_children(); |
1078 |
|
static_cast<Gtk::RadioMenuItem*>(children[i])->set_active(); |
1079 |
|
} |
1080 |
|
// update region chooser and dimension region chooser |
1081 |
|
m_RegionChooser.set_instrument(instr); |
1082 |
|
break; |
1083 |
|
} |
1084 |
|
} |
1085 |
} |
} |
1086 |
|
|
1087 |
void MainWindow::on_loader_progress() |
void MainWindow::on_loader_progress() |
1088 |
{ |
{ |
1089 |
load_dialog->set_fraction(loader->get_progress()); |
progress_dialog->set_fraction(loader->get_progress()); |
1090 |
} |
} |
1091 |
|
|
1092 |
void MainWindow::on_loader_finished() |
void MainWindow::on_loader_finished() |
1093 |
{ |
{ |
1094 |
printf("Loader finished!\n"); |
printf("Loader finished!\n"); |
1095 |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); |
1096 |
load_gig(loader->gig, loader->filename); |
load_gig(loader->gig, loader->filename.c_str()); |
1097 |
load_dialog->hide(); |
progress_dialog->hide(); |
1098 |
|
} |
1099 |
|
|
1100 |
|
void MainWindow::on_loader_error() |
1101 |
|
{ |
1102 |
|
Glib::ustring txt = _("Could not load file: ") + loader->error_message; |
1103 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1104 |
|
msg.run(); |
1105 |
|
progress_dialog->hide(); |
1106 |
} |
} |
1107 |
|
|
1108 |
void MainWindow::on_action_file_save() |
void MainWindow::on_action_file_save() |
1141 |
|
|
1142 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
1143 |
file_structure_to_be_changed_signal.emit(this->file); |
file_structure_to_be_changed_signal.emit(this->file); |
1144 |
try { |
|
1145 |
file->Save(); |
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1146 |
if (file_is_changed) { |
_("Saving") + Glib::ustring(" '") + |
1147 |
set_title(get_title().substr(1)); |
Glib::filename_display_basename(this->filename) + "' ...", |
1148 |
file_is_changed = false; |
*this |
1149 |
} |
); |
1150 |
} catch (RIFF::Exception e) { |
progress_dialog->show_all(); |
1151 |
file_structure_changed_signal.emit(this->file); |
saver = new Saver(this->file); //FIXME: memory leak! |
1152 |
Glib::ustring txt = _("Could not save file: ") + e.Message; |
saver->signal_progress().connect( |
1153 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1154 |
msg.run(); |
saver->signal_finished().connect( |
1155 |
return false; |
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1156 |
} |
saver->signal_error().connect( |
1157 |
std::cout << "Saving file done\n" << std::flush; |
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1158 |
|
saver->launch(); |
1159 |
|
|
1160 |
|
return true; |
1161 |
|
} |
1162 |
|
|
1163 |
|
void MainWindow::on_saver_progress() |
1164 |
|
{ |
1165 |
|
progress_dialog->set_fraction(saver->get_progress()); |
1166 |
|
} |
1167 |
|
|
1168 |
|
void MainWindow::on_saver_error() |
1169 |
|
{ |
1170 |
|
file_structure_changed_signal.emit(this->file); |
1171 |
|
Glib::ustring txt = _("Could not save file: ") + saver->error_message; |
1172 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1173 |
|
msg.run(); |
1174 |
|
} |
1175 |
|
|
1176 |
|
void MainWindow::on_saver_finished() |
1177 |
|
{ |
1178 |
|
this->file = saver->gig; |
1179 |
|
this->filename = saver->filename; |
1180 |
|
current_gig_dir = Glib::path_get_dirname(filename); |
1181 |
|
set_title(Glib::filename_display_basename(filename)); |
1182 |
|
file_has_name = true; |
1183 |
|
file_is_changed = false; |
1184 |
|
std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; |
1185 |
__import_queued_samples(); |
__import_queued_samples(); |
1186 |
|
std::cout << "Importing queued samples done.\n" << std::flush; |
1187 |
|
|
1188 |
file_structure_changed_signal.emit(this->file); |
file_structure_changed_signal.emit(this->file); |
1189 |
return true; |
|
1190 |
|
__refreshEntireGUI(); |
1191 |
|
progress_dialog->hide(); |
1192 |
} |
} |
1193 |
|
|
1194 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
1253 |
descriptionArea.show_all(); |
descriptionArea.show_all(); |
1254 |
|
|
1255 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
1256 |
file_structure_to_be_changed_signal.emit(this->file); |
std::string filename = dialog.get_filename(); |
1257 |
try { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
1258 |
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; |
|
1259 |
} |
} |
1260 |
__import_queued_samples(); |
printf("filename=%s\n", filename.c_str()); |
1261 |
file_structure_changed_signal.emit(this->file); |
|
1262 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
1263 |
|
_("Saving") + Glib::ustring(" '") + |
1264 |
|
Glib::filename_display_basename(filename) + "' ...", |
1265 |
|
*this |
1266 |
|
); |
1267 |
|
progress_dialog->show_all(); |
1268 |
|
|
1269 |
|
saver = new Saver(file, filename); //FIXME: memory leak! |
1270 |
|
saver->signal_progress().connect( |
1271 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
1272 |
|
saver->signal_finished().connect( |
1273 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
1274 |
|
saver->signal_error().connect( |
1275 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
1276 |
|
saver->launch(); |
1277 |
|
|
1278 |
return true; |
return true; |
1279 |
} |
} |
1280 |
return false; |
return false; |
1380 |
propDialog.deiconify(); |
propDialog.deiconify(); |
1381 |
} |
} |
1382 |
|
|
1383 |
|
void MainWindow::on_action_warn_user_on_extensions() { |
1384 |
|
Settings::singleton()->warnUserOnExtensions = |
1385 |
|
!Settings::singleton()->warnUserOnExtensions; |
1386 |
|
} |
1387 |
|
|
1388 |
|
void MainWindow::on_action_sync_sampler_instrument_selection() { |
1389 |
|
Settings::singleton()->syncSamplerInstrumentSelection = |
1390 |
|
!Settings::singleton()->syncSamplerInstrumentSelection; |
1391 |
|
} |
1392 |
|
|
1393 |
void MainWindow::on_action_help_about() |
void MainWindow::on_action_help_about() |
1394 |
{ |
{ |
1395 |
Gtk::AboutDialog dialog; |
Gtk::AboutDialog dialog; |
1399 |
dialog.set_name("Gigedit"); |
dialog.set_name("Gigedit"); |
1400 |
#endif |
#endif |
1401 |
dialog.set_version(VERSION); |
dialog.set_version(VERSION); |
1402 |
dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson"); |
dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); |
1403 |
dialog.set_comments(_( |
const std::string sComment = |
1404 |
"Released under the GNU General Public License.\n" |
_("Built " __DATE__ "\nUsing ") + |
1405 |
"\n" |
::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + |
1406 |
"Please notice that this is still a very young instrument editor. " |
_( |
1407 |
"So better backup your Gigasampler files before editing them with " |
"Gigedit is released under the GNU General Public License.\n" |
1408 |
"this application.\n" |
"\n" |
1409 |
"\n" |
"This program is distributed WITHOUT ANY WARRANTY; So better " |
1410 |
"Please report bugs to: http://bugs.linuxsampler.org") |
"backup your Gigasampler/GigaStudio files before editing them with " |
1411 |
); |
"this application.\n" |
1412 |
|
"\n" |
1413 |
|
"Please report bugs to: http://bugs.linuxsampler.org" |
1414 |
|
); |
1415 |
|
dialog.set_comments(sComment.c_str()); |
1416 |
dialog.set_website("http://www.linuxsampler.org"); |
dialog.set_website("http://www.linuxsampler.org"); |
1417 |
dialog.set_website_label("http://www.linuxsampler.org"); |
dialog.set_website_label("http://www.linuxsampler.org"); |
1418 |
dialog.run(); |
dialog.run(); |
1419 |
} |
} |
1420 |
|
|
1421 |
PropDialog::PropDialog() |
PropDialog::PropDialog() |
1422 |
: eName(_("Name")), |
: eFileFormat(_("File Format")), |
1423 |
|
eName(_("Name")), |
1424 |
eCreationDate(_("Creation date")), |
eCreationDate(_("Creation date")), |
1425 |
eComments(_("Comments")), |
eComments(_("Comments")), |
1426 |
eProduct(_("Product")), |
eProduct(_("Product")), |
1437 |
eCommissioned(_("Commissioned")), |
eCommissioned(_("Commissioned")), |
1438 |
eSubject(_("Subject")), |
eSubject(_("Subject")), |
1439 |
quitButton(Gtk::Stock::CLOSE), |
quitButton(Gtk::Stock::CLOSE), |
1440 |
table(2, 1) |
table(2, 1), |
1441 |
|
m_file(NULL) |
1442 |
{ |
{ |
1443 |
set_title(_("File Properties")); |
set_title(_("File Properties")); |
1444 |
eName.set_width_chars(50); |
eName.set_width_chars(50); |
1460 |
connect(eCommissioned, &DLS::Info::Commissioned); |
connect(eCommissioned, &DLS::Info::Commissioned); |
1461 |
connect(eSubject, &DLS::Info::Subject); |
connect(eSubject, &DLS::Info::Subject); |
1462 |
|
|
1463 |
|
table.add(eFileFormat); |
1464 |
table.add(eName); |
table.add(eName); |
1465 |
table.add(eCreationDate); |
table.add(eCreationDate); |
1466 |
table.add(eComments); |
table.add(eComments); |
1491 |
quitButton.grab_focus(); |
quitButton.grab_focus(); |
1492 |
quitButton.signal_clicked().connect( |
quitButton.signal_clicked().connect( |
1493 |
sigc::mem_fun(*this, &PropDialog::hide)); |
sigc::mem_fun(*this, &PropDialog::hide)); |
1494 |
|
eFileFormat.signal_value_changed().connect( |
1495 |
|
sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); |
1496 |
|
|
1497 |
quitButton.show(); |
quitButton.show(); |
1498 |
vbox.show(); |
vbox.show(); |
1499 |
show_all_children(); |
show_all_children(); |
1500 |
} |
} |
1501 |
|
|
1502 |
|
void PropDialog::set_file(gig::File* file) |
1503 |
|
{ |
1504 |
|
m_file = file; |
1505 |
|
|
1506 |
|
// update file format version combo box |
1507 |
|
const std::string sGiga = "Gigasampler/GigaStudio v"; |
1508 |
|
const int major = file->pVersion->major; |
1509 |
|
std::vector<std::string> txts; |
1510 |
|
std::vector<int> values; |
1511 |
|
txts.push_back(sGiga + "2"); values.push_back(2); |
1512 |
|
txts.push_back(sGiga + "3/v4"); values.push_back(3); |
1513 |
|
if (major != 2 && major != 3) { |
1514 |
|
txts.push_back(sGiga + ToString(major)); values.push_back(major); |
1515 |
|
} |
1516 |
|
std::vector<const char*> texts; |
1517 |
|
for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); |
1518 |
|
texts.push_back(NULL); values.push_back(0); |
1519 |
|
eFileFormat.set_choices(&texts[0], &values[0]); |
1520 |
|
eFileFormat.set_value(major); |
1521 |
|
} |
1522 |
|
|
1523 |
|
void PropDialog::onFileFormatChanged() { |
1524 |
|
const int major = eFileFormat.get_value(); |
1525 |
|
if (m_file) m_file->pVersion->major = major; |
1526 |
|
} |
1527 |
|
|
1528 |
void PropDialog::set_info(DLS::Info* info) |
void PropDialog::set_info(DLS::Info* info) |
1529 |
{ |
{ |
1530 |
update(info); |
update(info); |
1656 |
} |
} |
1657 |
} |
} |
1658 |
|
|
1659 |
|
void MainWindow::updateSampleRefCountMap(gig::File* gig) { |
1660 |
|
sample_ref_count.clear(); |
1661 |
|
|
1662 |
|
if (!gig) return; |
1663 |
|
|
1664 |
|
for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; |
1665 |
|
instrument = gig->GetNextInstrument()) |
1666 |
|
{ |
1667 |
|
for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; |
1668 |
|
rgn = instrument->GetNextRegion()) |
1669 |
|
{ |
1670 |
|
for (int i = 0; i < 256; ++i) { |
1671 |
|
if (!rgn->pDimensionRegions[i]) continue; |
1672 |
|
if (rgn->pDimensionRegions[i]->pSample) { |
1673 |
|
sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; |
1674 |
|
} |
1675 |
|
} |
1676 |
|
} |
1677 |
|
} |
1678 |
|
} |
1679 |
|
|
1680 |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
1681 |
{ |
{ |
1682 |
file = 0; |
file = 0; |
1687 |
file_has_name = filename; |
file_has_name = filename; |
1688 |
file_is_changed = false; |
file_is_changed = false; |
1689 |
|
|
1690 |
|
propDialog.set_file(gig); |
1691 |
propDialog.set_info(gig->pInfo); |
propDialog.set_info(gig->pInfo); |
1692 |
|
|
1693 |
instrument_name_connection.block(); |
instrument_name_connection.block(); |
1703 |
add_instrument_to_menu(name); |
add_instrument_to_menu(name); |
1704 |
} |
} |
1705 |
instrument_name_connection.unblock(); |
instrument_name_connection.unblock(); |
1706 |
uiManager->get_widget("/MenuBar/MenuInstrument")->show(); |
uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); |
1707 |
|
|
1708 |
|
updateSampleRefCountMap(gig); |
1709 |
|
|
1710 |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { |
1711 |
if (group->Name != "") { |
if (group->Name != "") { |
1723 |
gig_to_utf8(sample->pInfo->Name); |
gig_to_utf8(sample->pInfo->Name); |
1724 |
rowSample[m_SamplesModel.m_col_sample] = sample; |
rowSample[m_SamplesModel.m_col_sample] = sample; |
1725 |
rowSample[m_SamplesModel.m_col_group] = NULL; |
rowSample[m_SamplesModel.m_col_group] = NULL; |
1726 |
|
int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; |
1727 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
1728 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
1729 |
} |
} |
1730 |
} |
} |
1731 |
} |
} |
1732 |
|
|
1733 |
|
for (int i = 0; gig->GetScriptGroup(i); ++i) { |
1734 |
|
gig::ScriptGroup* group = gig->GetScriptGroup(i); |
1735 |
|
|
1736 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
1737 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
1738 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
1739 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
1740 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
1741 |
|
for (int s = 0; group->GetScript(s); ++s) { |
1742 |
|
gig::Script* script = group->GetScript(s); |
1743 |
|
|
1744 |
|
Gtk::TreeModel::iterator iterScript = |
1745 |
|
m_refScriptsTreeModel->append(rowGroup.children()); |
1746 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
1747 |
|
rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); |
1748 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
1749 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
1750 |
|
} |
1751 |
|
} |
1752 |
|
// unfold all sample groups & script groups by default |
1753 |
|
m_TreeViewSamples.expand_all(); |
1754 |
|
m_TreeViewScripts.expand_all(); |
1755 |
|
|
1756 |
file = gig; |
file = gig; |
1757 |
|
|
1759 |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
m_TreeView.get_selection()->select(Gtk::TreePath("0")); |
1760 |
|
|
1761 |
instr_props_set_instrument(); |
instr_props_set_instrument(); |
1762 |
|
gig::Instrument* instrument = get_instrument(); |
1763 |
|
if (instrument) { |
1764 |
|
midiRules.set_instrument(instrument); |
1765 |
|
} |
1766 |
} |
} |
1767 |
|
|
1768 |
bool MainWindow::instr_props_set_instrument() |
bool MainWindow::instr_props_set_instrument() |
1810 |
} |
} |
1811 |
} |
} |
1812 |
|
|
1813 |
|
void MainWindow::show_midi_rules() |
1814 |
|
{ |
1815 |
|
if (gig::Instrument* instrument = get_instrument()) |
1816 |
|
{ |
1817 |
|
midiRules.set_instrument(instrument); |
1818 |
|
midiRules.show(); |
1819 |
|
midiRules.deiconify(); |
1820 |
|
} |
1821 |
|
} |
1822 |
|
|
1823 |
|
void MainWindow::show_script_slots() { |
1824 |
|
if (!file) return; |
1825 |
|
// get selected instrument |
1826 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1827 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
1828 |
|
if (!it) return; |
1829 |
|
Gtk::TreeModel::Row row = *it; |
1830 |
|
gig::Instrument* instrument = row[m_Columns.m_col_instr]; |
1831 |
|
if (!instrument) return; |
1832 |
|
|
1833 |
|
ScriptSlots* window = new ScriptSlots; |
1834 |
|
window->setInstrument(instrument); |
1835 |
|
//window->reparent(*this); |
1836 |
|
window->show(); |
1837 |
|
} |
1838 |
|
|
1839 |
void MainWindow::on_action_view_status_bar() { |
void MainWindow::on_action_view_status_bar() { |
1840 |
Gtk::CheckMenuItem* item = |
Gtk::CheckMenuItem* item = |
1841 |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); |
1847 |
else m_StatusBar.hide(); |
else m_StatusBar.hide(); |
1848 |
} |
} |
1849 |
|
|
1850 |
|
bool MainWindow::is_copy_samples_unity_note_enabled() const { |
1851 |
|
Gtk::CheckMenuItem* item = |
1852 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); |
1853 |
|
if (!item) { |
1854 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n"; |
1855 |
|
return true; |
1856 |
|
} |
1857 |
|
return item->get_active(); |
1858 |
|
} |
1859 |
|
|
1860 |
|
bool MainWindow::is_copy_samples_fine_tune_enabled() const { |
1861 |
|
Gtk::CheckMenuItem* item = |
1862 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); |
1863 |
|
if (!item) { |
1864 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n"; |
1865 |
|
return true; |
1866 |
|
} |
1867 |
|
return item->get_active(); |
1868 |
|
} |
1869 |
|
|
1870 |
|
bool MainWindow::is_copy_samples_loop_enabled() const { |
1871 |
|
Gtk::CheckMenuItem* item = |
1872 |
|
dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); |
1873 |
|
if (!item) { |
1874 |
|
std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n"; |
1875 |
|
return true; |
1876 |
|
} |
1877 |
|
return item->get_active(); |
1878 |
|
} |
1879 |
|
|
1880 |
void MainWindow::on_button_release(GdkEventButton* button) |
void MainWindow::on_button_release(GdkEventButton* button) |
1881 |
{ |
{ |
1882 |
if (button->type == GDK_2BUTTON_PRESS) { |
if (button->type == GDK_2BUTTON_PRESS) { |
1883 |
show_instr_props(); |
show_instr_props(); |
1884 |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
} else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1885 |
|
// gig v2 files have no midi rules |
1886 |
|
const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); |
1887 |
|
static_cast<Gtk::MenuItem*>( |
1888 |
|
uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( |
1889 |
|
bEnabled |
1890 |
|
); |
1891 |
|
static_cast<Gtk::MenuItem*>( |
1892 |
|
uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( |
1893 |
|
bEnabled |
1894 |
|
); |
1895 |
popup_menu->popup(button->button, button->time); |
popup_menu->popup(button->button, button->time); |
1896 |
} |
} |
1897 |
} |
} |
1911 |
} |
} |
1912 |
} |
} |
1913 |
|
|
1914 |
|
void MainWindow::select_instrument(gig::Instrument* instrument) { |
1915 |
|
if (!instrument) return; |
1916 |
|
|
1917 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1918 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1919 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1920 |
|
if (row[m_Columns.m_col_instr] == instrument) { |
1921 |
|
// select and show the respective instrument in the list view |
1922 |
|
show_intruments_tab(); |
1923 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1924 |
|
Gtk::TreePath path( |
1925 |
|
m_TreeView.get_selection()->get_selected() |
1926 |
|
); |
1927 |
|
m_TreeView.scroll_to_row(path); |
1928 |
|
on_sel_change(); // the regular instrument selection change callback |
1929 |
|
} |
1930 |
|
} |
1931 |
|
} |
1932 |
|
|
1933 |
|
/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. |
1934 |
|
bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { |
1935 |
|
gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); |
1936 |
|
gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); |
1937 |
|
|
1938 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model(); |
1939 |
|
for (int i = 0; i < model->children().size(); ++i) { |
1940 |
|
Gtk::TreeModel::Row row = model->children()[i]; |
1941 |
|
if (row[m_Columns.m_col_instr] == pInstrument) { |
1942 |
|
// select and show the respective instrument in the list view |
1943 |
|
show_intruments_tab(); |
1944 |
|
m_TreeView.get_selection()->select(model->children()[i]); |
1945 |
|
Gtk::TreePath path( |
1946 |
|
m_TreeView.get_selection()->get_selected() |
1947 |
|
); |
1948 |
|
m_TreeView.scroll_to_row(path); |
1949 |
|
on_sel_change(); // the regular instrument selection change callback |
1950 |
|
|
1951 |
|
// select respective region in the region selector |
1952 |
|
m_RegionChooser.set_region(pRegion); |
1953 |
|
|
1954 |
|
// select and show the respective dimension region in the editor |
1955 |
|
//update_dimregs(); |
1956 |
|
if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; |
1957 |
|
//dimreg_edit.set_dim_region(dimRgn); |
1958 |
|
|
1959 |
|
return true; |
1960 |
|
} |
1961 |
|
} |
1962 |
|
|
1963 |
|
return false; |
1964 |
|
} |
1965 |
|
|
1966 |
|
void MainWindow::select_sample(gig::Sample* sample) { |
1967 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
1968 |
|
for (int g = 0; g < model->children().size(); ++g) { |
1969 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
1970 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
1971 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
1972 |
|
if (rowSample[m_SamplesModel.m_col_sample] == sample) { |
1973 |
|
show_samples_tab(); |
1974 |
|
m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); |
1975 |
|
Gtk::TreePath path( |
1976 |
|
m_TreeViewSamples.get_selection()->get_selected() |
1977 |
|
); |
1978 |
|
m_TreeViewSamples.scroll_to_row(path); |
1979 |
|
return; |
1980 |
|
} |
1981 |
|
} |
1982 |
|
} |
1983 |
|
} |
1984 |
|
|
1985 |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { |
1986 |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
1987 |
Gtk::Menu* sample_popup = |
Gtk::Menu* sample_popup = |
1996 |
group_selected = row[m_SamplesModel.m_col_group]; |
group_selected = row[m_SamplesModel.m_col_group]; |
1997 |
sample_selected = row[m_SamplesModel.m_col_sample]; |
sample_selected = row[m_SamplesModel.m_col_sample]; |
1998 |
} |
} |
1999 |
|
|
2000 |
|
|
2001 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> |
2002 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2003 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> |
2004 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2005 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> |
2006 |
set_sensitive(file); |
set_sensitive(file); |
2007 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> |
2008 |
|
set_sensitive(sample_selected); |
2009 |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> |
2010 |
set_sensitive(group_selected || sample_selected); |
set_sensitive(group_selected || sample_selected); |
2011 |
// show sample popup |
// show sample popup |
2012 |
sample_popup->popup(button->button, button->time); |
sample_popup->popup(button->button, button->time); |
2013 |
|
|
2014 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> |
2015 |
|
set_sensitive(group_selected || sample_selected); |
2016 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> |
2017 |
|
set_sensitive(group_selected || sample_selected); |
2018 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> |
2019 |
|
set_sensitive(file); |
2020 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> |
2021 |
|
set_sensitive(sample_selected); |
2022 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> |
2023 |
|
set_sensitive(group_selected || sample_selected); |
2024 |
} |
} |
2025 |
} |
} |
2026 |
|
|
2027 |
|
void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { |
2028 |
|
if (button->type == GDK_BUTTON_PRESS && button->button == 3) { |
2029 |
|
Gtk::Menu* script_popup = |
2030 |
|
dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu")); |
2031 |
|
// update enabled/disabled state of sample popup items |
2032 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2033 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2034 |
|
bool group_selected = false; |
2035 |
|
bool script_selected = false; |
2036 |
|
if (it) { |
2037 |
|
Gtk::TreeModel::Row row = *it; |
2038 |
|
group_selected = row[m_ScriptsModel.m_col_group]; |
2039 |
|
script_selected = row[m_ScriptsModel.m_col_script]; |
2040 |
|
} |
2041 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> |
2042 |
|
set_sensitive(group_selected || script_selected); |
2043 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> |
2044 |
|
set_sensitive(file); |
2045 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> |
2046 |
|
set_sensitive(script_selected); |
2047 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> |
2048 |
|
set_sensitive(group_selected || script_selected); |
2049 |
|
// show sample popup |
2050 |
|
script_popup->popup(button->button, button->time); |
2051 |
|
|
2052 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> |
2053 |
|
set_sensitive(group_selected || script_selected); |
2054 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> |
2055 |
|
set_sensitive(file); |
2056 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> |
2057 |
|
set_sensitive(script_selected); |
2058 |
|
dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> |
2059 |
|
set_sensitive(group_selected || script_selected); |
2060 |
|
} |
2061 |
|
} |
2062 |
|
|
2063 |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( |
2064 |
const Glib::ustring& name, int position) { |
const Glib::ustring& name, int position) { |
2185 |
} |
} |
2186 |
#endif |
#endif |
2187 |
instr_props_set_instrument(); |
instr_props_set_instrument(); |
2188 |
|
instr = get_instrument(); |
2189 |
|
if (instr) { |
2190 |
|
midiRules.set_instrument(instr); |
2191 |
|
} else { |
2192 |
|
midiRules.hide(); |
2193 |
|
} |
2194 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
2195 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2196 |
msg.run(); |
msg.run(); |
2206 |
msg.run(); |
msg.run(); |
2207 |
} |
} |
2208 |
|
|
2209 |
|
void MainWindow::on_action_add_script_group() { |
2210 |
|
static int __script_indexer = 0; |
2211 |
|
if (!file) return; |
2212 |
|
gig::ScriptGroup* group = file->AddScriptGroup(); |
2213 |
|
group->Name = gig_from_utf8(_("Unnamed Group")); |
2214 |
|
if (__script_indexer) group->Name += " " + ToString(__script_indexer); |
2215 |
|
__script_indexer++; |
2216 |
|
// update sample tree view |
2217 |
|
Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); |
2218 |
|
Gtk::TreeModel::Row rowGroup = *iterGroup; |
2219 |
|
rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); |
2220 |
|
rowGroup[m_ScriptsModel.m_col_script] = NULL; |
2221 |
|
rowGroup[m_ScriptsModel.m_col_group] = group; |
2222 |
|
file_changed(); |
2223 |
|
} |
2224 |
|
|
2225 |
|
void MainWindow::on_action_add_script() { |
2226 |
|
if (!file) return; |
2227 |
|
// get selected group |
2228 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2229 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2230 |
|
if (!it) return; |
2231 |
|
Gtk::TreeModel::Row row = *it; |
2232 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2233 |
|
if (!group) { // not a group, but a script is selected (probably) |
2234 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2235 |
|
if (!script) return; |
2236 |
|
it = row.parent(); // resolve parent (that is the script's group) |
2237 |
|
if (!it) return; |
2238 |
|
row = *it; |
2239 |
|
group = row[m_ScriptsModel.m_col_group]; |
2240 |
|
if (!group) return; |
2241 |
|
} |
2242 |
|
|
2243 |
|
// add a new script to the .gig file |
2244 |
|
gig::Script* script = group->AddScript(); |
2245 |
|
Glib::ustring name = _("Unnamed Script"); |
2246 |
|
script->Name = gig_from_utf8(name); |
2247 |
|
|
2248 |
|
// add script to the tree view |
2249 |
|
Gtk::TreeModel::iterator iterScript = |
2250 |
|
m_refScriptsTreeModel->append(row.children()); |
2251 |
|
Gtk::TreeModel::Row rowScript = *iterScript; |
2252 |
|
rowScript[m_ScriptsModel.m_col_name] = name; |
2253 |
|
rowScript[m_ScriptsModel.m_col_script] = script; |
2254 |
|
rowScript[m_ScriptsModel.m_col_group] = NULL; |
2255 |
|
|
2256 |
|
// unfold group of new script item in treeview |
2257 |
|
Gtk::TreeModel::Path path(iterScript); |
2258 |
|
m_TreeViewScripts.expand_to_path(path); |
2259 |
|
} |
2260 |
|
|
2261 |
|
void MainWindow::on_action_edit_script() { |
2262 |
|
if (!file) return; |
2263 |
|
// get selected script |
2264 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2265 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2266 |
|
if (!it) return; |
2267 |
|
Gtk::TreeModel::Row row = *it; |
2268 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2269 |
|
if (!script) return; |
2270 |
|
|
2271 |
|
ScriptEditor* editor = new ScriptEditor; |
2272 |
|
editor->setScript(script); |
2273 |
|
//editor->reparent(*this); |
2274 |
|
editor->show(); |
2275 |
|
} |
2276 |
|
|
2277 |
|
void MainWindow::on_action_remove_script() { |
2278 |
|
if (!file) return; |
2279 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2280 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2281 |
|
if (it) { |
2282 |
|
Gtk::TreeModel::Row row = *it; |
2283 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2284 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2285 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2286 |
|
try { |
2287 |
|
// remove script group or script from the gig file |
2288 |
|
if (group) { |
2289 |
|
// notify everybody that we're going to remove these samples |
2290 |
|
//TODO: scripts_to_be_removed_signal.emit(members); |
2291 |
|
// delete the group in the .gig file including the |
2292 |
|
// samples that belong to the group |
2293 |
|
file->DeleteScriptGroup(group); |
2294 |
|
// notify that we're done with removal |
2295 |
|
//TODO: scripts_removed_signal.emit(); |
2296 |
|
file_changed(); |
2297 |
|
} else if (script) { |
2298 |
|
// notify everybody that we're going to remove this sample |
2299 |
|
//TODO: std::list<gig::Script*> lscripts; |
2300 |
|
//TODO: lscripts.push_back(script); |
2301 |
|
//TODO: scripts_to_be_removed_signal.emit(lscripts); |
2302 |
|
// remove sample from the .gig file |
2303 |
|
script->GetGroup()->DeleteScript(script); |
2304 |
|
// notify that we're done with removal |
2305 |
|
//TODO: scripts_removed_signal.emit(); |
2306 |
|
dimreg_changed(); |
2307 |
|
file_changed(); |
2308 |
|
} |
2309 |
|
// remove respective row(s) from samples tree view |
2310 |
|
m_refScriptsTreeModel->erase(it); |
2311 |
|
} catch (RIFF::Exception e) { |
2312 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
2313 |
|
//TODO: scripts_removed_signal.emit(); |
2314 |
|
// show error message |
2315 |
|
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
2316 |
|
msg.run(); |
2317 |
|
} |
2318 |
|
} |
2319 |
|
} |
2320 |
|
|
2321 |
void MainWindow::on_action_add_group() { |
void MainWindow::on_action_add_group() { |
2322 |
static int __sample_indexer = 0; |
static int __sample_indexer = 0; |
2323 |
if (!file) return; |
if (!file) return; |
2451 |
&instrument, sizeof(instrument)) != SF_FALSE) |
&instrument, sizeof(instrument)) != SF_FALSE) |
2452 |
{ |
{ |
2453 |
sample->MIDIUnityNote = instrument.basenote; |
sample->MIDIUnityNote = instrument.basenote; |
2454 |
|
sample->FineTune = instrument.detune; |
2455 |
|
|
2456 |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
2457 |
sample->Loops = 1; |
sample->Loops = 1; |
2687 |
} |
} |
2688 |
} |
} |
2689 |
|
|
2690 |
|
// see comment on on_sample_treeview_drag_begin() |
2691 |
|
void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2692 |
|
{ |
2693 |
|
first_call_to_drag_data_get = true; |
2694 |
|
} |
2695 |
|
|
2696 |
|
void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2697 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2698 |
|
{ |
2699 |
|
if (!first_call_to_drag_data_get) return; |
2700 |
|
first_call_to_drag_data_get = false; |
2701 |
|
|
2702 |
|
// get selected script |
2703 |
|
gig::Script* script = NULL; |
2704 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection(); |
2705 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2706 |
|
if (it) { |
2707 |
|
Gtk::TreeModel::Row row = *it; |
2708 |
|
script = row[m_ScriptsModel.m_col_script]; |
2709 |
|
} |
2710 |
|
// pass the gig::Script as pointer |
2711 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, |
2712 |
|
(const guchar*)&script, |
2713 |
|
sizeof(script)/*length of data in bytes*/); |
2714 |
|
} |
2715 |
|
|
2716 |
|
// see comment on on_sample_treeview_drag_begin() |
2717 |
|
void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
2718 |
|
{ |
2719 |
|
first_call_to_drag_data_get = true; |
2720 |
|
} |
2721 |
|
|
2722 |
|
void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
2723 |
|
Gtk::SelectionData& selection_data, guint, guint) |
2724 |
|
{ |
2725 |
|
if (!first_call_to_drag_data_get) return; |
2726 |
|
first_call_to_drag_data_get = false; |
2727 |
|
|
2728 |
|
// get selected source instrument |
2729 |
|
gig::Instrument* src = NULL; |
2730 |
|
{ |
2731 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
2732 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2733 |
|
if (it) { |
2734 |
|
Gtk::TreeModel::Row row = *it; |
2735 |
|
src = row[m_Columns.m_col_instr]; |
2736 |
|
} |
2737 |
|
} |
2738 |
|
if (!src) return; |
2739 |
|
|
2740 |
|
// pass the source gig::Instrument as pointer |
2741 |
|
selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, |
2742 |
|
sizeof(src)/*length of data in bytes*/); |
2743 |
|
} |
2744 |
|
|
2745 |
|
void MainWindow::on_instruments_treeview_drop_drag_data_received( |
2746 |
|
const Glib::RefPtr<Gdk::DragContext>& context, int x, int y, |
2747 |
|
const Gtk::SelectionData& selection_data, guint, guint time) |
2748 |
|
{ |
2749 |
|
gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); |
2750 |
|
if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) |
2751 |
|
return; |
2752 |
|
|
2753 |
|
gig::Instrument* dst = NULL; |
2754 |
|
{ |
2755 |
|
Gtk::TreeModel::Path path; |
2756 |
|
const bool found = m_TreeView.get_path_at_pos(x, y, path); |
2757 |
|
if (!found) return; |
2758 |
|
|
2759 |
|
Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); |
2760 |
|
if (!iter) return; |
2761 |
|
Gtk::TreeModel::Row row = *iter; |
2762 |
|
dst = row[m_Columns.m_col_instr]; |
2763 |
|
} |
2764 |
|
if (!dst) return; |
2765 |
|
|
2766 |
|
//printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); |
2767 |
|
src->MoveTo(dst); |
2768 |
|
__refreshEntireGUI(); |
2769 |
|
select_instrument(src); |
2770 |
|
} |
2771 |
|
|
2772 |
// For some reason drag_data_get gets called two times for each |
// For some reason drag_data_get gets called two times for each |
2773 |
// 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 |
2774 |
// 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 |
2827 |
bool channels_changed = false; |
bool channels_changed = false; |
2828 |
if (sample->Channels == 1 && stereo_dimension) { |
if (sample->Channels == 1 && stereo_dimension) { |
2829 |
// remove the samplechannel dimension |
// remove the samplechannel dimension |
2830 |
|
/* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples |
2831 |
region->DeleteDimension(stereo_dimension); |
region->DeleteDimension(stereo_dimension); |
2832 |
channels_changed = true; |
channels_changed = true; |
2833 |
region_changed(); |
region_changed(); |
2834 |
|
*/ |
2835 |
} |
} |
2836 |
dimreg_edit.set_sample(sample); |
dimreg_edit.set_sample( |
2837 |
|
sample, |
2838 |
|
is_copy_samples_unity_note_enabled(), |
2839 |
|
is_copy_samples_fine_tune_enabled(), |
2840 |
|
is_copy_samples_loop_enabled() |
2841 |
|
); |
2842 |
|
|
2843 |
if (sample->Channels == 2 && !stereo_dimension) { |
if (sample->Channels == 2 && !stereo_dimension) { |
2844 |
// add samplechannel dimension |
// add samplechannel dimension |
2897 |
} |
} |
2898 |
} |
} |
2899 |
|
|
2900 |
|
void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, |
2901 |
|
const Gtk::TreeModel::iterator& iter) { |
2902 |
|
if (!iter) return; |
2903 |
|
Gtk::TreeModel::Row row = *iter; |
2904 |
|
Glib::ustring name = row[m_ScriptsModel.m_col_name]; |
2905 |
|
gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; |
2906 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2907 |
|
gig::String gigname(gig_from_utf8(name)); |
2908 |
|
if (group) { |
2909 |
|
if (group->Name != gigname) { |
2910 |
|
group->Name = gigname; |
2911 |
|
printf("script group name changed\n"); |
2912 |
|
file_changed(); |
2913 |
|
} |
2914 |
|
} else if (script) { |
2915 |
|
if (script->Name != gigname) { |
2916 |
|
script->Name = gigname; |
2917 |
|
printf("script name changed\n"); |
2918 |
|
file_changed(); |
2919 |
|
} |
2920 |
|
} |
2921 |
|
} |
2922 |
|
|
2923 |
|
void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, |
2924 |
|
Gtk::TreeViewColumn* column) |
2925 |
|
{ |
2926 |
|
Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); |
2927 |
|
if (!iter) return; |
2928 |
|
Gtk::TreeModel::Row row = *iter; |
2929 |
|
gig::Script* script = row[m_ScriptsModel.m_col_script]; |
2930 |
|
if (!script) return; |
2931 |
|
|
2932 |
|
ScriptEditor* editor = new ScriptEditor; |
2933 |
|
editor->setScript(script); |
2934 |
|
//editor->reparent(*this); |
2935 |
|
editor->show(); |
2936 |
|
} |
2937 |
|
|
2938 |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, |
2939 |
const Gtk::TreeModel::iterator& iter) { |
const Gtk::TreeModel::iterator& iter) { |
2940 |
if (!iter) return; |
if (!iter) return; |
2969 |
} |
} |
2970 |
} |
} |
2971 |
|
|
2972 |
|
void MainWindow::on_action_combine_instruments() { |
2973 |
|
CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); |
2974 |
|
d->show_all(); |
2975 |
|
d->resize(500, 400); |
2976 |
|
d->run(); |
2977 |
|
if (d->fileWasChanged()) { |
2978 |
|
// update GUI with new instrument just created |
2979 |
|
add_instrument(d->newCombinedInstrument()); |
2980 |
|
} |
2981 |
|
delete d; |
2982 |
|
} |
2983 |
|
|
2984 |
|
void MainWindow::on_action_view_references() { |
2985 |
|
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
2986 |
|
Gtk::TreeModel::iterator it = sel->get_selected(); |
2987 |
|
if (!it) return; |
2988 |
|
Gtk::TreeModel::Row row = *it; |
2989 |
|
gig::Sample* sample = row[m_SamplesModel.m_col_sample]; |
2990 |
|
if (!sample) return; |
2991 |
|
|
2992 |
|
ReferencesView* d = new ReferencesView(*this); |
2993 |
|
d->setSample(sample); |
2994 |
|
d->dimension_region_selected.connect( |
2995 |
|
sigc::mem_fun(*this, &MainWindow::select_dimension_region) |
2996 |
|
); |
2997 |
|
d->show_all(); |
2998 |
|
d->resize(500, 400); |
2999 |
|
d->run(); |
3000 |
|
delete d; |
3001 |
|
} |
3002 |
|
|
3003 |
|
void MainWindow::mergeFiles(const std::vector<std::string>& filenames) { |
3004 |
|
struct _Source { |
3005 |
|
std::vector<RIFF::File*> riffs; |
3006 |
|
std::vector<gig::File*> gigs; |
3007 |
|
|
3008 |
|
~_Source() { |
3009 |
|
for (int k = 0; k < gigs.size(); ++k) delete gigs[k]; |
3010 |
|
for (int k = 0; k < riffs.size(); ++k) delete riffs[k]; |
3011 |
|
riffs.clear(); |
3012 |
|
gigs.clear(); |
3013 |
|
} |
3014 |
|
} sources; |
3015 |
|
|
3016 |
|
if (filenames.empty()) |
3017 |
|
throw RIFF::Exception(_("No files selected, so nothing done.")); |
3018 |
|
|
3019 |
|
// first open all input files (to avoid output file corruption) |
3020 |
|
int i; |
3021 |
|
try { |
3022 |
|
for (i = 0; i < filenames.size(); ++i) { |
3023 |
|
const std::string& filename = filenames[i]; |
3024 |
|
printf("opening file=%s\n", filename.c_str()); |
3025 |
|
|
3026 |
|
RIFF::File* riff = new RIFF::File(filename); |
3027 |
|
sources.riffs.push_back(riff); |
3028 |
|
|
3029 |
|
gig::File* gig = new gig::File(riff); |
3030 |
|
sources.gigs.push_back(gig); |
3031 |
|
} |
3032 |
|
} catch (RIFF::Exception e) { |
3033 |
|
throw RIFF::Exception( |
3034 |
|
_("Error occurred while opening '") + |
3035 |
|
filenames[i] + |
3036 |
|
"': " + |
3037 |
|
e.Message |
3038 |
|
); |
3039 |
|
} catch (...) { |
3040 |
|
throw RIFF::Exception( |
3041 |
|
_("Unknown exception occurred while opening '") + |
3042 |
|
filenames[i] + "'" |
3043 |
|
); |
3044 |
|
} |
3045 |
|
|
3046 |
|
// now merge the opened .gig files to the main .gig file currently being |
3047 |
|
// open in gigedit |
3048 |
|
try { |
3049 |
|
for (i = 0; i < filenames.size(); ++i) { |
3050 |
|
const std::string& filename = filenames[i]; |
3051 |
|
printf("merging file=%s\n", filename.c_str()); |
3052 |
|
assert(i < sources.gigs.size()); |
3053 |
|
|
3054 |
|
this->file->AddContentOf(sources.gigs[i]); |
3055 |
|
} |
3056 |
|
} catch (RIFF::Exception e) { |
3057 |
|
throw RIFF::Exception( |
3058 |
|
_("Error occurred while merging '") + |
3059 |
|
filenames[i] + |
3060 |
|
"': " + |
3061 |
|
e.Message |
3062 |
|
); |
3063 |
|
} catch (...) { |
3064 |
|
throw RIFF::Exception( |
3065 |
|
_("Unknown exception occurred while merging '") + |
3066 |
|
filenames[i] + "'" |
3067 |
|
); |
3068 |
|
} |
3069 |
|
|
3070 |
|
// Finally save gig file persistently to disk ... |
3071 |
|
//NOTE: requires that this gig file already has a filename ! |
3072 |
|
{ |
3073 |
|
std::cout << "Saving file\n" << std::flush; |
3074 |
|
file_structure_to_be_changed_signal.emit(this->file); |
3075 |
|
|
3076 |
|
progress_dialog = new ProgressDialog( //FIXME: memory leak! |
3077 |
|
_("Saving") + Glib::ustring(" '") + |
3078 |
|
Glib::filename_display_basename(this->filename) + "' ...", |
3079 |
|
*this |
3080 |
|
); |
3081 |
|
progress_dialog->show_all(); |
3082 |
|
saver = new Saver(this->file); //FIXME: memory leak! |
3083 |
|
saver->signal_progress().connect( |
3084 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_progress)); |
3085 |
|
saver->signal_finished().connect( |
3086 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_finished)); |
3087 |
|
saver->signal_error().connect( |
3088 |
|
sigc::mem_fun(*this, &MainWindow::on_saver_error)); |
3089 |
|
saver->launch(); |
3090 |
|
} |
3091 |
|
} |
3092 |
|
|
3093 |
|
void MainWindow::on_action_merge_files() { |
3094 |
|
if (this->file->GetFileName().empty()) { |
3095 |
|
Glib::ustring txt = _( |
3096 |
|
"You seem to have a new .gig file open that has not been saved " |
3097 |
|
"yet. You must save it somewhere before starting to merge it with " |
3098 |
|
"other .gig files though, because during the merge operation the " |
3099 |
|
"other files' sample data must be written on file level to the " |
3100 |
|
"target .gig file." |
3101 |
|
); |
3102 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
3103 |
|
msg.run(); |
3104 |
|
return; |
3105 |
|
} |
3106 |
|
|
3107 |
|
Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); |
3108 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
3109 |
|
dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); |
3110 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
3111 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
3112 |
|
Gtk::FileFilter filter; |
3113 |
|
filter.add_pattern("*.gig"); |
3114 |
|
#else |
3115 |
|
Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create(); |
3116 |
|
filter->add_pattern("*.gig"); |
3117 |
|
#endif |
3118 |
|
dialog.set_filter(filter); |
3119 |
|
if (current_gig_dir != "") { |
3120 |
|
dialog.set_current_folder(current_gig_dir); |
3121 |
|
} |
3122 |
|
dialog.set_select_multiple(true); |
3123 |
|
|
3124 |
|
// show warning in the file picker dialog |
3125 |
|
Gtk::HBox descriptionArea; |
3126 |
|
descriptionArea.set_spacing(15); |
3127 |
|
Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); |
3128 |
|
descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); |
3129 |
|
#if GTKMM_MAJOR_VERSION < 3 |
3130 |
|
view::WrapLabel description; |
3131 |
|
#else |
3132 |
|
Gtk::Label description; |
3133 |
|
description.set_line_wrap(); |
3134 |
|
#endif |
3135 |
|
description.set_markup(_( |
3136 |
|
"\nSelect at least one .gig file that shall be merged to the .gig file " |
3137 |
|
"currently being open in gigedit.\n\n" |
3138 |
|
"<b>Please Note:</b> Merging with other files will modify your " |
3139 |
|
"currently open .gig file on file level! And be aware that the current " |
3140 |
|
"merge algorithm does not detect duplicate samples yet. So if you are " |
3141 |
|
"merging files which are using equivalent sample data, those " |
3142 |
|
"equivalent samples will currently be treated as separate samples and " |
3143 |
|
"will accordingly be stored separately in the target .gig file!" |
3144 |
|
)); |
3145 |
|
descriptionArea.pack_start(description); |
3146 |
|
dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); |
3147 |
|
descriptionArea.show_all(); |
3148 |
|
|
3149 |
|
if (dialog.run() == Gtk::RESPONSE_OK) { |
3150 |
|
printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); |
3151 |
|
std::vector<std::string> filenames = dialog.get_filenames(); |
3152 |
|
|
3153 |
|
// merge the selected files to the currently open .gig file |
3154 |
|
try { |
3155 |
|
mergeFiles(filenames); |
3156 |
|
} catch (RIFF::Exception e) { |
3157 |
|
Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR); |
3158 |
|
msg.run(); |
3159 |
|
} |
3160 |
|
|
3161 |
|
// update GUI |
3162 |
|
__refreshEntireGUI(); |
3163 |
|
} |
3164 |
|
} |
3165 |
|
|
3166 |
void MainWindow::set_file_is_shared(bool b) { |
void MainWindow::set_file_is_shared(bool b) { |
3167 |
this->file_is_shared = b; |
this->file_is_shared = b; |
3168 |
|
|
3177 |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) |
3178 |
); |
); |
3179 |
} |
} |
3180 |
|
|
3181 |
|
{ |
3182 |
|
Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>( |
3183 |
|
uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); |
3184 |
|
if (item) item->set_sensitive(b); |
3185 |
|
} |
3186 |
|
} |
3187 |
|
|
3188 |
|
void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { |
3189 |
|
if (!sample) return; |
3190 |
|
sample_ref_count[sample] += offset; |
3191 |
|
const int refcount = sample_ref_count[sample]; |
3192 |
|
|
3193 |
|
Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model(); |
3194 |
|
for (int g = 0; g < model->children().size(); ++g) { |
3195 |
|
Gtk::TreeModel::Row rowGroup = model->children()[g]; |
3196 |
|
for (int s = 0; s < rowGroup.children().size(); ++s) { |
3197 |
|
Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; |
3198 |
|
if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; |
3199 |
|
rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); |
3200 |
|
rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; |
3201 |
|
} |
3202 |
|
} |
3203 |
|
} |
3204 |
|
|
3205 |
|
void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { |
3206 |
|
on_sample_ref_count_incremented(oldSample, -1); |
3207 |
|
on_sample_ref_count_incremented(newSample, +1); |
3208 |
|
} |
3209 |
|
|
3210 |
|
void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) { |
3211 |
|
// just in case a new sample is added later with exactly the same memory |
3212 |
|
// address, which would lead to incorrect refcount if not deleted here |
3213 |
|
for (std::list<gig::Sample*>::const_iterator it = samples.begin(); |
3214 |
|
it != samples.end(); ++it) |
3215 |
|
{ |
3216 |
|
sample_ref_count.erase(*it); |
3217 |
|
} |
3218 |
|
} |
3219 |
|
|
3220 |
|
void MainWindow::show_samples_tab() { |
3221 |
|
m_TreeViewNotebook.set_current_page(0); |
3222 |
|
} |
3223 |
|
|
3224 |
|
void MainWindow::show_intruments_tab() { |
3225 |
|
m_TreeViewNotebook.set_current_page(1); |
3226 |
|
} |
3227 |
|
|
3228 |
|
void MainWindow::show_scripts_tab() { |
3229 |
|
m_TreeViewNotebook.set_current_page(2); |
3230 |
} |
} |
3231 |
|
|
3232 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3284 |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() { |
3285 |
return m_RegionChooser.signal_keyboard_key_released(); |
return m_RegionChooser.signal_keyboard_key_released(); |
3286 |
} |
} |
3287 |
|
|
3288 |
|
sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() { |
3289 |
|
return switch_sampler_instrument_signal; |
3290 |
|
} |