--- gigedit/trunk/src/gigedit/mainwindow.h 2014/06/08 19:09:26 2610 +++ gigedit/trunk/src/gigedit/mainwindow.h 2018/02/10 11:36:16 3418 @@ -1,5 +1,5 @@ /* -*- c++ -*- - * Copyright (C) 2006 - 2014 Andreas Persson + * Copyright (C) 2006 - 2017 Andreas Persson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,9 +20,17 @@ #ifndef GIGEDIT_MAINWINDOW_H #define GIGEDIT_MAINWINDOW_H -#include +#ifdef LIBGIG_HEADER_FILE +# include LIBGIG_HEADER_FILE(gig.h) +# include LIBGIG_HEADER_FILE(Serialization.h) +#else +# include +# include +#endif + +#include "compat.h" -#include +#include #include #include #include @@ -32,10 +40,18 @@ #include #include #include -#include +#include #include #include #include +#include +#include + +#if USE_GTKMM_BUILDER +# include +#else +# include // deprecated in gtkmm >= 3.21.4 +#endif #include @@ -46,15 +62,23 @@ #ifndef OLD_THREADS #include #endif +#include "ManagedWindow.h" class MainWindow; -class PropDialog : public Gtk::Window, +class PropDialog : public ManagedWindow, public PropEditor { public: PropDialog(); void set_info(DLS::Info* info); void set_file(gig::File* file); + + // implementation for abstract methods of interface class "ManagedWindow" + virtual Settings::Property* windowSettingX() { return &Settings::singleton()->filePropsWindowX; } + virtual Settings::Property* windowSettingY() { return &Settings::singleton()->filePropsWindowY; } + virtual Settings::Property* windowSettingWidth() { return &Settings::singleton()->filePropsWindowW; } + virtual Settings::Property* windowSettingHeight() { return &Settings::singleton()->filePropsWindowH; } + protected: ChoiceEntry eFileFormat; StringEntry eName; @@ -73,8 +97,8 @@ StringEntry eSourceForm; StringEntry eCommissioned; StringEntry eSubject; - Gtk::VBox vbox; - Gtk::HButtonBox buttonBox; + VBox vbox; + HButtonBox buttonBox; Gtk::Button quitButton; Table table; @@ -83,7 +107,7 @@ void onFileFormatChanged(); }; -class InstrumentProps : public Gtk::Window, +class InstrumentProps : public ManagedWindow, public PropEditor { public: InstrumentProps(); @@ -93,6 +117,13 @@ sigc::signal& signal_name_changed() { return sig_name_changed; } + + // implementation for abstract methods of interface class "ManagedWindow" + virtual Settings::Property* windowSettingX() { return &Settings::singleton()->instrPropsWindowX; } + virtual Settings::Property* windowSettingY() { return &Settings::singleton()->instrPropsWindowY; } + virtual Settings::Property* windowSettingWidth() { return &Settings::singleton()->instrPropsWindowW; } + virtual Settings::Property* windowSettingHeight() { return &Settings::singleton()->instrPropsWindowH; } + protected: void set_Name(const gig::String& name); void set_IsDrum(bool value); @@ -100,8 +131,8 @@ void set_MIDIProgram(uint32_t value); sigc::signal sig_name_changed; - Gtk::VBox vbox; - Gtk::HButtonBox buttonBox; + VBox vbox; + HButtonBox buttonBox; Gtk::Button quitButton; Table table; StringEntry eName; @@ -118,9 +149,9 @@ NoteEntry eDimensionKeyRangeHigh; }; -class LoadDialog : public Gtk::Dialog { +class ProgressDialog : public Gtk::Dialog { public: - LoadDialog(const Glib::ustring& title, Gtk::Window& parent); + ProgressDialog(const Glib::ustring& title, Gtk::Window& parent); void set_fraction(float fraction) { progressBar.set_fraction(fraction); } protected: Gtk::ProgressBar progressBar; @@ -131,22 +162,48 @@ Loader(const char* filename); void launch(); Glib::Dispatcher& signal_progress(); - Glib::Dispatcher& signal_finished(); + Glib::Dispatcher& signal_finished(); ///< Finished successfully, without error. + Glib::Dispatcher& signal_error(); + void progress_callback(float fraction); + float get_progress(); + const Glib::ustring filename; + Glib::ustring error_message; + gig::File* gig; + +private: + Glib::Threads::Thread* thread; + void thread_function(); + Glib::Dispatcher finished_dispatcher; + Glib::Dispatcher progress_dispatcher; + Glib::Dispatcher error_dispatcher; + Glib::Threads::Mutex progressMutex; + float progress; +}; + +class Saver : public sigc::trackable { +public: + Saver(gig::File* file, Glib::ustring filename = ""); ///< one argument means "save", two arguments means "save as" + void launch(); + Glib::Dispatcher& signal_progress(); + Glib::Dispatcher& signal_finished(); ///< Finished successfully, without error. + Glib::Dispatcher& signal_error(); void progress_callback(float fraction); float get_progress(); - const char* filename; gig::File* gig; + const Glib::ustring filename; + Glib::ustring error_message; private: Glib::Threads::Thread* thread; void thread_function(); Glib::Dispatcher finished_dispatcher; Glib::Dispatcher progress_dispatcher; + Glib::Dispatcher error_dispatcher; Glib::Threads::Mutex progressMutex; float progress; }; -class MainWindow : public Gtk::Window { +class MainWindow : public ManagedWindow { public: MainWindow(); virtual ~MainWindow(); @@ -170,9 +227,56 @@ sigc::signal& signal_keyboard_key_hit(); sigc::signal& signal_keyboard_key_released(); + sigc::signal& signal_switch_sampler_instrument(); + + sigc::signal signal_script_to_be_changed; + sigc::signal signal_script_changed; + + // implementation for abstract methods of interface class "ManagedWindow" + virtual Settings::Property* windowSettingX() { return &Settings::singleton()->mainWindowX; } + virtual Settings::Property* windowSettingY() { return &Settings::singleton()->mainWindowY; } + virtual Settings::Property* windowSettingWidth() { return &Settings::singleton()->mainWindowW; } + virtual Settings::Property* windowSettingHeight() { return &Settings::singleton()->mainWindowH; } + protected: +#if USE_GTKMM_BUILDER + Glib::RefPtr m_actionGroup; + Glib::RefPtr m_uiManager; +#else Glib::RefPtr actionGroup; Glib::RefPtr uiManager; +#endif + +#if USE_GLIB_ACTION + Glib::RefPtr m_actionMIDIRules; + + Glib::RefPtr m_actionCopyDimRgn; + Glib::RefPtr m_actionPasteDimRgn; + Glib::RefPtr m_actionAdjustClipboard; + + Glib::RefPtr m_actionSampleProperties; + Glib::RefPtr m_actionAddSample; + Glib::RefPtr m_actionRemoveSample; + Glib::RefPtr m_actionViewSampleRefs; + Glib::RefPtr m_actionReplaceSample; + Glib::RefPtr m_actionAddSampleGroup; + + Glib::RefPtr m_actionAddScriptGroup; + Glib::RefPtr m_actionAddScript; + Glib::RefPtr m_actionEditScript; + Glib::RefPtr m_actionRemoveScript; + + Glib::RefPtr m_actionToggleCopySampleUnity; + Glib::RefPtr m_actionToggleCopySampleTune; + Glib::RefPtr m_actionToggleCopySampleLoop; + Glib::RefPtr m_actionToggleStatusBar; + Glib::RefPtr m_actionToggleRestoreWinDim; + Glib::RefPtr m_actionToggleSaveWithTempFile; + Glib::RefPtr m_actionToggleWarnOnExtensions; + Glib::RefPtr m_actionToggleShowTooltips; + Glib::RefPtr m_actionToggleSyncSamplerSelection; + Glib::RefPtr m_actionToggleMoveRootNoteWithRegion; +#endif Gtk::Statusbar m_StatusBar; Gtk::Label m_AttachedStateLabel; @@ -185,6 +289,19 @@ InstrumentProps instrumentProps; MidiRules midiRules; + /** + * Ensures that the 2 signals MainWindow::dimreg_to_be_changed_signal and + * MainWindowv::dimreg_changed_signal are always triggered correctly as a + * pair. It behaves similar to a "mutex lock guard" design pattern. + */ + class DimRegionChangeGuard : public SignalGuard { + public: + DimRegionChangeGuard(MainWindow* w, gig::DimensionRegion* pDimReg) : + SignalGuard(w->dimreg_to_be_changed_signal, w->dimreg_changed_signal, pDimReg) + { + } + }; + sigc::signal file_structure_to_be_changed_signal; sigc::signal file_structure_changed_signal; sigc::signal > samples_to_be_removed_signal; @@ -199,12 +316,31 @@ sigc::signal note_on_signal; sigc::signal note_off_signal; + sigc::signal switch_sampler_instrument_signal; + +#if !USE_GTKMM_BUILDER void on_instrument_selection_change(Gtk::RadioMenuItem* item); +#endif void on_sel_change(); void region_changed(); void dimreg_changed(); + void select_instrument(gig::Instrument* instrument); + bool select_dimension_region(gig::DimensionRegion* dimRgn); + void select_sample(gig::Sample* sample); void on_loader_progress(); void on_loader_finished(); + void on_loader_error(); + void on_saver_progress(); + void on_saver_error(); + void on_saver_finished(); + void updateMacroMenu(); + void onMacroSelected(int iMacro); + void setupMacros(); + void onMacrosSetupChanged(const std::vector& macros); + void applyMacro(Serialization::Archive& macro); + void onScriptSlotsModified(gig::Instrument* pInstrument); + void bringToFront(); + void dimreg_all_dimregs_toggled(); gig::Instrument* get_instrument(); void add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs); @@ -213,23 +349,37 @@ class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns() { + add(m_col_nr); add(m_col_name); add(m_col_instr); + add(m_col_scripts); + add(m_col_tooltip); } + Gtk::TreeModelColumn m_col_nr; Gtk::TreeModelColumn m_col_name; Gtk::TreeModelColumn m_col_instr; + Gtk::TreeModelColumn m_col_scripts; + Gtk::TreeModelColumn m_col_tooltip; } m_Columns; - Gtk::VBox m_VBox; + VBox m_VBox; Gtk::HPaned m_HPaned; Gtk::ScrolledWindow m_ScrolledWindow; Gtk::TreeView m_TreeView; Glib::RefPtr m_refTreeModel; + Glib::RefPtr m_refTreeModelFilter; //FIXME: I really would love to get rid of TreeModelFilter, because it causes behavior conflicts with get_model() all over the place (see the respective comments regarding get_model()), however I found no other way to filter a treeview effectively. + +#if USE_GTKMM_BUILDER + Gtk::Menu* menuMacro; +#else + Gtk::Menu* instrument_menu; // kept for GTKMM 2 version only, will be completely removed in future +#endif + Gtk::Menu* assign_scripts_menu; - Gtk::Menu* instrument_menu; + std::map sample_ref_count; class SamplesModel : public Gtk::TreeModel::ColumnRecord { public: @@ -237,11 +387,15 @@ add(m_col_name); add(m_col_sample); add(m_col_group); + add(m_col_refcount); + add(m_color); } Gtk::TreeModelColumn m_col_name; Gtk::TreeModelColumn m_col_sample; Gtk::TreeModelColumn m_col_group; + Gtk::TreeModelColumn m_col_refcount; + Gtk::TreeModelColumn m_color; } m_SamplesModel; class SamplesTreeStore : public Gtk::TreeStore { @@ -283,15 +437,30 @@ Gtk::TreeView m_TreeViewScripts; Glib::RefPtr m_refScriptsTreeModel; - Gtk::VBox dimreg_vbox; - Gtk::HBox dimreg_hbox; + VBox dimreg_vbox; + HBox dimreg_hbox; Gtk::Label dimreg_label; Gtk::CheckButton dimreg_all_regions; Gtk::CheckButton dimreg_all_dimregs; Gtk::CheckButton dimreg_stereo; + + HBox legend_hbox; + Gtk::Label labelLegend; + Gtk::Image imageNoSample; + Gtk::Label labelNoSample; + Gtk::Image imageMissingSample; + Gtk::Label labelMissingSample; + Gtk::Image imageLooped; + Gtk::Label labelLooped; + Gtk::Image imageSomeLoops; + Gtk::Label labelSomeLoops; DimRegionEdit dimreg_edit; + VBox m_left_vbox; Gtk::Notebook m_TreeViewNotebook; + HBox m_searchField; + Gtk::Label m_searchLabel; + Gtk::Entry m_searchText; struct SampleImportItem { gig::Sample* gig_sample; // pointer to the gig::Sample to @@ -300,7 +469,7 @@ Glib::ustring sample_path; // file name of the sample to be // imported }; - std::list m_SampleImportQueue; + std::map m_SampleImportQueue; void on_action_file_new(); @@ -314,19 +483,38 @@ void show_midi_rules(); void show_script_slots(); void on_action_view_status_bar(); + void on_auto_restore_win_dim(); + void on_save_with_temporary_file(); + void on_action_refresh_all(); void on_action_warn_user_on_extensions(); + void on_action_show_tooltips(); + void on_show_tooltips_changed(); + void on_action_sync_sampler_instrument_selection(); + void on_action_move_root_note_with_region_moved(); void on_action_help_about(); + void on_notebook_tab_switched(void* page, guint page_num); + // sample right-click popup actions +#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 on_sample_treeview_button_release(Gdk::EventButton& button); +#else void on_sample_treeview_button_release(GdkEventButton* button); +#endif void on_action_sample_properties(); void on_action_add_group(); void on_action_add_sample(); + void on_action_replace_sample(); void on_action_replace_all_samples_in_all_groups(); void on_action_remove_sample(); - + void on_action_remove_unused_samples(); + // script right-click popup actions +#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 on_script_treeview_button_release(Gdk::EventButton& button); +#else void on_script_treeview_button_release(GdkEventButton* button); +#endif void on_action_add_script_group(); void on_action_add_script(); void on_action_edit_script(); @@ -336,14 +524,55 @@ void on_action_duplicate_instrument(); void on_action_remove_instrument(); + void show_samples_tab(); + void show_intruments_tab(); + void show_scripts_tab(); + + void select_prev_instrument(); + void select_next_instrument(); + void select_instrument_by_dir(int dir); + + void select_prev_region(); + void select_next_region(); + + void select_next_dim_rgn_zone(); + void select_prev_dim_rgn_zone(); + void select_add_next_dim_rgn_zone(); + void select_add_prev_dim_rgn_zone(); + void select_prev_dimension(); + void select_next_dimension(); + + Serialization::Archive m_serializationArchive; ///< Clipboard content. + std::vector m_macros; ///< User configured list of macros. + + void copy_selected_dimrgn(); + void paste_copied_dimrgn(); + void adjust_clipboard_content(); + void updateClipboardCopyAvailable(); + void updateClipboardPasteAvailable(); +#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 on_clipboard_owner_change(Gdk::EventOwnerChange& event); +#else + void on_clipboard_owner_change(GdkEventOwnerChange* event); +#endif + void on_clipboard_get(Gtk::SelectionData& selection_data, guint info); + void on_clipboard_clear(); + void on_clipboard_received(const Gtk::SelectionData& selection_data); + void on_clipboard_received_targets(const std::vector& targets); + void add_instrument(gig::Instrument* instrument); +#if !USE_GTKMM_BUILDER Gtk::RadioMenuItem* add_instrument_to_menu(const Glib::ustring& name, int position = -1); void remove_instrument_from_menu(int index); +#endif + bool onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr& tooltip); - LoadDialog* load_dialog; + ProgressDialog* progress_dialog; Loader* loader; + Saver* saver; void load_gig(gig::File* gig, const char* filename, bool isSharedInstrument = false); + void updateSampleRefCountMap(gig::File* gig); gig::File* file; bool file_is_shared; @@ -359,7 +588,18 @@ bool file_save_as(); bool check_if_savable(); +#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 on_button_release(Gdk::EventButton& button); +#else void on_button_release(GdkEventButton* button); +#endif + void on_instruments_treeview_drag_begin(const Glib::RefPtr& context); + void on_instruments_treeview_drag_data_get(const Glib::RefPtr&, + Gtk::SelectionData& selection_data, guint, guint); + void on_instruments_treeview_drop_drag_data_received( + const Glib::RefPtr& context, int, int, + const Gtk::SelectionData& selection_data, guint, guint time + ); void on_scripts_treeview_drag_begin(const Glib::RefPtr& context); void on_scripts_treeview_drag_data_get(const Glib::RefPtr&, Gtk::SelectionData& selection_data, guint, guint); @@ -373,25 +613,40 @@ void script_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter); + void script_double_clicked(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void sample_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter); void instrument_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter); void instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it); + bool instrument_row_visible(const Gtk::TreeModel::const_iterator& iter); sigc::connection instrument_name_connection; void on_action_combine_instruments(); + void on_action_view_references(); void on_action_merge_files(); void mergeFiles(const std::vector& filenames); + void on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample); + void on_sample_ref_count_incremented(gig::Sample* sample, int offset); + void on_samples_to_be_removed(std::list samples); + + void add_or_replace_sample(bool replace); + void __import_queued_samples(); void __clear(); void __refreshEntireGUI(); + void updateScriptListOfMenu(); + void assignScript(gig::Script* pScript); bool close_confirmation_dialog(); bool leaving_shared_mode_dialog(); Gtk::Menu* popup_menu; +#if USE_GTKMM_BUILDER + Gtk::Menu* sample_popup; + Gtk::Menu* script_popup; +#endif bool on_delete_event(GdkEventAny* event);