Clean up fade drawing code. Draw fade outs also.

This commit is contained in:
Jonathan Moore Liles 2008-04-14 20:08:06 -05:00
parent 19de318aae
commit 30c19870d6
2 changed files with 31 additions and 24 deletions

View File

@ -93,7 +93,7 @@ Region::init ( void )
_color = FL_BLUE; _color = FL_BLUE;
_fade_in.length = 256; _fade_in.length = 256;
_fade_in.type = Fade::Linear; _fade_in.type = Fade::Cosine;
_fade_out = _fade_in; _fade_out = _fade_in;
} }
@ -422,36 +422,43 @@ Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, int X, int W )
const int dy = y() + Fl::box_dy( box() ); const int dy = y() + Fl::box_dy( box() );
const int dh = h() - Fl::box_dh( box() ); const int dh = h() - Fl::box_dh( box() );
const int height = dh; const int height = dh;
const int width = timeline->ts_to_x( fade.length );
fl_color( fl_lighter( FL_BLACK ) ); fl_color( fl_lighter( FL_BLACK ) );
fl_line_style( FL_SOLID, 2 );
fl_begin_polygon(); fl_push_matrix();
if ( dir == Fade::In ) if ( dir == Fade::In )
{ {
fl_vertex( line_x(), dy ); fl_translate( line_x(), dy );
fl_vertex( line_x(), dy + height ); fl_scale( width, height );
} }
else else
{ {
fl_vertex( line_x() + w(), dy ); fl_translate( line_x() + abs_w(), dy + height );
fl_vertex( line_x() + w(), dy + height ); fl_scale( width, height );
/* flip */
fl_scale( -1.0, 1.0 );
fl_scale( 1.0, -1.0 );
} }
const int width = timeline->ts_to_x( fade.length ); fl_begin_polygon();
for ( int i = X; i < line_x() + width; i += 3 ) fl_vertex( 0.0, 0.0 );
fl_vertex( 0.0, 1.0 );
for ( int i = 0; i < width; ++i )
{ {
const int x = i; const float x = i / (float)width;
const float y = 1.0f - fade.gain( timeline->x_to_ts( i ) );
const int y = dy + (height * (1.0f - fade.gain( timeline->x_to_ts( i - this->x() ))));
fl_vertex( x, y ); fl_vertex( x, y );
} }
fl_end_polygon(); fl_end_polygon();
fl_line_style( FL_SOLID, 0 );
fl_pop_matrix();
} }
void void
@ -533,7 +540,7 @@ Region::draw ( int X, int Y, int W, int H )
/* FIXME: testing! */ /* FIXME: testing! */
Fade fade = _fade_in; Fade fade = _fade_in;
fade.length = 20000; fade.length = 20000;
fade.type = Fade::Cosine; fade.type = Fade::Sigmoid;
for ( int i = 0; i < channels; ++i ) for ( int i = 0; i < channels; ++i )
{ {
@ -546,15 +553,15 @@ Region::draw ( int X, int Y, int W, int H )
pb[ j ].max *= _scale; pb[ j ].max *= _scale;
} }
int fw = timeline->ts_to_x( fade.length ); /* int fw = timeline->ts_to_x( fade.length ); */
/* if ( draw_fade_waveform ) */ /* /\* if ( draw_fade_waveform ) *\/ */
for ( int j = min( fw, peaks ); j--; ) /* for ( int j = min( fw, peaks ); j--; ) */
{ /* { */
const float g = fade.gain( j ); /* const float g = fade.gain( j * timeline->fpp() ); */
pb[ j ].min *= g; /* pb[ j ].min *= g; */
pb[ j ].max *= g; /* pb[ j ].max *= g; */
} /* } */
Waveform::draw( X, (y() + Fl::box_dy( box() )) + (i * ch), W, ch, Waveform::draw( X, (y() + Fl::box_dy( box() )) + (i * ch), W, ch,
pb, peaks, pb, peaks,

View File

@ -41,7 +41,7 @@ public:
struct Fade struct Fade
{ {
enum fade_type_e { Linear, Cosine, Logarithmic, Parabolic }; enum fade_type_e { Linear, Sigmoid, Logarithmic, Parabolic };
enum fade_dir_e { In, Out }; enum fade_dir_e { In, Out };
fade_type_e type; fade_type_e type;
@ -75,7 +75,7 @@ public:
case Linear: case Linear:
g = fi; g = fi;
break; break;
case Cosine: case Sigmoid:
// g = sin( fi * M_PI / 2 ); // g = sin( fi * M_PI / 2 );
g = (1.0f - cos( fi * M_PI )) / 2.0f; g = (1.0f - cos( fi * M_PI )) / 2.0f;
break; break;