1 /* 2 * Copyright (C) 2005-2009 Nick Mainsbridge <mainsbridge@gmail.com> 3 * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com> 4 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com> 5 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com> 6 * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net> 7 * Copyright (C) 2008-2014 David Robillard <d@drobilla.net> 8 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org> 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 * 20 * You should have received a copy of the GNU General Public License along 21 * with this program; if not, write to the Free Software Foundation, Inc., 22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 */ 24 25 #ifndef __gtk_ardour_time_axis_view_item_h__ 26 #define __gtk_ardour_time_axis_view_item_h__ 27 28 #include <string> 29 #include <gdk/gdk.h> 30 #include <gdkmm/color.h> 31 #include <pangomm/fontdescription.h> 32 #include "pbd/signals.h" 33 #include "selectable.h" 34 35 class TimeAxisView; 36 37 namespace ArdourCanvas { 38 class Pixbuf; 39 class Rectangle; 40 class Item; 41 class Container; 42 class Text; 43 } 44 45 using ARDOUR::samplepos_t; 46 using ARDOUR::samplecnt_t; 47 48 /** 49 * Base class for items that may appear upon a TimeAxisView. 50 */ 51 52 class TimeAxisViewItem : public Selectable, public PBD::ScopedConnectionList 53 { 54 public: 55 virtual ~TimeAxisViewItem(); 56 57 virtual bool set_position(samplepos_t, void*, double* delta = 0); 58 samplepos_t get_position() const; 59 virtual bool set_duration(samplecnt_t, void*); 60 samplecnt_t get_duration() const; 61 virtual void set_max_duration(samplecnt_t, void*); 62 samplecnt_t get_max_duration() const; 63 virtual void set_min_duration(samplecnt_t, void*); 64 samplecnt_t get_min_duration() const; 65 virtual void set_position_locked(bool, void*); 66 bool get_position_locked() const; 67 void set_max_duration_active(bool, void*); 68 bool get_max_duration_active() const; 69 void set_min_duration_active(bool, void*); 70 bool get_min_duration_active() const; 71 void set_item_name(std::string, void*); 72 virtual std::string get_item_name() const; 73 virtual void set_selected(bool yn); set_sensitive(bool yn)74 void set_sensitive (bool yn) { _sensitive = yn; } sensitive()75 bool sensitive () const { return _sensitive; } 76 TimeAxisView& get_time_axis_view () const; 77 void set_name_text(const std::string&); 78 virtual void set_height(double h); height()79 virtual double height() const { return _height; } 80 void set_y (double); 81 void set_color (uint32_t); 82 void set_name_text_color (); 83 84 virtual uint32_t get_fill_color () const; 85 86 ArdourCanvas::Item* get_canvas_frame(); 87 ArdourCanvas::Item* get_canvas_group(); 88 ArdourCanvas::Item* get_name_highlight(); 89 90 virtual void set_samples_per_pixel (double); 91 92 double get_samples_per_pixel () const; 93 94 virtual void drag_start(); 95 virtual void drag_end(); dragging()96 bool dragging() const { return _dragging; } 97 raise()98 virtual void raise () { return; } raise_to_top()99 virtual void raise_to_top () { return; } lower()100 virtual void lower () { return; } lower_to_bottom()101 virtual void lower_to_bottom () { return; } 102 103 /** @return true if the name area should respond to events */ name_active()104 bool name_active() const { return name_connected; } 105 106 // Default sizes, font and spacing 107 static Pango::FontDescription NAME_FONT; 108 static void set_constant_heights (); 109 static const double NAME_X_OFFSET; 110 static const double GRAB_HANDLE_TOP; 111 static const double GRAB_HANDLE_WIDTH; 112 113 /* these are not constant, but vary with the pixel size 114 * of the font used to display the item name. 115 */ 116 static int NAME_HEIGHT; 117 static double NAME_Y_OFFSET; 118 static double NAME_HIGHLIGHT_SIZE; 119 static double NAME_HIGHLIGHT_THRESH; 120 121 /** 122 * Emitted when this Group has been removed. 123 * This is different to the CatchDeletion signal in that this signal 124 * is emitted during the deletion of this Time Axis, and not during 125 * the destructor, this allows us to capture the source of the deletion 126 * event 127 */ 128 129 sigc::signal<void,std::string,void*> ItemRemoved; 130 131 /** Emitted when the name of this item is changed */ 132 sigc::signal<void,std::string,std::string,void*> NameChanged; 133 134 /** Emiited when the position of this item changes */ 135 sigc::signal<void,samplepos_t,void*> PositionChanged; 136 137 /** Emitted when the position lock of this item is changed */ 138 sigc::signal<void,bool,void*> PositionLockChanged; 139 140 /** Emitted when the duration of this item changes */ 141 sigc::signal<void,samplecnt_t,void*> DurationChanged; 142 143 /** Emitted when the maximum item duration is changed */ 144 sigc::signal<void,samplecnt_t,void*> MaxDurationChanged; 145 146 /** Emitted when the mionimum item duration is changed */ 147 sigc::signal<void,samplecnt_t,void*> MinDurationChanged; 148 149 enum Visibility { 150 ShowFrame = 0x1, 151 ShowNameHighlight = 0x2, 152 ShowNameText = 0x4, 153 ShowHandles = 0x8, 154 HideFrameLeft = 0x10, 155 HideFrameRight = 0x20, 156 HideFrameTB = 0x40, 157 FullWidthNameHighlight = 0x80 158 }; 159 update_visibility()160 virtual void update_visibility () {} 161 162 protected: 163 TimeAxisViewItem (const std::string &, ArdourCanvas::Item&, TimeAxisView&, double, uint32_t fill_color, 164 samplepos_t, samplecnt_t, bool recording = false, bool automation = false, Visibility v = Visibility (0)); 165 166 TimeAxisViewItem (const TimeAxisViewItem&); 167 168 void init (ArdourCanvas::Item*, double, uint32_t, samplepos_t, samplepos_t, Visibility, bool, bool); 169 170 virtual bool canvas_group_event (GdkEvent*); 171 172 virtual void set_colors(); 173 virtual void set_frame_color(); 174 virtual void set_frame_gradient (); 175 void set_trim_handle_colors(); 176 177 virtual void reset_width_dependent_items (double); 178 179 static gint idle_remove_this_item(TimeAxisViewItem*, void*); 180 181 /** time axis that this item is on */ 182 TimeAxisView& trackview; 183 184 /** indicates whether this item is locked to its current position */ 185 bool position_locked; 186 187 /** position of this item on the timeline */ 188 samplepos_t sample_position; 189 190 /** duration of this item upon the timeline */ 191 samplecnt_t item_duration; 192 193 /** maximum duration that this item can have */ 194 samplecnt_t max_item_duration; 195 196 /** minimum duration that this item can have */ 197 samplecnt_t min_item_duration; 198 199 /** indicates whether the max duration constraint is active */ 200 bool max_duration_active; 201 202 /** indicates whether the min duration constraint is active */ 203 bool min_duration_active; 204 205 /** samples per canvas pixel */ 206 double samples_per_pixel; 207 208 /** should the item respond to events */ 209 bool _sensitive; 210 211 /** 212 * The unique item name of this Item. 213 * Each item upon a time axis must have a unique id. 214 */ 215 std::string item_name; 216 217 /** true if the name should respond to events */ 218 bool name_connected; 219 220 uint32_t fill_color; 221 222 uint32_t last_item_width; 223 int name_text_width; 224 bool wide_enough_for_name; 225 bool high_enough_for_name; 226 227 ArdourCanvas::Container* group; 228 ArdourCanvas::Rectangle* frame; 229 ArdourCanvas::Rectangle* selection_frame; 230 ArdourCanvas::Text* name_text; 231 ArdourCanvas::Rectangle* name_highlight; 232 233 /* with these two values, if frame_handle_start == 0 then frame_handle_end will also be 0 */ 234 ArdourCanvas::Rectangle* frame_handle_start; ///< `frame' (fade) handle for the start of the item, or 0 235 ArdourCanvas::Rectangle* frame_handle_end; ///< `frame' (fade) handle for the end of the item, or 0 236 237 bool frame_handle_crossing (GdkEvent*, ArdourCanvas::Rectangle*); 238 239 double _height; 240 Visibility visibility; 241 std::string fill_color_name; 242 bool _recregion; 243 bool _automation; ///< true if this is an automation region view 244 bool _dragging; 245 double _width; 246 247 void manage_name_text (); 248 249 private: 250 void parameter_changed (std::string); 251 void manage_name_highlight (); 252 253 }; /* class TimeAxisViewItem */ 254 255 #endif /* __gtk_ardour_time_axis_view_item_h__ */ 256