--- gigedit/trunk/src/gigedit/mainwindow.cpp 2017/07/31 11:20:18 3340 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2020/01/10 14:22:25 3711 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2017 Andreas Persson + * Copyright (C) 2006-2020 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,13 +20,7 @@ #include #include -#include -// threads.h must be included first to be able to build with -// G_DISABLE_DEPRECATED -#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ - (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 -#include -#endif +#include "compat.h" #include #include @@ -36,10 +30,14 @@ #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" @@ -49,7 +47,11 @@ #include "compat.h" #include -#include +#ifdef LIBSNDFILE_HEADER_FILE +# include LIBSNDFILE_HEADER_FILE(sndfile.h) +#else +# include +#endif #include #include "mainwindow.h" @@ -93,7 +95,11 @@ // set_border_width(5); if (!Settings::singleton()->autoRestoreWindowDimension) { - set_default_size(800, 600); +#if GTKMM_MAJOR_VERSION >= 3 + set_default_size(960, 600); +#else + set_default_size(865, 600); +#endif set_position(Gtk::WIN_POS_CENTER); } @@ -105,8 +111,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); @@ -119,8 +130,9 @@ m_ScrolledWindowScripts.add(m_TreeViewScripts); m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - +#if GTKMM_MAJOR_VERSION < 3 m_TreeViewNotebook.set_size_request(300); +#endif m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:")); m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK); @@ -143,30 +155,52 @@ 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); @@ -180,6 +214,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"))); @@ -236,6 +309,7 @@ actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script"))); actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); +#endif const Gdk::ModifierType primaryModifierKey = #if defined(__APPLE__) @@ -244,6 +318,47 @@ 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), @@ -308,7 +423,13 @@ _("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); @@ -323,8 +444,27 @@ 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_actionInstrDoubleClickOpensProps = + m_actionGroup->add_action_bool( + "OpenInstrPropsByDoubleClick", + sigc::mem_fun(*this, &MainWindow::on_instr_double_click_opens_props), + Settings::singleton()->instrumentDoubleClickOpensProps + ); + m_actionToggleShowTooltips = m_actionGroup->add_action_bool( + "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips), + Settings::singleton()->showTooltips + ); + 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"))); @@ -344,6 +484,21 @@ *this, &MainWindow::on_auto_restore_win_dim)); toggle_action = + Gtk::ToggleAction::create("OpenInstrPropsByDoubleClick", _("Instrument Properties by Double Click")); + toggle_action->set_active(Settings::singleton()->instrumentDoubleClickOpensProps); + actionGroup->add(toggle_action, + sigc::mem_fun( + *this, &MainWindow::on_instr_double_click_opens_props)); + + toggle_action = + Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners")); + toggle_action->set_active(Settings::singleton()->showTooltips); + actionGroup->add( + toggle_action, + sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips) + ); + + toggle_action = Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file")); toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile); actionGroup->add(toggle_action, @@ -354,7 +509,25 @@ 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())); @@ -378,8 +551,22 @@ 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 = @@ -405,8 +592,16 @@ 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( @@ -418,9 +613,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) @@ -455,8 +676,23 @@ _("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) @@ -473,7 +709,399 @@ 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" + " " + " " + " Tooltips for Beginners" + " AppMenu.ShowTooltips" + " " + " " + " Auto restore Window Dimensions" + " AppMenu.AutoRestoreWinDim" + " " + " " + " Instrument Properties by Double Click" + " AppMenu.OpenInstrPropsByDoubleClick" + " " + "
" + "
" + " " + " 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()); @@ -550,7 +1178,9 @@ " " " " " " + " " " " + " " " " " " " " @@ -598,7 +1228,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 @@ -618,7 +1266,7 @@ { Gtk::MenuItem* item = dynamic_cast( uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop")); - item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action.")); + item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop information to be altered by this action.")); } { Gtk::MenuItem* item = dynamic_cast( @@ -633,7 +1281,7 @@ { 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.")); + item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keyboard position dependent pitch will move exactly with the amount of semi tones the region was moved around.")); } { Gtk::MenuItem* item = dynamic_cast( @@ -656,6 +1304,11 @@ } { Gtk::MenuItem* item = dynamic_cast( + uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick")); + item->set_tooltip_text(_("If checked, double clicking an instrument opens its properties dialog.")); + } + { + 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.")); } @@ -664,15 +1317,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); @@ -683,8 +1350,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( @@ -702,7 +1373,10 @@ 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.")); + m_TreeView.set_has_tooltip(true); + m_TreeView.signal_query_tooltip().connect( + sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip) + ); instrument_name_connection = m_refTreeModel->signal_row_changed().connect( sigc::mem_fun(*this, &MainWindow::instrument_name_changed) ); @@ -756,9 +1430,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) ); @@ -775,9 +1455,15 @@ // 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) ); +#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) @@ -821,7 +1507,9 @@ sigc::mem_fun(*this, &MainWindow::file_changed)); instrumentProps.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); - propDialog.signal_changed().connect( + sampleProps.signal_changed().connect( + sigc::mem_fun(*this, &MainWindow::file_changed)); + fileProps.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); midiRules.signal_changed().connect( sigc::mem_fun(*this, &MainWindow::file_changed)); @@ -847,7 +1535,11 @@ sigc::hide( sigc::bind( file_structure_to_be_changed_signal.make_slot(), +#if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8) + std::ref(this->file) +#else sigc::ref(this->file) +#endif ) ) ); @@ -855,7 +1547,11 @@ sigc::hide( sigc::bind( file_structure_changed_signal.make_slot(), +#if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8) + std::ref(this->file) +#else sigc::ref(this->file) +#endif ) ) ); @@ -877,13 +1573,15 @@ sigc::mem_fun(*this, &MainWindow::update_dimregs)); m_searchText.signal_changed().connect( - sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter) + 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(); @@ -904,9 +1602,17 @@ // 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); @@ -921,6 +1627,13 @@ 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("/macro_12", GDK_KEY_F13, noModifier); + Gtk::AccelMap::add_entry("/macro_13", GDK_KEY_F14, noModifier); + Gtk::AccelMap::add_entry("/macro_14", GDK_KEY_F15, noModifier); + Gtk::AccelMap::add_entry("/macro_15", GDK_KEY_F16, noModifier); + Gtk::AccelMap::add_entry("/macro_16", GDK_KEY_F17, noModifier); + Gtk::AccelMap::add_entry("/macro_17", GDK_KEY_F18, noModifier); + Gtk::AccelMap::add_entry("/macro_18", GDK_KEY_F19, noModifier); Gtk::AccelMap::add_entry("/SetupMacros", 'm', primaryModifierKey); Glib::RefPtr accelGroup = this->get_accel_group(); @@ -943,11 +1656,21 @@ 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); + Gtk::AccelMap::add_entry("/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK); + Gtk::AccelMap::add_entry("/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK); Glib::RefPtr accelGroup = this->get_accel_group(); assign_scripts_menu->set_accel_group(accelGroup); } + on_show_tooltips_changed(); + Glib::signal_idle().connect_once( sigc::mem_fun(*this, &MainWindow::bringToFront), 200 @@ -967,9 +1690,11 @@ } 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 { @@ -1027,7 +1752,9 @@ item->set_accel_path("/SetupMacros"); } +#if HAS_GTKMM_SHOW_ALL_CHILDREN menuMacro->show_all_children(); +#endif } void MainWindow::onMacroSelected(int iMacro) { @@ -1064,7 +1791,8 @@ updateMacroMenu(); } -void MainWindow::on_notebook_tab_switched(GtkNotebookPage* page, guint page_num) { +//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 @@ -1092,7 +1820,8 @@ gig::Instrument* instrument = 0; std::vector rows = m_TreeView.get_selection()->get_selected_rows(); if (rows.empty()) return NULL; - Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); + //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]; @@ -1158,6 +1887,7 @@ void MainWindow::on_sel_change() { +#if !USE_GTKMM_BUILDER // select item in instrument menu std::vector rows = m_TreeView.get_selection()->get_selected_rows(); if (!rows.empty()) { @@ -1170,6 +1900,7 @@ static_cast(children[index])->set_active(); } } +#endif updateScriptListOfMenu(); @@ -1180,16 +1911,30 @@ } } + +LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) : + filename(filename), gig(gig), +#ifdef GLIB_THREADS + thread(0), +#endif + progress(0.f) +{ +} + void loader_progress_callback(gig::progress_t* progress) { - Loader* loader = static_cast(progress->custom); + LoaderSaverBase* loader = static_cast(progress->custom); loader->progress_callback(progress->factor); } -void Loader::progress_callback(float fraction) +void LoaderSaverBase::progress_callback(float fraction) { { +#ifdef GLIB_THREADS Glib::Threads::Mutex::Lock lock(progressMutex); +#else + std::lock_guard lock(progressMutex); +#endif progress = fraction; } progress_dispatcher(); @@ -1199,19 +1944,21 @@ // make sure stack is 16-byte aligned for SSE instructions __attribute__((force_align_arg_pointer)) #endif -void Loader::thread_function() +void LoaderSaverBase::thread_function() { +#ifdef GLIB_THREADS printf("thread_function self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "thread_function self=" << std::this_thread::get_id() << "\n"; +#endif printf("Start %s\n", filename.c_str()); try { - RIFF::File* riff = new RIFF::File(filename); - gig = new gig::File(riff); gig::progress_t progress; progress.callback = loader_progress_callback; progress.custom = this; - gig->GetInstrument(0, &progress); + thread_function_sub(progress); printf("End\n"); finished_dispatcher(); } catch (RIFF::Exception e) { @@ -1223,165 +1970,123 @@ } } -Loader::Loader(const char* filename) - : filename(filename), gig(0), thread(0), progress(0.f) -{ -} - -void Loader::launch() +void LoaderSaverBase::launch() { +#ifdef GLIB_THREADS #ifdef OLD_THREADS - thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true); + thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true); #else - thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function)); + thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function)); #endif printf("launch thread=%p\n", static_cast(thread)); +#else + thread = std::thread([this](){ thread_function(); }); + std::cout << "launch thread=" << thread.get_id() << "\n"; +#endif } -float Loader::get_progress() +float LoaderSaverBase::get_progress() { - float res; - { - Glib::Threads::Mutex::Lock lock(progressMutex); - res = progress; - } - return res; +#ifdef GLIB_THREADS + Glib::Threads::Mutex::Lock lock(progressMutex); +#else + std::lock_guard lock(progressMutex); +#endif + return progress; } -Glib::Dispatcher& Loader::signal_progress() +Glib::Dispatcher& LoaderSaverBase::signal_progress() { return progress_dispatcher; } -Glib::Dispatcher& Loader::signal_finished() +Glib::Dispatcher& LoaderSaverBase::signal_finished() { return finished_dispatcher; } -Glib::Dispatcher& Loader::signal_error() +Glib::Dispatcher& LoaderSaverBase::signal_error() { return error_dispatcher; } -void saver_progress_callback(gig::progress_t* progress) -{ - Saver* saver = static_cast(progress->custom); - saver->progress_callback(progress->factor); +void LoaderSaverBase::join() { +#ifdef GLIB_THREADS + thread->join(); +#else + thread.join(); +#endif } -void Saver::progress_callback(float fraction) + +Loader::Loader(const char* filename) : + LoaderSaverBase(filename, 0) { - { - Glib::Threads::Mutex::Lock lock(progressMutex); - progress = fraction; - } - progress_dispatcher.emit(); } -#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) -// make sure stack is 16-byte aligned for SSE instructions -__attribute__((force_align_arg_pointer)) -#endif -void Saver::thread_function() +void Loader::thread_function_sub(gig::progress_t& progress) { - printf("thread_function self=%p\n", - static_cast(Glib::Threads::Thread::self())); - printf("Start %s\n", filename.c_str()); - try { - gig::progress_t progress; - progress.callback = saver_progress_callback; - progress.custom = this; - - // if no filename was provided, that means "save", if filename was provided means "save as" - if (filename.empty()) { - if (!Settings::singleton()->saveWithTemporaryFile) { - // save directly over the existing .gig file - // (requires less disk space than solution below - // but may be slower) - gig->Save(&progress); - } else { - // save the file as separate temporary file first, - // then move the saved file over the old file - // (may result in performance speedup during save) - 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); - } + RIFF::File* riff = new RIFF::File(filename); + gig = new gig::File(riff); - printf("End\n"); - finished_dispatcher.emit(); - } catch (RIFF::Exception e) { - error_message = e.Message; - error_dispatcher.emit(); - } catch (...) { - error_message = _("Unknown exception occurred"); - error_dispatcher.emit(); - } + gig->GetInstrument(0, &progress); } -Saver::Saver(gig::File* file, Glib::ustring filename) - : gig(file), filename(filename), thread(0), progress(0.f) + +Saver::Saver(gig::File* file, Glib::ustring filename) : + LoaderSaverBase(filename, file) { } -void Saver::launch() +void Saver::thread_function_sub(gig::progress_t& progress) { -#ifdef OLD_THREADS - thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true); + // if no filename was provided, that means "save", if filename was provided means "save as" + if (filename.empty()) { + if (!Settings::singleton()->saveWithTemporaryFile) { + // save directly over the existing .gig file + // (requires less disk space than solution below + // but may be slower) + gig->Save(&progress); + } else { + // save the file as separate temporary file first, + // then move the saved file over the old file + // (may result in performance speedup during save) + 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 - thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function)); + throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno))); #endif - printf("launch thread=%p\n", static_cast(thread)); -} - -float Saver::get_progress() -{ - float res; - { - Glib::Threads::Mutex::Lock lock(progressMutex); - res = progress; + } + } + } else { + gig->Save(filename, &progress); } - return res; } -Glib::Dispatcher& Saver::signal_progress() -{ - return progress_dispatcher; -} - -Glib::Dispatcher& Saver::signal_finished() -{ - return finished_dispatcher; -} - -Glib::Dispatcher& Saver::signal_error() -{ - return error_dispatcher; -} ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent) : Gtk::Dialog(title, parent, true) { +#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); } @@ -1394,10 +2099,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; @@ -1409,10 +2116,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; @@ -1446,8 +2155,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(); @@ -1478,7 +2192,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(); @@ -1492,8 +2210,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; @@ -1507,10 +2230,16 @@ dialog.set_current_folder(current_gig_dir); } if (dialog.run() == Gtk::RESPONSE_OK) { + dialog.hide(); std::string filename = dialog.get_filename(); printf("filename=%s\n", filename.c_str()); +#ifdef GLIB_THREADS printf("on_action_file_open self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_action_file_open self=" << + std::this_thread::get_id() << "\n"; +#endif load_file(filename.c_str()); current_gig_dir = Glib::path_get_dirname(filename); } @@ -1525,7 +2254,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)); @@ -1559,12 +2290,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; @@ -1579,15 +2312,22 @@ void MainWindow::on_loader_finished() { + loader->join(); printf("Loader finished!\n"); +#ifdef GLIB_THREADS printf("on_loader_finished self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_loader_finished self=" << + std::this_thread::get_id() << "\n"; +#endif load_gig(loader->gig, loader->filename.c_str()); progress_dialog->hide(); } void MainWindow::on_loader_error() { + loader->join(); Glib::ustring txt = _("Could not load file: ") + loader->error_message; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); msg.run(); @@ -1636,7 +2376,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)); @@ -1656,6 +2398,7 @@ void MainWindow::on_saver_error() { + saver->join(); file_structure_changed_signal.emit(this->file); Glib::ustring txt = _("Could not save file: ") + saver->error_message; Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); @@ -1664,6 +2407,7 @@ void MainWindow::on_saver_finished() { + saver->join(); this->file = saver->gig; this->filename = saver->filename; current_gig_dir = Glib::path_get_dirname(filename); @@ -1689,8 +2433,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(); @@ -1719,7 +2468,7 @@ } // show warning in the dialog - Gtk::HBox descriptionArea; + HBox descriptionArea; descriptionArea.set_spacing(15); Gtk::Image warningIcon; warningIcon.set_from_icon_name("dialog-warning", @@ -1740,10 +2489,17 @@ "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) { + dialog.hide(); std::string filename = dialog.get_filename(); if (!Glib::str_has_suffix(filename, ".gig")) { filename += ".gig"; @@ -1755,7 +2511,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( @@ -1870,8 +2628,8 @@ void MainWindow::on_action_file_properties() { - propDialog.show(); - propDialog.deiconify(); + fileProps.show(); + fileProps.deiconify(); } void MainWindow::on_action_warn_user_on_extensions() { @@ -1879,6 +2637,30 @@ !Settings::singleton()->warnUserOnExtensions; } +void MainWindow::on_action_show_tooltips() { + Settings::singleton()->showTooltips = + !Settings::singleton()->showTooltips; + + on_show_tooltips_changed(); +} + +void MainWindow::on_show_tooltips_changed() { + const bool b = Settings::singleton()->showTooltips; + + dimreg_label.set_has_tooltip(b); + dimreg_all_regions.set_has_tooltip(b); + dimreg_all_dimregs.set_has_tooltip(b); + dimreg_stereo.set_has_tooltip(b); + + // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell + //m_TreeView.set_has_tooltip(b); + + m_TreeViewSamples.set_has_tooltip(b); + m_TreeViewScripts.set_has_tooltip(b); + + set_has_tooltip(b); +} + void MainWindow::on_action_sync_sampler_instrument_selection() { Settings::singleton()->syncSamplerInstrumentSelection = !Settings::singleton()->syncSamplerInstrumentSelection; @@ -1898,7 +2680,7 @@ dialog.set_name("Gigedit"); #endif dialog.set_version(VERSION); - dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson"); + dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson"); const std::string sComment = _("Built " __DATE__ "\nUsing ") + ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" + @@ -1909,16 +2691,16 @@ "backup your Gigasampler/GigaStudio files before editing them with " "this application.\n" "\n" - "Please report bugs to: http://bugs.linuxsampler.org" + "Please report bugs to: https://bugs.linuxsampler.org" ); dialog.set_comments(sComment.c_str()); - dialog.set_website("http://www.linuxsampler.org"); - dialog.set_website_label("http://www.linuxsampler.org"); + dialog.set_website("https://www.linuxsampler.org"); + dialog.set_website_label("https://www.linuxsampler.org"); dialog.set_position(Gtk::WIN_POS_CENTER); dialog.run(); } -PropDialog::PropDialog() +FilePropDialog::FilePropDialog() : eFileFormat(_("File Format")), eName(_("Name")), eCreationDate(_("Creation date")), @@ -1936,7 +2718,11 @@ 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) { @@ -1948,6 +2734,7 @@ set_title(_("File Properties")); eName.set_width_chars(50); + connect(eFileFormat, &FilePropDialog::set_FileFormat); connect(eName, &DLS::Info::Name); connect(eCreationDate, &DLS::Info::CreationDate); connect(eComments, &DLS::Info::Comments); @@ -1983,30 +2770,44 @@ 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 > 24) + 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 > 24) + buttonBox.set_margin(5); +#else buttonBox.set_border_width(5); +#endif buttonBox.show(); buttonBox.pack_start(quitButton); quitButton.set_can_default(); quitButton.grab_focus(); quitButton.signal_clicked().connect( - sigc::mem_fun(*this, &PropDialog::hide)); - eFileFormat.signal_value_changed().connect( - sigc::mem_fun(*this, &PropDialog::onFileFormatChanged)); + sigc::mem_fun(*this, &FilePropDialog::hide)); quitButton.show(); vbox.show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif } -void PropDialog::set_file(gig::File* file) +void FilePropDialog::set_file(gig::File* file) { m_file = file; + update(file->pInfo); // update file format version combo box const std::string sGiga = "Gigasampler/GigaStudio v"; @@ -2014,25 +2815,24 @@ std::vector txts; std::vector values; txts.push_back(sGiga + "2"); values.push_back(2); - txts.push_back(sGiga + "3/v4"); values.push_back(3); - if (major != 2 && major != 3) { + txts.push_back(sGiga + "3"); values.push_back(3); + txts.push_back(sGiga + "4"); values.push_back(4); + if (major < 2 || major > 4) { txts.push_back(sGiga + ToString(major)); values.push_back(major); } std::vector texts; for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str()); texts.push_back(NULL); values.push_back(0); + + update_model++; eFileFormat.set_choices(&texts[0], &values[0]); eFileFormat.set_value(major); + update_model--; } -void PropDialog::onFileFormatChanged() { - const int major = eFileFormat.get_value(); - if (m_file) m_file->pVersion->major = major; -} - -void PropDialog::set_info(DLS::Info* info) +void FilePropDialog::set_FileFormat(int value) { - update(info); + m_file->pVersion->major = value; } @@ -2064,20 +2864,40 @@ } InstrumentProps::InstrumentProps() : +#if HAS_GTKMM_STOCK quitButton(Gtk::Stock::CLOSE), +#else + quitButton(_("_Close")), +#endif table(2,1), eName(_("Name")), eIsDrum(_("Is drum")), eMIDIBank(_("MIDI bank"), 0, 16383), eMIDIProgram(_("MIDI program")), - eAttenuation(_("Attenuation"), 0, 96, 0, 1), - eGainPlus6(_("Gain +6dB"), eAttenuation, -6), + eAttenuation(_("Attenuation (dB)"), -96, +96, 0, 1), eEffectSend(_("Effect send"), 0, 65535), eFineTune(_("Fine tune"), -8400, 8400), - ePitchbendRange(_("Pitchbend range"), 0, 12), + ePitchbendRange(_("Pitchbend range (halftones)"), 0, 48), ePianoReleaseMode(_("Piano release mode")), eDimensionKeyRangeLow(_("Keyswitching range low")), - eDimensionKeyRangeHigh(_("Keyswitching range high")) + eDimensionKeyRangeHigh(_("Keyswitching range high")), + table2(2,1), + eName2(_("Name")), + eCreationDate(_("Creation date")), + eComments(_("Comments")), + eProduct(_("Product")), + eCopyright(_("Copyright")), + eArtists(_("Artists")), + eGenre(_("Genre")), + eKeywords(_("Keywords")), + eEngineer(_("Engineer")), + eTechnician(_("Technician")), + eSoftware(_("Software")), + eMedium(_("Medium")), + eSource(_("Source")), + eSourceForm(_("Source form")), + eCommissioned(_("Commissioned")), + eSubject(_("Subject")) { if (!Settings::singleton()->autoRestoreWindowDimension) { //set_default_size(470, 390); @@ -2086,6 +2906,9 @@ set_title(_("Instrument Properties")); + tabs.append_page(vbox[1], _("Settings")); + tabs.append_page(vbox[2], _("Info")); + eDimensionKeyRangeLow.set_tip( _("start of the keyboard area which should switch the " "\"keyswitching\" dimension") @@ -2100,7 +2923,6 @@ connect(eMIDIBank, &InstrumentProps::set_MIDIBank); connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); connect(eAttenuation, &gig::Instrument::Attenuation); - connect(eGainPlus6, &gig::Instrument::Attenuation); connect(eEffectSend, &gig::Instrument::EffectSend); connect(eFineTune, &gig::Instrument::FineTune); connect(ePitchbendRange, &gig::Instrument::PitchbendRange); @@ -2110,14 +2932,64 @@ eName.signal_value_changed().connect(sig_name_changed.make_slot()); + connect(eName2, &InstrumentProps::set_Name); + connectLambda(eCreationDate, [this](gig::String s) { + m->pInfo->CreationDate = s; + }); + connectLambda(eComments, [this](gig::String s) { + m->pInfo->Comments = s; + }); + connectLambda(eProduct, [this](gig::String s) { + m->pInfo->Product = s; + }); + connectLambda(eCopyright, [this](gig::String s) { + m->pInfo->Copyright = s; + }); + connectLambda(eArtists, [this](gig::String s) { + m->pInfo->Artists = s; + }); + connectLambda(eGenre, [this](gig::String s) { + m->pInfo->Genre = s; + }); + connectLambda(eKeywords, [this](gig::String s) { + m->pInfo->Keywords = s; + }); + connectLambda(eEngineer, [this](gig::String s) { + m->pInfo->Engineer = s; + }); + connectLambda(eTechnician, [this](gig::String s) { + m->pInfo->Technician = s; + }); + connectLambda(eSoftware, [this](gig::String s) { + m->pInfo->Software = s; + }); + connectLambda(eMedium, [this](gig::String s) { + m->pInfo->Medium = s; + }); + connectLambda(eSource, [this](gig::String s) { + m->pInfo->Source = s; + }); + connectLambda(eSourceForm, [this](gig::String s) { + m->pInfo->SourceForm = s; + }); + connectLambda(eCommissioned, [this](gig::String s) { + m->pInfo->Commissioned = s; + }); + connectLambda(eSubject, [this](gig::String s) { + m->pInfo->Subject = s; + }); + + // tab 1 +#if USE_GTKMM_GRID + table.set_column_spacing(5); +#else table.set_col_spacings(5); - +#endif table.add(eName); table.add(eIsDrum); table.add(eMIDIBank); table.add(eMIDIProgram); table.add(eAttenuation); - table.add(eGainPlus6); table.add(eEffectSend); table.add(eFineTune); table.add(ePitchbendRange); @@ -2125,13 +2997,47 @@ table.add(eDimensionKeyRangeLow); table.add(eDimensionKeyRangeHigh); - add(vbox); + // tab 2 +#if USE_GTKMM_GRID + table2.set_column_spacing(5); +#else + table2.set_col_spacings(5); +#endif + table2.add(eName2); + table2.add(eCreationDate); + table2.add(eComments); + table2.add(eProduct); + table2.add(eCopyright); + table2.add(eArtists); + table2.add(eGenre); + table2.add(eKeywords); + table2.add(eEngineer); + table2.add(eTechnician); + table2.add(eSoftware); + table2.add(eMedium); + table2.add(eSource); + table2.add(eSourceForm); + table2.add(eCommissioned); + table2.add(eSubject); + + add(vbox[0]); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + table.set_margin(5); +#else table.set_border_width(5); - vbox.pack_start(table); +#endif + vbox[1].pack_start(table); + vbox[2].pack_start(table2); table.show(); - vbox.pack_start(buttonBox, Gtk::PACK_SHRINK); + table2.show(); + vbox[0].pack_start(tabs); + vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK); buttonBox.set_layout(Gtk::BUTTONBOX_END); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + buttonBox.set_margin(5); +#else buttonBox.set_border_width(5); +#endif buttonBox.show(); buttonBox.pack_start(quitButton); quitButton.set_can_default(); @@ -2141,8 +3047,10 @@ sigc::mem_fun(*this, &InstrumentProps::hide)); quitButton.show(); - vbox.show(); + vbox[0].show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN show_all_children(); +#endif } void InstrumentProps::set_instrument(gig::Instrument* instrument) @@ -2150,10 +3058,318 @@ update(instrument); update_model++; + + // tab 1 eName.set_value(instrument->pInfo->Name); eIsDrum.set_value(instrument->IsDrum); eMIDIBank.set_value(instrument->MIDIBank); eMIDIProgram.set_value(instrument->MIDIProgram); + // tab 2 + eName2.set_value(instrument->pInfo->Name); + eCreationDate.set_value(instrument->pInfo->CreationDate); + eComments.set_value(instrument->pInfo->Comments); + eProduct.set_value(instrument->pInfo->Product); + eCopyright.set_value(instrument->pInfo->Copyright); + eArtists.set_value(instrument->pInfo->Artists); + eGenre.set_value(instrument->pInfo->Genre); + eKeywords.set_value(instrument->pInfo->Keywords); + eEngineer.set_value(instrument->pInfo->Engineer); + eTechnician.set_value(instrument->pInfo->Technician); + eSoftware.set_value(instrument->pInfo->Software); + eMedium.set_value(instrument->pInfo->Medium); + eSource.set_value(instrument->pInfo->Source); + eSourceForm.set_value(instrument->pInfo->SourceForm); + eCommissioned.set_value(instrument->pInfo->Commissioned); + eSubject.set_value(instrument->pInfo->Subject); + + update_model--; +} + + +SampleProps::SampleProps() : +#if HAS_GTKMM_STOCK + quitButton(Gtk::Stock::CLOSE), +#else + quitButton(_("_Close")), +#endif + table(2,1), + eName(_("Name")), + eUnityNote(_("Unity Note")), + eSampleGroup(_("Sample Group")), + eSampleFormatInfo(_("Sample Format")), + eSampleID("Sample ID"), + eChecksum("Wave Data CRC-32"), + eLoopsCount(_("Loops"), 0, 1), // we might support more than 1 loop in future + eLoopStart(_("Loop start position"), 0, 9999999), + eLoopLength(_("Loop size"), 0, 9999999), + eLoopType(_("Loop type")), + eLoopPlayCount(_("Playback count")), + table2(2,1), + eName2(_("Name")), + eCreationDate(_("Creation date")), + eComments(_("Comments")), + eProduct(_("Product")), + eCopyright(_("Copyright")), + eArtists(_("Artists")), + eGenre(_("Genre")), + eKeywords(_("Keywords")), + eEngineer(_("Engineer")), + eTechnician(_("Technician")), + eSoftware(_("Software")), + eMedium(_("Medium")), + eSource(_("Source")), + eSourceForm(_("Source form")), + eCommissioned(_("Commissioned")), + eSubject(_("Subject")) +{ + if (!Settings::singleton()->autoRestoreWindowDimension) { + //set_default_size(470, 390); + set_position(Gtk::WIN_POS_MOUSE); + } + + set_title(_("Sample Properties")); + + tabs.append_page(vbox[1], _("Settings")); + tabs.append_page(vbox[2], _("Info")); + + connect(eName, &SampleProps::set_Name); + connect(eUnityNote, &gig::Sample::MIDIUnityNote); + connect(eLoopsCount, &gig::Sample::Loops); + connectLambda(eLoopStart, [this](uint32_t start){ + m->LoopStart = start; + m->LoopEnd = start + m->LoopSize; + }); + connectLambda(eLoopLength, [this](uint32_t length){ + m->LoopSize = length; + m->LoopEnd = m->LoopStart + length; + }); + { + const char* choices[] = { _("normal"), _("bidirectional"), _("backward"), 0 }; + static const gig::loop_type_t values[] = { + gig::loop_type_normal, + gig::loop_type_bidirectional, + gig::loop_type_backward + }; + eLoopType.set_choices(choices, values); + } + connect(eLoopType, &gig::Sample::LoopType); + connect(eLoopPlayCount, &gig::Sample::LoopPlayCount); + + eName.signal_value_changed().connect(sig_name_changed.make_slot()); + + connect(eName2, &SampleProps::set_Name); + connectLambda(eCreationDate, [this](gig::String s) { + m->pInfo->CreationDate = s; + }); + connectLambda(eComments, [this](gig::String s) { + m->pInfo->Comments = s; + }); + connectLambda(eProduct, [this](gig::String s) { + m->pInfo->Product = s; + }); + connectLambda(eCopyright, [this](gig::String s) { + m->pInfo->Copyright = s; + }); + connectLambda(eArtists, [this](gig::String s) { + m->pInfo->Artists = s; + }); + connectLambda(eGenre, [this](gig::String s) { + m->pInfo->Genre = s; + }); + connectLambda(eKeywords, [this](gig::String s) { + m->pInfo->Keywords = s; + }); + connectLambda(eEngineer, [this](gig::String s) { + m->pInfo->Engineer = s; + }); + connectLambda(eTechnician, [this](gig::String s) { + m->pInfo->Technician = s; + }); + connectLambda(eSoftware, [this](gig::String s) { + m->pInfo->Software = s; + }); + connectLambda(eMedium, [this](gig::String s) { + m->pInfo->Medium = s; + }); + connectLambda(eSource, [this](gig::String s) { + m->pInfo->Source = s; + }); + connectLambda(eSourceForm, [this](gig::String s) { + m->pInfo->SourceForm = s; + }); + connectLambda(eCommissioned, [this](gig::String s) { + m->pInfo->Commissioned = s; + }); + connectLambda(eSubject, [this](gig::String s) { + m->pInfo->Subject = s; + }); + + // tab 1 +#if USE_GTKMM_GRID + table.set_column_spacing(5); +#else + table.set_col_spacings(5); +#endif + table.add(eName); + table.add(eUnityNote); + table.add(eSampleGroup); + table.add(eSampleFormatInfo); + table.add(eSampleID); + table.add(eChecksum); + table.add(eLoopsCount); + table.add(eLoopStart); + table.add(eLoopLength); + table.add(eLoopType); + table.add(eLoopPlayCount); + + // tab 2 +#if USE_GTKMM_GRID + table2.set_column_spacing(5); +#else + table2.set_col_spacings(5); +#endif + table2.add(eName2); + table2.add(eCreationDate); + table2.add(eComments); + table2.add(eProduct); + table2.add(eCopyright); + table2.add(eArtists); + table2.add(eGenre); + table2.add(eKeywords); + table2.add(eEngineer); + table2.add(eTechnician); + table2.add(eSoftware); + table2.add(eMedium); + table2.add(eSource); + table2.add(eSourceForm); + table2.add(eCommissioned); + table2.add(eSubject); + + add(vbox[0]); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + table.set_margin(5); +#else + table.set_border_width(5); +#endif + vbox[1].pack_start(table); + vbox[2].pack_start(table2); + table.show(); + table2.show(); + vbox[0].pack_start(tabs); + vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK); + buttonBox.set_layout(Gtk::BUTTONBOX_END); +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + buttonBox.set_margin(5); +#else + buttonBox.set_border_width(5); +#endif + buttonBox.show(); + buttonBox.pack_start(quitButton); + quitButton.set_can_default(); + quitButton.grab_focus(); + + quitButton.signal_clicked().connect( + sigc::mem_fun(*this, &SampleProps::hide)); + + quitButton.show(); + vbox[0].show(); +#if HAS_GTKMM_SHOW_ALL_CHILDREN + show_all_children(); +#endif +} + +void SampleProps::set_sample(gig::Sample* sample) +{ + update(sample); + + update_model++; + + // tab 1 + eName.set_value(sample->pInfo->Name); + eUnityNote.set_value(sample->MIDIUnityNote); + // show sample group name + { + Glib::ustring s = "---"; + if (sample && sample->GetGroup()) + s = sample->GetGroup()->Name; + eSampleGroup.text.set_text(s); + } + // assemble sample format info string + { + Glib::ustring s; + if (sample) { + switch (sample->Channels) { + case 1: s = _("Mono"); break; + case 2: s = _("Stereo"); break; + default: + s = ToString(sample->Channels) + _(" audio channels"); + break; + } + s += " " + ToString(sample->BitDepth) + " Bits"; + s += " " + ToString(sample->SamplesPerSecond/1000) + "." + + ToString((sample->SamplesPerSecond%1000)/100) + " kHz"; + } else { + s = _("No sample assigned to this dimension region."); + } + eSampleFormatInfo.text.set_text(s); + } + // generate sample's memory address pointer string + { + Glib::ustring s; + if (sample) { + char buf[64] = {}; + snprintf(buf, sizeof(buf), "%p", sample); + s = buf; + } else { + s = "---"; + } + eSampleID.text.set_text(s); + } + // generate raw wave form data CRC-32 checksum string + { + Glib::ustring s = "---"; + if (sample) { + char buf[64] = {}; + snprintf(buf, sizeof(buf), "%x", sample->GetWaveDataCRC32Checksum()); + s = buf; + } + eChecksum.text.set_text(s); + } + eLoopsCount.set_value(sample->Loops); + eLoopStart.set_value(sample->LoopStart); + eLoopLength.set_value(sample->LoopSize); + eLoopType.set_value(sample->LoopType); + eLoopPlayCount.set_value(sample->LoopPlayCount); + // tab 2 + eName2.set_value(sample->pInfo->Name); + eCreationDate.set_value(sample->pInfo->CreationDate); + eComments.set_value(sample->pInfo->Comments); + eProduct.set_value(sample->pInfo->Product); + eCopyright.set_value(sample->pInfo->Copyright); + eArtists.set_value(sample->pInfo->Artists); + eGenre.set_value(sample->pInfo->Genre); + eKeywords.set_value(sample->pInfo->Keywords); + eEngineer.set_value(sample->pInfo->Engineer); + eTechnician.set_value(sample->pInfo->Technician); + eSoftware.set_value(sample->pInfo->Software); + eMedium.set_value(sample->pInfo->Medium); + eSource.set_value(sample->pInfo->Source); + eSourceForm.set_value(sample->pInfo->SourceForm); + eCommissioned.set_value(sample->pInfo->Commissioned); + eSubject.set_value(sample->pInfo->Subject); + + update_model--; +} + +void SampleProps::set_Name(const gig::String& name) +{ + m->pInfo->Name = name; +} + +void SampleProps::update_name() +{ + update_model++; + eName.set_value(m->pInfo->Name); update_model--; } @@ -2187,6 +3403,55 @@ } } +bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr& tooltip) { + Gtk::TreeModel::iterator iter; + if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) { + return false; + } + Gtk::TreeModel::Path path(iter); + Gtk::TreeModel::Row row = *iter; + Gtk::TreeViewColumn* pointedColumn = NULL; + // resolve the precise table column the mouse points to + { + Gtk::TreeModel::Path path; // unused + int cellX, cellY; // unused + m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY); + } + Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2); + if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ... + // show the script(s) assigned to the hovered instrument as tooltip + tooltip->set_markup( row[m_Columns.m_col_tooltip] ); + m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL); + } else { + // if beginners' tooltips is disabled then don't show the following one + if (!Settings::singleton()->showTooltips) + return false; + // yeah, a beginners tooltip + tooltip->set_text(_( + "Right click here for actions on instruments & MIDI Rules. " + "Drag & drop to change the order of instruments." + )); + m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL); + } + return true; +} + +static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) { + Glib::ustring name(gig_to_utf8(instrument->pInfo->Name)); + const int iScriptSlots = instrument->ScriptSlotCount(); + Glib::ustring tooltip = "(" + ToString(index) + ") “" + name + "”\n\n"; + if (!iScriptSlots) + tooltip += "No script assigned"; + else { + for (int i = 0; i < iScriptSlots; ++i) { + tooltip += "• " + ToString(i+1) + ". Script: “" + + instrument->GetScriptOfSlot(i)->Name + "”"; + if (i + 1 < iScriptSlots) tooltip += "\n\n"; + } + } + return tooltip; +} + void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) { file = 0; @@ -2200,8 +3465,7 @@ file_has_name = filename; file_is_changed = false; - propDialog.set_file(gig); - propDialog.set_info(gig->pInfo); + fileProps.set_file(gig); instrument_name_connection.block(); int index = 0; @@ -2216,11 +3480,16 @@ row[m_Columns.m_col_name] = name; row[m_Columns.m_col_instr] = instrument; row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : ""; + row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index); +#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); @@ -2291,7 +3560,8 @@ instrumentProps.hide(); return false; } - Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]); + //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]; @@ -2308,7 +3578,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() @@ -2327,7 +3598,64 @@ gig::Instrument* instrument = row[m_Columns.m_col_instr]; Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name)); if (gigname != name) { + Gtk::TreeModel::Path path(*it); + const int index = path[0]; row[m_Columns.m_col_name] = gigname; + row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index); + } +} + +bool MainWindow::sample_props_set_sample() +{ + sampleProps.signal_name_changed().clear(); + + std::vector rows = m_TreeViewSamples.get_selection()->get_selected_rows(); + if (rows.empty()) { + sampleProps.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_refSamplesTreeModel->get_iter(rows[0]); + if (it) { + Gtk::TreeModel::Row row = *it; + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + + sampleProps.set_sample(sample); + + // make sure sample tree is updated when user changes the + // sample name in sample properties window + sampleProps.signal_name_changed().connect( + sigc::bind( + sigc::mem_fun(*this, + &MainWindow::sample_name_changed_by_sample_props + ), it + ) + ); + } else { + sampleProps.hide(); + } + //NOTE: explicit boolean cast required for GTKMM4 development branch here + return it ? true : false; +} + +void MainWindow::show_sample_props() +{ + if (sample_props_set_sample()) { + sampleProps.show(); + sampleProps.deiconify(); + } +} + +void MainWindow::sample_name_changed_by_sample_props(Gtk::TreeModel::iterator& it) +{ + Gtk::TreeModel::Row row = *it; + Glib::ustring name = row[m_SamplesModel.m_col_name]; + + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + Glib::ustring gigname(gig_to_utf8(sample->pInfo->Name)); + if (gigname != name) { + Gtk::TreeModel::Path path(*it); + row[m_SamplesModel.m_col_name] = gigname; } } @@ -2373,6 +3701,7 @@ 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) : ""; + row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i); break; } @@ -2398,11 +3727,36 @@ onScriptSlotsModified(pInstrument); } +void MainWindow::dropAllScriptSlots() { + gig::Instrument* pInstrument = get_instrument(); + if (!pInstrument) { + printf("!instrument\n"); + return; + } + + const int iScriptSlots = pInstrument->ScriptSlotCount(); + for (int i = iScriptSlots - 1; i >= 0; --i) + pInstrument->RemoveScriptSlot(i); + + 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) { @@ -2411,9 +3765,18 @@ } 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) { @@ -2421,9 +3784,37 @@ return; } Settings::singleton()->autoRestoreWindowDimension = item->get_active(); +#endif +} + +void MainWindow::on_instr_double_click_opens_props() { +#if USE_GLIB_ACTION + bool active = false; + m_actionInstrDoubleClickOpensProps->get_state(active); + // for some reason toggle state does not change automatically + active = !active; + m_actionInstrDoubleClickOpensProps->change_state(active); + Settings::singleton()->instrumentDoubleClickOpensProps = active; +#else + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick")); + if (!item) { + std::cerr << "/MenuBar/MenuView/OpenInstrPropsByDoubleClick == NULL\n"; + return; + } + Settings::singleton()->instrumentDoubleClickOpensProps = 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) { @@ -2431,9 +3822,15 @@ 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) { @@ -2441,9 +3838,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) { @@ -2451,9 +3854,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) { @@ -2461,15 +3870,24 @@ 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(); + if (Settings::singleton()->instrumentDoubleClickOpensProps) + 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 @@ -2478,10 +3896,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 = @@ -2496,6 +3919,7 @@ } } } +#endif void MainWindow::select_instrument(gig::Instrument* instrument) { if (!instrument) return; @@ -2510,7 +3934,13 @@ // 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 > 24) + 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()) @@ -2535,7 +3965,12 @@ // 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 > 24) + 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()) @@ -2566,7 +4001,12 @@ 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 > 24) + auto iterSel = rowGroup.children()[s].get_iter(); + m_TreeViewSamples.get_selection()->select(iterSel); +#else m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]); +#endif std::vector rows = m_TreeViewSamples.get_selection()->get_selected_rows(); if (rows.empty()) return; @@ -2577,7 +4017,12 @@ } } +#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 @@ -2598,8 +4043,11 @@ } }*/ +#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(); std::vector rows = sel->get_selected_rows(); @@ -2614,6 +4062,14 @@ 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(n == 1); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> @@ -2624,9 +4080,11 @@ set_sensitive(nSamples == 1); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> 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(n == 1); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> @@ -2637,13 +4095,25 @@ set_sensitive(nSamples == 1); dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> 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(); @@ -2654,6 +4124,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"))-> @@ -2662,9 +4138,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"))-> @@ -2673,7 +4151,11 @@ 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() { @@ -2719,9 +4201,24 @@ assign_scripts_menu->append(*item); } + // add separator line to menu + assign_scripts_menu->append(*new Gtk::SeparatorMenuItem); + + { + Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts")); + item->signal_activate().connect( + sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots) + ); + assign_scripts_menu->append(*item); + item->set_accel_path("/DropAllScriptSlots"); + } + +#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) { @@ -2745,7 +4242,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(); @@ -2753,6 +4252,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)); @@ -2761,13 +4261,17 @@ 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; + const int index = m_refTreeModel->children().size() - 1; + rowInstr[m_Columns.m_col_nr] = index; rowInstr[m_Columns.m_col_name] = name; rowInstr[m_Columns.m_col_instr] = instrument; rowInstr[m_Columns.m_col_scripts] = ""; + rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index); instrument_name_connection.unblock(); +#if !USE_GTKMM_BUILDER add_instrument_to_menu(name); +#endif select_instrument(instrument); file_changed(); } @@ -2836,7 +4340,9 @@ 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); @@ -2847,7 +4353,9 @@ it != m_refTreeModel->children().end(); ++it, ++index) { Gtk::TreeModel::Row row = *it; + gig::Instrument* instrument = row[m_Columns.m_col_instr]; row[m_Columns.m_col_nr] = index; + row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index); } } @@ -2877,11 +4385,7 @@ } void MainWindow::on_action_sample_properties() { - //TODO: show a dialog where the selected sample's properties can be edited - Gtk::MessageDialog msg( - *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO - ); - msg.run(); + show_sample_props(); } void MainWindow::on_action_add_script_group() { @@ -3051,8 +4555,13 @@ // show 'browse for file' dialog 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); +#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 @@ -3095,13 +4604,14 @@ dialog.set_current_folder(current_sample_dir); } if (dialog.run() == Gtk::RESPONSE_OK) { + dialog.hide(); current_sample_dir = dialog.get_current_folder(); Glib::ustring error_files; std::vector filenames = dialog.get_filenames(); for (std::vector::iterator iter = filenames.begin(); iter != filenames.end(); ++iter) { printf("Adding sample %s\n",(*iter).c_str()); - // use libsndfile to retrieve file informations + // use libsndfile to retrieve file information SF_INFO info; info.format = 0; SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info); @@ -3242,17 +4752,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 != "") { @@ -3260,6 +4785,7 @@ } if (dialog.run() == Gtk::RESPONSE_OK) { + dialog.hide(); current_sample_dir = dialog.get_current_folder(); Glib::ustring error_files; std::string folder = dialog.get_filename(); @@ -3658,6 +5184,10 @@ file_changed(); } } + // change name in the sample properties window + if (sampleProps.get_sample() == sample && sample) { + sampleProps.set_sample(sample); + } } void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path, @@ -3710,6 +5240,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(); @@ -3722,6 +5253,7 @@ item->set_active(); #endif } +#endif // change name in gig gig::Instrument* instrument = row[m_Columns.m_col_instr]; @@ -3746,7 +5278,12 @@ trim(pattern); if (pattern.empty()) return true; +#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24) + //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(); @@ -3778,7 +5315,11 @@ } d->setSelectedInstruments(indeces); +#if HAS_GTKMM_SHOW_ALL_CHILDREN d->show_all(); +#else + d->show(); +#endif d->run(); if (d->fileWasChanged()) { // update GUI with new instrument just created @@ -3802,7 +5343,11 @@ 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; @@ -3886,7 +5431,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)); @@ -3913,7 +5462,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 @@ -3930,7 +5483,7 @@ dialog.set_select_multiple(true); // show warning in the file picker dialog - Gtk::HBox descriptionArea; + HBox descriptionArea; descriptionArea.set_spacing(15); Gtk::Image warningIcon; warningIcon.set_from_icon_name("dialog-warning", @@ -3953,12 +5506,26 @@ "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) { + dialog.hide(); +#ifdef GLIB_THREADS printf("on_action_merge_files self=%p\n", static_cast(Glib::Threads::Thread::self())); +#else + std::cout << "on_action_merge_files self=" << + std::this_thread::get_id() << "\n"; +#endif std::vector filenames = dialog.get_filenames(); // merge the selected files to the currently open .gig file @@ -3990,9 +5557,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 } } @@ -4149,12 +5720,20 @@ 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(); } @@ -4221,6 +5800,10 @@ 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); @@ -4228,6 +5811,7 @@ static_cast( uiManager->get_widget("/MenuBar/MenuEdit/AdjustClipboard") )->set_sensitive(bDimensionRegionPasteIsPossible); +#endif } sigc::signal& MainWindow::signal_file_structure_to_be_changed() {