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 "rgb_macros.h"
29 #include "audio_time_axis.h"
30 #include "public_editor.h"
31 #include "audio_region_view.h"
33 #include "canvas_impl.h"
36 using namespace ARDOUR;
38 using namespace Editing;
39 using namespace Gnome;
40 using namespace Canvas;
42 sigc::signal<void,CrossfadeView*> CrossfadeView::GoingAway;
44 CrossfadeView::CrossfadeView (ArdourCanvas::Group *parent,
45 RouteTimeAxisView &tv,
46 boost::shared_ptr<Crossfade> xf,
48 Gdk::Color& basic_color,
49 AudioRegionView& lview,
50 AudioRegionView& rview)
53 : TimeAxisViewItem ("xfade" /*xf.name()*/, *parent, tv, spu, basic_color, xf->position(),
54 xf->length(), TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
63 fade_in = new Line (*group);
64 fade_in->property_fill_color_rgba() = color_map[cCrossfadeLine];
65 fade_in->property_width_pixels() = 1;
67 fade_out = new Line (*group);
68 fade_out->property_fill_color_rgba() = color_map[cCrossfadeLine];
69 fade_out->property_width_pixels() = 1;
71 set_height (get_time_axis_view().height);
73 /* no frame around the xfade or overlap rects */
75 frame->property_outline_what() = 0;
77 /* never show the vestigial frame */
79 vestigial_frame->hide();
80 show_vestigial = false;
82 group->signal_event().connect (bind (mem_fun (tv.editor, &PublicEditor::canvas_crossfade_view_event), group, this));
84 crossfade_changed (Change (~0));
86 crossfade->StateChanged.connect (mem_fun(*this, &CrossfadeView::crossfade_changed));
89 CrossfadeView::~CrossfadeView ()
91 GoingAway (this) ; /* EMIT_SIGNAL */
95 CrossfadeView::reset_width_dependent_items (double pixel_width)
97 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
101 if (pixel_width < 5) {
108 CrossfadeView::set_height (double height)
110 if (height == TimeAxisView::hSmaller ||
111 height == TimeAxisView::hSmall)
112 TimeAxisViewItem::set_height (height - 3 );
114 TimeAxisViewItem::set_height (height - NAME_HIGHLIGHT_SIZE - 3 );
120 CrossfadeView::crossfade_changed (Change what_changed)
122 bool need_redraw_curves = false;
124 if (what_changed & BoundsChanged) {
125 set_position (crossfade->position(), this);
126 set_duration (crossfade->length(), this);
127 need_redraw_curves = true;
130 if (what_changed & Crossfade::FollowOverlapChanged) {
131 need_redraw_curves = true;
134 if (what_changed & Crossfade::ActiveChanged) {
135 /* calls redraw_curves */
137 } else if (need_redraw_curves) {
143 CrossfadeView::redraw_curves ()
150 if (!crossfade->following_overlap()) {
151 /* curves should not be visible */
158 At "height - 3.0" the bottom of the crossfade touches the name highlight or the bottom of the track (if the
159 track is either Small or Smaller.
161 double tav_height = get_time_axis_view().height;
162 if (tav_height == TimeAxisView::hSmaller ||
163 tav_height == TimeAxisView::hSmall) {
164 h = tav_height - 3.0;
166 h = tav_height - NAME_HIGHLIGHT_SIZE - 3.0;
170 /* no space allocated yet */
174 npoints = get_time_axis_view().editor.frame_to_pixel (crossfade->length());
175 npoints = std::min (gdk_screen_width(), npoints);
177 if (!_visible || !crossfade->active() || npoints < 3) {
186 points = get_canvas_points ("xfade edit redraw", npoints);
187 vec = new float[npoints];
189 crossfade->fade_in().get_vector (0, crossfade->length(), vec, npoints);
190 for (int i = 0, pci = 0; i < npoints; ++i) {
191 Art::Point &p = (*points)[pci++];
193 p.set_y(2.0 + h - (h * vec[i]));
195 fade_in->property_points() = *points;
197 crossfade->fade_out().get_vector (0, crossfade->length(), vec, npoints);
198 for (int i = 0, pci = 0; i < npoints; ++i) {
199 Art::Point &p = (*points)[pci++];
201 p.set_y(2.0 + h - (h * vec[i]));
203 fade_out->property_points() = *points;
209 /* XXX this is ugly, but it will have to wait till Crossfades are reimplented
210 as regions. This puts crossfade views on top of a track, above all regions.
213 group->raise_to_top();
217 CrossfadeView::active_changed ()
219 if (crossfade->active()) {
220 frame->property_fill_color_rgba() = color_map[cActiveCrossfade];
222 frame->property_fill_color_rgba() = color_map[cInactiveCrossfade];
229 CrossfadeView::set_valid (bool yn)
235 CrossfadeView::upper_regionview () const
237 if (left_view.region()->layer() > right_view.region()->layer()) {
245 CrossfadeView::show ()
252 CrossfadeView::hide ()
259 CrossfadeView::fake_hide ()