Update GPL boilerplate and (C)
[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 (take_id);
73                         add (natural_pos);
74                         add (path);
75                         add (color_);
76                         add (region);
77                         add (natural_s);
78                 }
79
80                 Gtk::TreeModelColumn<std::string> name;
81                 Gtk::TreeModelColumn<boost::shared_ptr<ARDOUR::Region> > region;
82                 Gtk::TreeModelColumn<Gdk::Color> color_;
83                 Gtk::TreeModelColumn<std::string> natural_pos;
84                 Gtk::TreeModelColumn<std::string> path;
85                 Gtk::TreeModelColumn<std::string> take_id;
86                 Gtk::TreeModelColumn<samplepos_t> natural_s;
87         };
88
89         Columns _columns;
90
91         Gtk::TreeModel::RowReference last_row;
92
93         void freeze_tree_model ();
94         void thaw_tree_model ();
95         void source_changed (boost::shared_ptr<ARDOUR::Region>);
96         void populate_row (Gtk::TreeModel::Row row, boost::shared_ptr<ARDOUR::Region> region);
97         void selection_changed ();
98
99         sigc::connection _change_connection;
100
101         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
102
103         Gtk::Widget* old_focus;
104
105         bool key_press (GdkEventKey *);
106         bool button_press (GdkEventButton *);
107
108         bool focus_in (GdkEventFocus*);
109         bool focus_out (GdkEventFocus*);
110         bool enter_notify (GdkEventCrossing*);
111         bool leave_notify (GdkEventCrossing*);
112
113         void show_context_menu (int button, int time);
114
115         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
116
117         void add_source (boost::shared_ptr<ARDOUR::Region>);
118         void remove_source (boost::shared_ptr<ARDOUR::Source>);
119
120         void clock_format_changed ();
121
122         void redisplay ();
123
124         void suspend_redisplay () {
125                 _no_redisplay = true;
126         }
127
128         void resume_redisplay () {
129                 _no_redisplay = false;
130                 redisplay ();
131         }
132
133         void drag_data_received (
134                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
135                 );
136
137         Gtk::Menu* _menu;
138         Gtk::ScrolledWindow _scroller;
139         Gtk::Frame _frame;
140
141         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
142
143         Glib::RefPtr<Gtk::TreeStore> _model;
144
145         PBD::ScopedConnection source_property_connection;
146         PBD::ScopedConnection add_source_connection;
147         PBD::ScopedConnection remove_source_connection;
148
149         PBD::ScopedConnection editor_freeze_connection;
150         PBD::ScopedConnection editor_thaw_connection;
151
152         Selection* _selection;
153         
154         bool _no_redisplay;
155
156 };
157
158 #endif /* __gtk_ardour_editor_regions_h__ */