Skip to content

Commit

Permalink
Implement tension and fill parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Oct 7, 2015
1 parent bc9d380 commit 26c781b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/modules/qt/filter_audiospectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ static void draw_spectrum( mlt_filter filter, mlt_frame frame, QImage* qimg )
mlt_position position = mlt_filter_get_position( filter, frame );
mlt_position length = mlt_filter_get_length2( filter, frame );
int fill = mlt_properties_get_int( filter_properties, "fill" );
double tension = mlt_properties_get_double( filter_properties, "tension" );
mlt_rect rect = mlt_properties_anim_get_rect( filter_properties, "rect", position, length );
if ( strchr( mlt_properties_get( filter_properties, "rect" ), '%' ) ) {
rect.x *= qimg->width();
Expand All @@ -197,7 +198,7 @@ static void draw_spectrum( mlt_filter filter, mlt_frame frame, QImage* qimg )
}
float* spectrum = (float*)mlt_pool_alloc( bands * sizeof(float) );
convert_fft_to_spectrum( filter, frame, bands, spectrum );
paint_line_graph( p, r, bands, spectrum, fill );
paint_line_graph( p, r, bands, spectrum, tension, fill );
mlt_pool_release( spectrum );

p.end();
Expand Down Expand Up @@ -300,6 +301,7 @@ mlt_filter filter_audiospectrum_init( mlt_profile profile, mlt_service_type type
mlt_properties_set( properties, "rect", "0% 0% 100% 100%" );
mlt_properties_set( properties, "thickness", "0" );
mlt_properties_set( properties, "fill", "0" );
mlt_properties_set( properties, "tension", "0.4" );
mlt_properties_set( properties, "angle", "0" );
mlt_properties_set( properties, "gorient", "v" );
mlt_properties_set_int( properties, "bands", 31 );
Expand Down
12 changes: 12 additions & 0 deletions src/modules/qt/filter_audiospectrum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ parameters:
mutable: yes
widget: checkbox

- identifier: tension
title: Line Tension
description: >
Affects the amount of curve in the line interpolating between points.
0.0 = a straight line between points.
1.0 = very curved lines between points.
values < 0 and > 1 will cause loops in the lines.
type: float
default: 0.4
readonly: no
mutable: yes

- identifier: gorient
title: Gradient Orientation
description: Direction of the color gradient.
Expand Down
16 changes: 11 additions & 5 deletions src/modules/qt/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ void setup_graph_pen( QPainter& p, QRectF& r, mlt_properties filter_properties )
p.setPen(pen);
}

void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, int fill )
void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, double tension, int fill )
{
double width = rect.width();
double height = rect.height();
double t = 0.3;
double pixelsPerPoint = width / (double)(points - 1);

// Calculate cubic control points
Expand All @@ -121,8 +120,8 @@ void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, int
double y2 = rect.y() + height - values[i + 2] * height;
double d01 = sqrt( pow( x1 - x0, 2 ) + pow( y1 - y0, 2) );
double d12 = sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2) );
double fa = t * d01 / ( d01 + d12 );
double fb = t * d12 / ( d01 + d12 );
double fa = tension * d01 / ( d01 + d12 );
double fb = tension * d12 / ( d01 + d12 );
double p1x = x1 - fa * ( x2 - x0 );
double p1y = y1 - fa * ( y2 - y0 );
double p2x = x1 + fb * ( x2 - x0 );
Expand All @@ -149,5 +148,12 @@ void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, int
curvePath.cubicTo( c1, c2, end );
}

p.drawPath( curvePath );
if( fill ) {
curvePath.lineTo( rect.x() + width, rect.y() + height );
curvePath.lineTo( rect.x(), rect.y() + height );
curvePath.closeSubpath();
p.fillPath( curvePath, p.pen().brush() );
} else {
p.drawPath( curvePath );
}
}
2 changes: 1 addition & 1 deletion src/modules/qt/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

void setup_graph_painter( QPainter& p, QRectF& rect, mlt_properties filter_properties );
void setup_graph_pen( QPainter& p, QRectF& rect, mlt_properties filter_properties );
void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, int fill );
void paint_line_graph( QPainter& p, QRectF& rect, int points, float* values, double tension, int fill );


#endif // GRAPH_H

0 comments on commit 26c781b

Please sign in to comment.