(Source List) Revert to displaying whole-file Regions instead of Sources.
[ardour.git] / gtk2_ardour / editor_sources.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_sources_h__
20 #define __gtk_ardour_editor_sources_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 #include "selection.h"
32
33 class EditorSources : public EditorComponent, public ARDOUR::SessionHandlePtr
34 {
35 public:
36         EditorSources (Editor *);
37
38         void set_session (ARDOUR::Session *);
39
40         void set_selection (Selection *sel) { _selection = sel; }
41
42         Gtk::Widget& widget () {
43                 return _scroller;
44         }
45
46         void clear ();
47         
48         void selection_mapover (sigc::slot<void,boost::shared_ptr<ARDOUR::Region> >);
49
50         boost::shared_ptr<ARDOUR::Region> get_dragged_region ();
51         boost::shared_ptr<ARDOUR::Region> get_single_selection ();
52
53         void block_change_connection (bool b) {
54                 _change_connection.block (b);
55         }
56
57         void unselect_all () {
58                 _display.get_selection()->unselect_all ();
59         }
60
61         //user actions
62         void remove_selected_sources ();
63         void recover_selected_sources();
64
65         XMLNode& get_state () const;
66         void set_state (const XMLNode &);
67
68 private:
69
70         struct Columns : public Gtk::TreeModel::ColumnRecord {
71                 Columns () {
72                         add (name);
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<boost::shared_ptr<ARDOUR::Region> > region;
83                 Gtk::TreeModelColumn<Gdk::Color> color_;
84                 Gtk::TreeModelColumn<std::string> natural_pos;
85                 Gtk::TreeModelColumn<std::string> path;
86                 Gtk::TreeModelColumn<std::string> take_id;
87                 Gtk::TreeModelColumn<samplepos_t> natural_s;
88         };
89
90         Columns _columns;
91
92         Gtk::TreeModel::RowReference last_row;
93
94         void freeze_tree_model ();
95         void thaw_tree_model ();
96         void source_changed (boost::shared_ptr<ARDOUR::Region>);
97         void populate_row (Gtk::TreeModel::Row row, boost::shared_ptr<ARDOUR::Region> region);
98         void selection_changed ();
99
100         sigc::connection _change_connection;
101
102         bool selection_filter (const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool yn);
103
104         Gtk::Widget* old_focus;
105
106         bool key_press (GdkEventKey *);
107         bool button_press (GdkEventButton *);
108
109         bool focus_in (GdkEventFocus*);
110         bool focus_out (GdkEventFocus*);
111         bool enter_notify (GdkEventCrossing*);
112         bool leave_notify (GdkEventCrossing*);
113
114         void show_context_menu (int button, int time);
115
116         void format_position (ARDOUR::samplepos_t pos, char* buf, size_t bufsize, bool onoff = true);
117
118         void add_source (boost::shared_ptr<ARDOUR::Region>);
119         void remove_source (boost::shared_ptr<ARDOUR::Region>);
120
121         void clock_format_changed ();
122
123         void redisplay ();
124
125         void suspend_redisplay () {
126                 _no_redisplay = true;
127         }
128
129         void resume_redisplay () {
130                 _no_redisplay = false;
131                 redisplay ();
132         }
133
134         void drag_data_received (
135                 Glib::RefPtr<Gdk::DragContext> const &, gint, gint, Gtk::SelectionData const &, guint, guint
136                 );
137
138         Gtk::Menu* _menu;
139         Gtk::ScrolledWindow _scroller;
140         Gtk::Frame _frame;
141
142         Gtkmm2ext::DnDTreeView<boost::shared_ptr<ARDOUR::Region> > _display;
143
144         Glib::RefPtr<Gtk::TreeStore> _model;
145
146         PBD::ScopedConnection region_property_connection;
147         PBD::ScopedConnection check_new_region_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__ */