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.
23 #include <ardour/region.h>
24 #include <gtkmm2ext/doi.h>
26 #include "canvas-simplerect.h"
27 #include "canvas-curve.h"
28 #include "crossfade_view.h"
29 #include "rgb_macros.h"
30 #include "audio_time_axis.h"
31 #include "public_editor.h"
32 #include "regionview.h"
36 using namespace ARDOUR;
37 using namespace Editing;
39 sigc::signal<void,CrossfadeView*> CrossfadeView::GoingAway;
41 CrossfadeView::CrossfadeView (Gnome::Canvas::Group *parent,
42 AudioTimeAxisView &tv,
45 Gdk::Color& basic_color,
46 AudioRegionView& lview,
47 AudioRegionView& rview)
50 : TimeAxisViewItem ("xf.name()", *parent, tv, spu, basic_color, xf.position(),
51 xf.overlap_length(), TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
60 fade_in = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
61 gnome_canvas_line_get_type(),
62 "fill_color_rgba", color_map[cCrossfadeLine],
63 "width_pixels", (guint) 1,
66 fade_out = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
67 gnome_canvas_line_get_type(),
68 "fill_color_rgba", color_map[cCrossfadeLine],
69 "width_pixels", (guint) 1,
72 set_height (get_time_axis_view().height);
74 /* no frame around the xfade or overlap rects */
76 frame->set_property ("outline_what", 0);
78 /* never show the vestigial frame */
80 vestigial_frame->hide();
81 show_vestigial = false;
83 group->signal_event.connect (bind (mem_fun (editor, &Public::canvas_crossfade_view_event), group, this));
85 crossfade_changed (Change (~0));
87 crossfade.StateChanged.connect (mem_fun(*this, &CrossfadeView::crossfade_changed));
90 CrossfadeView::~CrossfadeView ()
92 GoingAway (this) ; /* EMIT_SIGNAL */
96 CrossfadeView::get_item_name ()
99 // return crossfade.name();
103 CrossfadeView::reset_width_dependent_items (double pixel_width)
105 TimeAxisViewItem::reset_width_dependent_items (pixel_width);
109 if (pixel_width < 5) {
110 gnome_canvas_item_hide (fade_in);
111 gnome_canvas_item_hide (fade_out);
116 CrossfadeView::set_height (double height)
118 if (height == TimeAxisView::Smaller ||
119 height == TimeAxisView::Small)
120 TimeAxisViewItem::set_height (height - 3 );
122 TimeAxisViewItem::set_height (height - NAME_HIGHLIGHT_SIZE - 3 );
128 CrossfadeView::crossfade_changed (Change what_changed)
130 bool need_redraw_curves = false;
132 if (what_changed & BoundsChanged) {
133 set_position (crossfade.position(), this);
134 set_duration (crossfade.overlap_length(), this);
135 need_redraw_curves = true;
138 if (what_changed & Crossfade::ActiveChanged) {
139 /* calls redraw_curves */
141 } else if (need_redraw_curves) {
147 CrossfadeView::redraw_curves ()
149 GnomeCanvasPoints* points;
156 At "height - 3.0" the bottom of the crossfade touches the name highlight or the bottom of the track (if the
157 track is either Small or Smaller.
159 switch(get_time_axis_view().height) {
160 case TimeAxisView::Smaller:
161 case TimeAxisView::Small:
162 h = get_time_axis_view().height - 3.0;
166 h = get_time_axis_view().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) {
178 gnome_canvas_item_hide (fade_in);
179 gnome_canvas_item_hide (fade_out);
182 gnome_canvas_item_show (fade_in);
183 gnome_canvas_item_show (fade_out);
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 points->coords[pci++] = i;
192 points->coords[pci++] = 2.0 + h - (h * vec[i]);
194 gnome_canvas_item_set (fade_in, "points", points, NULL);
196 crossfade.fade_out().get_vector (0, crossfade.length(), vec, npoints);
197 for (int i = 0, pci = 0; i < npoints; ++i) {
198 points->coords[pci++] = i;
199 points->coords[pci++] = 2.0 + h - (h * vec[i]);
201 gnome_canvas_item_set (fade_out, "points", points, NULL);
205 gnome_canvas_points_unref (points);
207 /* XXX this is ugly, but it will have to wait till Crossfades are reimplented
208 as regions. This puts crossfade views on top of a track, above all regions.
211 group->raise_to_top();
215 CrossfadeView::active_changed ()
217 if (crossfade.active()) {
218 frame->set_property ("fill_color_rgba", color_map[cActiveCrossfade]);
220 frame->set_property ("fill_color_rgba", color_map[cInactiveCrossfade]);
227 CrossfadeView::set_valid (bool yn)
233 CrossfadeView::upper_regionview () const
235 if (left_view.region.layer() > right_view.region.layer()) {
243 CrossfadeView::show ()
250 CrossfadeView::hide ()
257 CrossfadeView::fake_hide ()