Mixer: Fix optimized meter drawing.

pull/3/head
Jonathan Moore Liles 2009-12-26 00:03:34 -06:00
parent 0d20f9da81
commit b93041a0bd
5 changed files with 38 additions and 45 deletions

View File

@ -103,6 +103,8 @@ DPM::resize ( int X, int Y, int W, int H )
else
_segments = H / _pixels_per_segment;
// _last_drawn_hi_segment = 0;
Fl_Widget::resize( X, Y, W, H );
}
@ -125,16 +127,16 @@ DPM::draw ( void )
/* only draw as many segments as necessary */
if ( damage() == FL_DAMAGE_USER1 )
{
if ( _last_drawn_hi_segment > pos( value() ) )
{
hi = _last_drawn_hi_segment;
lo = v;
}
else
if ( v > _last_drawn_hi_segment )
{
hi = v;
lo = _last_drawn_hi_segment;
}
else
{
hi = _last_drawn_hi_segment;
lo = v;
}
}
else
{
@ -142,9 +144,9 @@ DPM::draw ( void )
hi = _segments;
}
_last_drawn_hi_segment = hi;
_last_drawn_hi_segment = v;
for ( int p = hi; p > lo; p-- )
for ( int p = lo; p <= hi; p++ )
{
Fl_Color c = DPM::div_color( p );

View File

@ -27,7 +27,6 @@ class Meter : public Fl_Valuator
{
float _peak;
float _old_value;
float _value;
protected:
@ -41,8 +40,8 @@ protected:
// if ( Fl::event_button3() )
// hide();
// else
reset();
return 1;
reset();
return 1;
}
return Fl_Widget::handle( m );
@ -73,31 +72,24 @@ protected:
return def / 115.0f;
}
float old_value ( void ) const { return _old_value; }
public:
Meter ( int X, int Y, int W, int H, const char *L = 0 ) :
Fl_Valuator( X, Y, W, H, L )
{
_peak = _value = -80.0f;
_old_value = 4.0f;
}
virtual ~Meter ( ) { }
void value ( float v )
{
if ( _value != v )
{
damage( FL_DAMAGE_USER1 );
damage( FL_DAMAGE_USER1 );
_old_value = _value;
_value = v;
_value = v;
if ( _value > _peak )
_peak = _value;
}
if ( _value > _peak )
_peak = _value;
}
float value ( void ) const { return _value; }

View File

@ -63,7 +63,8 @@ Meter_Indicator_Module::Meter_Indicator_Module ( int W, int H, const char *L )
Meter_Indicator_Module::~Meter_Indicator_Module ( )
{
if ( control_value )
delete[] control_value;
}
@ -117,8 +118,7 @@ Meter_Indicator_Module::update_cb ( void )
}
}
redraw();
// redraw();
}
void

View File

@ -31,13 +31,15 @@ const float METER_UPDATE_FREQ = 0.1f;
Meter_Module::Meter_Module ( int W, int H, const char *L )
Meter_Module::Meter_Module ( int W, int, const char *L )
: Module ( W, 100, L )
{
box( FL_THIN_UP_FRAME );
dpm_pack = new Fl_Scalepack( x(), y(), w(), h() );
dpm_pack->type( FL_HORIZONTAL );
control_value = 0;
color( FL_BLACK );
end();
@ -59,6 +61,8 @@ Meter_Module::Meter_Module ( int W, int H, const char *L )
Meter_Module::~Meter_Module ( )
{
if ( control_value )
delete[] control_value;
}
void
@ -73,7 +77,7 @@ Meter_Module::update_cb ( void )
Fl::repeat_timeout( METER_UPDATE_FREQ, update_cb, this );
for ( int i = dpm_pack->children(); i--; )
dpm_pack->child( i )->redraw();
((DPM*)dpm_pack->child( i ))->value( control_value[i] );
}
bool
@ -127,6 +131,12 @@ Meter_Module::configure_inputs ( int n )
control_output[0].connect_to( f);
}
if ( control_value )
delete [] control_value;
control_value = new float[n];
return true;
}
@ -179,23 +189,14 @@ get_peak_sample ( const sample_t* buf, nframes_t nframes )
void
Meter_Module::process ( void )
{
for ( int i = 0; i < audio_input.size(); ++i )
for ( unsigned int i = 0; i < audio_input.size(); ++i )
{
DPM *dpm = (DPM*)dpm_pack->child( i );
if ( audio_input[i].connected() )
{
dpm->activate();
float dB = 20 * log10( get_peak_sample( (float*)audio_input[i].buffer(), nframes() ) / 2.0f );
dpm->value( dB );
/* if ( control_output[i].connected() ) */
/* { */
((float*)control_output[0].buffer())[i] = dB;
/* } */
control_value[i] = dB;
}
else
dpm->deactivate();
}
}

View File

@ -27,6 +27,11 @@ class Meter_Module : public Module
{
Fl_Scalepack *dpm_pack;
volatile float *control_value;
static void update_cb ( void *v );
void update_cb ( void );
public:
Meter_Module ( int W, int H, const char *L=0 );
@ -37,15 +42,8 @@ public:
int can_support_inputs ( int n ) { return n > 0 ? n : -1; }
bool configure_inputs ( int n );
static void update_cb ( void *v );
void update_cb ( void );
protected:
// virtual void draw ( void );
virtual int handle ( int m );
virtual void process ( void );
};