DSP-Load Window: subscribe to newly added routes
[ardour.git] / gtk2_ardour / editor_regions.h
1 /*
2     Copyright (C) 2000-2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19 #ifndef __gtk_ardour_editor_regions_h__
20 #define __gtk_ardour_editor_regions_h__
21
22 #include <boost/unordered_map.hpp>
23
24 #include <gtkmm/scrolledwindow.h>
25 #include <gtkmm/treemodel.h>
26 #include <gtkmm/treerowreference.h>
27 #include <gtkmm/treestore.h>
28
29 #include "editor_component.h"
30
31 class EditorRegions : public EditorComponent, public ARDOUR::SessionHandlePtr
32 {
33 public:
34         EditorRegions (Editor *);
35
36         void set_session (ARDOUR::Session *);
37
38         Gtk::Widget& widget () {
39                 return _scroller;
40         }
41
42         void clear ();
43
44         void toggle_full ();
45         void toggle_show_auto_regions ();
46         void reset_sort_direction (bool);
47         void reset_sort_type (Editing::RegionListSortType, bool);
48         void set_selected (RegionSelection &);
49         void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
50
51         boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
52         boost::shared_ptr<ARDOUR::Region> get_single_selection ();
53
54         Editing::RegionListSortType sort_type () const {
55                 return _sort_type;
56         }
57
58         void redisplay ();
59
60         void suspend_redisplay () {
61                 _no_redisplay = true;
62         }
63
64         void resume_redisplay () {
65                 _no_redisplay = false;
66                 redisplay ();
67         }
68
69         void block_change_connection (bool b) {
70                 _change_connection.block (b);
71         }
72
73         void unselect_all () {
74                 _display.get_selection()->unselect_all ();
75         }
76
77         void remove_unused_regions ();
78
79         XMLNode& get_state () const;
80         void set_state (const XMLNode &);
81
82 private:
83
84         struct Columns : public Gtk::TreeModel::ColumnRecord {
85                 Columns () {
86                         add (name);
87                         add (region);
88                         add (color_);
89                         add (position);
90                         add (end);
91                         add (length);
92                         add (sync);
93                         add (fadein);
94                         add (fadeout);
95                         add (locked);
96                         add (glued);
97                         add (muted);
98                         add (opaque);
99                         add (used);
100                         add (path);
101                         add (property_toggles_visible);
102                 }
103
104                 Gtk::TreeModelColumn<std::string> name;
105                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
106                 Gtk::TreeModelColumn<Gdk::Color> color_;
107                 Gtk::TreeModelColumn<std::string> position;
108                 Gtk::TreeModelColumn<std::string> end;
109                 Gtk::TreeModelColumn<std::string> length;
110                 Gtk::TreeModelColumn<std::string> sync;
111                 Gtk::TreeModelColumn<std::string> fadein;
112                 Gtk::TreeModelColumn<std::string> fadeout;
113                 Gtk::TreeModelColumn<bool> locked;
114                 Gtk::TreeModelColumn<bool> glued;
115                 Gtk::TreeModelColumn<bool> muted;
116                 Gtk::TreeModelColumn<bool> opaque;
117                 Gtk::TreeModelColumn<std::string> used;
118                 Gtk::TreeModelColumn<std::string> path;
119                 /** used to indicate whether the locked/glued/muted/opaque should be visible or not */
120                 Gtk::TreeModelColumn<bool> property_toggles_visible;
121         };
122
123         Columns _columns;
124
125         Gtk::TreeModel::RowReference last_row;
126
127         void freeze_tree_model ();
128         void thaw_tree_model ();
129         void region_changed (boost::shared_ptr<ARDOUR::Region>, PBD::PropertyChange const &);
130         void selection_changed ();
131
132         sigc::connection _change_connection;
133
134         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
135
136         Gtk::Widget* old_focus;
137         Gtk::CellEditable* name_editable;
138         void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
139
140         void name_edit (const std::string&, const std::string&);
141         void locked_changed (std::string const &);
142         void glued_changed (std::string const &);
143         void muted_changed (std::string const &);
144         void opaque_changed (std::string const &);
145
146         bool key_press (GdkEventKey *);
147         bool button_press (GdkEventButton *);
148
149         bool focus_in (GdkEventFocus*);
150         bool focus_out (GdkEventFocus*);
151         bool enter_notify (GdkEventCrossing*);
152         bool leave_notify (GdkEventCrossing*);
153
154         void show_context_menu (int button, int time);
155
156         int sorter (Gtk::TreeModel::iterator, Gtk::TreeModel::iterator);
157
158         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
159
160         void add_region (boost::shared_ptr<ARDOUR::Region>);
161
162         void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
163         void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
164         void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
165         void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
166         void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
167         void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used, boost::shared_ptr<ARDOUR::AudioRegion>);
168         void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used, boost::shared_ptr<ARDOUR::AudioRegion>);
169         void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
170         void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
171         void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
172         void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, uint32_t used);
173         void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
174         void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
175         void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
176
177         void update_row (boost::shared_ptr<ARDOUR::Region>);
178         void update_all_rows ();
179
180         void insert_into_tmp_regionlist (boost::shared_ptr<ARDOUR::Region>);
181
182         void drag_data_received (
183                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
184                 );
185
186         Glib::RefPtr<Gtk::RadioAction> sort_type_action (Editing::RegionListSortType) const;
187         void set_full (bool);
188
189         Glib::RefPtr<Gtk::Action> hide_action () const;
190         Glib::RefPtr<Gtk::Action> show_action () const;
191         Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
192         Glib::RefPtr<Gtk::ToggleAction> toggle_full_action () const;
193         Glib::RefPtr<Gtk::ToggleAction> toggle_show_auto_regions_action () const;
194
195         Gtk::Menu* _menu;
196         Gtk::ScrolledWindow _scroller;
197         Gtk::Frame _frame;
198
199         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
200
201         Glib::RefPtr<Gtk::TreeStore> _model;
202
203         bool _show_automatic_regions;
204         bool ignore_region_list_selection_change;
205         bool ignore_selected_region_change;
206         bool _no_redisplay;
207
208         Editing::RegionListSortType _sort_type;
209
210         std::list<boost::shared_ptr<ARDOUR::Region> > tmp_region_list;
211
212         typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
213         typedef boost::unordered_map<std::string, Gtk::TreeModel::RowReference > RegionSourceMap;
214
215         RegionRowMap region_row_map;
216         RegionSourceMap parent_regions_sources_map;
217
218         PBD::ScopedConnection region_property_connection;
219         PBD::ScopedConnection check_new_region_connection;
220
221         PBD::ScopedConnection editor_freeze_connection;
222         PBD::ScopedConnection editor_thaw_connection;
223
224         bool expanded;
225 };
226
227 #endif /* __gtk_ardour_editor_regions_h__ */