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"
|
|
|
|
#include "regionview.h"
|
|
|
|
#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;
|
|
|
|
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,
|
2005-09-25 14:42:24 -04:00
|
|
|
AudioTimeAxisView &tv,
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2005-11-12 22:53:51 -05:00
|
|
|
: TimeAxisViewItem ("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 ()
|
|
|
|
{
|
|
|
|
GoingAway (this) ; /* EMIT_SIGNAL */
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
CrossfadeView::get_item_name ()
|
|
|
|
{
|
|
|
|
return "xfade";
|
|
|
|
// return crossfade.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (height == TimeAxisView::Smaller ||
|
|
|
|
height == TimeAxisView::Small)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
switch(get_time_axis_view().height) {
|
|
|
|
case TimeAxisView::Smaller:
|
|
|
|
case TimeAxisView::Small:
|
|
|
|
h = get_time_axis_view().height - 3.0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
h = get_time_axis_view().height - NAME_HIGHLIGHT_SIZE - 3.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if (left_view.region.layer() > right_view.region.layer()) {
|
|
|
|
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
|
|
|
}
|