Ardour  9.0-pre0-822-g12e3bc5c20
region_list_base.h
Go to the documentation of this file.
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  * Copyright (C) 2021 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 #ifndef _gtk_ardour_region_list_base_h_
23 #define _gtk_ardour_region_list_base_h_
24 
25 #include <unordered_map>
26 
27 #include <ytkmm/celleditable.h>
28 #include <ytkmm/frame.h>
29 #include <ytkmm/scrolledwindow.h>
30 #include <ytkmm/treemodel.h>
31 #include <ytkmm/treerowreference.h>
32 #include <ytkmm/treestore.h>
33 
34 #include "gtkmm2ext/utils.h"
35 
36 #include "pbd/properties.h"
37 #include "pbd/signals.h"
38 
39 #include "ardour/session_handle.h"
40 #include "ardour/types.h"
41 
42 #include "gtkmm2ext/dndtreeview.h"
43 
44 //#define SHOW_REGION_EXTRAS
45 
46 namespace ARDOUR
47 {
48  class Region;
49  class AudioRegion;
50 }
51 
53 {
54 public:
56 
58 
59  Gtk::Widget& widget ()
60  {
61  return _scroller;
62  }
63 
64  void clear ();
65 
66  void redisplay ();
67 
69  {
70  _no_redisplay = true;
71  }
72 
74  {
75  _no_redisplay = false;
76  redisplay ();
77  }
78 
80  {
81  _change_connection.block (b);
82  }
83 
84  void unselect_all ()
85  {
86  _display.get_selection ()->unselect_all ();
87  }
88 
89 protected:
90  struct Columns : public Gtk::TreeModel::ColumnRecord {
92  {
93  add (name); // 0
94  add (channels); // 1
95  add (regionfx); // 2
96  add (tags); // 3
97  add (start); // 4
98  add (length); // 5
99  add (end); // 6
100  add (sync); // 7
101  add (fadein); // 8
102  add (fadeout); // 9
103  add (locked); // 10
104  add (muted); // 11
105  add (opaque); // 12
106  add (path); // 13
107  add (region); // 14
108  add (color_); // 15
109  add (position); // 16
110  /* src-list */
111  add (captd_for); // 17
112  add (take_id); // 18
113  add (natural_pos); // 19
114  add (natural_s); // 20
115  add (captd_xruns); // 21
116  }
117 
118  Gtk::TreeModelColumn<std::string> name;
119  Gtk::TreeModelColumn<int> channels;
120  Gtk::TreeModelColumn<size_t> regionfx;
121  Gtk::TreeModelColumn<std::string> tags;
122  Gtk::TreeModelColumn<Temporal::timepos_t> position;
123  Gtk::TreeModelColumn<std::string> start;
124  Gtk::TreeModelColumn<std::string> end;
125  Gtk::TreeModelColumn<std::string> length;
126  Gtk::TreeModelColumn<std::string> sync;
127  Gtk::TreeModelColumn<std::string> fadein;
128  Gtk::TreeModelColumn<std::string> fadeout;
129  Gtk::TreeModelColumn<bool> locked;
130  Gtk::TreeModelColumn<bool> muted;
131  Gtk::TreeModelColumn<bool> opaque;
132  Gtk::TreeModelColumn<std::string> path;
133  Gtk::TreeModelColumn<std::shared_ptr<ARDOUR::Region>> region;
134  Gtk::TreeModelColumn<Gdk::Color> color_;
135  Gtk::TreeModelColumn<std::string> captd_for;
136  Gtk::TreeModelColumn<std::string> take_id;
137  Gtk::TreeModelColumn<std::string> natural_pos;
138  Gtk::TreeModelColumn<Temporal::timepos_t> natural_s;
139  Gtk::TreeModelColumn<size_t> captd_xruns;
140  };
141 
143  void add_tag_column ();
144 
145  template <class T>
146  Gtk::TreeViewColumn* append_col (Gtk::TreeModelColumn<T> const& col, int width)
147  {
148  Gtk::TreeViewColumn* c = manage (new Gtk::TreeViewColumn ("", col));
149  c->set_fixed_width (width);
150  c->set_sizing (Gtk::TREE_VIEW_COLUMN_FIXED);
151  _display.append_column (*c);
152  return c;
153  }
154 
155  template <class T>
156  Gtk::TreeViewColumn* append_col (Gtk::TreeModelColumn<T> const& col, std::string const& sizing_text)
157  {
158  int w, h;
159  Glib::RefPtr<Pango::Layout> layout = _display.create_pango_layout (sizing_text);
160  layout->get_pixel_size (w, h);
161  return append_col (col, w);
162  }
163 
164  void setup_col (Gtk::TreeViewColumn*, int, Gtk::AlignmentEnum, const char*, const char*, bool require_mod_to_edit = false);
165  void setup_toggle (Gtk::TreeViewColumn*, sigc::slot<void, std::string>);
166 
169  void remove_weak_region (std::weak_ptr<ARDOUR::Region>);
170 
171  virtual void regions_changed (std::shared_ptr<ARDOUR::RegionList>, PBD::PropertyChange const&);
172 
173  void name_editing_started (Gtk::CellEditable*, const Glib::ustring&);
175  void tag_editing_started (Gtk::CellEditable*, const Glib::ustring&);
177 
178  virtual void name_edit (const std::string&, const std::string&);
179  virtual void tag_edit (const std::string&, const std::string&);
180 
181  void locked_changed (std::string const&);
182  void muted_changed (std::string const&);
183  void opaque_changed (std::string const&);
184 
185  virtual bool key_press (GdkEventKey*);
186  virtual bool button_press (GdkEventButton*)
187  {
188  return false;
189  }
190 
191  bool focus_in (GdkEventFocus*);
192  bool focus_out (GdkEventFocus*);
193 
194  bool enter_notify (GdkEventCrossing*);
195  bool leave_notify (GdkEventCrossing*);
196 
197  void format_position (Temporal::timepos_t const& pos, char* buf, size_t bufsize, bool onoff = true) const;
198 
199  void add_region (std::shared_ptr<ARDOUR::Region>);
200 
201  void populate_row (std::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::Row const&, PBD::PropertyChange const&);
202  void populate_row_used (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
203  void populate_row_position (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
204  void populate_row_end (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
205  void populate_row_sync (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
206  void populate_row_fade_in (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, std::shared_ptr<ARDOUR::AudioRegion>);
207  void populate_row_fade_out (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row, std::shared_ptr<ARDOUR::AudioRegion>);
208  void populate_row_locked (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
209  void populate_row_muted (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
210  void populate_row_opaque (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
211  void populate_row_length (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
212  void populate_row_name (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
213  void populate_row_source (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
214  void populate_row_regionfx (std::shared_ptr<ARDOUR::Region> region, Gtk::TreeModel::Row const& row);
215 
217 
218  void drag_begin (Glib::RefPtr<Gdk::DragContext> const&);
219  void drag_end (Glib::RefPtr<Gdk::DragContext> const&);
220  void drag_data_get (Glib::RefPtr<Gdk::DragContext> const&, Gtk::SelectionData&, guint, guint);
221 
222  virtual bool list_region (std::shared_ptr<ARDOUR::Region>) const;
223 
225 
227  Gtk::SortType _sort_type;
228 
229  Gtk::CellEditable* _name_editable;
230  Gtk::CellEditable* _tags_editable;
231  Gtk::Widget* _old_focus;
232 
233  Gtk::ScrolledWindow _scroller;
234  Gtk::Frame _frame;
235 
237 
238  Glib::RefPtr<Gtk::TreeStore> _model;
239 
241 
242  typedef std::unordered_map<std::shared_ptr<ARDOUR::Region>, Gtk::TreeModel::iterator> RegionRowMap;
243 
245 
246  sigc::connection _change_connection;
247 
250 
252 };
253 
254 #endif /* _gtk_ardour_region_list_base_h_ */
void populate_row(std::shared_ptr< ARDOUR::Region >, Gtk::TreeModel::Row const &, PBD::PropertyChange const &)
virtual void regions_changed(std::shared_ptr< ARDOUR::RegionList >, PBD::PropertyChange const &)
void locked_changed(std::string const &)
Gtk::CellEditable * _tags_editable
bool leave_notify(GdkEventCrossing *)
virtual bool key_press(GdkEventKey *)
void opaque_changed(std::string const &)
void populate_row_source(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
PBD::ScopedConnection _editor_thaw_connection
Gtk::TreeViewColumn * append_col(Gtk::TreeModelColumn< T > const &col, std::string const &sizing_text)
virtual bool list_region(std::shared_ptr< ARDOUR::Region >) const
void add_tag_column()
void tag_editing_canceled()
void populate_row_fade_in(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row, std::shared_ptr< ARDOUR::AudioRegion >)
Gtkmm2ext::DnDTreeView< std::shared_ptr< ARDOUR::Region > > _display
void tag_editing_started(Gtk::CellEditable *, const Glib::ustring &)
void clock_format_changed()
virtual bool button_press(GdkEventButton *)
Gtk::Widget * _old_focus
void name_editing_started(Gtk::CellEditable *, const Glib::ustring &)
std::unordered_map< std::shared_ptr< ARDOUR::Region >, Gtk::TreeModel::iterator > RegionRowMap
void populate_row_position(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void populate_row_muted(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
Gtk::CellEditable * _name_editable
void format_position(Temporal::timepos_t const &pos, char *buf, size_t bufsize, bool onoff=true) const
void populate_row_opaque(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void setup_col(Gtk::TreeViewColumn *, int, Gtk::AlignmentEnum, const char *, const char *, bool require_mod_to_edit=false)
Glib::RefPtr< Gtk::TreeStore > _model
void add_region(std::shared_ptr< ARDOUR::Region >)
void populate_row_end(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void populate_row_length(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void populate_row_fade_out(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row, std::shared_ptr< ARDOUR::AudioRegion >)
RegionRowMap region_row_map
void set_session(ARDOUR::Session *)
void drag_begin(Glib::RefPtr< Gdk::DragContext > const &)
void remove_weak_region(std::weak_ptr< ARDOUR::Region >)
void drag_data_get(Glib::RefPtr< Gdk::DragContext > const &, Gtk::SelectionData &, guint, guint)
bool focus_in(GdkEventFocus *)
virtual void tag_edit(const std::string &, const std::string &)
Gtk::Widget & widget()
sigc::connection _change_connection
void populate_row_used(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void populate_row_name(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
bool enter_notify(GdkEventCrossing *)
void block_change_connection(bool b)
Gtk::SortType _sort_type
virtual void name_edit(const std::string &, const std::string &)
PBD::ScopedConnectionList _remove_region_connections
Gtk::TreeViewColumn * append_col(Gtk::TreeModelColumn< T > const &col, int width)
void populate_row_locked(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
bool focus_out(GdkEventFocus *)
void thaw_tree_model()
void populate_row_regionfx(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void add_name_column()
void muted_changed(std::string const &)
PBD::ScopedConnection _editor_freeze_connection
Gtk::ScrolledWindow _scroller
void name_editing_canceled()
void setup_toggle(Gtk::TreeViewColumn *, sigc::slot< void, std::string >)
void drag_end(Glib::RefPtr< Gdk::DragContext > const &)
void populate_row_sync(std::shared_ptr< ARDOUR::Region > region, Gtk::TreeModel::Row const &row)
void suspend_redisplay()
void freeze_tree_model()
PBD::PropertyDescriptor< bool > region
Gtk::TreeModelColumn< std::string > fadeout
Gtk::TreeModelColumn< std::string > length
Gtk::TreeModelColumn< std::string > natural_pos
Gtk::TreeModelColumn< std::string > fadein
Gtk::TreeModelColumn< std::string > name
Gtk::TreeModelColumn< size_t > regionfx
Gtk::TreeModelColumn< Temporal::timepos_t > position
Gtk::TreeModelColumn< std::string > take_id
Gtk::TreeModelColumn< std::shared_ptr< ARDOUR::Region > > region
Gtk::TreeModelColumn< Gdk::Color > color_
Gtk::TreeModelColumn< std::string > path
Gtk::TreeModelColumn< std::string > sync
Gtk::TreeModelColumn< std::string > captd_for
Gtk::TreeModelColumn< bool > muted
Gtk::TreeModelColumn< Temporal::timepos_t > natural_s
Gtk::TreeModelColumn< std::string > end
Gtk::TreeModelColumn< bool > opaque
Gtk::TreeModelColumn< bool > locked
Gtk::TreeModelColumn< size_t > captd_xruns
Gtk::TreeModelColumn< int > channels
Gtk::TreeModelColumn< std::string > tags
Gtk::TreeModelColumn< std::string > start