2005-09-25 14:42:24 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2003 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include <ardour/region.h>
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm2ext/doi.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "canvas-simplerect.h"
|
|
|
|
#include "canvas-curve.h"
|
|
|
|
#include "crossfade_view.h"
|
|
|
|
#include "rgb_macros.h"
|
|
|
|
#include "audio_time_axis.h"
|
|
|
|
#include "public_editor.h"
|
2006-07-31 23:23:35 -04:00
|
|
|
#include "audio_region_view.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "utils.h"
|
2005-12-29 19:34:21 -05:00
|
|
|
#include "canvas_impl.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
using namespace sigc;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Editing;
|
2005-11-22 00:10:12 -05:00
|
|
|
using namespace Gnome;
|
|
|
|
using namespace Canvas;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-09-25 16:33:00 -04:00
|
|
|
sigc::signal<void,CrossfadeView*> CrossfadeView::GoingAway;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2005-11-23 12:21:12 -05:00
|
|
|
CrossfadeView::CrossfadeView (ArdourCanvas::Group *parent,
|
2006-07-31 23:23:35 -04:00
|
|
|
RouteTimeAxisView &tv,
|
2005-09-25 14:42:24 -04:00
|
|
|
Crossfade& xf,
|
|
|
|
double spu,
|
2005-10-06 00:59:20 -04:00
|
|
|
Gdk::Color& basic_color,
|
2005-09-25 14:42:24 -04:00
|
|
|
AudioRegionView& lview,
|
|
|
|
AudioRegionView& rview)
|
|
|
|
|
|
|
|
|
2006-06-20 14:50:38 -04:00
|
|
|
: TimeAxisViewItem ("xfade" /*xf.name()*/, *parent, tv, spu, basic_color, xf.position(),
|
2005-09-25 14:42:24 -04:00
|
|
|
xf.overlap_length(), TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
|
|
|
|
crossfade (xf),
|
|
|
|
left_view (lview),
|
|
|
|
right_view (rview)
|
|
|
|
|
|
|
|
{
|
|
|
|
_valid = true;
|
|
|
|
_visible = true;
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in = new Line (*group);
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_in->property_fill_color_rgba() = color_map[cCrossfadeLine];
|
|
|
|
fade_in->property_width_pixels() = 1;
|
2005-11-22 00:10:12 -05:00
|
|
|
|
|
|
|
fade_out = new Line (*group);
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_out->property_fill_color_rgba() = color_map[cCrossfadeLine];
|
|
|
|
fade_out->property_width_pixels() = 1;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
set_height (get_time_axis_view().height);
|
|
|
|
|
|
|
|
/* no frame around the xfade or overlap rects */
|
|
|
|
|
2005-11-27 17:35:04 -05:00
|
|
|
frame->property_outline_what() = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* never show the vestigial frame */
|
|
|
|
|
2005-11-12 22:53:51 -05:00
|
|
|
vestigial_frame->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
show_vestigial = false;
|
2005-12-24 13:25:26 -05:00
|
|
|
|
2005-12-29 19:34:21 -05:00
|
|
|
group->signal_event().connect (bind (mem_fun (tv.editor, &PublicEditor::canvas_crossfade_view_event), group, this));
|
2005-11-15 21:57:22 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
crossfade_changed (Change (~0));
|
|
|
|
|
2005-09-25 17:19:23 -04:00
|
|
|
crossfade.StateChanged.connect (mem_fun(*this, &CrossfadeView::crossfade_changed));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CrossfadeView::~CrossfadeView ()
|
|
|
|
{
|
2006-10-25 16:11:42 -04:00
|
|
|
GoingAway (this) ; /* EMIT_SIGNAL */
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::reset_width_dependent_items (double pixel_width)
|
|
|
|
{
|
|
|
|
TimeAxisViewItem::reset_width_dependent_items (pixel_width);
|
|
|
|
|
|
|
|
active_changed ();
|
|
|
|
|
|
|
|
if (pixel_width < 5) {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->hide();
|
|
|
|
fade_out->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::set_height (double height)
|
|
|
|
{
|
2006-09-26 11:38:51 -04:00
|
|
|
if (height == TimeAxisView::hSmaller ||
|
|
|
|
height == TimeAxisView::hSmall)
|
2005-09-25 14:42:24 -04:00
|
|
|
TimeAxisViewItem::set_height (height - 3 );
|
|
|
|
else
|
|
|
|
TimeAxisViewItem::set_height (height - NAME_HIGHLIGHT_SIZE - 3 );
|
|
|
|
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::crossfade_changed (Change what_changed)
|
|
|
|
{
|
|
|
|
bool need_redraw_curves = false;
|
|
|
|
|
|
|
|
if (what_changed & BoundsChanged) {
|
|
|
|
set_position (crossfade.position(), this);
|
|
|
|
set_duration (crossfade.overlap_length(), this);
|
|
|
|
need_redraw_curves = true;
|
|
|
|
}
|
2006-10-20 12:09:42 -04:00
|
|
|
|
|
|
|
if (what_changed & Crossfade::FollowOverlapChanged) {
|
|
|
|
need_redraw_curves = true;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
if (what_changed & Crossfade::ActiveChanged) {
|
|
|
|
/* calls redraw_curves */
|
|
|
|
active_changed ();
|
|
|
|
} else if (need_redraw_curves) {
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::redraw_curves ()
|
|
|
|
{
|
2005-11-22 00:10:12 -05:00
|
|
|
Points* points;
|
2005-09-25 14:42:24 -04:00
|
|
|
int32_t npoints;
|
|
|
|
float* vec;
|
|
|
|
double h;
|
|
|
|
|
2006-10-20 12:09:42 -04:00
|
|
|
if (!crossfade.following_overlap()) {
|
|
|
|
/* curves should not be visible */
|
|
|
|
fade_in->hide ();
|
|
|
|
fade_out->hide ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
/*
|
|
|
|
At "height - 3.0" the bottom of the crossfade touches the name highlight or the bottom of the track (if the
|
|
|
|
track is either Small or Smaller.
|
|
|
|
*/
|
2006-09-26 11:38:51 -04:00
|
|
|
double tav_height = get_time_axis_view().height;
|
|
|
|
if (tav_height == TimeAxisView::hSmaller ||
|
|
|
|
tav_height == TimeAxisView::hSmall) {
|
|
|
|
h = tav_height - 3.0;
|
|
|
|
} else {
|
|
|
|
h = tav_height - NAME_HIGHLIGHT_SIZE - 3.0;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h < 0) {
|
|
|
|
/* no space allocated yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
npoints = get_time_axis_view().editor.frame_to_pixel (crossfade.length());
|
|
|
|
npoints = std::min (gdk_screen_width(), npoints);
|
|
|
|
|
|
|
|
if (!_visible || !crossfade.active() || npoints < 3) {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->hide();
|
|
|
|
fade_out->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
return;
|
|
|
|
} else {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->show();
|
|
|
|
fade_out->show();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
points = get_canvas_points ("xfade edit redraw", npoints);
|
|
|
|
vec = new float[npoints];
|
|
|
|
|
|
|
|
crossfade.fade_in().get_vector (0, crossfade.length(), vec, npoints);
|
|
|
|
for (int i = 0, pci = 0; i < npoints; ++i) {
|
2005-11-22 00:10:12 -05:00
|
|
|
Art::Point &p = (*points)[pci++];
|
|
|
|
p.set_x(i);
|
|
|
|
p.set_y(2.0 + h - (h * vec[i]));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_in->property_points() = *points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
crossfade.fade_out().get_vector (0, crossfade.length(), vec, npoints);
|
|
|
|
for (int i = 0, pci = 0; i < npoints; ++i) {
|
2005-11-22 00:10:12 -05:00
|
|
|
Art::Point &p = (*points)[pci++];
|
|
|
|
p.set_x(i);
|
|
|
|
p.set_y(2.0 + h - (h * vec[i]));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_out->property_points() = *points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
delete [] vec;
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
delete points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* XXX this is ugly, but it will have to wait till Crossfades are reimplented
|
|
|
|
as regions. This puts crossfade views on top of a track, above all regions.
|
|
|
|
*/
|
|
|
|
|
2005-11-12 22:53:51 -05:00
|
|
|
group->raise_to_top();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::active_changed ()
|
|
|
|
{
|
|
|
|
if (crossfade.active()) {
|
2005-11-27 17:35:04 -05:00
|
|
|
frame->property_fill_color_rgba() = color_map[cActiveCrossfade];
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2005-11-27 17:35:04 -05:00
|
|
|
frame->property_fill_color_rgba() = color_map[cInactiveCrossfade];
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::set_valid (bool yn)
|
|
|
|
{
|
|
|
|
_valid = yn;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioRegionView&
|
|
|
|
CrossfadeView::upper_regionview () const
|
|
|
|
{
|
2006-08-24 21:07:15 -04:00
|
|
|
if (left_view.region()->layer() > right_view.region()->layer()) {
|
2005-09-25 14:42:24 -04:00
|
|
|
return left_view;
|
|
|
|
} else {
|
|
|
|
return right_view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::show ()
|
|
|
|
{
|
2005-11-12 22:53:51 -05:00
|
|
|
group->show();
|
2005-09-25 14:42:24 -04:00
|
|
|
_visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::hide ()
|
|
|
|
{
|
2005-11-12 22:53:51 -05:00
|
|
|
group->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
_visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::fake_hide ()
|
|
|
|
{
|
2005-11-12 22:53:51 -05:00
|
|
|
group->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|