17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
|
#include <libintl.h> |
|
20 |
#include <iostream> |
#include <iostream> |
21 |
|
|
22 |
#include <gtkmm/filechooserdialog.h> |
#include <gtkmm/filechooserdialog.h> |
25 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
26 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
27 |
|
|
28 |
|
#include "global.h" |
29 |
|
|
30 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
31 |
#define ABOUT_DIALOG |
#define ABOUT_DIALOG |
32 |
#include <gtkmm/aboutdialog.h> |
#include <gtkmm/aboutdialog.h> |
33 |
#endif |
#endif |
34 |
|
|
35 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2 |
36 |
|
namespace Glib { |
37 |
|
Glib::ustring filename_display_basename(const std::string& filename) |
38 |
|
{ |
39 |
|
gchar* gstr = g_path_get_basename(filename.c_str()); |
40 |
|
Glib::ustring str(gstr); |
41 |
|
g_free(gstr); |
42 |
|
return Glib::filename_to_utf8(str); |
43 |
|
} |
44 |
|
} |
45 |
|
#endif |
46 |
|
|
47 |
#include <stdio.h> |
#include <stdio.h> |
48 |
#include <sndfile.h> |
#include <sndfile.h> |
49 |
|
|
50 |
#include "mainwindow.h" |
#include "mainwindow.h" |
51 |
|
|
|
#define _(String) gettext(String) |
|
|
|
|
52 |
template<class T> inline std::string ToString(T o) { |
template<class T> inline std::string ToString(T o) { |
53 |
std::stringstream ss; |
std::stringstream ss; |
54 |
ss << o; |
ss << o; |
245 |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
std::list<Gtk::TargetEntry> drag_target_gig_sample; |
246 |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") ); |
247 |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
m_TreeViewSamples.drag_source_set(drag_target_gig_sample); |
248 |
|
m_TreeViewSamples.signal_drag_begin().connect( |
249 |
|
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin) |
250 |
|
); |
251 |
m_TreeViewSamples.signal_drag_data_get().connect( |
m_TreeViewSamples.signal_drag_data_get().connect( |
252 |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_data_get) |
253 |
); |
); |
256 |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received) |
257 |
); |
); |
258 |
dimreg_edit.signal_dimreg_changed().connect( |
dimreg_edit.signal_dimreg_changed().connect( |
259 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); |
260 |
m_RegionChooser.signal_instrument_changed().connect( |
m_RegionChooser.signal_instrument_changed().connect( |
261 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
262 |
m_DimRegionChooser.signal_region_changed().connect( |
m_DimRegionChooser.signal_region_changed().connect( |
263 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
264 |
instrumentProps.signal_instrument_changed().connect( |
instrumentProps.signal_instrument_changed().connect( |
265 |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
sigc::mem_fun(*this, &MainWindow::file_changed)); |
266 |
|
|
267 |
|
dimreg_edit.signal_dimreg_to_be_changed().connect( |
268 |
|
dimreg_to_be_changed_signal.make_slot()); |
269 |
|
dimreg_edit.signal_dimreg_changed().connect( |
270 |
|
dimreg_changed_signal.make_slot()); |
271 |
|
dimreg_edit.signal_sample_ref_changed().connect( |
272 |
|
sample_ref_changed_signal.make_slot()); |
273 |
|
|
274 |
|
m_RegionChooser.signal_instrument_struct_to_be_changed().connect( |
275 |
|
sigc::hide( |
276 |
|
sigc::bind( |
277 |
|
file_structure_to_be_changed_signal.make_slot(), |
278 |
|
sigc::ref(this->file) |
279 |
|
) |
280 |
|
) |
281 |
|
); |
282 |
|
m_RegionChooser.signal_instrument_struct_changed().connect( |
283 |
|
sigc::hide( |
284 |
|
sigc::bind( |
285 |
|
file_structure_changed_signal.make_slot(), |
286 |
|
sigc::ref(this->file) |
287 |
|
) |
288 |
|
) |
289 |
|
); |
290 |
|
m_RegionChooser.signal_region_to_be_changed().connect( |
291 |
|
region_to_be_changed_signal.make_slot()); |
292 |
|
m_RegionChooser.signal_region_changed_signal().connect( |
293 |
|
region_changed_signal.make_slot()); |
294 |
|
|
295 |
file = 0; |
file = 0; |
296 |
file_is_changed = false; |
file_is_changed = false; |
297 |
|
file_is_shared = false; |
298 |
|
|
299 |
show_all_children(); |
show_all_children(); |
300 |
|
|
308 |
|
|
309 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
310 |
{ |
{ |
311 |
return file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
312 |
} |
} |
313 |
|
|
314 |
void MainWindow::on_action_quit() |
void MainWindow::on_action_quit() |
315 |
{ |
{ |
316 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
317 |
hide(); |
hide(); |
318 |
} |
} |
319 |
|
|
427 |
m_refTreeModel->clear(); |
m_refTreeModel->clear(); |
428 |
m_refSamplesTreeModel->clear(); |
m_refSamplesTreeModel->clear(); |
429 |
// free libgig's gig::File instance |
// free libgig's gig::File instance |
430 |
if (file) { |
if (file && !file_is_shared) delete file; |
431 |
delete file; |
file = NULL; |
432 |
file = NULL; |
file_is_shared = false; |
|
} |
|
433 |
} |
} |
434 |
|
|
435 |
void MainWindow::on_action_file_new() |
void MainWindow::on_action_file_new() |
436 |
{ |
{ |
437 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
438 |
|
|
439 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
440 |
|
|
441 |
// clear all GUI elements |
// clear all GUI elements |
442 |
__clear(); |
__clear(); |
455 |
Glib::filename_display_basename(filename).c_str()); |
Glib::filename_display_basename(filename).c_str()); |
456 |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
457 |
g_free(msg); |
g_free(msg); |
458 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
459 |
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.")); |
460 |
|
#endif |
461 |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); |
462 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
463 |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); |
464 |
dialog.set_default_response(Gtk::RESPONSE_YES); |
dialog.set_default_response(Gtk::RESPONSE_YES); |
465 |
int response = dialog.run(); |
int response = dialog.run(); |
466 |
|
dialog.hide(); |
467 |
if (response == Gtk::RESPONSE_YES) return file_save(); |
if (response == Gtk::RESPONSE_YES) return file_save(); |
468 |
return response != Gtk::RESPONSE_CANCEL; |
return response != Gtk::RESPONSE_CANCEL; |
469 |
} |
} |
470 |
|
|
471 |
|
bool MainWindow::leaving_shared_mode_dialog() { |
472 |
|
Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?"); |
473 |
|
Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
474 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2 |
475 |
|
dialog.set_secondary_text( |
476 |
|
_("If you proceed to work on another instrument file, it won't be " |
477 |
|
"used by the sampler until you tell the sampler explicitly to " |
478 |
|
"load it.") |
479 |
|
); |
480 |
|
#endif |
481 |
|
dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); |
482 |
|
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
483 |
|
dialog.set_default_response(Gtk::RESPONSE_CANCEL); |
484 |
|
int response = dialog.run(); |
485 |
|
dialog.hide(); |
486 |
|
return response == Gtk::RESPONSE_YES; |
487 |
|
} |
488 |
|
|
489 |
void MainWindow::on_action_file_open() |
void MainWindow::on_action_file_open() |
490 |
{ |
{ |
491 |
if (file_is_changed && !close_confirmation_dialog()) return; |
if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return; |
492 |
|
|
493 |
|
if (file_is_shared && !leaving_shared_mode_dialog()) return; |
494 |
|
|
495 |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
Gtk::FileChooserDialog dialog(*this, _("Open file")); |
496 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
505 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
506 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
507 |
printf("filename=%s\n", filename.c_str()); |
printf("filename=%s\n", filename.c_str()); |
|
__clear(); |
|
508 |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
printf("on_action_file_open self=%x\n", Glib::Thread::self()); |
509 |
load_file(filename.c_str()); |
load_file(filename.c_str()); |
510 |
current_dir = Glib::path_get_dirname(filename); |
current_dir = Glib::path_get_dirname(filename); |
513 |
|
|
514 |
void MainWindow::load_file(const char* name) |
void MainWindow::load_file(const char* name) |
515 |
{ |
{ |
516 |
|
__clear(); |
517 |
load_dialog = new LoadDialog("Loading...", *this); |
load_dialog = new LoadDialog("Loading...", *this); |
518 |
load_dialog->show_all(); |
load_dialog->show_all(); |
519 |
loader = new Loader(strdup(name)); |
loader = new Loader(strdup(name)); |
531 |
msg.run(); |
msg.run(); |
532 |
Gtk::Main::quit(); |
Gtk::Main::quit(); |
533 |
} |
} |
534 |
|
// clear all GUI elements |
535 |
|
__clear(); |
536 |
|
// load the instrument |
537 |
gig::File* pFile = (gig::File*) instr->GetParent(); |
gig::File* pFile = (gig::File*) instr->GetParent(); |
538 |
load_gig(pFile, 0 /*file name*/); |
load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); |
539 |
//TODO: automatically select the given instrument |
//TODO: automatically select the given instrument |
540 |
} |
} |
541 |
|
|
557 |
file_save(); |
file_save(); |
558 |
} |
} |
559 |
|
|
560 |
bool MainWindow::file_save() |
bool MainWindow::check_if_savable() |
561 |
{ |
{ |
562 |
if (!file) return false; |
if (!file) return false; |
563 |
if (!file_has_name) return file_save_as(); |
|
564 |
|
if (!file->GetFirstSample()) { |
565 |
|
Gtk::MessageDialog(*this, _("The file could not be saved " |
566 |
|
"because it contains no samples"), |
567 |
|
false, Gtk::MESSAGE_ERROR).run(); |
568 |
|
return false; |
569 |
|
} |
570 |
|
|
571 |
|
for (gig::Instrument* instrument = file->GetFirstInstrument() ; instrument ; |
572 |
|
instrument = file->GetNextInstrument()) { |
573 |
|
if (!instrument->GetFirstRegion()) { |
574 |
|
Gtk::MessageDialog(*this, _("The file could not be saved " |
575 |
|
"because there are instruments " |
576 |
|
"that have no regions"), |
577 |
|
false, Gtk::MESSAGE_ERROR).run(); |
578 |
|
return false; |
579 |
|
} |
580 |
|
} |
581 |
|
return true; |
582 |
|
} |
583 |
|
|
584 |
|
bool MainWindow::file_save() |
585 |
|
{ |
586 |
|
if (!check_if_savable()) return false; |
587 |
|
if (!file_is_shared && !file_has_name) return file_save_as(); |
588 |
|
|
589 |
std::cout << "Saving file\n" << std::flush; |
std::cout << "Saving file\n" << std::flush; |
590 |
|
file_structure_to_be_changed_signal.emit(this->file); |
591 |
try { |
try { |
592 |
file->Save(); |
file->Save(); |
593 |
if (file_is_changed) { |
if (file_is_changed) { |
595 |
file_is_changed = false; |
file_is_changed = false; |
596 |
} |
} |
597 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
598 |
Glib::ustring txt = "Could not save file: " + e.Message; |
file_structure_changed_signal.emit(this->file); |
599 |
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
600 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
601 |
msg.run(); |
msg.run(); |
602 |
return false; |
return false; |
603 |
} |
} |
604 |
std::cout << "Saving file done\n" << std::flush; |
std::cout << "Saving file done\n" << std::flush; |
605 |
__import_queued_samples(); |
__import_queued_samples(); |
606 |
|
file_structure_changed_signal.emit(this->file); |
607 |
return true; |
return true; |
608 |
} |
} |
609 |
|
|
610 |
void MainWindow::on_action_file_save_as() |
void MainWindow::on_action_file_save_as() |
611 |
{ |
{ |
612 |
|
if (!check_if_savable()) return; |
613 |
file_save_as(); |
file_save_as(); |
614 |
} |
} |
615 |
|
|
616 |
bool MainWindow::file_save_as() |
bool MainWindow::file_save_as() |
617 |
{ |
{ |
|
if (!file) return false; |
|
618 |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); |
619 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
620 |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); |
636 |
dialog.set_current_name(Glib::filename_display_basename(filename)); |
dialog.set_current_name(Glib::filename_display_basename(filename)); |
637 |
|
|
638 |
if (dialog.run() == Gtk::RESPONSE_OK) { |
if (dialog.run() == Gtk::RESPONSE_OK) { |
639 |
|
file_structure_to_be_changed_signal.emit(this->file); |
640 |
try { |
try { |
641 |
std::string filename = dialog.get_filename(); |
std::string filename = dialog.get_filename(); |
642 |
if (!Glib::str_has_suffix(filename, ".gig")) { |
if (!Glib::str_has_suffix(filename, ".gig")) { |
650 |
file_has_name = true; |
file_has_name = true; |
651 |
file_is_changed = false; |
file_is_changed = false; |
652 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
653 |
Glib::ustring txt = "Could not save file: " + e.Message; |
file_structure_changed_signal.emit(this->file); |
654 |
|
Glib::ustring txt = _("Could not save file: ") + e.Message; |
655 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
656 |
msg.run(); |
msg.run(); |
657 |
return false; |
return false; |
658 |
} |
} |
659 |
__import_queued_samples(); |
__import_queued_samples(); |
660 |
|
file_structure_changed_signal.emit(this->file); |
661 |
return true; |
return true; |
662 |
} |
} |
663 |
return false; |
return false; |
748 |
} |
} |
749 |
// show error message box when some sample(s) could not be imported |
// show error message box when some sample(s) could not be imported |
750 |
if (error_files.size()) { |
if (error_files.size()) { |
751 |
Glib::ustring txt = "Could not import the following sample(s):\n" + error_files; |
Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files; |
752 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
753 |
msg.run(); |
msg.run(); |
754 |
} |
} |
942 |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
if (h < l) eDimensionKeyRangeLow.set_value(h); |
943 |
} |
} |
944 |
|
|
945 |
sigc::signal<void> InstrumentProps::signal_instrument_changed() |
sigc::signal<void>& InstrumentProps::signal_instrument_changed() |
946 |
{ |
{ |
947 |
return instrument_changed; |
return instrument_changed; |
948 |
} |
} |
955 |
} |
} |
956 |
} |
} |
957 |
|
|
958 |
void MainWindow::load_gig(gig::File* gig, const char* filename) |
void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) |
959 |
{ |
{ |
960 |
file = 0; |
file = 0; |
961 |
|
file_is_shared = isSharedInstrument; |
962 |
|
|
963 |
this->filename = filename ? filename : _("Unsaved Gig File"); |
this->filename = filename ? filename : _("Unsaved Gig File"); |
964 |
set_title(Glib::filename_display_basename(this->filename)); |
set_title(Glib::filename_display_basename(this->filename)); |
1092 |
|
|
1093 |
void MainWindow::on_action_remove_instrument() { |
void MainWindow::on_action_remove_instrument() { |
1094 |
if (!file) return; |
if (!file) return; |
1095 |
|
if (file_is_shared) { |
1096 |
|
Gtk::MessageDialog msg( |
1097 |
|
*this, |
1098 |
|
_("You cannot delete an instrument from this file, since it's " |
1099 |
|
"currently used by the sampler."), |
1100 |
|
false, Gtk::MESSAGE_INFO |
1101 |
|
); |
1102 |
|
msg.run(); |
1103 |
|
return; |
1104 |
|
} |
1105 |
|
|
1106 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection(); |
1107 |
Gtk::TreeModel::iterator it = sel->get_selected(); |
Gtk::TreeModel::iterator it = sel->get_selected(); |
1108 |
if (it) { |
if (it) { |
1238 |
{ |
{ |
1239 |
sample->MIDIUnityNote = instrument.basenote; |
sample->MIDIUnityNote = instrument.basenote; |
1240 |
|
|
1241 |
|
#if HAVE_SF_INSTRUMENT_LOOPS |
1242 |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) { |
1243 |
sample->Loops = 1; |
sample->Loops = 1; |
1244 |
|
|
1258 |
sample->LoopPlayCount = instrument.loops[0].count; |
sample->LoopPlayCount = instrument.loops[0].count; |
1259 |
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1; |
1260 |
} |
} |
1261 |
|
#endif |
1262 |
} |
} |
1263 |
|
|
1264 |
// schedule resizing the sample (which will be done |
// schedule resizing the sample (which will be done |
1289 |
} |
} |
1290 |
// 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 |
1291 |
if (error_files.size()) { |
if (error_files.size()) { |
1292 |
Glib::ustring txt = "Could not add the following sample(s):\n" + error_files; |
Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; |
1293 |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
1294 |
msg.run(); |
msg.run(); |
1295 |
} |
} |
1315 |
pSample; pSample = group->GetNextSample()) { |
pSample; pSample = group->GetNextSample()) { |
1316 |
members.push_back(pSample); |
members.push_back(pSample); |
1317 |
} |
} |
1318 |
|
// notify everybody that we're going to remove these samples |
1319 |
|
samples_to_be_removed_signal.emit(members); |
1320 |
// delete the group in the .gig file including the |
// delete the group in the .gig file including the |
1321 |
// samples that belong to the group |
// samples that belong to the group |
1322 |
file->DeleteGroup(group); |
file->DeleteGroup(group); |
1323 |
|
// notify that we're done with removal |
1324 |
|
samples_removed_signal.emit(); |
1325 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
1326 |
// them from the import queue |
// them from the import queue |
1327 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
1338 |
} |
} |
1339 |
file_changed(); |
file_changed(); |
1340 |
} else if (sample) { |
} else if (sample) { |
1341 |
|
// notify everybody that we're going to remove this sample |
1342 |
|
std::list<gig::Sample*> lsamples; |
1343 |
|
lsamples.push_back(sample); |
1344 |
|
samples_to_be_removed_signal.emit(lsamples); |
1345 |
// remove sample from the .gig file |
// remove sample from the .gig file |
1346 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
1347 |
|
// notify that we're done with removal |
1348 |
|
samples_removed_signal.emit(); |
1349 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
1350 |
// the import queue |
// the import queue |
1351 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1357 |
break; |
break; |
1358 |
} |
} |
1359 |
} |
} |
1360 |
|
dimreg_changed(); |
1361 |
file_changed(); |
file_changed(); |
1362 |
} |
} |
1363 |
// remove respective row(s) from samples tree view |
// remove respective row(s) from samples tree view |
1364 |
m_refSamplesTreeModel->erase(it); |
m_refSamplesTreeModel->erase(it); |
1365 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
1366 |
|
// pretend we're done with removal (i.e. to avoid dead locks) |
1367 |
|
samples_removed_signal.emit(); |
1368 |
|
// show error message |
1369 |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); |
1370 |
msg.run(); |
msg.run(); |
1371 |
} |
} |
1372 |
} |
} |
1373 |
} |
} |
1374 |
|
|
1375 |
|
// For some reason drag_data_get gets called two times for each |
1376 |
|
// drag'n'drop (at least when target is an Entry). This work-around |
1377 |
|
// makes sure the code in drag_data_get and drop_drag_data_received is |
1378 |
|
// only executed once, as drag_begin only gets called once. |
1379 |
|
void MainWindow::on_sample_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context) |
1380 |
|
{ |
1381 |
|
first_call_to_drag_data_get = true; |
1382 |
|
} |
1383 |
|
|
1384 |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
void MainWindow::on_sample_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&, |
1385 |
Gtk::SelectionData& selection_data, guint, guint) |
Gtk::SelectionData& selection_data, guint, guint) |
1386 |
{ |
{ |
1387 |
|
if (!first_call_to_drag_data_get) return; |
1388 |
|
first_call_to_drag_data_get = false; |
1389 |
|
|
1390 |
// get selected sample |
// get selected sample |
1391 |
gig::Sample* sample = NULL; |
gig::Sample* sample = NULL; |
1392 |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection(); |
1407 |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
gig::Sample* sample = *((gig::Sample**) selection_data.get_data()); |
1408 |
|
|
1409 |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
if (sample && selection_data.get_length() == sizeof(gig::Sample*)) { |
1410 |
if (dimreg_edit.set_sample(sample)) { |
std::cout << "Drop received sample \"" << |
1411 |
std::cout << "Drop received sample \"" << |
sample->pInfo->Name << "\"" << std::endl; |
1412 |
sample->pInfo->Name << "\"" << std::endl; |
// drop success |
1413 |
// drop success |
context->drop_reply(true, time); |
1414 |
context->drop_reply(true, time); |
|
1415 |
return; |
//TODO: we should better move most of the following code to DimRegionEdit::set_sample() |
1416 |
|
|
1417 |
|
// notify everybody that we're going to alter the region |
1418 |
|
gig::Region* region = m_RegionChooser.get_region(); |
1419 |
|
region_to_be_changed_signal.emit(region); |
1420 |
|
|
1421 |
|
// find the samplechannel dimension |
1422 |
|
gig::dimension_def_t* stereo_dimension = 0; |
1423 |
|
for (int i = 0 ; i < region->Dimensions ; i++) { |
1424 |
|
if (region->pDimensionDefinitions[i].dimension == |
1425 |
|
gig::dimension_samplechannel) { |
1426 |
|
stereo_dimension = ®ion->pDimensionDefinitions[i]; |
1427 |
|
break; |
1428 |
|
} |
1429 |
|
} |
1430 |
|
bool channels_changed = false; |
1431 |
|
if (sample->Channels == 1 && stereo_dimension) { |
1432 |
|
// remove the samplechannel dimension |
1433 |
|
region->DeleteDimension(stereo_dimension); |
1434 |
|
channels_changed = true; |
1435 |
|
region_changed(); |
1436 |
|
} |
1437 |
|
dimreg_edit.set_sample(sample); |
1438 |
|
|
1439 |
|
if (sample->Channels == 2 && !stereo_dimension) { |
1440 |
|
// add samplechannel dimension |
1441 |
|
gig::dimension_def_t dim; |
1442 |
|
dim.dimension = gig::dimension_samplechannel; |
1443 |
|
dim.bits = 1; |
1444 |
|
dim.zones = 2; |
1445 |
|
region->AddDimension(&dim); |
1446 |
|
channels_changed = true; |
1447 |
|
region_changed(); |
1448 |
|
} |
1449 |
|
if (channels_changed) { |
1450 |
|
// unmap all samples with wrong number of channels |
1451 |
|
// TODO: maybe there should be a warning dialog for this |
1452 |
|
for (int i = 0 ; i < region->DimensionRegions ; i++) { |
1453 |
|
gig::DimensionRegion* d = region->pDimensionRegions[i]; |
1454 |
|
if (d->pSample && d->pSample->Channels != sample->Channels) { |
1455 |
|
gig::Sample* oldref = d->pSample; |
1456 |
|
d->pSample = NULL; |
1457 |
|
sample_ref_changed_signal.emit(oldref, NULL); |
1458 |
|
} |
1459 |
|
} |
1460 |
} |
} |
1461 |
|
|
1462 |
|
// notify we're done with altering |
1463 |
|
region_changed_signal.emit(region); |
1464 |
|
|
1465 |
|
return; |
1466 |
} |
} |
1467 |
// drop failed |
// drop failed |
1468 |
context->drop_reply(false, time); |
context->drop_reply(false, time); |
1501 |
file_changed(); |
file_changed(); |
1502 |
} |
} |
1503 |
} |
} |
1504 |
|
|
1505 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
1506 |
|
return file_structure_to_be_changed_signal; |
1507 |
|
} |
1508 |
|
|
1509 |
|
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() { |
1510 |
|
return file_structure_changed_signal; |
1511 |
|
} |
1512 |
|
|
1513 |
|
sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() { |
1514 |
|
return samples_to_be_removed_signal; |
1515 |
|
} |
1516 |
|
|
1517 |
|
sigc::signal<void>& MainWindow::signal_samples_removed() { |
1518 |
|
return samples_removed_signal; |
1519 |
|
} |
1520 |
|
|
1521 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() { |
1522 |
|
return region_to_be_changed_signal; |
1523 |
|
} |
1524 |
|
|
1525 |
|
sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() { |
1526 |
|
return region_changed_signal; |
1527 |
|
} |
1528 |
|
|
1529 |
|
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() { |
1530 |
|
return sample_ref_changed_signal; |
1531 |
|
} |
1532 |
|
|
1533 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() { |
1534 |
|
return dimreg_to_be_changed_signal; |
1535 |
|
} |
1536 |
|
|
1537 |
|
sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() { |
1538 |
|
return dimreg_changed_signal; |
1539 |
|
} |