Drop references held by any GUI Lua script after execution
[ardour.git] / gtk2_ardour / editor_regions.h
index f899b00c550f5d3d52cabf151d4f2acc5bb035ca..5e39fc831437d849cf6e4fd999194d88d12849d3 100644 (file)
@@ -1,24 +1,33 @@
 /*
-    Copyright (C) 2000-2009 Paul Davis
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
+ * Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #ifndef __gtk_ardour_editor_regions_h__
 #define __gtk_ardour_editor_regions_h__
 
+#include <boost/unordered_map.hpp>
+
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/treemodel.h>
+#include <gtkmm/treerowreference.h>
+#include <gtkmm/treestore.h>
+
 #include "editor_component.h"
 
 class EditorRegions : public EditorComponent, public ARDOUR::SessionHandlePtr
@@ -34,22 +43,18 @@ public:
 
        void clear ();
 
-       void toggle_full ();
-       void toggle_show_auto_regions ();
-       void reset_sort_direction (bool);
-       void reset_sort_type (Editing::RegionListSortType, bool);
        void set_selected (RegionSelection &);
        void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
+
        boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
        boost::shared_ptr<ARDOUR::Region> get_single_selection ();
-       Editing::RegionListSortType sort_type () const {
-               return _sort_type;
-       }
+
        void redisplay ();
 
        void suspend_redisplay () {
                _no_redisplay = true;
        }
+
        void resume_redisplay () {
                _no_redisplay = false;
                redisplay ();
@@ -63,6 +68,8 @@ public:
                _display.get_selection()->unselect_all ();
        }
 
+       void remove_unused_regions ();
+
        XMLNode& get_state () const;
        void set_state (const XMLNode &);
 
@@ -71,11 +78,10 @@ private:
        struct Columns : public Gtk::TreeModel::ColumnRecord {
                Columns () {
                        add (name);
-                       add (region);
-                       add (color_);
-                       add (position);
-                       add (end);
+                       add (tags);
+                       add (start);
                        add (length);
+                       add (end);
                        add (sync);
                        add (fadein);
                        add (fadeout);
@@ -83,15 +89,16 @@ private:
                        add (glued);
                        add (muted);
                        add (opaque);
-                       add (used);
                        add (path);
-                       add (property_toggles_visible);
+                       add (region);
+                       add (color_);
+                       add (position);
                }
 
                Gtk::TreeModelColumn<std::string> name;
-               Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
-               Gtk::TreeModelColumn<Gdk::Color> color_;
-               Gtk::TreeModelColumn<std::string> position;
+               Gtk::TreeModelColumn<std::string> tags;
+               Gtk::TreeModelColumn<samplepos_t> position;
+               Gtk::TreeModelColumn<std::string> start;
                Gtk::TreeModelColumn<std::string> end;
                Gtk::TreeModelColumn<std::string> length;
                Gtk::TreeModelColumn<std::string> sync;
@@ -101,20 +108,36 @@ private:
                Gtk::TreeModelColumn<bool> glued;
                Gtk::TreeModelColumn<bool> muted;
                Gtk::TreeModelColumn<bool> opaque;
-               Gtk::TreeModelColumn<std::string> used;
                Gtk::TreeModelColumn<std::string> path;
-               /** used to indicate whether the locked/glued/muted/opaque should be visible or not */
-               Gtk::TreeModelColumn<bool> property_toggles_visible;
+               Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
+               Gtk::TreeModelColumn<Gdk::Color> color_;
        };
 
        Columns _columns;
 
+       Gtk::TreeModel::RowReference last_row;
+
+       void freeze_tree_model ();
+       void thaw_tree_model ();
        void region_changed (boost::shared_ptr<ARDOUR::Region>, PBD::PropertyChange const &);
        void selection_changed ();
+
        sigc::connection _change_connection;
-       bool set_selected_in_subrow (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, int);
+
        bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
+
+       Gtk::Widget* old_focus;
+
+       Gtk::CellEditable* name_editable;
+       void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
        void name_edit (const std::string&, const std::string&);
+
+
+       Gtk::CellEditable* tags_editable;
+       void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
+       void tag_edit (const std::string&, const std::string&);
+
+
        void locked_changed (std::string const &);
        void glued_changed (std::string const &);
        void muted_changed (std::string const &);
@@ -122,61 +145,63 @@ private:
 
        bool key_press (GdkEventKey *);
        bool button_press (GdkEventButton *);
-       void show_context_menu (int button, int time);
 
-       int sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
+       bool focus_in (GdkEventFocus*);
+       bool focus_out (GdkEventFocus*);
+       bool enter_notify (GdkEventCrossing*);
+       bool leave_notify (GdkEventCrossing*);
 
-        void format_position (ARDOUR::framepos_t pos, char* buf, size_t bufsize);
+       void show_context_menu (int button, int time);
+
+       void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
 
        void add_region (boost::shared_ptr<ARDOUR::Region>);
-       void add_regions (std::vector<boost::shared_ptr<ARDOUR::Region> > & );
-       void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &);
-        void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used, boost::shared_ptr<ARDOUR::AudioRegion>);
-        void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used, boost::shared_ptr<ARDOUR::AudioRegion>);
-        void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
-        void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
-        void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
-        void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void destroy_region (boost::shared_ptr<ARDOUR::Region>);
+
+       void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
+       void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
+       void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
+       void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
+       void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
 
        void update_row (boost::shared_ptr<ARDOUR::Region>);
-       bool update_subrows (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, int);
-       void update_all_rows ();
-       void update_all_subrows (Gtk::TreeModel::Row const &, int);
-       void insert_into_tmp_regionlist (boost::shared_ptr<ARDOUR::Region>);
+
+       void clock_format_changed ();
 
        void drag_data_received (
                Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
                );
 
-       Glib::RefPtr<Gtk::RadioAction> sort_type_action (Editing::RegionListSortType) const;
-       void set_full (bool);
+       Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
 
-       Glib::RefPtr<Gtk::Action> hide_action () const;
-       Glib::RefPtr<Gtk::Action> show_action () const;
-       Glib::RefPtr<Gtk::ToggleAction> toggle_full_action () const;
-       Glib::RefPtr<Gtk::ToggleAction> toggle_show_auto_regions_action () const;
-       
        Gtk::Menu* _menu;
        Gtk::ScrolledWindow _scroller;
        Gtk::Frame _frame;
+
        Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
+
        Glib::RefPtr<Gtk::TreeStore> _model;
-       bool _show_automatic_regions;
-       Editing::RegionListSortType _sort_type;
+
        bool _no_redisplay;
-       std::list<boost::shared_ptr<ARDOUR::Region> > tmp_region_list;
+
+       typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
+
+       RegionRowMap region_row_map;
+
        PBD::ScopedConnection region_property_connection;
        PBD::ScopedConnection check_new_region_connection;
-       bool ignore_region_list_selection_change;
-       bool ignore_selected_region_change;
-        bool expanded;
+
+       PBD::ScopedConnection editor_freeze_connection;
+       PBD::ScopedConnection editor_thaw_connection;
 };
 
 #endif /* __gtk_ardour_editor_regions_h__ */