3f9c756448a44ba5db72318db487575de0cd9fd1
[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 (tags);
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> tags;
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
129         Gtk::CellEditable* name_editable;
130         void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
131         void name_edit (const std::string&, const std::string&);
132
133
134         Gtk::CellEditable* tags_editable;
135         void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
136         void tag_edit (const std::string&, const std::string&);
137
138
139         void locked_changed (std::string const &);
140         void glued_changed (std::string const &);
141         void muted_changed (std::string const &);
142         void opaque_changed (std::string const &);
143
144         bool key_press (GdkEventKey *);
145         bool button_press (GdkEventButton *);
146
147         bool focus_in (GdkEventFocus*);
148         bool focus_out (GdkEventFocus*);
149         bool enter_notify (GdkEventCrossing*);
150         bool leave_notify (GdkEventCrossing*);
151
152         void show_context_menu (int button, int time);
153
154         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
155
156         void add_region (boost::shared_ptr<ARDOUR::Region>);
157         void destroy_region (boost::shared_ptr<ARDOUR::Region>);
158
159         void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
160         void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
161         void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
162         void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
163         void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
164         void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
165         void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
166         void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
167         void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
168         void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
169         void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
170         void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
171         void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
172         void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
173
174         void update_row (boost::shared_ptr<ARDOUR::Region>);
175
176         void clock_format_changed ();
177
178         void drag_data_received (
179                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
180                 );
181
182         Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
183
184         Gtk::Menu* _menu;
185         Gtk::ScrolledWindow _scroller;
186         Gtk::Frame _frame;
187
188         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
189
190         Glib::RefPtr<Gtk::TreeStore> _model;
191
192         bool _no_redisplay;
193
194         typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
195
196         RegionRowMap region_row_map;
197
198         PBD::ScopedConnection region_property_connection;
199         PBD::ScopedConnection check_new_region_connection;
200
201         PBD::ScopedConnection editor_freeze_connection;
202         PBD::ScopedConnection editor_thaw_connection;
203 };
204
205 #endif /* __gtk_ardour_editor_regions_h__ */