Fix MIDI disk-writer flush
[ardour.git] / gtk2_ardour / editor_regions.h
1 /*
2  * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2018 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2018 Ben Loftis <ben@harrisonconsoles.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef __gtk_ardour_editor_regions_h__
22 #define __gtk_ardour_editor_regions_h__
23
24 #include <boost/unordered_map.hpp>
25
26 #include <gtkmm/scrolledwindow.h>
27 #include <gtkmm/treemodel.h>
28 #include <gtkmm/treerowreference.h>
29 #include <gtkmm/treestore.h>
30
31 #include "editor_component.h"
32
33 class EditorRegions : public EditorComponent, public ARDOUR::SessionHandlePtr
34 {
35 public:
36         EditorRegions (Editor *);
37
38         void set_session (ARDOUR::Session *);
39
40         Gtk::Widget& widget () {
41                 return _scroller;
42         }
43
44         void clear ();
45
46         void set_selected (RegionSelection &);
47         void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
48
49         boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
50         boost::shared_ptr<ARDOUR::Region> get_single_selection ();
51
52         void redisplay ();
53
54         void suspend_redisplay () {
55                 _no_redisplay = true;
56         }
57
58         void resume_redisplay () {
59                 _no_redisplay = false;
60                 redisplay ();
61         }
62
63         void block_change_connection (bool b) {
64                 _change_connection.block (b);
65         }
66
67         void unselect_all () {
68                 _display.get_selection()->unselect_all ();
69         }
70
71         void remove_unused_regions ();
72
73         XMLNode& get_state () const;
74         void set_state (const XMLNode &);
75
76 private:
77
78         struct Columns : public Gtk::TreeModel::ColumnRecord {
79                 Columns () {
80                         add (name);
81                         add (tags);
82                         add (start);
83                         add (length);
84                         add (end);
85                         add (sync);
86                         add (fadein);
87                         add (fadeout);
88                         add (locked);
89                         add (glued);
90                         add (muted);
91                         add (opaque);
92                         add (path);
93                         add (region);
94                         add (color_);
95                         add (position);
96                 }
97
98                 Gtk::TreeModelColumn<std::string> name;
99                 Gtk::TreeModelColumn<std::string> tags;
100                 Gtk::TreeModelColumn<samplepos_t> position;
101                 Gtk::TreeModelColumn<std::string> start;
102                 Gtk::TreeModelColumn<std::string> end;
103                 Gtk::TreeModelColumn<std::string> length;
104                 Gtk::TreeModelColumn<std::string> sync;
105                 Gtk::TreeModelColumn<std::string> fadein;
106                 Gtk::TreeModelColumn<std::string> fadeout;
107                 Gtk::TreeModelColumn<bool> locked;
108                 Gtk::TreeModelColumn<bool> glued;
109                 Gtk::TreeModelColumn<bool> muted;
110                 Gtk::TreeModelColumn<bool> opaque;
111                 Gtk::TreeModelColumn<std::string> path;
112                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
113                 Gtk::TreeModelColumn<Gdk::Color> color_;
114         };
115
116         Columns _columns;
117
118         Gtk::TreeModel::RowReference last_row;
119
120         void freeze_tree_model ();
121         void thaw_tree_model ();
122         void region_changed (boost::shared_ptr<ARDOUR::Region>, PBD::PropertyChange const &);
123         void selection_changed ();
124
125         sigc::connection _change_connection;
126
127         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
128
129         Gtk::Widget* old_focus;
130
131         Gtk::CellEditable* name_editable;
132         void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
133         void name_edit (const std::string&, const std::string&);
134
135
136         Gtk::CellEditable* tags_editable;
137         void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
138         void tag_edit (const std::string&, const std::string&);
139
140
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         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
157
158         void add_region (boost::shared_ptr<ARDOUR::Region>);
159         void destroy_region (boost::shared_ptr<ARDOUR::Region>);
160
161         void populate_row (boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const &, PBD::PropertyChange const &);
162         void populate_row_used (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
163         void populate_row_position (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
164         void populate_row_end (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
165         void populate_row_sync (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
166         void populate_row_fade_in (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
167         void populate_row_fade_out (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, boost::shared_ptr<ARDOUR::AudioRegion>);
168         void populate_row_locked (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
169         void populate_row_muted (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
170         void populate_row_glued (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
171         void populate_row_opaque (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
172         void populate_row_length (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
173         void populate_row_name (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
174         void populate_row_source (boost::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
175
176         void update_row (boost::shared_ptr<ARDOUR::Region>);
177
178         void clock_format_changed ();
179
180         void drag_data_received (
181                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
182                 );
183
184         Glib::RefPtr<Gtk::Action> remove_unused_regions_action () const;
185
186         Gtk::Menu* _menu;
187         Gtk::ScrolledWindow _scroller;
188         Gtk::Frame _frame;
189
190         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
191
192         Glib::RefPtr<Gtk::TreeStore> _model;
193
194         bool _no_redisplay;
195
196         typedef boost::unordered_map<boost::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
197
198         RegionRowMap region_row_map;
199
200         PBD::ScopedConnection region_property_connection;
201         PBD::ScopedConnection check_new_region_connection;
202
203         PBD::ScopedConnection editor_freeze_connection;
204         PBD::ScopedConnection editor_thaw_connection;
205 };
206
207 #endif /* __gtk_ardour_editor_regions_h__ */