--- gigedit/trunk/src/gigedit/mainwindow.cpp 2015/01/06 16:08:48 2694 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2017/11/14 18:07:25 3364 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2015 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,17 +20,31 @@ #include #include +#include "compat.h" +// 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 #include +#include #include #include #include -#include +#if HAS_GTKMM_STOCK +# include +#endif #include #include -#include +#if GTKMM_MAJOR_VERSION < 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION < 89) +# include +#endif +#include #if GTKMM_MAJOR_VERSION < 3 #include "wrapLabel.hh" #endif @@ -39,7 +53,11 @@ #include "compat.h" #include -#include +#ifdef LIBSNDFILE_HEADER_FILE +# include LIBSNDFILE_HEADER_FILE(sndfile.h) +#else +# include +#endif #include #include "mainwindow.h" @@ -50,18 +68,42 @@ #include "ReferencesView.h" #include "../../gfx/status_attached.xpm" #include "../../gfx/status_detached.xpm" +#include "gfx/builtinpix.h" +#include "MacroEditor.h" +#include "MacrosSetup.h" +#if defined(__APPLE__) +# include "MacHelper.h" +#endif +static 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 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(); + + this->file = NULL; + // set_border_width(5); -// set_default_size(400, 200); + if (!Settings::singleton()->autoRestoreWindowDimension) { + set_default_size(800, 600); + set_position(Gtk::WIN_POS_CENTER); + } add(m_VBox); @@ -71,8 +113,13 @@ // m_TreeView.set_reorderable(); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + m_TreeView.signal_button_press_event().connect( + sigc::mem_fun(*this, &MainWindow::on_button_release)); +#else m_TreeView.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &MainWindow::on_button_release)); +#endif // Add the TreeView tab, inside a ScrolledWindow, with the button underneath: m_ScrolledWindow.add(m_TreeView); @@ -88,7 +135,16 @@ m_TreeViewNotebook.set_size_request(300); - m_HPaned.add1(m_TreeViewNotebook); + m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:")); + m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK); + m_searchField.pack_start(m_searchText); + m_searchField.set_spacing(5); + + m_left_vbox.pack_start(m_TreeViewNotebook); + m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK); + + m_HPaned.add1(m_left_vbox); + dimreg_hbox.add(dimreg_label); dimreg_hbox.add(dimreg_all_regions); dimreg_hbox.add(dimreg_all_dimregs); @@ -96,6 +152,58 @@ 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); +#if HAS_GTKMM_ALIGNMENT + imageNoSample.set_alignment(Gtk::ALIGN_END); + labelNoSample.set_alignment(Gtk::ALIGN_START); +#else + imageNoSample.set_halign(Gtk::ALIGN_END); + labelNoSample.set_halign(Gtk::ALIGN_START); +#endif + legend_hbox.add(imageNoSample); + legend_hbox.add(labelNoSample); + + imageMissingSample.set(yellowDot); +#if HAS_GTKMM_ALIGNMENT + imageMissingSample.set_alignment(Gtk::ALIGN_END); + labelMissingSample.set_alignment(Gtk::ALIGN_START); +#else + imageMissingSample.set_halign(Gtk::ALIGN_END); + labelMissingSample.set_halign(Gtk::ALIGN_START); +#endif + legend_hbox.add(imageMissingSample); + legend_hbox.add(labelMissingSample); + + imageLooped.set(blackLoop); +#if HAS_GTKMM_ALIGNMENT + imageLooped.set_alignment(Gtk::ALIGN_END); + labelLooped.set_alignment(Gtk::ALIGN_START); +#else + imageLooped.set_halign(Gtk::ALIGN_END); + labelLooped.set_halign(Gtk::ALIGN_START); +#endif + legend_hbox.add(imageLooped); + legend_hbox.add(labelLooped); + + imageSomeLoops.set(grayLoop); +#if HAS_GTKMM_ALIGNMENT + imageSomeLoops.set_alignment(Gtk::ALIGN_END); + labelSomeLoops.set_alignment(Gtk::ALIGN_START); +#else + imageSomeLoops.set_halign(Gtk::ALIGN_END); + labelSomeLoops.set_halign(Gtk::ALIGN_START); +#endif + legend_hbox.add(imageSomeLoops); + legend_hbox.add(labelSomeLoops); + +#if HAS_GTKMM_SHOW_ALL_CHILDREN + legend_hbox.show_all_children(); +#endif + } + 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.")); @@ -107,6 +215,45 @@ m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments")); m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts")); +#if USE_GLIB_ACTION + m_actionGroup = Gio::SimpleActionGroup::create(); + m_actionGroup->add_action( + "New", sigc::mem_fun(*this, &MainWindow::on_action_file_new) + ); + m_actionGroup->add_action( + "Open", sigc::mem_fun(*this, &MainWindow::on_action_file_open) + ); + m_actionGroup->add_action( + "Save", sigc::mem_fun(*this, &MainWindow::on_action_file_save) + ); + m_actionGroup->add_action( + "SaveAs", sigc::mem_fun(*this, &MainWindow::on_action_file_save_as) + ); + m_actionGroup->add_action( + "Properties", sigc::mem_fun(*this, &MainWindow::on_action_file_properties) + ); + m_actionGroup->add_action( + "InstrProperties", sigc::mem_fun(*this, &MainWindow::show_instr_props) + ); + m_actionMIDIRules = m_actionGroup->add_action( + "MidiRules", sigc::mem_fun(*this, &MainWindow::show_midi_rules) + ); + m_actionGroup->add_action( + "ScriptSlots", sigc::mem_fun(*this, &MainWindow::show_script_slots) + ); + m_actionGroup->add_action( + "Quit", sigc::mem_fun(*this, &MainWindow::on_action_quit) + ); + m_actionGroup->add_action( + "MenuSample", sigc::mem_fun(*this, &MainWindow::show_samples_tab) + ); + m_actionGroup->add_action( + "MenuInstrument", sigc::mem_fun(*this, &MainWindow::show_intruments_tab) + ); + m_actionGroup->add_action( + "MenuScript", sigc::mem_fun(*this, &MainWindow::show_scripts_tab) + ); +#else actionGroup = Gtk::ActionGroup::create(); actionGroup->add(Gtk::Action::create("MenuFile", _("_File"))); @@ -156,13 +303,134 @@ sigc::mem_fun(*this, &MainWindow::show_intruments_tab) ); actionGroup->add( - Gtk::Action::create("MenuScript", _("S_cript")), + 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("AssignScripts", _("Assign Script"))); actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); +#endif + + 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 + +#if USE_GLIB_ACTION + m_actionCopyDimRgn = m_actionGroup->add_action( + "CopyDimRgn", sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn) + ); + m_actionPasteDimRgn = m_actionGroup->add_action( + "PasteDimRgn", sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn) + ); + m_actionAdjustClipboard = m_actionGroup->add_action( + "AdjustClipboard", sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content) + ); + m_actionGroup->add_action( + "SelectPrevInstr", sigc::mem_fun(*this, &MainWindow::select_prev_instrument) + ); + m_actionGroup->add_action( + "SelectNextInstr", sigc::mem_fun(*this, &MainWindow::select_next_instrument) + ); + m_actionGroup->add_action( + "SelectPrevRegion", sigc::mem_fun(*this, &MainWindow::select_prev_region) + ); + m_actionGroup->add_action( + "SelectNextRegion", sigc::mem_fun(*this, &MainWindow::select_next_region) + ); + m_actionGroup->add_action( + "SelectPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone) + ); + m_actionGroup->add_action( + "SelectNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone) + ); + m_actionGroup->add_action( + "SelectPrevDimension", sigc::mem_fun(*this, &MainWindow::select_prev_dimension) + ); + m_actionGroup->add_action( + "SelectNextDimension", sigc::mem_fun(*this, &MainWindow::select_next_dimension) + ); + m_actionGroup->add_action( + "SelectAddPrevDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone) + ); + m_actionGroup->add_action( + "SelectAddNextDimRgnZone", sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone) + ); +#else + 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("SelectPrevInstr", + _("Select Previous Instrument")), + Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey), + sigc::mem_fun(*this, &MainWindow::select_prev_instrument)); + + actionGroup->add(Gtk::Action::create("SelectNextInstr", + _("Select Next Instrument")), + Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey), + sigc::mem_fun(*this, &MainWindow::select_next_instrument)); + + 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)); +#endif +#if USE_GLIB_ACTION + m_actionToggleCopySampleUnity = m_actionGroup->add_action_bool("CopySampleUnity", true); + m_actionToggleCopySampleTune = m_actionGroup->add_action_bool("CopySampleTune", true); + m_actionToggleCopySampleLoop = m_actionGroup->add_action_bool("CopySampleLoop", true); +#else Glib::RefPtr toggle_action = Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note")); toggle_action->set_active(true); @@ -177,9 +445,21 @@ Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points")); toggle_action->set_active(true); actionGroup->add(toggle_action); +#endif +#if USE_GLIB_ACTION + m_actionToggleStatusBar = + m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true); + m_actionToggleRestoreWinDim = + m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension); + m_actionToggleSaveWithTempFile = + m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile); + m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)); +#else + actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro"))); - 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); @@ -187,6 +467,43 @@ sigc::mem_fun( *this, &MainWindow::on_action_view_status_bar)); + 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) + ); +#endif + +#if USE_GLIB_ACTION + m_actionGroup->add_action( + "About", sigc::mem_fun(*this, &MainWindow::on_action_help_about) + ); + m_actionGroup->add_action( + "AddInstrument", sigc::mem_fun(*this, &MainWindow::on_action_add_instrument) + ); + m_actionGroup->add_action( + "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) + ); + m_actionGroup->add_action( + "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) + ); + m_actionGroup->add_action( + "RemoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) + ); +#else action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); actionGroup->add(Gtk::Action::create("MenuHelp", action->property_label())); @@ -202,11 +519,30 @@ sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument) ); actionGroup->add( + Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")), + Gtk::AccelKey(GDK_KEY_j, primaryModifierKey), + sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) + ); + actionGroup->add( Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE), sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument) ); +#endif - +#if USE_GLIB_ACTION + m_actionToggleWarnOnExtensions = m_actionGroup->add_action_bool( + "WarnUserOnExtensions", sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions), + Settings::singleton()->warnUserOnExtensions + ); + m_actionToggleSyncSamplerSelection = m_actionGroup->add_action_bool( + "SyncSamplerInstrumentSelection", sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection), + Settings::singleton()->syncSamplerInstrumentSelection + ); + m_actionToggleMoveRootNoteWithRegion = m_actionGroup->add_action_bool( + "MoveRootNoteWithRegionMoved", sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved), + Settings::singleton()->moveRootNoteWithRegionMoved + ); +#else actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings"))); toggle_action = @@ -225,7 +561,23 @@ 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) + ); +#endif +#if USE_GLIB_ACTION + m_actionGroup->add_action( + "CombineInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments) + ); + m_actionGroup->add_action( + "MergeFiles", sigc::mem_fun(*this, &MainWindow::on_action_merge_files) + ); +#else actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools"))); actionGroup->add( @@ -237,9 +589,35 @@ Gtk::Action::create("MergeFiles", _("_Merge Files...")), sigc::mem_fun(*this, &MainWindow::on_action_merge_files) ); - +#endif // sample right-click popup actions +#if USE_GLIB_ACTION + m_actionSampleProperties = m_actionGroup->add_action( + "SampleProperties", sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) + ); + m_actionAddSampleGroup = m_actionGroup->add_action( + "AddGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_group) + ); + m_actionAddSample = m_actionGroup->add_action( + "AddSample", sigc::mem_fun(*this, &MainWindow::on_action_add_sample) + ); + m_actionRemoveSample = m_actionGroup->add_action( + "RemoveSample", sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) + ); + m_actionGroup->add_action( + "RemoveUnusedSamples", sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples) + ); + m_actionViewSampleRefs = m_actionGroup->add_action( + "ShowSampleRefs", sigc::mem_fun(*this, &MainWindow::on_action_view_references) + ); + m_actionReplaceSample = m_actionGroup->add_action( + "ReplaceSample", sigc::mem_fun(*this, &MainWindow::on_action_replace_sample) + ); + m_actionGroup->add_action( + "ReplaceAllSamplesInAllGroups", sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) + ); +#else actionGroup->add( Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES), sigc::mem_fun(*this, &MainWindow::on_action_sample_properties) @@ -257,16 +635,40 @@ 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) ); +#endif // script right-click popup actions +#if USE_GLIB_ACTION + m_actionAddScriptGroup = m_actionGroup->add_action( + "AddScriptGroup", sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) + ); + m_actionAddScript = m_actionGroup->add_action( + "AddScript", sigc::mem_fun(*this, &MainWindow::on_action_add_script) + ); + m_actionEditScript = m_actionGroup->add_action( + "EditScript", sigc::mem_fun(*this, &MainWindow::on_action_edit_script) + ); + m_actionRemoveScript = m_actionGroup->add_action( + "RemoveScript", sigc::mem_fun(*this, &MainWindow::on_action_remove_script) + ); +#else actionGroup->add( Gtk::Action::create("AddScriptGroup", _("Add _Group")), sigc::mem_fun(*this, &MainWindow::on_action_add_script_group) @@ -283,7 +685,391 @@ Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE), sigc::mem_fun(*this, &MainWindow::on_action_remove_script) ); +#endif +#if USE_GTKMM_BUILDER + insert_action_group("AppMenu", m_actionGroup); + + m_uiManager = Gtk::Builder::create(); + Glib::ustring ui_info = + "" + " " + " " + " _File" + "
" + " " + " New" + " AppMenu.New" + " " + " " + " Open" + " AppMenu.Open" + " " + "
" + "
" + " " + " Save" + " AppMenu.Save" + " " + " " + " Save As" + " AppMenu.SaveAs" + " " + "
" + "
" + " " + " Properties" + " AppMenu.Properties" + " " + "
" + "
" + " " + " Quit" + " AppMenu.Quit" + " " + "
" + "
" + " " + " Edit" + "
" + " " + " Copy Dimension Region" + " AppMenu.CopyDimRgn" + " " + " " + " Adjust Clipboard" + " AppMenu.AdjustClipboard" + " " + " " + " Paste Dimension Region" + " AppMenu.PasteDimRgn" + " " + "
" + " " + " Previous Instrument" + " AppMenu.SelectPrevInstr" + " " + " " + " Next Instrument" + " AppMenu.SelectNextInstr" + " " + "
" + " " + " Previous Region" + " AppMenu.SelectPrevRegion" + " " + " " + " Next Region" + " AppMenu.SelectNextRegion" + " " + "
" + " " + " Previous Dimension" + " AppMenu.SelectPrevDimension" + " " + " " + " Next Dimension" + " AppMenu.SelectNextDimension" + " " + " " + " Previous Dimension Region Zone" + " AppMenu.SelectPrevDimRgnZone" + " " + " " + " Next Dimension Region Zone" + " AppMenu.SelectNextDimRgnZone" + " " + " " + " Add Previous Dimension Region Zone" + " AppMenu.SelectAddPrevDimRgnZone" + " " + " " + " Add Next Dimension Region Zone" + " AppMenu.SelectAddNextDimRgnZone" + " " + "
" + " " + " Copy Sample Unity" + " AppMenu.CopySampleUnity" + " " + " " + " Copy Sample Tune" + " AppMenu.CopySampleTune" + " " + " " + " Copy Sample Loop" + " AppMenu.CopySampleLoop" + " " + "
" + "
" + " " + " Macro" + "
" + "
" + "
" + " " + " Sample" + "
" + " " + " Properties" + " AppMenu.SampleProperties" + " " + " " + " Add Group" + " AppMenu.AddGroup" + " " + " " + " Add Sample" + " AppMenu.AddSample" + " " + " " + " Show Sample References" + " AppMenu.ShowSampleRefs" + " " + " " + " Replace Sample" + " AppMenu.ReplaceSample" + " " + " " + " Replace all Samples in all Groups" + " AppMenu.ReplaceAllSamplesInAllGroups" + " " + "
" + "
" + " " + " Remove Sample" + " AppMenu.RemoveSample" + " " + " " + " Remove unused Samples" + " AppMenu.RemoveUnusedSamples" + " " + "
" + "
" + " " + " Instrument" + "
" + " " + " Properties" + " AppMenu.InstrProperties" + " " + " " + " MIDI Rules" + " AppMenu.MidiRules" + " " + " " + " Script Slots" + " AppMenu.ScriptSlots" + " " + "
" + " " + " Assign Scripts" + " " + "
" + " " + " Add Instrument" + " AppMenu.AddInstrument" + " " + " " + " Duplicate Instrument" + " AppMenu.DupInstrument" + " " + " " + " Combine Instrument" + " AppMenu.CombInstruments" + " " + "
" + "
" + " " + " Remove Instrument" + " AppMenu.RemoveInstrument" + " " + "
" + "
" + " " + " Script" + "
" + " " + " Add Script Group" + " AppMenu.AddScriptGroup" + " " + " " + " Add Script" + " AppMenu.AddScript" + " " + " " + " Edit Script" + " AppMenu.EditScript" + " " + "
" + "
" + " " + " Remove Script" + " AppMenu.RemoveScript" + " " + "
" + "
" + " " + " View" + "
" + " " + " Statusbar" + " AppMenu.Statusbar" + " " + " " + " Auto restore Window Dimensions" + " AppMenu.AutoRestoreWinDim" + " " + "
" + "
" + " " + " Refresh All" + " AppMenu.RefreshAll" + " " + "
" + "
" + " " + " Tools" + "
" + " " + " Combine Instruments ..." + " AppMenu.CombineInstruments" + " " + " " + " Merge Files ..." + " AppMenu.MergeFiles" + " " + "
" + "
" + " " + " Settings" + "
" + " " + " Warning on Format Extensions" + " AppMenu.WarnUserOnExtensions" + " " + " " + " Synchronize Sampler Selection" + " AppMenu.SyncSamplerInstrumentSelection" + " " + " " + " Move Root Note with Region moved" + " AppMenu.MoveRootNoteWithRegionMoved" + " " + " " + " Save with temporary file" + " AppMenu.SaveWithTemporaryFile" + " " + "
" + "
" + " " + " Help" + "
" + " " + " About ..." + " AppMenu.About" + " " + "
" + "
" + "
" + // popups + " " + "
" + " " + " Instrument Properties" + " AppMenu.InstrProperties" + " " + " " + " MIDI Rules" + " AppMenu.MidiRules" + " " + " " + " Script Slots" + " AppMenu.ScriptSlots" + " " + " " + " Add Instrument" + " AppMenu.AddInstrument" + " " + " " + " Duplicate Instrument" + " AppMenu.DupInstrument" + " " + " " + " Combine Instruments" + " AppMenu.CombInstruments" + " " + "
" + "
" + " " + " Remove Instruments" + " AppMenu.RemoveInstrument" + " " + "
" + "
" + " " + "
" + " " + " Sample Properties" + " AppMenu.SampleProperties" + " " + " " + " Add Sample Group" + " AppMenu.AddGroup" + " " + " " + " Add Sample" + " AppMenu.AddSample" + " " + " " + " Show Sample References ..." + " AppMenu.ShowSampleRefs" + " " + " " + " Replace Sample" + " AppMenu.ReplaceSample" + " " + " " + " Replace all Samples ..." + " AppMenu.ReplaceAllSamplesInAllGroups" + " " + "
" + "
" + " " + " Remove Sample" + " AppMenu.RemoveSample" + " " + " " + " Remove unused Samples" + " AppMenu.RemoveUnusedSamples" + " " + "
" + "
" + " " + "
" + " " + " Add Script Group" + " AppMenu.AddScriptGroup" + " " + " " + " Add Script" + " AppMenu.AddScript" + " " + " " + " Edit Script" + " AppMenu.EditScript" + " " + "
" + "
" + " " + " Remove Script" + " AppMenu.RemoveScript" + " " + "
" + "
" + "
"; + m_uiManager->add_from_string(ui_info); +#else uiManager = Gtk::UIManager::create(); uiManager->insert_action_group(actionGroup); add_accel_group(uiManager->get_accel_group()); @@ -303,18 +1089,39 @@ " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " " " " " + " " + " " " " " " " " " " " " + " " " " " " " " + " " " " " " " " @@ -323,8 +1130,10 @@ " " " " " " + " " " " " " + " " " " " " " " @@ -337,6 +1146,9 @@ " " " " " " + " " + " " + " " " " " " " " @@ -345,6 +1157,8 @@ " " " " " " + " " + " " " " " " " " @@ -356,6 +1170,7 @@ " " " " " " + " " " " " " " " @@ -364,9 +1179,11 @@ " " " " " " + " " " " " " " " + " " " " " " " " @@ -377,7 +1194,25 @@ " " ""; uiManager->add_ui_from_string(ui_info); +#endif +#if USE_GTKMM_BUILDER + popup_menu = new Gtk::Menu( + Glib::RefPtr::cast_dynamic( + m_uiManager->get_object("PopupMenu") + ) + ); + sample_popup = new Gtk::Menu( + Glib::RefPtr::cast_dynamic( + m_uiManager->get_object("SamplePopupMenu") + ) + ); + script_popup = new Gtk::Menu( + Glib::RefPtr::cast_dynamic( + m_uiManager->get_object("ScriptPopupMenu") + ) + ); +#else popup_menu = dynamic_cast(uiManager->get_widget("/PopupMenu")); // Set tooltips for menu items (for some reason, setting a tooltip on the @@ -411,6 +1246,30 @@ } { 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.")); } @@ -419,12 +1278,29 @@ uiManager->get_widget("/MenuBar/MenuTools/MergeFiles")); item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file.")); } +#endif - +#if USE_GTKMM_BUILDER + assign_scripts_menu = new Gtk::Menu( + Glib::RefPtr::cast_dynamic( + m_uiManager->get_object("AssignScripts") + ) + ); +#else instrument_menu = static_cast( uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); + assign_scripts_menu = static_cast( + uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu(); +#endif + +#if USE_GTKMM_BUILDER + Gtk::Widget* menuBar = NULL; + m_uiManager->get_widget("MenuBar", menuBar); +#else Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); +#endif + m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); m_VBox.pack_start(m_HPaned); m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); @@ -435,8 +1311,12 @@ set_file_is_shared(false); // Status Bar: +#if USE_GTKMM_BOX +# warning No status bar layout for GTKMM 4 yet +#else m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); +#endif m_StatusBar.show(); m_RegionChooser.signal_region_selected().connect( @@ -447,19 +1327,46 @@ // 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_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel); + m_refTreeModelFilter->set_visible_func( + sigc::mem_fun(*this, &MainWindow::instrument_row_visible) + ); + m_TreeView.set_model(m_refTreeModelFilter); + + 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.append_column(_("Scripts"), m_Columns.m_col_scripts); + 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(_("Name"), m_SamplesModel.m_col_name); @@ -481,9 +1388,15 @@ ); } m_TreeViewSamples.set_headers_visible(true); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + m_TreeViewSamples.signal_button_press_event().connect( + sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) + ); +#else m_TreeViewSamples.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release) ); +#endif m_refSamplesTreeModel->signal_row_changed().connect( sigc::mem_fun(*this, &MainWindow::sample_name_changed) ); @@ -500,10 +1413,16 @@ // m_TreeViewScripts.set_reorderable(); m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name); m_TreeViewScripts.set_headers_visible(false); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + m_TreeViewScripts.signal_button_press_event().connect( + sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) + ); +#else 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 fired while CTRL key is pressed ? +#endif + //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) ); @@ -540,6 +1459,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( @@ -599,23 +1520,216 @@ dimreg_stereo.signal_toggled().connect( sigc::mem_fun(*this, &MainWindow::update_dimregs)); + m_searchText.signal_changed().connect( + sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter) + ); + file = 0; file_is_changed = false; +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif // start with a new gig file by default on_action_file_new(); + m_TreeViewNotebook.signal_switch_page().connect( + sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched) + ); + // 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(); + + // setup macros and their keyboard accelerators + { +#if USE_GTKMM_BUILDER + menuMacro = new Gtk::Menu( + Glib::RefPtr::cast_dynamic( + m_uiManager->get_object("MenuMacro") + ) + ); +#else + Gtk::Menu* menuMacro = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuMacro") + )->get_submenu(); +#endif + + const Gdk::ModifierType noModifier = (Gdk::ModifierType)0; + Gtk::AccelMap::add_entry("/macro_0", GDK_KEY_F1, noModifier); + Gtk::AccelMap::add_entry("/macro_1", GDK_KEY_F2, noModifier); + Gtk::AccelMap::add_entry("/macro_2", GDK_KEY_F3, noModifier); + Gtk::AccelMap::add_entry("/macro_3", GDK_KEY_F4, noModifier); + Gtk::AccelMap::add_entry("/macro_4", GDK_KEY_F5, noModifier); + Gtk::AccelMap::add_entry("/macro_5", GDK_KEY_F6, noModifier); + Gtk::AccelMap::add_entry("/macro_6", GDK_KEY_F7, noModifier); + Gtk::AccelMap::add_entry("/macro_7", GDK_KEY_F8, noModifier); + Gtk::AccelMap::add_entry("/macro_8", GDK_KEY_F9, noModifier); + Gtk::AccelMap::add_entry("/macro_9", GDK_KEY_F10, noModifier); + Gtk::AccelMap::add_entry("/macro_10", GDK_KEY_F11, noModifier); + Gtk::AccelMap::add_entry("/macro_11", GDK_KEY_F12, noModifier); + Gtk::AccelMap::add_entry("/SetupMacros", 'm', primaryModifierKey); + + Glib::RefPtr accelGroup = this->get_accel_group(); + menuMacro->set_accel_group(accelGroup); + + updateMacroMenu(); + } + + // setup "Assign Scripts" keyboard accelerators + { + Gtk::AccelMap::add_entry("/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK); + + Glib::RefPtr accelGroup = this->get_accel_group(); + assign_scripts_menu->set_accel_group(accelGroup); + } + + Glib::signal_idle().connect_once( + sigc::mem_fun(*this, &MainWindow::bringToFront), + 200 + ); } MainWindow::~MainWindow() { } +void MainWindow::bringToFront() { + #if defined(__APPLE__) + macRaiseAppWindow(); + #endif + raise(); + present(); +} + +void MainWindow::updateMacroMenu() { +#if !USE_GTKMM_BUILDER + Gtk::Menu* menuMacro = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuMacro") + )->get_submenu(); +#endif + + // remove all entries from "Macro" menu + { + const std::vector children = menuMacro->get_children(); + for (int i = 0; i < children.size(); ++i) { + Gtk::Widget* child = children[i]; + menuMacro->remove(*child); + delete child; + } + } + + // (re)load all macros from config file + try { + Settings::singleton()->loadMacros(m_macros); + } catch (Serialization::Exception e) { + std::cerr << "Exception while loading macros: " << e.Message << std::endl; + } catch (...) { + std::cerr << "Unknown exception while loading macros!" << std::endl; + } + + // add all configured macros as menu items to the "Macro" menu + for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) { + const Serialization::Archive& macro = m_macros[iMacro]; + std::string name = + macro.name().empty() ? + (std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name(); + Gtk::MenuItem* item = new Gtk::MenuItem(name); + item->signal_activate().connect( + sigc::bind( + sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro + ) + ); + menuMacro->append(*item); + item->set_accel_path("/macro_" + ToString(iMacro)); + Glib::ustring comment = macro.comment(); + if (!comment.empty()) + item->set_tooltip_text(comment); + } + // if there are no macros configured at all, then show a dummy entry instead + if (m_macros.empty()) { + Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros")); + item->set_sensitive(false); + menuMacro->append(*item); + } + + // add separator line to menu + menuMacro->append(*new Gtk::SeparatorMenuItem); + + { + Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ...")); + item->signal_activate().connect( + sigc::mem_fun(*this, &MainWindow::setupMacros) + ); + menuMacro->append(*item); + item->set_accel_path("/SetupMacros"); + } + +#if HAS_GTKMM_SHOW_ALL_CHILDREN + menuMacro->show_all_children(); +#endif +} + +void MainWindow::onMacroSelected(int iMacro) { + printf("onMacroSelected(%d)\n", iMacro); + if (iMacro < 0 || iMacro >= m_macros.size()) return; + Glib::ustring errorText; + try { + applyMacro(m_macros[iMacro]); + } catch (Serialization::Exception e) { + errorText = e.Message; + } catch (...) { + errorText = _("Unknown exception while applying macro"); + } + if (!errorText.empty()) { + Glib::ustring txt = _("Applying macro failed:\n") + errorText; + Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); + msg.run(); + } +} + +void MainWindow::setupMacros() { + MacrosSetup* setup = new MacrosSetup(); + gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); + setup->setMacros(m_macros, &m_serializationArchive, pDimRgn); + setup->signal_macros_changed().connect( + sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged) + ); + setup->show(); +} + +void MainWindow::onMacrosSetupChanged(const std::vector& macros) { + m_macros = macros; + Settings::singleton()->saveMacros(m_macros); + updateMacroMenu(); +} + +//NOTE: the actual signal's first argument for argument 'page' is on some gtkmm version GtkNotebookPage* and on some Gtk::Widget*. Since we don't need that argument, it is simply void* here for now. +void MainWindow::on_notebook_tab_switched(void* page, guint page_num) { + bool isInstrumentsPage = (page_num == 1); + // so far we only support filtering for the instruments list, so hide the + // filter text entry field if another tab is selected + m_searchField.set_visible(isInstrumentsPage); +} + bool MainWindow::on_delete_event(GdkEventAny* event) { return !file_is_shared && file_is_changed && !close_confirmation_dialog(); @@ -635,8 +1749,10 @@ 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; + //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though. + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); if (it) { Gtk::TreeModel::Row row = *it; instrument = row[m_Columns.m_col_instr]; @@ -679,6 +1795,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() @@ -695,15 +1818,22 @@ void MainWindow::on_sel_change() { +#if !USE_GTKMM_BUILDER // 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(); + } } +#endif + + updateScriptListOfMenu(); m_RegionChooser.set_instrument(get_instrument()); @@ -727,9 +1857,14 @@ 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("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); @@ -751,7 +1886,7 @@ } Loader::Loader(const char* filename) - : filename(filename), thread(0), progress(0.f) + : filename(filename), gig(0), thread(0), progress(0.f) { } @@ -762,7 +1897,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() @@ -805,9 +1940,14 @@ 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=%x\n", Glib::Threads::Thread::self()); + printf("thread_function self=%p\n", + static_cast(Glib::Threads::Thread::self())); printf("Start %s\n", filename.c_str()); try { gig::progress_t progress; @@ -816,7 +1956,34 @@ // if no filename was provided, that means "save", if filename was provided means "save as" if (filename.empty()) { - gig->Save(&progress); + 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) + gig::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): " + gig::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): " + gig::String(strerror(errno))); + #endif + } + } } else { gig->Save(filename, &progress); } @@ -844,7 +2011,7 @@ #else thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); #endif - printf("launch thread=%x\n", thread); + printf("launch thread=%p\n", static_cast(thread)); } float Saver::get_progress() @@ -875,8 +2042,14 @@ ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) { +#if USE_GTKMM_BOX + get_content_area()->pack_start(progressBar); +#else get_vbox()->pack_start(progressBar); +#endif +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif resize(600,50); } @@ -889,10 +2062,12 @@ m_refTreeModel->clear(); m_refSamplesTreeModel->clear(); m_refScriptsTreeModel->clear(); +#if !USE_GTKMM_BUILDER // remove all entries from "Instrument" menu while (!instrument_menu->get_children().empty()) { remove_instrument_from_menu(0); } +#endif // free libgig's gig::File instance if (file && !file_is_shared) delete file; file = NULL; @@ -904,10 +2079,12 @@ m_refTreeModel->clear(); m_refSamplesTreeModel->clear(); m_refScriptsTreeModel->clear(); +#if !USE_GTKMM_BUILDER // remove all entries from "Instrument" menu while (!instrument_menu->get_children().empty()) { remove_instrument_from_menu(0); } +#endif if (!this->file) return; @@ -941,8 +2118,13 @@ 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); +#if HAS_GTKMM_STOCK 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); +#else + dialog.add_button(_("_OK"), Gtk::RESPONSE_OK); + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); +#endif dialog.set_default_response(Gtk::RESPONSE_YES); int response = dialog.run(); dialog.hide(); @@ -973,7 +2155,11 @@ "used by the sampler until you tell the sampler explicitly to " "load it.")); dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES); +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); +#endif dialog.set_default_response(Gtk::RESPONSE_CANCEL); int response = dialog.run(); dialog.hide(); @@ -987,8 +2173,13 @@ if (file_is_shared && !leaving_shared_mode_dialog()) return; Gtk::FileChooserDialog dialog(*this, _("Open file")); +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); +#endif dialog.set_default_response(Gtk::RESPONSE_OK); #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 Gtk::FileFilter filter; @@ -1004,7 +2195,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); } @@ -1019,7 +2211,9 @@ Glib::filename_display_basename(name) + "' ...", *this ); +#if HAS_GTKMM_SHOW_ALL_CHILDREN progress_dialog->show_all(); +#endif loader = new Loader(name); //FIXME: memory leak! loader->signal_progress().connect( sigc::mem_fun(*this, &MainWindow::on_loader_progress)); @@ -1053,12 +2247,14 @@ // make sure the selected item in the "instruments" tree view is // visible (scroll to it) m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); +#if !USE_GTKMM_BUILDER // select item in instrument menu { const std::vector children = instrument_menu->get_children(); static_cast(children[i])->set_active(); } +#endif // update region chooser and dimension region chooser m_RegionChooser.set_instrument(instr); break; @@ -1074,7 +2270,8 @@ void MainWindow::on_loader_finished() { printf("Loader finished!\n"); - printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self()); + printf("on_loader_finished self=%p\n", + static_cast(Glib::Threads::Thread::self())); load_gig(loader->gig, loader->filename.c_str()); progress_dialog->hide(); } @@ -1129,7 +2326,9 @@ Glib::filename_display_basename(this->filename) + "' ...", *this ); +#if HAS_GTKMM_SHOW_ALL_CHILDREN progress_dialog->show_all(); +#endif saver = new Saver(this->file); //FIXME: memory leak! saver->signal_progress().connect( sigc::mem_fun(*this, &MainWindow::on_saver_progress)); @@ -1169,7 +2368,7 @@ file_structure_changed_signal.emit(this->file); - load_gig(this->file, this->filename.c_str()); + __refreshEntireGUI(); progress_dialog->hide(); } @@ -1182,8 +2381,13 @@ bool MainWindow::file_save_as() { Gtk::FileChooserDialog dialog(*this, _("Save as"), Gtk::FILE_CHOOSER_ACTION_SAVE); +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Save"), Gtk::RESPONSE_OK); +#endif dialog.set_default_response(Gtk::RESPONSE_OK); dialog.set_do_overwrite_confirmation(); @@ -1212,9 +2416,11 @@ } // show warning in the dialog - Gtk::HBox descriptionArea; + 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; @@ -1231,8 +2437,14 @@ "same .gig file will end up in corrupted sample wave data!\n") ); descriptionArea.pack_start(description); +#if USE_GTKMM_BOX + dialog.get_content_area()->pack_start(descriptionArea, Gtk::PACK_SHRINK); +#else dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); +#endif +#if HAS_GTKMM_SHOW_ALL_CHILDREN descriptionArea.show_all(); +#endif if (dialog.run() == Gtk::RESPONSE_OK) { std::string filename = dialog.get_filename(); @@ -1246,7 +2458,9 @@ Glib::filename_display_basename(filename) + "' ...", *this ); +#if HAS_GTKMM_SHOW_ALL_CHILDREN progress_dialog->show_all(); +#endif saver = new Saver(file, filename); //FIXME: memory leak! saver->signal_progress().connect( @@ -1266,13 +2480,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")); @@ -1295,6 +2509,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: { @@ -1304,7 +2521,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; @@ -1324,7 +2541,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; @@ -1335,16 +2552,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; } } @@ -1372,6 +2589,11 @@ !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; @@ -1381,7 +2603,7 @@ dialog.set_name("Gigedit"); #endif dialog.set_version(VERSION); - dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson"); + dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson"); const std::string sComment = _("Built " __DATE__ "\nUsing ") + ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + @@ -1397,6 +2619,7 @@ dialog.set_comments(sComment.c_str()); dialog.set_website("http://www.linuxsampler.org"); dialog.set_website_label("http://www.linuxsampler.org"); + dialog.set_position(Gtk::WIN_POS_CENTER); dialog.run(); } @@ -1418,10 +2641,19 @@ eSourceForm(_("Source form")), eCommissioned(_("Commissioned")), eSubject(_("Subject")), +#if HAS_GTKMM_STOCK quitButton(Gtk::Stock::CLOSE), +#else + quitButton(_("_Close")), +#endif table(2, 1), m_file(NULL) { + if (!Settings::singleton()->autoRestoreWindowDimension) { + set_default_size(470, 390); + set_position(Gtk::WIN_POS_MOUSE); + } + set_title(_("File Properties")); eName.set_width_chars(50); @@ -1460,13 +2692,26 @@ table.add(eCommissioned); table.add(eSubject); +#if USE_GTKMM_GRID + table.set_column_spacing(5); +#else table.set_col_spacings(5); +#endif + add(vbox); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + table.set_margin(5); +#else table.set_border_width(5); +#endif vbox.add(table); vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); buttonBox.set_layout(Gtk::BUTTONBOX_END); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + buttonBox.set_margin(5); +#else buttonBox.set_border_width(5); +#endif buttonBox.show(); buttonBox.pack_start(quitButton); quitButton.set_can_default(); @@ -1478,7 +2723,9 @@ quitButton.show(); vbox.show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif } void PropDialog::set_file(gig::File* file) @@ -1541,7 +2788,11 @@ } InstrumentProps::InstrumentProps() : +#if HAS_GTKMM_STOCK quitButton(Gtk::Stock::CLOSE), +#else + quitButton(_("_Close")), +#endif table(2,1), eName(_("Name")), eIsDrum(_("Is drum")), @@ -1551,11 +2802,16 @@ eGainPlus6(_("Gain +6dB"), eAttenuation, -6), eEffectSend(_("Effect send"), 0, 65535), eFineTune(_("Fine tune"), -8400, 8400), - ePitchbendRange(_("Pitchbend range"), 0, 12), + ePitchbendRange(_("Pitchbend range"), 0, 48), ePianoReleaseMode(_("Piano release mode")), eDimensionKeyRangeLow(_("Keyswitching range low")), eDimensionKeyRangeHigh(_("Keyswitching range high")) { + if (!Settings::singleton()->autoRestoreWindowDimension) { + //set_default_size(470, 390); + set_position(Gtk::WIN_POS_MOUSE); + } + set_title(_("Instrument Properties")); eDimensionKeyRangeLow.set_tip( @@ -1582,7 +2838,11 @@ eName.signal_value_changed().connect(sig_name_changed.make_slot()); +#if USE_GTKMM_GRID + table.set_column_spacing(5); +#else table.set_col_spacings(5); +#endif table.add(eName); table.add(eIsDrum); @@ -1598,12 +2858,20 @@ table.add(eDimensionKeyRangeHigh); add(vbox); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + table.set_margin(5); +#else table.set_border_width(5); +#endif vbox.pack_start(table); table.show(); vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); buttonBox.set_layout(Gtk::BUTTONBOX_END); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + buttonBox.set_margin(5); +#else buttonBox.set_border_width(5); +#endif buttonBox.show(); buttonBox.pack_start(quitButton); quitButton.set_can_default(); @@ -1614,7 +2882,9 @@ quitButton.show(); vbox.show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif } void InstrumentProps::set_instrument(gig::Instrument* instrument) @@ -1664,7 +2934,10 @@ 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; @@ -1673,19 +2946,27 @@ 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)); + const int iScriptSlots = instrument->ScriptSlotCount(); 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; + row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : ""; +#if !USE_GTKMM_BUILDER add_instrument_to_menu(name); +#endif } instrument_name_connection.unblock(); +#if !USE_GTKMM_BUILDER uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); +#endif updateSampleRefCountMap(gig); @@ -1751,8 +3032,13 @@ { 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; + } + //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though. + Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]); if (it) { Gtk::TreeModel::Row row = *it; gig::Instrument* instrument = row[m_Columns.m_col_instr]; @@ -1769,7 +3055,8 @@ } else { instrumentProps.hide(); } - return it; + //NOTE: explicit boolean cast required for GTKMM4 development branch here + return it ? true : false; } void MainWindow::show_instr_props() @@ -1805,8 +3092,9 @@ void MainWindow::show_script_slots() { if (!file) return; // get selected instrument - Glib::RefPtr sel = m_TreeView.get_selection(); - Gtk::TreeModel::iterator it = sel->get_selected(); + 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]; @@ -1814,11 +3102,66 @@ ScriptSlots* window = new ScriptSlots; window->setInstrument(instrument); + window->signal_script_slots_changed().connect( + sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified) + ); //window->reparent(*this); window->show(); } +void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) { + if (!pInstrument) return; + const int iScriptSlots = pInstrument->ScriptSlotCount(); + + //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error! + //Glib::RefPtr model = m_TreeView.get_model(); + Glib::RefPtr model = m_refTreeModelFilter->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) continue; + row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : ""; + break; + } + + // causes the sampler to reload the instrument with the new script + on_sel_change(); +} + +void MainWindow::assignScript(gig::Script* pScript) { + if (!pScript) { + printf("assignScript() : !script\n"); + return; + } + printf("assignScript('%s')\n", pScript->Name.c_str()); + + gig::Instrument* pInstrument = get_instrument(); + if (!pInstrument) { + printf("!instrument\n"); + return; + } + + pInstrument->AddScriptSlot(pScript); + + onScriptSlotsModified(pInstrument); +} + +void MainWindow::on_action_refresh_all() { + __refreshEntireGUI(); +} + void MainWindow::on_action_view_status_bar() { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleStatusBar->get_state(active); + // for some reason toggle state does not change automatically + active = !active; + m_actionToggleStatusBar->change_state(active); + if (active) + m_StatusBar.show(); + else + m_StatusBar.hide(); +#else Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); if (!item) { @@ -1827,9 +3170,53 @@ } if (item->get_active()) m_StatusBar.show(); else m_StatusBar.hide(); +#endif +} + +void MainWindow::on_auto_restore_win_dim() { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleRestoreWinDim->get_state(active); + // for some reason toggle state does not change automatically + active = !active; + m_actionToggleRestoreWinDim->change_state(active); + Settings::singleton()->autoRestoreWindowDimension = active; +#else + 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(); +#endif +} + +void MainWindow::on_save_with_temporary_file() { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleSaveWithTempFile->get_state(active); + // for some reason toggle state does not change automatically + active = !active; + m_actionToggleSaveWithTempFile->change_state(active); + Settings::singleton()->saveWithTemporaryFile = active; +#else + 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(); +#endif } bool MainWindow::is_copy_samples_unity_note_enabled() const { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleCopySampleUnity->get_state(active); + return active; +#else Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity")); if (!item) { @@ -1837,9 +3224,15 @@ return true; } return item->get_active(); +#endif } bool MainWindow::is_copy_samples_fine_tune_enabled() const { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleCopySampleTune->get_state(active); + return active; +#else Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune")); if (!item) { @@ -1847,9 +3240,15 @@ return true; } return item->get_active(); +#endif } bool MainWindow::is_copy_samples_loop_enabled() const { +#if USE_GLIB_ACTION + bool active = false; + m_actionToggleCopySampleLoop->get_state(active); + return active; +#else Gtk::CheckMenuItem* item = dynamic_cast(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); if (!item) { @@ -1857,15 +3256,23 @@ return true; } return item->get_active(); +#endif } -void MainWindow::on_button_release(GdkEventButton* button) -{ +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 +bool MainWindow::on_button_release(Gdk::EventButton& _button) { + GdkEventButton* button = _button.gobj(); +#else +void MainWindow::on_button_release(GdkEventButton* button) { +#endif if (button->type == GDK_2BUTTON_PRESS) { 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); +#if USE_GTKMM_BUILDER + m_actionMIDIRules->property_enabled() = bEnabled; +#else static_cast( uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( bEnabled @@ -1874,10 +3281,15 @@ uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( bEnabled ); +#endif popup_menu->popup(button->button, button->time); } +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + return false; +#endif } +#if !USE_GTKMM_BUILDER void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) { if (item->get_active()) { const std::vector children = @@ -1892,6 +3304,78 @@ } } } +#endif + +void MainWindow::select_instrument(gig::Instrument* instrument) { + if (!instrument) return; + + //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error! + Glib::RefPtr model = m_TreeView.get_model(); + //Glib::RefPtr model = m_refTreeModelFilter->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(); + +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + auto iterSel = model->children()[i].get_iter(); + m_TreeView.get_selection()->select(iterSel); +#else + m_TreeView.get_selection()->select(model->children()[i]); +#endif + 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(); + + //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error! + Glib::RefPtr model = m_TreeView.get_model(); + //Glib::RefPtr model = m_refTreeModelFilter->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(); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + auto iterSel = model->children()[i].get_iter(); + m_TreeView.get_selection()->select(iterSel); +#else + m_TreeView.get_selection()->select(model->children()[i]); +#endif + 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(); @@ -1901,63 +3385,120 @@ Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; if (rowSample[m_SamplesModel.m_col_sample] == sample) { show_samples_tab(); + m_TreeViewSamples.get_selection()->unselect_all(); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + auto iterSel = rowGroup.children()[s].get_iter(); + m_TreeViewSamples.get_selection()->select(iterSel); +#else m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); - Gtk::TreePath path( - m_TreeViewSamples.get_selection()->get_selected() - ); - m_TreeViewSamples.scroll_to_row(path); +#endif + std::vector rows = + m_TreeViewSamples.get_selection()->get_selected_rows(); + if (rows.empty()) return; + m_TreeViewSamples.scroll_to_row(rows[0]); return; } } } } +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 +bool MainWindow::on_sample_treeview_button_release(Gdk::EventButton& _button) { + GdkEventButton* button = _button.gobj(); +#else void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) { +#endif 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); + } + } + }*/ + +#if !USE_GTKMM_BUILDER Gtk::Menu* sample_popup = dynamic_cast(uiManager->get_widget("/SamplePopupMenu")); +#endif + // 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++; } - - + +#if USE_GTKMM_BUILDER + m_actionSampleProperties->property_enabled() = (n == 1); + m_actionAddSample->property_enabled() = (n); + m_actionAddSampleGroup->property_enabled() = (file); + m_actionViewSampleRefs->property_enabled() = (nSamples == 1); + m_actionRemoveSample->property_enabled() = (n); + m_actionReplaceSample->property_enabled() = (nSamples == 1); +#else 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(sample_selected); + set_sensitive(nSamples == 1); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n); +#endif // show sample popup sample_popup->popup(button->button, button->time); +#if !USE_GTKMM_BUILDER dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n == 1); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> set_sensitive(file); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> - set_sensitive(sample_selected); + set_sensitive(nSamples == 1); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> - set_sensitive(group_selected || sample_selected); + set_sensitive(n); +#endif } + +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + return false; +#endif } +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 +bool MainWindow::on_script_treeview_button_release(Gdk::EventButton& _button) { + GdkEventButton* button = _button.gobj(); +#else void MainWindow::on_script_treeview_button_release(GdkEventButton* button) { +#endif if (button->type == GDK_BUTTON_PRESS && button->button == 3) { +#if !USE_GTKMM_BUILDER Gtk::Menu* script_popup = dynamic_cast(uiManager->get_widget("/ScriptPopupMenu")); +#endif // update enabled/disabled state of sample popup items Glib::RefPtr sel = m_TreeViewScripts.get_selection(); Gtk::TreeModel::iterator it = sel->get_selected(); @@ -1968,6 +3509,12 @@ group_selected = row[m_ScriptsModel.m_col_group]; script_selected = row[m_ScriptsModel.m_col_script]; } +#if USE_GTKMM_BUILDER + m_actionAddScript->property_enabled() = (group_selected || script_selected); + m_actionAddScriptGroup->property_enabled() = (file); + m_actionEditScript->property_enabled() = (script_selected); + m_actionRemoveScript->property_enabled() = (group_selected || script_selected); +#else dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScript"))-> set_sensitive(group_selected || script_selected); dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))-> @@ -1976,9 +3523,11 @@ set_sensitive(script_selected); dynamic_cast(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))-> set_sensitive(group_selected || script_selected); +#endif // show sample popup script_popup->popup(button->button, button->time); +#if !USE_GTKMM_BUILDER dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> set_sensitive(group_selected || script_selected); dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> @@ -1987,9 +3536,62 @@ set_sensitive(script_selected); dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> set_sensitive(group_selected || script_selected); +#endif } +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 + return false; +#endif } +void MainWindow::updateScriptListOfMenu() { + // remove all entries from "Assign Script" menu + { + const std::vector children = assign_scripts_menu->get_children(); + for (int i = 0; i < children.size(); ++i) { + Gtk::Widget* child = children[i]; + assign_scripts_menu->remove(*child); + delete child; + } + } + + int iTotalScripts = 0; + + if (!file) goto noScripts; + + // add all configured macros as menu items to the "Macro" menu + for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) { + gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup); + for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) { + gig::Script* pScript = pGroup->GetScript(iScript); + std::string name = pScript->Name; + + Gtk::MenuItem* item = new Gtk::MenuItem(name); + item->signal_activate().connect( + sigc::bind( + sigc::mem_fun(*this, &MainWindow::assignScript), pScript + ) + ); + assign_scripts_menu->append(*item); + item->set_accel_path("/script_" + ToString(iTotalScripts)); + //item->set_tooltip_text(comment); + } + } + + noScripts: + + // if there are no macros configured at all, then show a dummy entry instead + if (!iTotalScripts) { + Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts")); + item->set_sensitive(false); + assign_scripts_menu->append(*item); + } + +#if HAS_GTKMM_SHOW_ALL_CHILDREN + assign_scripts_menu->show_all_children(); +#endif +} + +#if !USE_GTKMM_BUILDER Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu( const Glib::ustring& name, int position) { @@ -2013,7 +3615,9 @@ item)); return item; } +#endif +#if !USE_GTKMM_BUILDER void MainWindow::remove_instrument_from_menu(int index) { const std::vector children = instrument_menu->get_children(); @@ -2021,6 +3625,7 @@ instrument_menu->remove(*child); delete child; } +#endif void MainWindow::add_instrument(gig::Instrument* instrument) { const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); @@ -2029,14 +3634,16 @@ 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; + rowInstr[m_Columns.m_col_scripts] = ""; instrument_name_connection.unblock(); +#if !USE_GTKMM_BUILDER add_instrument_to_menu(name); - - m_TreeView.get_selection()->select(iterInstr); - +#endif + select_instrument(instrument); file_changed(); } @@ -2057,19 +3664,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() { @@ -2086,8 +3697,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 { @@ -2098,10 +3711,22 @@ if (instr) file->DeleteInstrument(instr); file_changed(); +#if !USE_GTKMM_BUILDER remove_instrument_from_menu(index); +#endif // 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 @@ -2199,6 +3824,12 @@ 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(); @@ -2264,28 +3895,47 @@ 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)")); + Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)")); +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); - dialog.set_select_multiple(true); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); + dialog.add_button(_("_Open"), Gtk::RESPONSE_OK); +#endif + 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 @@ -2356,8 +4006,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 @@ -2408,21 +4058,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(); @@ -2433,7 +4087,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(); } @@ -2466,17 +4124,32 @@ Gtk::Label description(str); description.set_line_wrap(); #endif - Gtk::HBox entryArea; + HBox entryArea; Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START); Gtk::Entry postfixEntryBox; postfixEntryBox.set_text(".wav"); entryArea.pack_start(entryLabel); entryArea.pack_start(postfixEntryBox); +#if USE_GTKMM_BOX + dialog.get_content_area()->pack_start(description, Gtk::PACK_SHRINK); + dialog.get_content_area()->pack_start(entryArea, Gtk::PACK_SHRINK); +#else dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK); dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK); +#endif description.show(); + +#if HAS_GTKMM_SHOW_ALL_CHILDREN entryArea.show_all(); +#else + entryArea.show(); +#endif + +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); +#endif dialog.add_button(_("Select"), Gtk::RESPONSE_OK); dialog.set_select_multiple(false); if (current_sample_dir != "") { @@ -2500,18 +4173,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); @@ -2520,7 +4189,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(); } @@ -2544,8 +4213,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]; @@ -2570,15 +4241,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(); @@ -2593,14 +4261,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(); @@ -2617,6 +4281,66 @@ } } +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) { @@ -2643,6 +4367,65 @@ 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 @@ -2661,10 +4444,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, @@ -2804,6 +4590,12 @@ 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(); @@ -2815,6 +4607,7 @@ Gtk::TreeModel::Row row = *iter; Glib::ustring name = row[m_Columns.m_col_name]; +#if !USE_GTKMM_BUILDER // change name in instrument menu int index = path[0]; const std::vector children = instrument_menu->get_children(); @@ -2827,6 +4620,7 @@ item->set_active(); #endif } +#endif // change name in gig gig::Instrument* instrument = row[m_Columns.m_col_instr]; @@ -2843,10 +4637,56 @@ } } +bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) { + if (!iter) + return true; + + Glib::ustring pattern = m_searchText.get_text().lowercase(); + trim(pattern); + if (pattern.empty()) return true; + +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22) + //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though. + Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter); +#else + Gtk::TreeModel::Row row = *iter; +#endif + Glib::ustring name = row[m_Columns.m_col_name]; + name = name.lowercase(); + + std::vector tokens = Glib::Regex::split_simple(" ", pattern); + for (int t = 0; t < tokens.size(); ++t) + if (name.find(tokens[t]) == Glib::ustring::npos) + return false; + + return true; +} + void MainWindow::on_action_combine_instruments() { CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file); + + // take over selection from instruments list view for the combine dialog's + // list view as pre-selection + std::set indeces; + { + Glib::RefPtr sel = m_TreeView.get_selection(); + 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; + int index = row[m_Columns.m_col_nr]; + indeces.insert(index); + } + } + } + d->setSelectedInstruments(indeces); + +#if HAS_GTKMM_SHOW_ALL_CHILDREN d->show_all(); - d->resize(500, 400); +#else + d->show(); +#endif d->run(); if (d->fileWasChanged()) { // update GUI with new instrument just created @@ -2857,7 +4697,9 @@ void MainWindow::on_action_view_references() { 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 = row[m_SamplesModel.m_col_sample]; @@ -2865,7 +4707,14 @@ ReferencesView* d = new ReferencesView(*this); d->setSample(sample); + d->dimension_region_selected.connect( + sigc::mem_fun(*this, &MainWindow::select_dimension_region) + ); +#if HAS_GTKMM_SHOW_ALL_CHILDREN d->show_all(); +#else + d->show(); +#endif d->resize(500, 400); d->run(); delete d; @@ -2949,7 +4798,11 @@ Glib::filename_display_basename(this->filename) + "' ...", *this ); +#if HAS_GTKMM_SHOW_ALL_CHILDREN progress_dialog->show_all(); +#else + progress_dialog->show(); +#endif saver = new Saver(this->file); //FIXME: memory leak! saver->signal_progress().connect( sigc::mem_fun(*this, &MainWindow::on_saver_progress)); @@ -2976,7 +4829,11 @@ } Gtk::FileChooserDialog dialog(*this, _("Merge .gig files")); +#if HAS_GTKMM_STOCK dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); +#else + dialog.add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL); +#endif 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 @@ -2993,9 +4850,11 @@ dialog.set_select_multiple(true); // show warning in the file picker dialog - Gtk::HBox descriptionArea; + 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; @@ -3014,11 +4873,20 @@ "will accordingly be stored separately in the target .gig file!" )); descriptionArea.pack_start(description); +#if USE_GTKMM_BOX +# warning No description area implemented for dialog on GTKMM 3 +#else dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK); +#endif +#if HAS_GTKMM_SHOW_ALL_CHILDREN descriptionArea.show_all(); +#else + descriptionArea.show(); +#endif 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 @@ -3030,7 +4898,7 @@ } // update GUI - __refreshEntireGUI(); + __refreshEntireGUI(); } } @@ -3050,9 +4918,13 @@ } { +#if USE_GTKMM_BUILDER + m_actionToggleSyncSamplerSelection->property_enabled() = b; +#else Gtk::MenuItem* item = dynamic_cast( uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection")); if (item) item->set_sensitive(b); +#endif } } @@ -3100,6 +4972,209 @@ m_TreeViewNotebook.set_current_page(2); } +void MainWindow::select_instrument_by_dir(int dir) { + if (!file) return; + gig::Instrument* pInstrument = get_instrument(); + if (!pInstrument) { + select_instrument( file->GetInstrument(0) ); + return; + } + for (int i = 0; file->GetInstrument(i); ++i) { + if (file->GetInstrument(i) == pInstrument) { + select_instrument( file->GetInstrument(i + dir) ); + return; + } + } +} + +void MainWindow::select_prev_instrument() { + select_instrument_by_dir(-1); +} + +void MainWindow::select_next_instrument() { + select_instrument_by_dir(1); +} + +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, true); + 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(); +#if USE_GTKMM_BUILDER + m_actionCopyDimRgn->property_enabled() = bDimensionRegionCopyIsPossible; +#else + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn") + )->set_sensitive(bDimensionRegionCopyIsPossible); +#endif +} + +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2 +void MainWindow::on_clipboard_owner_change(Gdk::EventOwnerChange& event) { +#else +void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) { +#endif + 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(); +} + +//NOTE: Might throw exception !!! +void MainWindow::applyMacro(Serialization::Archive& macro) { + gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); + if (!pDimRgn) return; + + for (std::set::iterator itDimReg = dimreg_edit.dimregs.begin(); + itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) + { + gig::DimensionRegion* pDimRgn = *itDimReg; + DimRegionChangeGuard(this, pDimRgn); + macro.deserialize(pDimRgn); + } + //region_changed() + file_changed(); + dimreg_changed(); +} + +void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { + const std::string target = selection_data.get_target(); + if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { + Glib::ustring errorText; + try { + m_serializationArchive.decode( + selection_data.get_data(), selection_data.get_length() + ); + applyMacro(m_serializationArchive); + } catch (Serialization::Exception e) { + errorText = e.Message; + } catch (...) { + errorText = _("Unknown exception while pasting DimensionRegion"); + } + 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(); + +#if USE_GTKMM_BUILDER + m_actionPasteDimRgn->property_enabled() = bDimensionRegionPasteIsPossible; + m_actionAdjustClipboard->property_enabled() = bDimensionRegionPasteIsPossible; +#else + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn") + )->set_sensitive(bDimensionRegionPasteIsPossible); + + static_cast( + uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard") + )->set_sensitive(bDimensionRegionPasteIsPossible); +#endif +} + sigc::signal& MainWindow::signal_file_structure_to_be_changed() { return file_structure_to_be_changed_signal; }