fix mistaken "do not roll" conclusion in TransportFSM::compute_should_roll()
[ardour.git] / gtk2_ardour / editor_sources.h
1 /*
2  * Copyright (C) 2018-2019 Ben Loftis <ben@harrisonconsoles.com>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 #ifndef __gtk_ardour_editor_sources_h__
19 #define __gtk_ardour_editor_sources_h__
20
21 #include <boost/unordered_map.hpp>
22
23 #include <gtkmm/scrolledwindow.h>
24 #include <gtkmm/treemodel.h>
25 #include <gtkmm/treerowreference.h>
26 #include <gtkmm/treestore.h>
27
28 #include "editor_component.h"
29
30 #include "selection.h"
31
32 class EditorSources : public EditorComponent, public ARDOUR::SessionHandlePtr
33 {
34 public:
35         EditorSources (Editor *);
36
37         void set_session (ARDOUR::Session *);
38
39         void set_selection (Selection *sel) { _selection = sel; }
40
41         Gtk::Widget& widget () {
42                 return _scroller;
43         }
44
45         void clear ();
46         
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 block_change_connection (bool b) {
53                 _change_connection.block (b);
54         }
55
56         void unselect_all () {
57                 _display.get_selection()->unselect_all ();
58         }
59
60         //user actions
61         void remove_selected_sources ();
62         void recover_selected_sources();
63
64         XMLNode& get_state () const;
65         void set_state (const XMLNode &);
66
67 private:
68
69         struct Columns : public Gtk::TreeModel::ColumnRecord {
70                 Columns () {
71                         add (name);
72                         add (tags);
73                         add (take_id);
74                         add (natural_pos);
75                         add (path);
76                         add (color_);
77                         add (region);
78                         add (natural_s);
79                 }
80
81                 Gtk::TreeModelColumn<std::string> name;
82                 Gtk::TreeModelColumn<std::string> tags;
83                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
84                 Gtk::TreeModelColumn<Gdk::Color> color_;
85                 Gtk::TreeModelColumn<std::string> natural_pos;
86                 Gtk::TreeModelColumn<std::string> path;
87                 Gtk::TreeModelColumn<std::string> take_id;
88                 Gtk::TreeModelColumn<samplepos_t> natural_s;
89         };
90
91         Columns _columns;
92
93         Gtk::TreeModel::RowReference last_row;
94
95         void freeze_tree_model ();
96         void thaw_tree_model ();
97         void source_changed (boost::shared_ptr<ARDOUR::Region>);
98         void populate_row (Gtk::TreeModel::Row row, boost::shared_ptr<ARDOUR::Region> region);
99         void selection_changed ();
100
101         sigc::connection _change_connection;
102
103         Gtk::Widget* old_focus;
104
105         Gtk::CellEditable* tags_editable;
106         void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
107         void tag_edit (const std::string&, const std::string&);
108
109         bool key_press (GdkEventKey *);
110         bool button_press (GdkEventButton *);
111
112         bool focus_in (GdkEventFocus*);
113         bool focus_out (GdkEventFocus*);
114         bool enter_notify (GdkEventCrossing*);
115         bool leave_notify (GdkEventCrossing*);
116
117         void show_context_menu (int button, int time);
118
119         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
120
121         void add_source (boost::shared_ptr<ARDOUR::Region>);
122         void remove_source (boost::shared_ptr<ARDOUR::Source>);
123         void remove_weak_source (boost::weak_ptr<ARDOUR::Source>);
124
125         void clock_format_changed ();
126
127         void redisplay ();
128
129         void suspend_redisplay () {
130                 _no_redisplay = true;
131         }
132
133         void resume_redisplay () {
134                 _no_redisplay = false;
135                 redisplay ();
136         }
137
138         void drag_data_received (
139                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
140                 );
141
142         Gtk::Menu* _menu;
143         Gtk::ScrolledWindow _scroller;
144         Gtk::Frame _frame;
145
146         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
147
148         Glib::RefPtr<Gtk::TreeStore> _model;
149
150         PBD::ScopedConnection source_property_connection;
151         PBD::ScopedConnection add_source_connection;
152         PBD::ScopedConnection remove_source_connection;
153
154         PBD::ScopedConnection editor_freeze_connection;
155         PBD::ScopedConnection editor_thaw_connection;
156
157         Selection* _selection;
158         
159         bool _no_redisplay;
160 };
161
162 #endif /* __gtk_ardour_editor_regions_h__ */