2 Copyright (C) 2003 Paul Davis
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.
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.
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.
22 #include "ardour/region.h"
23 #include <gtkmm2ext/doi.h>
25 #include "canvas-simplerect.h"
26 #include "canvas-curve.h"
27 #include "crossfade_view.h"
28 #include "gui_thread.h"
29 #include "rgb_macros.h"
30 #include "audio_time_axis.h"
31 #include "public_editor.h"
32 #include "audio_region_view.h"
34 #include "canvas_impl.h"
35 #include "ardour_ui.h"
37 using namespace ARDOUR;
39 using namespace Editing;
40 using namespace Gnome;
41 using namespace Canvas;
43 PBD::Signal1<void,CrossfadeView*> CrossfadeView::CatchDeletion;
45 CrossfadeView::CrossfadeView (ArdourCanvas::Group *parent,
46 RouteTimeAxisView &tv,
47 boost::shared_ptr<Crossfade> xf,
49 Gdk::Color& basic_color,
50 AudioRegionView& lview,
51 AudioRegionView& rview)
54 : TimeAxisViewItem ("xfade" /*xf.name()*/, *parent, tv, spu, basic_color, xf->position(),
55 xf->length(), false, TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
63 fade_in = new Line (*group);
64 fade_in->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
65 fade_in->property_width_pixels() = 1;
67 fade_out = new Line (*group);
68 fade_out->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
69 fade_out->property_width_pixels() = 1;
71 /* no frame around the xfade or overlap rects */
73 frame->property_outline_what() = 0;
75 /* never show the vestigial frame */
76 vestigial_frame->hide();
77 show_vestigial = false;
79 group->signal_event().connect (sigc::bind (sigc::mem_fun (tv.editor(), &PublicEditor::canvas_crossfade_view_event), group, this));
81 PropertyChange all_crossfade_properties;
82 all_crossfade_properties.add (ARDOUR::Properties::active);
83 all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
84 crossfade_changed (all_crossfade_properties);
86 crossfade->PropertyChanged.connect (*this, invalidator (*this), ui_bind (&CrossfadeView::crossfade_changed, this, _1), gui_context());
87 ColorsChanged.connect (sigc::mem_fun (*this, &CrossfadeView::color_handler));
90 CrossfadeView::~CrossfadeView ()
92 CatchDeletion (this) ; /* EMIT_SIGNAL */
96 CrossfadeView::reset_width_dependent_items (double pixel_width)
98 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
102 if (pixel_width < 5) {
109 CrossfadeView::set_height (double h)
111 if (h <= TimeAxisView::preset_height (HeightSmall)) {
114 h -= NAME_HIGHLIGHT_SIZE + 3.0;
117 TimeAxisViewItem::set_height (h);
123 CrossfadeView::crossfade_changed (const PropertyChange& what_changed)
125 bool need_redraw_curves = false;
127 if (what_changed.contains (ARDOUR::bounds_change)) {
128 set_position (crossfade->position(), this);
129 set_duration (crossfade->length(), this);
131 /* set_duration will call reset_width_dependent_items which in turn will call redraw_curves via active_changed,
132 so no need for us to call it */
133 need_redraw_curves = false;
136 if (what_changed.contains (ARDOUR::Properties::follow_overlap)) {
137 need_redraw_curves = true;
140 if (what_changed.contains (ARDOUR::Properties::active)) {
141 /* calls redraw_curves */
143 } else if (need_redraw_curves) {
149 CrossfadeView::redraw_curves ()
155 if (!crossfade->following_overlap()) {
156 /* curves should not be visible */
163 /* no space allocated yet */
167 npoints = get_time_axis_view().editor().frame_to_pixel (crossfade->length());
168 // npoints = std::min (gdk_screen_width(), npoints);
170 if (!_visible || !crossfade->active() || npoints < 3) {
179 points = get_canvas_points ("xfade edit redraw", npoints);
180 vec = new float[npoints];
182 crossfade->fade_in().curve().get_vector (0, crossfade->length(), vec, npoints);
184 for (int i = 0, pci = 0; i < npoints; ++i) {
185 Art::Point &p = (*points)[pci++];
187 p.set_y(2.0 + _height - (_height * vec[i]));
190 fade_in->property_points() = *points;
192 crossfade->fade_out().curve().get_vector (0, crossfade->length(), vec, npoints);
194 for (int i = 0, pci = 0; i < npoints; ++i) {
195 Art::Point &p = (*points)[pci++];
197 p.set_y(2.0 + _height - (_height * vec[i]));
200 fade_out->property_points() = *points;
206 /* XXX this is ugly, but it will have to wait till Crossfades are reimplented
207 as regions. This puts crossfade views on top of a track, above all regions.
210 group->raise_to_top();
214 CrossfadeView::active_changed ()
216 if (crossfade->active()) {
217 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ActiveCrossfade.get();
219 frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_InactiveCrossfade.get();
226 CrossfadeView::color_handler ()
232 CrossfadeView::set_valid (bool yn)
238 CrossfadeView::upper_regionview () const
240 if (left_view.region()->layer() > right_view.region()->layer()) {
248 CrossfadeView::show ()
255 CrossfadeView::hide ()
262 CrossfadeView::fake_hide ()