--- gigedit/trunk/src/gigedit/mainwindow.cpp 2014/05/20 14:35:36 2566 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2017/05/05 18:44:59 3151 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Andreas Persson + * Copyright (C) 2006-2017 Andreas Persson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,6 +20,14 @@ #include #include +#include +// threads.h must be included first to be able to build with +// G_DISABLE_DEPRECATED +#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ + (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 +#include +#endif + #include #include #include @@ -27,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -45,20 +52,31 @@ #include "mainwindow.h" #include "Settings.h" #include "CombineInstrumentsDialog.h" +#include "scripteditor.h" +#include "scriptslots.h" +#include "ReferencesView.h" #include "../../gfx/status_attached.xpm" #include "../../gfx/status_detached.xpm" - +#include "gfx/builtinpix.h" +#include "MacroEditor.h" MainWindow::MainWindow() : + m_DimRegionChooser(*this), dimreg_label(_("Changes apply to:")), dimreg_all_regions(_("all regions")), dimreg_all_dimregs(_("all dimension splits")), - dimreg_stereo(_("both channels")) + dimreg_stereo(_("both channels")), + labelLegend(_("Legend:")), + labelNoSample(_(" No Sample")), + labelMissingSample(_(" Missing some Sample(s)")), + labelLooped(_(" Looped")), + labelSomeLoops(_(" Some Loop(s)")) { + loadBuiltInPix(); + // set_border_width(5); // set_default_size(400, 200); - add(m_VBox); // Handle selection @@ -78,6 +96,9 @@ m_ScrolledWindowSamples.add(m_TreeViewSamples); m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + m_ScrolledWindowScripts.add(m_TreeViewScripts); + m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + m_TreeViewNotebook.set_size_request(300); @@ -89,6 +110,36 @@ dimreg_hbox.add(dimreg_stereo); dimreg_vbox.add(dimreg_edit); dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK); + { + legend_hbox.add(labelLegend); + + imageNoSample.set(redDot); + imageNoSample.set_alignment(Gtk::ALIGN_END); + labelNoSample.set_alignment(Gtk::ALIGN_START); + legend_hbox.add(imageNoSample); + legend_hbox.add(labelNoSample); + + imageMissingSample.set(yellowDot); + imageMissingSample.set_alignment(Gtk::ALIGN_END); + labelMissingSample.set_alignment(Gtk::ALIGN_START); + legend_hbox.add(imageMissingSample); + legend_hbox.add(labelMissingSample); + + imageLooped.set(blackLoop); + imageLooped.set_alignment(Gtk::ALIGN_END); + labelLooped.set_alignment(Gtk::ALIGN_START); + legend_hbox.add(imageLooped); + legend_hbox.add(labelLooped); + + imageSomeLoops.set(grayLoop); + imageSomeLoops.set_alignment(Gtk::ALIGN_END); + labelSomeLoops.set_alignment(Gtk::ALIGN_START); + legend_hbox.add(imageSomeLoops); + legend_hbox.add(labelSomeLoops); + + legend_hbox.show_all_children(); + } + dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK); m_HPaned.add2(dimreg_vbox); dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right.")); @@ -98,49 +149,125 @@ m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples")); m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); - + m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); actionGroup = Gtk::ActionGroup::create(); actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); - actionGroup->add(Gtk::Action::create("New", Gtk::Stock::NEW), + actionGroup->add(Gtk::Action::create("New", _("_New")), + Gtk::AccelKey("n"), sigc::mem_fun( *this, &MainWindow::on_action_file_new)); - Glib::RefPtr action = - Gtk::Action::create("Open", Gtk::Stock::OPEN); - action->property_label() = action->property_label() + "..."; - actionGroup->add(action, + actionGroup->add(Gtk::Action::create("Open", _("_Open...")), + Gtk::AccelKey("o"), sigc::mem_fun( *this, &MainWindow::on_action_file_open)); - actionGroup->add(Gtk::Action::create("Save", Gtk::Stock::SAVE), + actionGroup->add(Gtk::Action::create("Save", _("_Save")), + Gtk::AccelKey("s"), sigc::mem_fun( *this, &MainWindow::on_action_file_save)); - action = Gtk::Action::create("SaveAs", Gtk::Stock::SAVE_AS); - action->property_label() = action->property_label() + "..."; - actionGroup->add(action, + actionGroup->add(Gtk::Action::create("SaveAs", _("Save _As...")), Gtk::AccelKey("s"), sigc::mem_fun( *this, &MainWindow::on_action_file_save_as)); actionGroup->add(Gtk::Action::create("Properties", - Gtk::Stock::PROPERTIES), + _("_Properties")), sigc::mem_fun( *this, &MainWindow::on_action_file_properties)); actionGroup->add(Gtk::Action::create("InstrProperties", - Gtk::Stock::PROPERTIES), + _("_Properties")), sigc::mem_fun( *this, &MainWindow::show_instr_props)); actionGroup->add(Gtk::Action::create("MidiRules", - _("_Midi Rules")), + _("_Midi Rules...")), sigc::mem_fun( *this, &MainWindow::show_midi_rules)); - actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), + actionGroup->add(Gtk::Action::create("ScriptSlots", + _("_Script Slots...")), + sigc::mem_fun( + *this, &MainWindow::show_script_slots)); + actionGroup->add(Gtk::Action::create("Quit", _("_Quit")), + Gtk::AccelKey("q"), sigc::mem_fun( *this, &MainWindow::on_action_quit)); - actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); - + actionGroup->add( + Gtk::Action::create("MenuSample", _("_Sample")), + sigc::mem_fun(*this, &MainWindow::show_samples_tab) + ); + actionGroup->add( + Gtk::Action::create("MenuInstrument", _("_Instrument")), + sigc::mem_fun(*this, &MainWindow::show_intruments_tab) + ); + actionGroup->add( + Gtk::Action::create("MenuScript", _("Scr_ipt")), + sigc::mem_fun(*this, &MainWindow::show_scripts_tab) + ); + actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); + const Gdk::ModifierType primaryModifierKey = +#if defined(__APPLE__) + Gdk::META_MASK; // Cmd key on Mac +#else + Gdk::CONTROL_MASK; // Ctrl key on all other OSs +#endif + + actionGroup->add(Gtk::Action::create("CopyDimRgn", + _("Copy selected dimension region")), + Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn)); + + actionGroup->add(Gtk::Action::create("PasteDimRgn", + _("Paste dimension region")), + Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn)); + + actionGroup->add(Gtk::Action::create("AdjustClipboard", + _("Adjust Clipboard Content")), + Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content)); + + actionGroup->add(Gtk::Action::create("SelectPrevRegion", + _("Select Previous Region")), + Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey), + sigc::mem_fun(*this, &MainWindow::select_prev_region)); + + actionGroup->add(Gtk::Action::create("SelectNextRegion", + _("Select Next Region")), + Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey), + sigc::mem_fun(*this, &MainWindow::select_next_region)); + + actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone", + _("Select Previous Dimension Region Zone")), + Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone)); + + actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone", + _("Select Next Dimension Region Zone")), + Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone)); + + actionGroup->add(Gtk::Action::create("SelectPrevDimension", + _("Select Previous Dimension")), + Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::select_prev_dimension)); + + actionGroup->add(Gtk::Action::create("SelectNextDimension", + _("Select Next Dimension")), + Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK), + sigc::mem_fun(*this, &MainWindow::select_next_dimension)); + + actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone", + _("Add Previous Dimension Region Zone to Selection")), + Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), + sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone)); + + actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone", + _("Add Next Dimension Region Zone to Selection")), + Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK), + sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone)); + Glib::RefPtr toggle_action = Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); toggle_action->set_active(true); @@ -157,7 +284,7 @@ actionGroup->add(toggle_action); - actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); + actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w"))); toggle_action = Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); toggle_action->set_active(true); @@ -165,10 +292,27 @@ sigc::mem_fun( *this, &MainWindow::on_action_view_status_bar)); - action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); - actionGroup->add(Gtk::Action::create("MenuHelp", - action->property_label())); - actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT), + toggle_action = + Gtk::ToggleAction::create("AutoRestoreWinDim", _("_Auto Restore Window Dimension")); + toggle_action->set_active(Settings::singleton()->autoRestoreWindowDimension); + actionGroup->add(toggle_action, + sigc::mem_fun( + *this, &MainWindow::on_auto_restore_win_dim)); + + toggle_action = + Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file")); + toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile); + actionGroup->add(toggle_action, + sigc::mem_fun( + *this, &MainWindow::on_save_with_temporary_file)); + + actionGroup->add( + Gtk::Action::create("RefreshAll", _("_Refresh All")), + sigc::mem_fun(*this, &MainWindow::on_action_refresh_all) + ); + + actionGroup->add(Gtk::Action::create("MenuHelp", _("_Help"))); + actionGroup->add(Gtk::Action::create("About", _("_About")), sigc::mem_fun( *this, &MainWindow::on_action_help_about)); actionGroup->add( @@ -180,7 +324,7 @@ sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) ); actionGroup->add( - Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), + Gtk::Action::create("RemoveInstrument", _("_Remove")), sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) ); @@ -195,6 +339,22 @@ sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions) ); + toggle_action = + Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection")); + toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection); + actionGroup->add( + toggle_action, + sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection) + ); + + toggle_action = + Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved")); + toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved); + actionGroup->add( + toggle_action, + sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved) + ); + actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); @@ -211,7 +371,7 @@ // sample right-click popup actions actionGroup->add( - Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), + Gtk::Action::create("SampleProperties", _("_Properties")), sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) ); actionGroup->add( @@ -223,14 +383,45 @@ sigc::mem_fun(*this, &MainWindow::on_action_add_sample) ); actionGroup->add( - Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE), + Gtk::Action::create("RemoveSample", _("_Remove")), sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) ); actionGroup->add( + Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")), + sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) + ); + actionGroup->add( + Gtk::Action::create("ShowSampleRefs", _("Show References...")), + sigc::mem_fun(*this, &MainWindow::on_action_view_references) + ); + actionGroup->add( + Gtk::Action::create("ReplaceSample", + _("Replace Sample...")), + sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) + ); + actionGroup->add( Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples in All Groups...")), sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) ); + + // script right-click popup actions + actionGroup->add( + Gtk::Action::create("AddScriptGroup", _("Add _Group")), + sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) + ); + actionGroup->add( + Gtk::Action::create("AddScript", _("Add _Script")), + sigc::mem_fun(*this, &MainWindow::on_action_add_script) + ); + actionGroup->add( + Gtk::Action::create("EditScript", _("_Edit Script...")), + sigc::mem_fun(*this, &MainWindow::on_action_edit_script) + ); + actionGroup->add( + Gtk::Action::create("RemoveScript", _("_Remove")), + sigc::mem_fun(*this, &MainWindow::on_action_remove_script) + ); uiManager = Gtk::UIManager::create(); uiManager->insert_action_group(actionGroup); @@ -251,14 +442,59 @@ " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " " " + " " + " " + " " " " " " " " @@ -266,6 +502,9 @@ " " " " " " + " " + " " + " " " " " " " " @@ -274,6 +513,7 @@ " " " " " " + " " " " " " " " @@ -283,9 +523,19 @@ " " " " " " + " " + " " " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " " " ""; uiManager->add_ui_from_string(ui_info); @@ -318,6 +568,35 @@ } { Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); + 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).")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved")); + item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around.")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples")); + item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones).")); + // copy tooltip to popup menu + Gtk::MenuItem* item2 = dynamic_cast( + uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples")); + item2->set_tooltip_text(item->get_tooltip_text()); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuView/RefreshAll")); + item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface.")); + } + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); + item->set_tooltip_text(_("If checked, size and position of all windows will be saved and automatically restored next time.")); + } + { + Gtk::MenuItem* item = dynamic_cast( uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments")); item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file.")); } @@ -329,7 +608,7 @@ instrument_menu = static_cast( - uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); + uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); @@ -355,22 +634,60 @@ // Create the Tree model: m_refTreeModel = Gtk::ListStore::create(m_Columns); m_TreeView.set_model(m_refTreeModel); - m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules.")); + m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); + m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments.")); instrument_name_connection = m_refTreeModel->signal_row_changed().connect( sigc::mem_fun(*this, &MainWindow::instrument_name_changed) ); // Add the TreeView's view columns: - m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name); - m_TreeView.set_headers_visible(false); + m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr); + m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name); + m_TreeView.set_headers_visible(true); + + // establish drag&drop within the instrument tree view, allowing to reorder + // the sequence of instruments within the gig file + { + std::vector drag_target_instrument; + drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument")); + m_TreeView.drag_source_set(drag_target_instrument); + m_TreeView.drag_dest_set(drag_target_instrument); + m_TreeView.signal_drag_begin().connect( + sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin) + ); + m_TreeView.signal_drag_data_get().connect( + sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get) + ); + m_TreeView.signal_drag_data_received().connect( + sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received) + ); + } // create samples treeview (including its data model) m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel); m_TreeViewSamples.set_model(m_refSamplesTreeModel); + m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE); m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples.")); // m_TreeViewSamples.set_reorderable(); - m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name); - m_TreeViewSamples.set_headers_visible(false); + m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name); + m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount); + { + Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); + Gtk::CellRendererText* cellrenderer = + dynamic_cast(column->get_first_cell()); + column->add_attribute( + cellrenderer->property_foreground(), m_SamplesModel.m_color + ); + } + { + Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); + Gtk::CellRendererText* cellrenderer = + dynamic_cast(column->get_first_cell()); + column->add_attribute( + cellrenderer->property_foreground(), m_SamplesModel.m_color + ); + } + m_TreeViewSamples.set_headers_visible(true); m_TreeViewSamples.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) ); @@ -378,6 +695,40 @@ sigc::mem_fun(*this, &MainWindow::sample_name_changed) ); + // create scripts treeview (including its data model) + m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); + m_TreeViewScripts.set_model(m_refScriptsTreeModel); + m_TreeViewScripts.set_tooltip_text(_( + "Use CTRL + double click for editing a script." + "\n\n" + "Note: instrument scripts are a LinuxSampler extension of the gig " + "format. This feature will not work with the GigaStudio software!" + )); + // m_TreeViewScripts.set_reorderable(); + m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); + m_TreeViewScripts.set_headers_visible(false); + m_TreeViewScripts.signal_button_press_event().connect_notify( + sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) + ); + //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ? + m_TreeViewScripts.signal_row_activated().connect( + sigc::mem_fun(*this, &MainWindow::script_double_clicked) + ); + m_refScriptsTreeModel->signal_row_changed().connect( + sigc::mem_fun(*this, &MainWindow::script_name_changed) + ); + + // establish drag&drop between scripts tree view and ScriptSlots window + std::vector drag_target_gig_script; + drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script")); + m_TreeViewScripts.drag_source_set(drag_target_gig_script); + m_TreeViewScripts.signal_drag_begin().connect( + sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin) + ); + m_TreeViewScripts.signal_drag_data_get().connect( + sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get) + ); + // establish drag&drop between samples tree view and dimension region 'Sample' text entry std::vector drag_target_gig_sample; drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample")); @@ -396,6 +747,8 @@ sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed))); m_RegionChooser.signal_instrument_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); + m_RegionChooser.signal_instrument_changed().connect( + sigc::mem_fun(*this, &MainWindow::region_changed)); m_DimRegionChooser.signal_region_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); instrumentProps.signal_changed().connect( @@ -411,6 +764,16 @@ dimreg_changed_signal.make_slot()); dimreg_edit.signal_sample_ref_changed().connect( sample_ref_changed_signal.make_slot()); + sample_ref_changed_signal.connect( + sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed) + ); + samples_to_be_removed_signal.connect( + sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed) + ); + + dimreg_edit.signal_select_sample().connect( + sigc::mem_fun(*this, &MainWindow::select_sample) + ); m_RegionChooser.signal_instrument_struct_to_be_changed().connect( sigc::hide( @@ -455,7 +818,13 @@ // select 'Instruments' tab by default // (gtk allows this only if the tab childs are visible, thats why it's here) - m_TreeViewNotebook.set_current_page(1); + m_TreeViewNotebook.set_current_page(1); + + Gtk::Clipboard::get()->signal_owner_change().connect( + sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change) + ); + updateClipboardPasteAvailable(); + updateClipboardCopyAvailable(); } MainWindow::~MainWindow() @@ -481,8 +850,9 @@ gig::Instrument* MainWindow::get_instrument() { gig::Instrument* instrument = 0; - Gtk::TreeModel::const_iterator it = - m_TreeView.get_selection()->get_selected(); + std::vector rows = m_TreeView.get_selection()->get_selected_rows(); + if (rows.empty()) return NULL; + Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); if (it) { Gtk::TreeModel::Row row = *it; instrument = row[m_Columns.m_col_instr]; @@ -525,6 +895,13 @@ add_region_to_dimregs(region, stereo, all_dimregs); } } + + m_RegionChooser.setModifyAllRegions(all_regions); + m_DimRegionChooser.setModifyAllRegions(all_regions); + m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); + m_DimRegionChooser.setModifyBothChannels(stereo); + + updateClipboardCopyAvailable(); } void MainWindow::dimreg_all_dimregs_toggled() @@ -536,22 +913,29 @@ void MainWindow::dimreg_changed() { update_dimregs(); - dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); + dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); } void MainWindow::on_sel_change() { // select item in instrument menu - Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected(); - if (it) { - Gtk::TreePath path(it); - int index = path[0]; - const std::vector children = - instrument_menu->get_children(); - static_cast(children[index])->set_active(); + std::vector rows = m_TreeView.get_selection()->get_selected_rows(); + if (!rows.empty()) { + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); + if (it) { + Gtk::TreePath path(it); + int index = path[0]; + const std::vector children = + instrument_menu->get_children(); + static_cast(children[index])->set_active(); + } } m_RegionChooser.set_instrument(get_instrument()); + + if (Settings::singleton()->syncSamplerInstrumentSelection) { + switch_sampler_instrument_signal.emit(get_instrument()); + } } void loader_progress_callback(gig::progress_t* progress) @@ -569,23 +953,36 @@ progress_dispatcher(); } +#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) +// make sure stack is 16-byte aligned for SSE instructions +__attribute__((force_align_arg_pointer)) +#endif void Loader::thread_function() { - printf("thread_function self=%x\n", Glib::Threads::Thread::self()); - printf("Start %s\n", filename); - RIFF::File* riff = new RIFF::File(filename); - gig = new gig::File(riff); - gig::progress_t progress; - progress.callback = loader_progress_callback; - progress.custom = this; - - gig->GetInstrument(0, &progress); - printf("End\n"); - finished_dispatcher(); + printf("thread_function self=%p\n", + static_cast(Glib::Threads::Thread::self())); + printf("Start %s\n", filename.c_str()); + try { + RIFF::File* riff = new RIFF::File(filename); + gig = new gig::File(riff); + gig::progress_t progress; + progress.callback = loader_progress_callback; + progress.custom = this; + + gig->GetInstrument(0, &progress); + printf("End\n"); + finished_dispatcher(); + } catch (RIFF::Exception e) { + error_message = e.Message; + error_dispatcher.emit(); + } catch (...) { + error_message = _("Unknown exception occurred"); + error_dispatcher.emit(); + } } Loader::Loader(const char* filename) - : filename(filename), thread(0) + : filename(filename), gig(0), thread(0), progress(0.f) { } @@ -596,7 +993,7 @@ #else thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); #endif - printf("launch thread=%x\n", thread); + printf("launch thread=%p\n", static_cast(thread)); } float Loader::get_progress() @@ -619,11 +1016,131 @@ return finished_dispatcher; } -LoadDialog::LoadDialog(const Glib::ustring& title, Gtk::Window& parent) +Glib::Dispatcher& Loader::signal_error() +{ + return error_dispatcher; +} + +void saver_progress_callback(gig::progress_t* progress) +{ + Saver* saver = static_cast(progress->custom); + saver->progress_callback(progress->factor); +} + +void Saver::progress_callback(float fraction) +{ + { + Glib::Threads::Mutex::Lock lock(progressMutex); + progress = fraction; + } + progress_dispatcher.emit(); +} + +#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) +// make sure stack is 16-byte aligned for SSE instructions +__attribute__((force_align_arg_pointer)) +#endif +void Saver::thread_function() +{ + printf("thread_function self=%p\n", + static_cast(Glib::Threads::Thread::self())); + printf("Start %s\n", filename.c_str()); + try { + gig::progress_t progress; + progress.callback = saver_progress_callback; + progress.custom = this; + + // if no filename was provided, that means "save", if filename was provided means "save as" + if (filename.empty()) { + if (!Settings::singleton()->saveWithTemporaryFile) { + // save directly over the existing .gig file + // (requires less disk space than solution below + // but may be slower) + gig->Save(&progress); + } else { + // save the file as separate temporary file first, + // then move the saved file over the old file + // (may result in performance speedup during save) + String tmpname = filename + ".TMP"; + gig->Save(tmpname, &progress); + #if defined(WIN32) + if (!DeleteFile(filename.c_str())) { + throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file)."); + } + #else // POSIX ... + if (unlink(filename.c_str())) { + throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno))); + } + #endif + if (rename(tmpname.c_str(), filename.c_str())) { + #if defined(WIN32) + throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file)."); + #else + throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno))); + #endif + } + } + } else { + gig->Save(filename, &progress); + } + + printf("End\n"); + finished_dispatcher.emit(); + } catch (RIFF::Exception e) { + error_message = e.Message; + error_dispatcher.emit(); + } catch (...) { + error_message = _("Unknown exception occurred"); + error_dispatcher.emit(); + } +} + +Saver::Saver(gig::File* file, Glib::ustring filename) + : gig(file), filename(filename), thread(0), progress(0.f) +{ +} + +void Saver::launch() +{ +#ifdef OLD_THREADS + thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); +#else + thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); +#endif + printf("launch thread=%p\n", static_cast(thread)); +} + +float Saver::get_progress() +{ + float res; + { + Glib::Threads::Mutex::Lock lock(progressMutex); + res = progress; + } + return res; +} + +Glib::Dispatcher& Saver::signal_progress() +{ + return progress_dispatcher; +} + +Glib::Dispatcher& Saver::signal_finished() +{ + return finished_dispatcher; +} + +Glib::Dispatcher& Saver::signal_error() +{ + return error_dispatcher; +} + +ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) { get_vbox()->pack_start(progressBar); show_all_children(); + resize(600,50); } // Clear all GUI elements / controls. This method is typically called @@ -634,6 +1151,7 @@ // clear the samples and instruments tree views m_refTreeModel->clear(); m_refSamplesTreeModel->clear(); + m_refScriptsTreeModel->clear(); // remove all entries from "Instrument" menu while (!instrument_menu->get_children().empty()) { remove_instrument_from_menu(0); @@ -648,6 +1166,7 @@ // clear the samples and instruments tree views m_refTreeModel->clear(); m_refSamplesTreeModel->clear(); + m_refScriptsTreeModel->clear(); // remove all entries from "Instrument" menu while (!instrument_menu->get_children().empty()) { remove_instrument_from_menu(0); @@ -685,13 +1204,28 @@ g_free(msg); dialog.set_secondary_text(_("If you close without saving, your changes will be lost.")); dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(file_has_name ? _("_Save") : _("Save _As"), Gtk::RESPONSE_YES); dialog.set_default_response(Gtk::RESPONSE_YES); int response = dialog.run(); dialog.hide(); - if (response == Gtk::RESPONSE_YES) return file_save(); - return response != Gtk::RESPONSE_CANCEL; + + // user decided to exit app without saving + if (response == Gtk::RESPONSE_NO) return true; + + // user cancelled dialog, thus don't close app + if (response == Gtk::RESPONSE_CANCEL) return false; + + // TODO: the following return valid is disabled and hard coded instead for + // now, due to the fact that saving with progress bar is now implemented + // asynchronously, as a result the app does not close automatically anymore + // after saving the file has completed + // + // if (response == Gtk::RESPONSE_YES) return file_save(); + // return response != Gtk::RESPONSE_CANCEL; + // + if (response == Gtk::RESPONSE_YES) file_save(); + return false; // always prevent closing the app for now (see comment above) } bool MainWindow::leaving_shared_mode_dialog() { @@ -702,7 +1236,7 @@ "used by the sampler until you tell the sampler explicitly to " "load it.")); dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); dialog.set_default_response(Gtk::RESPONSE_CANCEL); int response = dialog.run(); dialog.hide(); @@ -716,8 +1250,8 @@ if (file_is_shared && !leaving_shared_mode_dialog()) return; Gtk::FileChooserDialog dialog(*this, _("Open file")); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); dialog.set_default_response(Gtk::RESPONSE_OK); #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 Gtk::FileFilter filter; @@ -733,7 +1267,8 @@ if (dialog.run() == Gtk::RESPONSE_OK) { std::string filename = dialog.get_filename(); printf("filename=%s\n", filename.c_str()); - printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self()); + printf("on_action_file_open self=%p\n", + static_cast(Glib::Threads::Thread::self())); load_file(filename.c_str()); current_gig_dir = Glib::path_get_dirname(filename); } @@ -742,13 +1277,20 @@ void MainWindow::load_file(const char* name) { __clear(); - load_dialog = new LoadDialog(_("Loading..."), *this); - load_dialog->show_all(); - loader = new Loader(strdup(name)); + + progress_dialog = new ProgressDialog( //FIXME: memory leak! + _("Loading") + Glib::ustring(" '") + + Glib::filename_display_basename(name) + "' ...", + *this + ); + progress_dialog->show_all(); + loader = new Loader(name); //FIXME: memory leak! loader->signal_progress().connect( sigc::mem_fun(*this, &MainWindow::on_loader_progress)); loader->signal_finished().connect( sigc::mem_fun(*this, &MainWindow::on_loader_finished)); + loader->signal_error().connect( + sigc::mem_fun(*this, &MainWindow::on_loader_error)); loader->launch(); } @@ -764,20 +1306,50 @@ // load the instrument gig::File* pFile = (gig::File*) instr->GetParent(); load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); - //TODO: automatically select the given instrument + // automatically select the given instrument + int i = 0; + for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; + instrument = pFile->GetNextInstrument(), ++i) + { + if (instrument == instr) { + // select item in "instruments" tree view + m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); + // make sure the selected item in the "instruments" tree view is + // visible (scroll to it) + m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); + // select item in instrument menu + { + const std::vector children = + instrument_menu->get_children(); + static_cast(children[i])->set_active(); + } + // update region chooser and dimension region chooser + m_RegionChooser.set_instrument(instr); + break; + } + } } void MainWindow::on_loader_progress() { - load_dialog->set_fraction(loader->get_progress()); + progress_dialog->set_fraction(loader->get_progress()); } void MainWindow::on_loader_finished() { printf("Loader finished!\n"); - printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); - load_gig(loader->gig, loader->filename); - load_dialog->hide(); + printf("on_loader_finished self=%p\n", + static_cast(Glib::Threads::Thread::self())); + load_gig(loader->gig, loader->filename.c_str()); + progress_dialog->hide(); +} + +void MainWindow::on_loader_error() +{ + Glib::ustring txt = _("Could not load file: ") + loader->error_message; + Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); + msg.run(); + progress_dialog->hide(); } void MainWindow::on_action_file_save() @@ -816,23 +1388,54 @@ std::cout << "Saving file\n" << std::flush; file_structure_to_be_changed_signal.emit(this->file); - try { - file->Save(); - if (file_is_changed) { - set_title(get_title().substr(1)); - 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; - } - std::cout << "Saving file done\n" << std::flush; + + progress_dialog = new ProgressDialog( //FIXME: memory leak! + _("Saving") + Glib::ustring(" '") + + Glib::filename_display_basename(this->filename) + "' ...", + *this + ); + progress_dialog->show_all(); + saver = new Saver(this->file); //FIXME: memory leak! + saver->signal_progress().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_progress)); + saver->signal_finished().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_finished)); + saver->signal_error().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_error)); + saver->launch(); + + return true; +} + +void MainWindow::on_saver_progress() +{ + progress_dialog->set_fraction(saver->get_progress()); +} + +void MainWindow::on_saver_error() +{ + file_structure_changed_signal.emit(this->file); + Glib::ustring txt = _("Could not save file: ") + saver->error_message; + Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); + msg.run(); +} + +void MainWindow::on_saver_finished() +{ + this->file = saver->gig; + this->filename = saver->filename; + current_gig_dir = Glib::path_get_dirname(filename); + set_title(Glib::filename_display_basename(filename)); + file_has_name = true; + file_is_changed = false; + std::cout << "Saving file done. Importing queued samples now ...\n" << std::flush; __import_queued_samples(); + std::cout << "Importing queued samples done.\n" << std::flush; + file_structure_changed_signal.emit(this->file); - return true; + + __refreshEntireGUI(); + progress_dialog->hide(); } void MainWindow::on_action_file_save_as() @@ -843,9 +1446,9 @@ bool MainWindow::file_save_as() { - Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + Gtk::FileChooserDialog dialog(*this, _("Save As"), Gtk::FILE_CHOOSER_ACTION_SAVE); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); dialog.set_default_response(Gtk::RESPONSE_OK); dialog.set_do_overwrite_confirmation(); @@ -876,7 +1479,9 @@ // show warning in the dialog Gtk::HBox descriptionArea; descriptionArea.set_spacing(15); - Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); + Gtk::Image warningIcon; + warningIcon.set_from_icon_name("dialog-warning", + Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); #if GTKMM_MAJOR_VERSION < 3 view::WrapLabel description; @@ -897,28 +1502,28 @@ descriptionArea.show_all(); if (dialog.run() == Gtk::RESPONSE_OK) { - file_structure_to_be_changed_signal.emit(this->file); - try { - std::string filename = dialog.get_filename(); - 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; + std::string filename = dialog.get_filename(); + if (!Glib::str_has_suffix(filename, ".gig")) { + filename += ".gig"; } - __import_queued_samples(); - file_structure_changed_signal.emit(this->file); + printf("filename=%s\n", filename.c_str()); + + progress_dialog = new ProgressDialog( //FIXME: memory leak! + _("Saving") + Glib::ustring(" '") + + Glib::filename_display_basename(filename) + "' ...", + *this + ); + progress_dialog->show_all(); + + saver = new Saver(file, filename); //FIXME: memory leak! + saver->signal_progress().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_progress)); + saver->signal_finished().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_finished)); + saver->signal_error().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_error)); + saver->launch(); + return true; } return false; @@ -928,13 +1533,13 @@ void MainWindow::__import_queued_samples() { std::cout << "Starting sample import\n" << std::flush; Glib::ustring error_files; - printf("Samples to import: %d\n", m_SampleImportQueue.size()); - for (std::list::iterator iter = m_SampleImportQueue.begin(); + printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); + for (std::map::iterator iter = m_SampleImportQueue.begin(); iter != m_SampleImportQueue.end(); ) { - printf("Importing sample %s\n",(*iter).sample_path.c_str()); + printf("Importing sample %s\n",iter->second.sample_path.c_str()); SF_INFO info; info.format = 0; - SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info); + SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info); sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); try { if (!hFile) throw std::string(_("could not open file")); @@ -957,6 +1562,9 @@ throw std::string(_("format not supported")); // unsupported subformat (yet?) } + // reset write position for sample + iter->first->SetPos(0); + const int bufsize = 10000; switch (bitdepth) { case 16: { @@ -966,7 +1574,7 @@ // libsndfile does the conversion for us (if needed) int n = sf_readf_short(hFile, buffer, bufsize); // write from buffer directly (physically) into .gig file - iter->gig_sample->Write(buffer, n); + iter->first->Write(buffer, n); cnt -= n; } delete[] buffer; @@ -986,7 +1594,7 @@ dstbuf[j++] = srcbuf[i] >> 24; } // write from buffer directly (physically) into .gig file - iter->gig_sample->Write(dstbuf, n); + iter->first->Write(dstbuf, n); cnt -= n; } delete[] srcbuf; @@ -997,16 +1605,16 @@ // cleanup sf_close(hFile); // let the sampler re-cache the sample if needed - sample_changed_signal.emit(iter->gig_sample); + sample_changed_signal.emit(iter->first); // on success we remove the sample from the import queue, // otherwise keep it, maybe it works the next time ? - std::list::iterator cur = iter; + std::map::iterator cur = iter; ++iter; m_SampleImportQueue.erase(cur); } catch (std::string what) { // remember the files that made trouble (and their cause) if (!error_files.empty()) error_files += "\n"; - error_files += (*iter).sample_path += " (" + what + ")"; + error_files += iter->second.sample_path += " (" + what + ")"; ++iter; } } @@ -1029,6 +1637,16 @@ !Settings::singleton()->warnUserOnExtensions; } +void MainWindow::on_action_sync_sampler_instrument_selection() { + Settings::singleton()->syncSamplerInstrumentSelection = + !Settings::singleton()->syncSamplerInstrumentSelection; +} + +void MainWindow::on_action_move_root_note_with_region_moved() { + Settings::singleton()->moveRootNoteWithRegionMoved = + !Settings::singleton()->moveRootNoteWithRegionMoved; +} + void MainWindow::on_action_help_about() { Gtk::AboutDialog dialog; @@ -1038,15 +1656,15 @@ dialog.set_name("Gigedit"); #endif dialog.set_version(VERSION); - dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson"); + dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson"); const std::string sComment = _("Built " __DATE__ "\nUsing ") + ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + _( "Gigedit is released under the GNU General Public License.\n" "\n" - "Please notice that this is still a very young instrument editor. " - "So better backup your Gigasampler files before editing them with " + "This program is distributed WITHOUT ANY WARRANTY; So better " + "backup your Gigasampler/GigaStudio files before editing them with " "this application.\n" "\n" "Please report bugs to: http://bugs.linuxsampler.org" @@ -1075,7 +1693,7 @@ eSourceForm(_("Source form")), eCommissioned(_("Commissioned")), eSubject(_("Subject")), - quitButton(Gtk::Stock::CLOSE), + quitButton(_("_Close"), true), table(2, 1), m_file(NULL) { @@ -1154,7 +1772,7 @@ } std::vector texts; for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); - texts.push_back(NULL); values.push_back(NULL); + texts.push_back(NULL); values.push_back(0); eFileFormat.set_choices(&texts[0], &values[0]); eFileFormat.set_value(major); } @@ -1198,7 +1816,7 @@ } InstrumentProps::InstrumentProps() : - quitButton(Gtk::Stock::CLOSE), + quitButton(_("_Close"), true), table(2,1), eName(_("Name")), eIsDrum(_("Is drum")), @@ -1295,12 +1913,36 @@ } } +void MainWindow::updateSampleRefCountMap(gig::File* gig) { + sample_ref_count.clear(); + + if (!gig) return; + + for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument; + instrument = gig->GetNextInstrument()) + { + for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; + rgn = instrument->GetNextRegion()) + { + for (int i = 0; i < 256; ++i) { + if (!rgn->pDimensionRegions[i]) continue; + if (rgn->pDimensionRegions[i]->pSample) { + sample_ref_count[rgn->pDimensionRegions[i]->pSample]++; + } + } + } + } +} + void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) { file = 0; set_file_is_shared(isSharedInstrument); - this->filename = filename ? filename : _("Unsaved Gig File"); + this->filename = + (filename && strlen(filename) > 0) ? + filename : (!gig->GetFileName().empty()) ? + gig->GetFileName() : _("Unsaved Gig File"); set_title(Glib::filename_display_basename(this->filename)); file_has_name = filename; file_is_changed = false; @@ -1309,19 +1951,23 @@ propDialog.set_info(gig->pInfo); instrument_name_connection.block(); + int index = 0; for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ; - instrument = gig->GetNextInstrument()) { + instrument = gig->GetNextInstrument(), ++index) { Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); Gtk::TreeModel::iterator iter = m_refTreeModel->append(); Gtk::TreeModel::Row row = *iter; + row[m_Columns.m_col_nr] = index; row[m_Columns.m_col_name] = name; row[m_Columns.m_col_instr] = instrument; add_instrument_to_menu(name); } instrument_name_connection.unblock(); - uiManager->get_widget("/MenuBar/MenuInstrument")->show(); + uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); + + updateSampleRefCountMap(gig); for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) { if (group->Name != "") { @@ -1339,9 +1985,35 @@ gig_to_utf8(sample->pInfo->Name); rowSample[m_SamplesModel.m_col_sample] = sample; rowSample[m_SamplesModel.m_col_group] = NULL; + int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; + rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); + rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; } } } + + for (int i = 0; gig->GetScriptGroup(i); ++i) { + gig::ScriptGroup* group = gig->GetScriptGroup(i); + + Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); + Gtk::TreeModel::Row rowGroup = *iterGroup; + rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); + rowGroup[m_ScriptsModel.m_col_group] = group; + rowGroup[m_ScriptsModel.m_col_script] = NULL; + for (int s = 0; group->GetScript(s); ++s) { + gig::Script* script = group->GetScript(s); + + Gtk::TreeModel::iterator iterScript = + m_refScriptsTreeModel->append(rowGroup.children()); + Gtk::TreeModel::Row rowScript = *iterScript; + rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name); + rowScript[m_ScriptsModel.m_col_script] = script; + rowScript[m_ScriptsModel.m_col_group] = NULL; + } + } + // unfold all sample groups & script groups by default + m_TreeViewSamples.expand_all(); + m_TreeViewScripts.expand_all(); file = gig; @@ -1359,8 +2031,12 @@ { instrumentProps.signal_name_changed().clear(); - Gtk::TreeModel::const_iterator it = - m_TreeView.get_selection()->get_selected(); + std::vector rows = m_TreeView.get_selection()->get_selected_rows(); + if (rows.empty()) { + instrumentProps.hide(); + return false; + } + Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); if (it) { Gtk::TreeModel::Row row = *it; gig::Instrument* instrument = row[m_Columns.m_col_instr]; @@ -1410,6 +2086,27 @@ } } +void MainWindow::show_script_slots() { + if (!file) return; + // get selected instrument + std::vector rows = m_TreeView.get_selection()->get_selected_rows(); + if (rows.empty()) return; + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); + if (!it) return; + Gtk::TreeModel::Row row = *it; + gig::Instrument* instrument = row[m_Columns.m_col_instr]; + if (!instrument) return; + + ScriptSlots* window = new ScriptSlots; + window->setInstrument(instrument); + //window->reparent(*this); + window->show(); +} + +void MainWindow::on_action_refresh_all() { + __refreshEntireGUI(); +} + void MainWindow::on_action_view_status_bar() { Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); @@ -1421,6 +2118,26 @@ else m_StatusBar.hide(); } +void MainWindow::on_auto_restore_win_dim() { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/AutoRestoreWinDim")); + if (!item) { + std::cerr << "/MenuBar/MenuView/AutoRestoreWinDim == NULL\n"; + return; + } + Settings::singleton()->autoRestoreWindowDimension = item->get_active(); +} + +void MainWindow::on_save_with_temporary_file() { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile")); + if (!item) { + std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n"; + return; + } + Settings::singleton()->saveWithTemporaryFile = item->get_active(); +} + bool MainWindow::is_copy_samples_unity_note_enabled() const { Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); @@ -1457,9 +2174,15 @@ show_instr_props(); } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { // gig v2 files have no midi rules + const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); + static_cast( + uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( + bEnabled + ); static_cast( uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( - !(file->pVersion && file->pVersion->major == 2)); + bEnabled + ); popup_menu->popup(button->button, button->time); } } @@ -1479,33 +2202,178 @@ } } +void MainWindow::select_instrument(gig::Instrument* instrument) { + if (!instrument) return; + + Glib::RefPtr model = m_TreeView.get_model(); + for (int i = 0; i < model->children().size(); ++i) { + Gtk::TreeModel::Row row = model->children()[i]; + if (row[m_Columns.m_col_instr] == instrument) { + // select and show the respective instrument in the list view + show_intruments_tab(); + m_TreeView.get_selection()->unselect_all(); + m_TreeView.get_selection()->select(model->children()[i]); + std::vector rows = + m_TreeView.get_selection()->get_selected_rows(); + if (!rows.empty()) + m_TreeView.scroll_to_row(rows[0]); + on_sel_change(); // the regular instrument selection change callback + } + } +} + +/// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error. +bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) { + gig::Region* pRegion = (gig::Region*) dimRgn->GetParent(); + gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent(); + + Glib::RefPtr model = m_TreeView.get_model(); + for (int i = 0; i < model->children().size(); ++i) { + Gtk::TreeModel::Row row = model->children()[i]; + if (row[m_Columns.m_col_instr] == pInstrument) { + // select and show the respective instrument in the list view + show_intruments_tab(); + m_TreeView.get_selection()->unselect_all(); + m_TreeView.get_selection()->select(model->children()[i]); + std::vector rows = + m_TreeView.get_selection()->get_selected_rows(); + if (!rows.empty()) + m_TreeView.scroll_to_row(rows[0]); + on_sel_change(); // the regular instrument selection change callback + + // select respective region in the region selector + m_RegionChooser.set_region(pRegion); + + // select and show the respective dimension region in the editor + //update_dimregs(); + if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false; + //dimreg_edit.set_dim_region(dimRgn); + + return true; + } + } + + return false; +} + +void MainWindow::select_sample(gig::Sample* sample) { + Glib::RefPtr model = m_TreeViewSamples.get_model(); + for (int g = 0; g < model->children().size(); ++g) { + Gtk::TreeModel::Row rowGroup = model->children()[g]; + for (int s = 0; s < rowGroup.children().size(); ++s) { + Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; + if (rowSample[m_SamplesModel.m_col_sample] == sample) { + show_samples_tab(); + m_TreeViewSamples.get_selection()->unselect_all(); + m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); + std::vector rows = + m_TreeViewSamples.get_selection()->get_selected_rows(); + if (rows.empty()) return; + m_TreeViewSamples.scroll_to_row(rows[0]); + return; + } + } + } +} + void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { if (button->type == GDK_BUTTON_PRESS && button->button == 3) { + // by default if Ctrl keys is pressed down, then a mouse right-click + // does not select the respective row, so we must assure this + // programmatically ... + /*{ + Gtk::TreeModel::Path path; + Gtk::TreeViewColumn* pColumn = NULL; + int cellX, cellY; + bool bSuccess = m_TreeViewSamples.get_path_at_pos( + (int)button->x, (int)button->y, + path, pColumn, cellX, cellY + ); + if (bSuccess) { + if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) { + printf("not selected !!!\n"); + m_TreeViewSamples.get_selection()->select(path); + } + } + }*/ + Gtk::Menu* sample_popup = dynamic_cast(uiManager->get_widget("/SamplePopupMenu")); // update enabled/disabled state of sample popup items Glib::RefPtr sel = m_TreeViewSamples.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); - bool group_selected = false; - bool sample_selected = false; - if (it) { + std::vector rows = sel->get_selected_rows(); + const int n = rows.size(); + int nGroups = 0; + int nSamples = 0; + for (int r = 0; r < n; ++r) { + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); + if (!it) continue; Gtk::TreeModel::Row row = *it; - group_selected = row[m_SamplesModel.m_col_group]; - sample_selected = row[m_SamplesModel.m_col_sample]; + if (row[m_SamplesModel.m_col_group]) nGroups++; + if (row[m_SamplesModel.m_col_sample]) nSamples++; } + dynamic_cast(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n == 1); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> set_sensitive(file); + dynamic_cast(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> + set_sensitive(nSamples == 1); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n); // show sample popup sample_popup->popup(button->button, button->time); + + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> + set_sensitive(n == 1); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> + set_sensitive(n); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> + set_sensitive(file); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> + set_sensitive(nSamples == 1); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> + set_sensitive(n); } } +void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { + if (button->type == GDK_BUTTON_PRESS && button->button == 3) { + Gtk::Menu* script_popup = + dynamic_cast(uiManager->get_widget("/ScriptPopupMenu")); + // update enabled/disabled state of sample popup items + Glib::RefPtr sel = m_TreeViewScripts.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + bool group_selected = false; + bool script_selected = false; + if (it) { + Gtk::TreeModel::Row row = *it; + group_selected = row[m_ScriptsModel.m_col_group]; + script_selected = row[m_ScriptsModel.m_col_script]; + } + dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> + set_sensitive(group_selected || script_selected); + dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> + set_sensitive(file); + dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/EditScript"))-> + set_sensitive(script_selected); + dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> + set_sensitive(group_selected || script_selected); + // show sample popup + script_popup->popup(button->button, button->time); + + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> + set_sensitive(group_selected || script_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> + set_sensitive(file); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> + set_sensitive(script_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> + set_sensitive(group_selected || script_selected); + } +} Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( const Glib::ustring& name, int position) { @@ -1546,6 +2414,7 @@ instrument_name_connection.block(); Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append(); Gtk::TreeModel::Row rowInstr = *iterInstr; + rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1; rowInstr[m_Columns.m_col_name] = name; rowInstr[m_Columns.m_col_instr] = instrument; instrument_name_connection.unblock(); @@ -1574,19 +2443,23 @@ // retrieve the currently selected instrument // (being the original instrument to be duplicated) Glib::RefPtr sel = m_TreeView.get_selection(); - Gtk::TreeModel::iterator itSelection = sel->get_selected(); - if (!itSelection) return; - Gtk::TreeModel::Row row = *itSelection; - gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; - if (!instrOrig) return; - - // duplicate the orginal instrument - gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); - instrNew->pInfo->Name = - instrOrig->pInfo->Name + - gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); + std::vector rows = sel->get_selected_rows(); + for (int r = 0; r < rows.size(); ++r) { + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); + if (it) { + Gtk::TreeModel::Row row = *it; + gig::Instrument* instrOrig = row[m_Columns.m_col_instr]; + if (instrOrig) { + // duplicate the orginal instrument + gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig); + instrNew->pInfo->Name = + instrOrig->pInfo->Name + + gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")"); - add_instrument(instrNew); + add_instrument(instrNew); + } + } + } } void MainWindow::on_action_remove_instrument() { @@ -1603,8 +2476,10 @@ } Glib::RefPtr sel = m_TreeView.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); - if (it) { + std::vector rows = sel->get_selected_rows(); + for (int r = rows.size() - 1; r >= 0; --r) { + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]); + if (!it) continue; Gtk::TreeModel::Row row = *it; gig::Instrument* instr = row[m_Columns.m_col_instr]; try { @@ -1619,6 +2494,16 @@ // remove row from instruments tree view m_refTreeModel->erase(it); + // update "Nr" column of all instrument rows + { + int index = 0; + for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin(); + it != m_refTreeModel->children().end(); ++it, ++index) + { + Gtk::TreeModel::Row row = *it; + row[m_Columns.m_col_nr] = index; + } + } #if GTKMM_MAJOR_VERSION < 3 // select another instrument (in gtk3 this is done @@ -1653,6 +2538,124 @@ msg.run(); } +void MainWindow::on_action_add_script_group() { + static int __script_indexer = 0; + if (!file) return; + gig::ScriptGroup* group = file->AddScriptGroup(); + group->Name = gig_from_utf8(_("Unnamed Group")); + if (__script_indexer) group->Name += " " + ToString(__script_indexer); + __script_indexer++; + // update sample tree view + Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append(); + Gtk::TreeModel::Row rowGroup = *iterGroup; + rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name); + rowGroup[m_ScriptsModel.m_col_script] = NULL; + rowGroup[m_ScriptsModel.m_col_group] = group; + file_changed(); +} + +void MainWindow::on_action_add_script() { + if (!file) return; + // get selected group + Glib::RefPtr sel = m_TreeViewScripts.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + if (!it) return; + Gtk::TreeModel::Row row = *it; + gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; + if (!group) { // not a group, but a script is selected (probably) + gig::Script* script = row[m_ScriptsModel.m_col_script]; + if (!script) return; + it = row.parent(); // resolve parent (that is the script's group) + if (!it) return; + row = *it; + group = row[m_ScriptsModel.m_col_group]; + if (!group) return; + } + + // add a new script to the .gig file + gig::Script* script = group->AddScript(); + Glib::ustring name = _("Unnamed Script"); + script->Name = gig_from_utf8(name); + + // add script to the tree view + Gtk::TreeModel::iterator iterScript = + m_refScriptsTreeModel->append(row.children()); + Gtk::TreeModel::Row rowScript = *iterScript; + rowScript[m_ScriptsModel.m_col_name] = name; + rowScript[m_ScriptsModel.m_col_script] = script; + rowScript[m_ScriptsModel.m_col_group] = NULL; + + // unfold group of new script item in treeview + Gtk::TreeModel::Path path(iterScript); + m_TreeViewScripts.expand_to_path(path); +} + +void MainWindow::on_action_edit_script() { + if (!file) return; + // get selected script + Glib::RefPtr sel = m_TreeViewScripts.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + if (!it) return; + Gtk::TreeModel::Row row = *it; + gig::Script* script = row[m_ScriptsModel.m_col_script]; + if (!script) return; + + ScriptEditor* editor = new ScriptEditor; + editor->signal_script_to_be_changed.connect( + signal_script_to_be_changed.make_slot() + ); + editor->signal_script_changed.connect( + signal_script_changed.make_slot() + ); + editor->setScript(script); + //editor->reparent(*this); + editor->show(); +} + +void MainWindow::on_action_remove_script() { + if (!file) return; + Glib::RefPtr sel = m_TreeViewScripts.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + if (it) { + Gtk::TreeModel::Row row = *it; + gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; + gig::Script* script = row[m_ScriptsModel.m_col_script]; + Glib::ustring name = row[m_ScriptsModel.m_col_name]; + try { + // remove script group or script from the gig file + if (group) { + // notify everybody that we're going to remove these samples +//TODO: scripts_to_be_removed_signal.emit(members); + // delete the group in the .gig file including the + // samples that belong to the group + file->DeleteScriptGroup(group); + // notify that we're done with removal +//TODO: scripts_removed_signal.emit(); + file_changed(); + } else if (script) { + // notify everybody that we're going to remove this sample +//TODO: std::list lscripts; +//TODO: lscripts.push_back(script); +//TODO: scripts_to_be_removed_signal.emit(lscripts); + // remove sample from the .gig file + script->GetGroup()->DeleteScript(script); + // notify that we're done with removal +//TODO: scripts_removed_signal.emit(); + dimreg_changed(); + file_changed(); + } + // remove respective row(s) from samples tree view + m_refScriptsTreeModel->erase(it); + } catch (RIFF::Exception e) { + // pretend we're done with removal (i.e. to avoid dead locks) +//TODO: scripts_removed_signal.emit(); + // show error message + Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); + msg.run(); + } + } +} + void MainWindow::on_action_add_group() { static int __sample_indexer = 0; if (!file) return; @@ -1669,28 +2672,42 @@ file_changed(); } +void MainWindow::on_action_replace_sample() { + add_or_replace_sample(true); +} + void MainWindow::on_action_add_sample() { + add_or_replace_sample(false); +} + +void MainWindow::add_or_replace_sample(bool replace) { if (!file) return; - // get selected group + + // get selected group (and probably selected sample) Glib::RefPtr sel = m_TreeViewSamples.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); + std::vector rows = sel->get_selected_rows(); + if (rows.empty()) return; + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); if (!it) return; Gtk::TreeModel::Row row = *it; + gig::Sample* sample = NULL; gig::Group* group = row[m_SamplesModel.m_col_group]; if (!group) { // not a group, but a sample is selected (probably) - gig::Sample* sample = row[m_SamplesModel.m_col_sample]; - if (!sample) return; + if (replace) sample = row[m_SamplesModel.m_col_sample]; + if (!row[m_SamplesModel.m_col_sample]) return; it = row.parent(); // resolve parent (that is the sample's group) if (!it) return; - row = *it; - group = row[m_SamplesModel.m_col_group]; + if (!replace) row = *it; + group = (*it)[m_SamplesModel.m_col_group]; if (!group) return; } + if (replace && !sample) return; + // show 'browse for file' dialog - Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)")); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); - dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - dialog.set_select_multiple(true); + Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); + dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample // matches all file types supported by libsndfile #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 @@ -1761,8 +2778,8 @@ sf_close(hFile); // close sound file throw std::string(_("format not supported")); // unsupported subformat (yet?) } - // add a new sample to the .gig file - gig::Sample* sample = file->AddSample(); + // add a new sample to the .gig file (if adding is requested actually) + if (!replace) sample = file->AddSample(); // file name without path Glib::ustring filename = Glib::filename_display_basename(*iter); // remove file extension if there is one @@ -1813,21 +2830,25 @@ // physically when File::Save() is called) sample->Resize(info.frames); // make sure sample is part of the selected group - group->AddSample(sample); + if (!replace) group->AddSample(sample); // schedule that physical resize and sample import // (data copying), performed when "Save" is requested SampleImportItem sched_item; sched_item.gig_sample = sample; sched_item.sample_path = *iter; - m_SampleImportQueue.push_back(sched_item); + m_SampleImportQueue[sample] = sched_item; // add sample to the tree view - Gtk::TreeModel::iterator iterSample = - m_refSamplesTreeModel->append(row.children()); - Gtk::TreeModel::Row rowSample = *iterSample; - rowSample[m_SamplesModel.m_col_name] = - gig_to_utf8(sample->pInfo->Name); - rowSample[m_SamplesModel.m_col_sample] = sample; - rowSample[m_SamplesModel.m_col_group] = NULL; + if (replace) { + row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); + } else { + Gtk::TreeModel::iterator iterSample = + m_refSamplesTreeModel->append(row.children()); + Gtk::TreeModel::Row rowSample = *iterSample; + rowSample[m_SamplesModel.m_col_name] = + gig_to_utf8(sample->pInfo->Name); + rowSample[m_SamplesModel.m_col_sample] = sample; + rowSample[m_SamplesModel.m_col_group] = NULL; + } // close sound file sf_close(hFile); file_changed(); @@ -1838,7 +2859,11 @@ } // show error message box when some file(s) could not be opened / added if (!error_files.empty()) { - Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files; + Glib::ustring txt = + (replace + ? _("Failed to replace sample with:\n") + : _("Could not add the following sample(s):\n")) + + error_files; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); } @@ -1881,7 +2906,7 @@ dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); description.show(); entryArea.show_all(); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); dialog.add_button(_("Select"), Gtk::RESPONSE_OK); dialog.set_select_multiple(false); if (current_sample_dir != "") { @@ -1905,18 +2930,14 @@ try { if (!hFile) throw std::string(_("could not open file")); - int bitdepth; switch (info.format & 0xff) { case SF_FORMAT_PCM_S8: case SF_FORMAT_PCM_16: case SF_FORMAT_PCM_U8: - bitdepth = 16; - break; case SF_FORMAT_PCM_24: case SF_FORMAT_PCM_32: case SF_FORMAT_FLOAT: case SF_FORMAT_DOUBLE: - bitdepth = 24; break; default: sf_close(hFile); @@ -1925,7 +2946,7 @@ SampleImportItem sched_item; sched_item.gig_sample = sample; sched_item.sample_path = filename; - m_SampleImportQueue.push_back(sched_item); + m_SampleImportQueue[sample] = sched_item; sf_close(hFile); file_changed(); } @@ -1949,8 +2970,10 @@ void MainWindow::on_action_remove_sample() { if (!file) return; Glib::RefPtr sel = m_TreeViewSamples.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); - if (it) { + std::vector rows = sel->get_selected_rows(); + for (int r = rows.size() - 1; r >= 0; --r) { + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]); + if (!it) continue; Gtk::TreeModel::Row row = *it; gig::Group* group = row[m_SamplesModel.m_col_group]; gig::Sample* sample = row[m_SamplesModel.m_col_sample]; @@ -1975,15 +2998,12 @@ // if sample(s) were just previously added, remove // them from the import queue for (std::list::iterator member = members.begin(); - member != members.end(); ++member) { - for (std::list::iterator iter = m_SampleImportQueue.begin(); - iter != m_SampleImportQueue.end(); ++iter) { - if ((*iter).gig_sample == *member) { - printf("Removing previously added sample '%s' from group '%s'\n", - (*iter).sample_path.c_str(), name.c_str()); - m_SampleImportQueue.erase(iter); - break; - } + member != members.end(); ++member) + { + if (m_SampleImportQueue.count(*member)) { + printf("Removing previously added sample '%s' from group '%s'\n", + m_SampleImportQueue[sample].sample_path.c_str(), name.c_str()); + m_SampleImportQueue.erase(*member); } } file_changed(); @@ -1998,14 +3018,10 @@ samples_removed_signal.emit(); // if sample was just previously added, remove it from // the import queue - for (std::list::iterator iter = m_SampleImportQueue.begin(); - iter != m_SampleImportQueue.end(); ++iter) { - if ((*iter).gig_sample == sample) { - printf("Removing previously added sample '%s'\n", - (*iter).sample_path.c_str()); - m_SampleImportQueue.erase(iter); - break; - } + if (m_SampleImportQueue.count(sample)) { + printf("Removing previously added sample '%s'\n", + m_SampleImportQueue[sample].sample_path.c_str()); + m_SampleImportQueue.erase(sample); } dimreg_changed(); file_changed(); @@ -2022,6 +3038,151 @@ } } +void MainWindow::on_action_remove_unused_samples() { + if (!file) return; + + // collect all samples that are not referenced by any instrument + std::list lsamples; + for (int iSample = 0; file->GetSample(iSample); ++iSample) { + gig::Sample* sample = file->GetSample(iSample); + bool isUsed = false; + for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument; + instrument = file->GetNextInstrument()) + { + for (gig::Region* rgn = instrument->GetFirstRegion(); rgn; + rgn = instrument->GetNextRegion()) + { + for (int i = 0; i < 256; ++i) { + if (!rgn->pDimensionRegions[i]) continue; + if (rgn->pDimensionRegions[i]->pSample != sample) continue; + isUsed = true; + goto endOfRefSearch; + } + } + } + endOfRefSearch: + if (!isUsed) lsamples.push_back(sample); + } + + if (lsamples.empty()) return; + + // notify everybody that we're going to remove these samples + samples_to_be_removed_signal.emit(lsamples); + + // remove collected samples + try { + for (std::list::iterator itSample = lsamples.begin(); + itSample != lsamples.end(); ++itSample) + { + gig::Sample* sample = *itSample; + // remove sample from the .gig file + file->DeleteSample(sample); + // if sample was just previously added, remove it from the import queue + if (m_SampleImportQueue.count(sample)) { + printf("Removing previously added sample '%s'\n", + m_SampleImportQueue[sample].sample_path.c_str()); + m_SampleImportQueue.erase(sample); + } + } + } catch (RIFF::Exception e) { + // show error message + Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR); + msg.run(); + } + + // notify everybody that we're done with removal + samples_removed_signal.emit(); + + dimreg_changed(); + file_changed(); + __refreshEntireGUI(); +} + +// see comment on on_sample_treeview_drag_begin() +void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr& context) +{ + first_call_to_drag_data_get = true; +} + +void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr&, + Gtk::SelectionData& selection_data, guint, guint) +{ + if (!first_call_to_drag_data_get) return; + first_call_to_drag_data_get = false; + + // get selected script + gig::Script* script = NULL; + Glib::RefPtr sel = m_TreeViewScripts.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + if (it) { + Gtk::TreeModel::Row row = *it; + script = row[m_ScriptsModel.m_col_script]; + } + // pass the gig::Script as pointer + selection_data.set(selection_data.get_target(), 0/*unused*/, + (const guchar*)&script, + sizeof(script)/*length of data in bytes*/); +} + +// see comment on on_sample_treeview_drag_begin() +void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr& context) +{ + first_call_to_drag_data_get = true; +} + +void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr&, + Gtk::SelectionData& selection_data, guint, guint) +{ + if (!first_call_to_drag_data_get) return; + first_call_to_drag_data_get = false; + + // get selected source instrument + gig::Instrument* src = NULL; + { + Glib::RefPtr sel = m_TreeView.get_selection(); + std::vector rows = sel->get_selected_rows(); + if (!rows.empty()) { + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); + if (it) { + Gtk::TreeModel::Row row = *it; + src = row[m_Columns.m_col_instr]; + } + } + } + if (!src) return; + + // pass the source gig::Instrument as pointer + selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src, + sizeof(src)/*length of data in bytes*/); +} + +void MainWindow::on_instruments_treeview_drop_drag_data_received( + const Glib::RefPtr& context, int x, int y, + const Gtk::SelectionData& selection_data, guint, guint time) +{ + gig::Instrument* src = *((gig::Instrument**) selection_data.get_data()); + if (!src || selection_data.get_length() != sizeof(gig::Instrument*)) + return; + + gig::Instrument* dst = NULL; + { + Gtk::TreeModel::Path path; + const bool found = m_TreeView.get_path_at_pos(x, y, path); + if (!found) return; + + Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path); + if (!iter) return; + Gtk::TreeModel::Row row = *iter; + dst = row[m_Columns.m_col_instr]; + } + if (!dst) return; + + //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str()); + src->MoveTo(dst); + __refreshEntireGUI(); + select_instrument(src); +} + // For some reason drag_data_get gets called two times for each // drag'n'drop (at least when target is an Entry). This work-around // makes sure the code in drag_data_get and drop_drag_data_received is @@ -2040,10 +3201,13 @@ // get selected sample gig::Sample* sample = NULL; Glib::RefPtr sel = m_TreeViewSamples.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); - if (it) { - Gtk::TreeModel::Row row = *it; - sample = row[m_SamplesModel.m_col_sample]; + std::vector rows = sel->get_selected_rows(); + if (!rows.empty()) { + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); + if (it) { + Gtk::TreeModel::Row row = *it; + sample = row[m_SamplesModel.m_col_sample]; + } } // pass the gig::Sample as pointer selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample, @@ -2150,6 +3314,50 @@ } } +void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, + const Gtk::TreeModel::iterator& iter) { + if (!iter) return; + Gtk::TreeModel::Row row = *iter; + Glib::ustring name = row[m_ScriptsModel.m_col_name]; + gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group]; + gig::Script* script = row[m_ScriptsModel.m_col_script]; + gig::String gigname(gig_from_utf8(name)); + if (group) { + if (group->Name != gigname) { + group->Name = gigname; + printf("script group name changed\n"); + file_changed(); + } + } else if (script) { + if (script->Name != gigname) { + script->Name = gigname; + printf("script name changed\n"); + file_changed(); + } + } +} + +void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column) +{ + Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); + if (!iter) return; + Gtk::TreeModel::Row row = *iter; + gig::Script* script = row[m_ScriptsModel.m_col_script]; + if (!script) return; + + ScriptEditor* editor = new ScriptEditor; + editor->signal_script_to_be_changed.connect( + signal_script_to_be_changed.make_slot() + ); + editor->signal_script_changed.connect( + signal_script_changed.make_slot() + ); + editor->setScript(script); + //editor->reparent(*this); + editor->show(); +} + void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter) { if (!iter) return; @@ -2196,6 +3404,27 @@ delete d; } +void MainWindow::on_action_view_references() { + Glib::RefPtr sel = m_TreeViewSamples.get_selection(); + std::vector rows = sel->get_selected_rows(); + if (rows.empty()) return; + Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]); + if (!it) return; + Gtk::TreeModel::Row row = *it; + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + if (!sample) return; + + ReferencesView* d = new ReferencesView(*this); + d->setSample(sample); + d->dimension_region_selected.connect( + sigc::mem_fun(*this, &MainWindow::select_dimension_region) + ); + d->show_all(); + d->resize(500, 400); + d->run(); + delete d; +} + void MainWindow::mergeFiles(const std::vector& filenames) { struct _Source { std::vector riffs; @@ -2263,8 +3492,27 @@ ); } - // Note: requires that this file already has a filename ! - this->file->Save(); + // Finally save gig file persistently to disk ... + //NOTE: requires that this gig file already has a filename ! + { + std::cout << "Saving file\n" << std::flush; + file_structure_to_be_changed_signal.emit(this->file); + + progress_dialog = new ProgressDialog( //FIXME: memory leak! + _("Saving") + Glib::ustring(" '") + + Glib::filename_display_basename(this->filename) + "' ...", + *this + ); + progress_dialog->show_all(); + saver = new Saver(this->file); //FIXME: memory leak! + saver->signal_progress().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_progress)); + saver->signal_finished().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_finished)); + saver->signal_error().connect( + sigc::mem_fun(*this, &MainWindow::on_saver_error)); + saver->launch(); + } } void MainWindow::on_action_merge_files() { @@ -2282,7 +3530,7 @@ } Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); - dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); dialog.add_button(_("Merge"), Gtk::RESPONSE_OK); dialog.set_default_response(Gtk::RESPONSE_CANCEL); #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 @@ -2301,7 +3549,9 @@ // show warning in the file picker dialog Gtk::HBox descriptionArea; descriptionArea.set_spacing(15); - Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); + Gtk::Image warningIcon; + warningIcon.set_from_icon_name("dialog-warning", + Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK); #if GTKMM_MAJOR_VERSION < 3 view::WrapLabel description; @@ -2324,7 +3574,8 @@ descriptionArea.show_all(); if (dialog.run() == Gtk::RESPONSE_OK) { - printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self()); + printf("on_action_merge_files self=%p\n", + static_cast(Glib::Threads::Thread::self())); std::vector filenames = dialog.get_filenames(); // merge the selected files to the currently open .gig file @@ -2336,7 +3587,7 @@ } // update GUI - __refreshEntireGUI(); + __refreshEntireGUI(); } } @@ -2354,6 +3605,225 @@ Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) ); } + + { + Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); + if (item) item->set_sensitive(b); + } +} + +void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) { + if (!sample) return; + sample_ref_count[sample] += offset; + const int refcount = sample_ref_count[sample]; + + Glib::RefPtr model = m_TreeViewSamples.get_model(); + for (int g = 0; g < model->children().size(); ++g) { + Gtk::TreeModel::Row rowGroup = model->children()[g]; + for (int s = 0; s < rowGroup.children().size(); ++s) { + Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; + if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; + rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); + rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; + } + } +} + +void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) { + on_sample_ref_count_incremented(oldSample, -1); + on_sample_ref_count_incremented(newSample, +1); +} + +void MainWindow::on_samples_to_be_removed(std::list samples) { + // just in case a new sample is added later with exactly the same memory + // address, which would lead to incorrect refcount if not deleted here + for (std::list::const_iterator it = samples.begin(); + it != samples.end(); ++it) + { + sample_ref_count.erase(*it); + } +} + +void MainWindow::show_samples_tab() { + m_TreeViewNotebook.set_current_page(0); +} + +void MainWindow::show_intruments_tab() { + m_TreeViewNotebook.set_current_page(1); +} + +void MainWindow::show_scripts_tab() { + m_TreeViewNotebook.set_current_page(2); +} + +void MainWindow::select_prev_region() { + m_RegionChooser.select_prev_region(); +} + +void MainWindow::select_next_region() { + m_RegionChooser.select_next_region(); +} + +void MainWindow::select_next_dim_rgn_zone() { + if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser + m_DimRegionChooser.select_next_dimzone(); +} + +void MainWindow::select_prev_dim_rgn_zone() { + if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser + m_DimRegionChooser.select_prev_dimzone(); +} + +void MainWindow::select_add_next_dim_rgn_zone() { + m_DimRegionChooser.select_next_dimzone(true); +} + +void MainWindow::select_add_prev_dim_rgn_zone() { + m_DimRegionChooser.select_prev_dimzone(true); +} + +void MainWindow::select_prev_dimension() { + if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser + m_DimRegionChooser.select_prev_dimension(); +} + +void MainWindow::select_next_dimension() { + if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser + m_DimRegionChooser.select_next_dimension(); +} + +#define CLIPBOARD_DIMENSIONREGION_TARGET \ + ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat()) + +void MainWindow::copy_selected_dimrgn() { + gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); + if (!pDimRgn) { + updateClipboardPasteAvailable(); + updateClipboardCopyAvailable(); + return; + } + + std::vector targets; + targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) ); + + Glib::RefPtr clipboard = Gtk::Clipboard::get(); + clipboard->set( + targets, + sigc::mem_fun(*this, &MainWindow::on_clipboard_get), + sigc::mem_fun(*this, &MainWindow::on_clipboard_clear) + ); + + m_serializationArchive.serialize(pDimRgn); + + updateClipboardPasteAvailable(); +} + +void MainWindow::paste_copied_dimrgn() { + Glib::RefPtr clipboard = Gtk::Clipboard::get(); + clipboard->request_contents( + CLIPBOARD_DIMENSIONREGION_TARGET, + sigc::mem_fun(*this, &MainWindow::on_clipboard_received) + ); + updateClipboardPasteAvailable(); +} + +void MainWindow::adjust_clipboard_content() { + MacroEditor* editor = new MacroEditor; + editor->setMacro(&m_serializationArchive); + editor->show(); +} + +void MainWindow::updateClipboardPasteAvailable() { + Glib::RefPtr clipboard = Gtk::Clipboard::get(); + clipboard->request_targets( + sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets) + ); +} + +void MainWindow::updateClipboardCopyAvailable() { + bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion(); + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn") + )->set_sensitive(bDimensionRegionCopyIsPossible); +} + +void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) { + updateClipboardPasteAvailable(); +} + +void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) { + const std::string target = selection_data.get_target(); + if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { + selection_data.set( + CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/, + &m_serializationArchive.rawData()[0], + m_serializationArchive.rawData().size() + ); + } else { + std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n"; + } +} + +void MainWindow::on_clipboard_clear() { + m_serializationArchive.clear(); + updateClipboardPasteAvailable(); + updateClipboardCopyAvailable(); +} + +void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { + const std::string target = selection_data.get_target(); + if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { + gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); + if (!pDimRgn) return; + + Glib::ustring errorText; + try { + m_serializationArchive.decode( + selection_data.get_data(), selection_data.get_length() + ); + + for (std::set::iterator itDimReg = dimreg_edit.dimregs.begin(); + itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) + { + gig::DimensionRegion* pDimRgn = *itDimReg; + + dimreg_to_be_changed_signal.emit(pDimRgn); + + m_serializationArchive.deserialize(pDimRgn); + + dimreg_changed_signal.emit(pDimRgn); + } + + //region_changed() + file_changed(); + dimreg_changed(); + + } catch (Serialization::Exception e) { + errorText = e.Message; + } catch (...) { + errorText = _("Unknown exception during deserialization decoding"); + } + if (!errorText.empty()) { + Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; + Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); + msg.run(); + } + } +} + +void MainWindow::on_clipboard_received_targets(const std::vector& targets) { + const bool bDimensionRegionPasteIsPossible = + std::find(targets.begin(), targets.end(), + CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end(); + + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn") + )->set_sensitive(bDimensionRegionPasteIsPossible); + + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard") + )->set_sensitive(bDimensionRegionPasteIsPossible); } sigc::signal& MainWindow::signal_file_structure_to_be_changed() { @@ -2411,3 +3881,7 @@ sigc::signal& MainWindow::signal_keyboard_key_released() { return m_RegionChooser.signal_keyboard_key_released(); } + +sigc::signal& MainWindow::signal_switch_sampler_instrument() { + return switch_sampler_instrument_signal; +}