94124e98ad34eda0d032e26a71f8dfe080d8c203
[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 set_selected (RegionSelection &);
45         void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
46
47         boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
48         boost::shared_ptr<ARDOUR::Region> get_single_selection ();
49
50         void redisplay ();
51
52         void suspend_redisplay () {
53                 _no_redisplay = true;
54         }
55
56         void resume_redisplay () {
57                 _no_redisplay = false;
58                 redisplay ();
59         }
60
61         void block_change_connection (bool b) {
62                 _change_connection.block (b);
63         }
64
65         void unselect_all () {
66                 _display.get_selection()->unselect_all ();
67         }
68
69         void remove_unused_regions ();
70
71         XMLNode& get_state () const;
72         void set_state (const XMLNode &);
73
74 private:
75
76         struct Columns : public Gtk::TreeModel::ColumnRecord {
77                 Columns () {
78                         add (name);
79                         add (take_id);
80                         add (start);
81                         add (end);
82                         add (length);
83                         add (sync);
84                         add (fadein);
85                         add (fadeout);
86                         add (locked);
87                         add (glued);
88                         add (muted);
89                         add (opaque);
90                         add (path);
91                         add (region);
92                         add (color_);
93                         add (position);
94                 }
95
96                 Gtk::TreeModelColumn<std::string> name;
97                 Gtk::TreeModelColumn<std::string> take_id;
98                 Gtk::TreeModelColumn<samplepos_t> position;
99                 Gtk::TreeModelColumn<std::string> start;
100                 Gtk::TreeModelColumn<std::string> end;
101                 Gtk::TreeModelColumn<std::string> length;
102                 Gtk::TreeModelColumn<std::string> sync;
103                 Gtk::TreeModelColumn<std::string> fadein;
104                 Gtk::TreeModelColumn<std::string> fadeout;
105                 Gtk::TreeModelColumn<bool> locked;
106                 Gtk::TreeModelColumn<bool> glued;
107                 Gtk::TreeModelColumn<bool> muted;
108                 Gtk::TreeModelColumn<bool> opaque;
109                 Gtk::TreeModelColumn<std::string> path;
110                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
111                 Gtk::TreeModelColumn<Gdk::Color> color_;
112         };
113
114         Columns _columns;
115
116         Gtk::TreeModel::RowReference last_row;
117
118         void freeze_tree_model ();
119         void thaw_tree_model ();
120         void region_changed (boost::shared_ptr<ARDOUR::Region>, PBD::PropertyChange const &);
121         void selection_changed ();
122
123         sigc::connection _change_connection;
124
125         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
126
127         Gtk::Widget* old_focus;
128         Gtk::CellEditable* name_editable;
129         void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
130
131         void name_edit (const std::string&, const std::string&);
132         void locked_changed (std::string const &);
133         void glued_changed (std::string const &);
134         void muted_changed (std::string const &);
135         void opaque_changed (std::string const &);
136
137         bool key_press (GdkEventKey *);
138         bool button_press (GdkEventButton *);
139
140         bool focus_in (GdkEventFocus*);
141         bool focus_out (GdkEventFocus*);
142         bool enter_notify (GdkEventCrossing*);
143         bool leave_notify (GdkEventCrossing*);
144
145         void show_context_menu (int button, int time);
146
147         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
148
149         void add_region (boost::shared_ptr<ARDOUR::Region>);
150         void destroy_region (boost::shared_ptr<ARDOUR::Region>);
151
152         void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
153         void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
154         void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
155         void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
156         void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
157         void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
158         void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
159         void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
160         void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
161         void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
162         void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
163         void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
164         void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
165         void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
166
167         void update_row (boost::shared_ptr<ARDOUR::Region>);
168
169         void clock_format_changed ();
170
171         void drag_data_received (
172                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
173                 );
174
175         Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
176
177         Gtk::Menu* _menu;
178         Gtk::ScrolledWindow _scroller;
179         Gtk::Frame _frame;
180
181         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
182
183         Glib::RefPtr<Gtk::TreeStore> _model;
184
185         bool _no_redisplay;
186
187         typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
188
189         RegionRowMap region_row_map;
190
191         PBD::ScopedConnection region_property_connection;
192         PBD::ScopedConnection check_new_region_connection;
193
194         PBD::ScopedConnection editor_freeze_connection;
195         PBD::ScopedConnection editor_thaw_connection;
196 };
197
198 #endif /* __gtk_ardour_editor_regions_h__ */