Mixer: Fix some issues with the new spectrum view.
This commit is contained in:
parent
6673dcd28e
commit
d332da3c39
|
@ -682,8 +682,14 @@ Module::show_analysis_window ( void )
|
|||
nframes_t nframes = 4096;
|
||||
float *buf = new float[nframes];
|
||||
|
||||
memset( buf, 0, sizeof(float) * nframes );
|
||||
|
||||
buf[0] = 1;
|
||||
|
||||
if ( ! get_impulse_response( buf, nframes ) )
|
||||
return false;
|
||||
{
|
||||
// return false;
|
||||
}
|
||||
|
||||
Fl_Double_Window *w = new Fl_Double_Window( 1000, 500 );
|
||||
|
||||
|
|
|
@ -48,6 +48,18 @@
|
|||
|
||||
|
||||
#include "SpectrumView.H"
|
||||
#include "string.h"
|
||||
|
||||
bool
|
||||
Module_Parameter_Editor::is_probably_eq ( void )
|
||||
{
|
||||
const char *name = _module->label();
|
||||
|
||||
return strcasestr( name, "eq" ) ||
|
||||
strcasestr( name, "filter" ) ||
|
||||
strcasestr( name, "parametric" ) ||
|
||||
strcasestr( name, "band" );
|
||||
}
|
||||
|
||||
Module_Parameter_Editor::Module_Parameter_Editor ( Module *module ) : Fl_Double_Window( 900,240)
|
||||
{
|
||||
|
@ -125,19 +137,28 @@ Module_Parameter_Editor::update_spectrum ( void )
|
|||
{
|
||||
nframes_t nframes = 4096;
|
||||
float *buf = new float[nframes];
|
||||
|
||||
memset( buf, 0, sizeof(float) * nframes );
|
||||
|
||||
buf[0] = 1;
|
||||
|
||||
SpectrumView *o = spectrum_view;
|
||||
|
||||
o->sample_rate( _module->sample_rate() );
|
||||
|
||||
bool show = false;
|
||||
|
||||
if ( ! _module->get_impulse_response( buf, nframes ) )
|
||||
{
|
||||
o->data( buf, 1 );
|
||||
/* o->hide(); */
|
||||
}
|
||||
show = is_probably_eq();
|
||||
else
|
||||
show = true;
|
||||
|
||||
o->data( buf, nframes );
|
||||
|
||||
if ( show && ! o->parent()->visible() )
|
||||
{
|
||||
o->data( buf, nframes );
|
||||
o->parent()->show();
|
||||
update_control_visibility();
|
||||
}
|
||||
|
||||
o->redraw();
|
||||
|
@ -156,7 +177,9 @@ Module_Parameter_Editor::make_controls ( void )
|
|||
|
||||
|
||||
Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( (Fl_Widget*)o );
|
||||
|
||||
flg->hide();
|
||||
|
||||
control_pack->add( flg );
|
||||
}
|
||||
|
||||
|
@ -417,10 +440,24 @@ Module_Parameter_Editor::make_controls ( void )
|
|||
controls_by_port[radius_port_number] = o;
|
||||
}
|
||||
|
||||
update_control_visibility();
|
||||
|
||||
update_spectrum();
|
||||
|
||||
update_control_visibility();
|
||||
}
|
||||
|
||||
void
|
||||
Module_Parameter_Editor::update_control_visibility ( void )
|
||||
{
|
||||
for ( unsigned int i = 0; i < _module->control_input.size(); ++i )
|
||||
{
|
||||
const Module::Port *p = &_module->control_input[i];
|
||||
|
||||
if ( p->hints.visible )
|
||||
controls_by_port[i]->parent()->show();
|
||||
else
|
||||
controls_by_port[i]->parent()->hide();
|
||||
}
|
||||
|
||||
control_pack->dolayout();
|
||||
|
||||
int width = control_pack->w() + 100;
|
||||
|
@ -435,20 +472,7 @@ Module_Parameter_Editor::make_controls ( void )
|
|||
|
||||
size( width, height );
|
||||
size_range( width, height, width, height );
|
||||
}
|
||||
|
||||
void
|
||||
Module_Parameter_Editor::update_control_visibility ( void )
|
||||
{
|
||||
for ( unsigned int i = 0; i < _module->control_input.size(); ++i )
|
||||
{
|
||||
const Module::Port *p = &_module->control_input[i];
|
||||
|
||||
if ( p->hints.visible )
|
||||
controls_by_port[i]->parent()->show();
|
||||
else
|
||||
controls_by_port[i]->parent()->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -79,6 +79,8 @@ class Module_Parameter_Editor : public Fl_Double_Window
|
|||
void make_controls ( void );
|
||||
void update_spectrum ( void );
|
||||
|
||||
bool is_probably_eq ( void );
|
||||
|
||||
static void menu_cb ( Fl_Widget *w, void *v );
|
||||
void menu_cb ( Fl_Menu_ *m );
|
||||
|
||||
|
|
|
@ -781,10 +781,6 @@ Plugin_Module::handle_port_connection_change ( void )
|
|||
bool
|
||||
Plugin_Module::get_impulse_response ( sample_t *buf, nframes_t nframes )
|
||||
{
|
||||
memset( buf, 0, sizeof( float ) * nframes );
|
||||
|
||||
buf[0] = 1;
|
||||
|
||||
apply( buf, nframes );
|
||||
|
||||
if ( buffer_is_digital_black( buf + 1, nframes - 1 ))
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
static std::map<int,float*> _cached_plan;
|
||||
|
||||
unsigned int SpectrumView::_nframes = 0;
|
||||
float SpectrumView::_fmin = 10;
|
||||
float SpectrumView::_fmax = 24000;
|
||||
unsigned int SpectrumView::_sample_rate = 48000;
|
||||
|
@ -52,13 +53,30 @@ SpectrumView::data ( float *data, unsigned int nframes )
|
|||
delete[] _data;
|
||||
|
||||
_data = data;
|
||||
_nframes = nframes;
|
||||
|
||||
_data_frames = nframes;
|
||||
|
||||
clear_bands();
|
||||
|
||||
impulse_frames( nframes );
|
||||
|
||||
redraw();
|
||||
}
|
||||
|
||||
void
|
||||
SpectrumView::clear_plans ( void )
|
||||
{
|
||||
/* invalidate all plans */
|
||||
|
||||
for ( std::map<int,float*>::iterator i = _cached_plan.begin();
|
||||
i != _cached_plan.end();
|
||||
i++ )
|
||||
{
|
||||
delete[] i->second;
|
||||
}
|
||||
|
||||
_cached_plan.clear();
|
||||
}
|
||||
|
||||
void
|
||||
SpectrumView::sample_rate ( unsigned int sample_rate )
|
||||
{
|
||||
|
@ -68,16 +86,18 @@ SpectrumView::sample_rate ( unsigned int sample_rate )
|
|||
_fmin = 10;
|
||||
_fmax = _sample_rate * 0.5f;
|
||||
|
||||
/* invalidate all plans */
|
||||
clear_plans();
|
||||
}
|
||||
}
|
||||
|
||||
for ( std::map<int,float*>::iterator i = _cached_plan.begin();
|
||||
i != _cached_plan.end();
|
||||
i++ )
|
||||
{
|
||||
delete[] i->second;
|
||||
}
|
||||
void
|
||||
SpectrumView::impulse_frames ( unsigned int nframes )
|
||||
{
|
||||
if ( _nframes != nframes )
|
||||
{
|
||||
clear_plans();
|
||||
|
||||
_cached_plan.clear();
|
||||
_nframes = nframes;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,6 +147,9 @@ qft_plan ( unsigned frames, unsigned samples, float Fs, float Fmin, float Fmax )
|
|||
void
|
||||
SpectrumView::analyze_data ( unsigned int _plan_size )
|
||||
{
|
||||
if ( ! _data )
|
||||
return;
|
||||
|
||||
float res[_plan_size * 2];
|
||||
memset(res,0,sizeof(float) * _plan_size * 2);
|
||||
|
||||
|
@ -192,7 +215,7 @@ SpectrumView::SpectrumView ( int X, int Y, int W, int H, const char *L )
|
|||
{
|
||||
_auto_level = 0;
|
||||
_data = 0;
|
||||
_nframes = 0;
|
||||
_data_frames = 0;
|
||||
_bands = 0;
|
||||
_dbmin = -70;
|
||||
_dbmax = 30;
|
||||
|
@ -265,6 +288,9 @@ SpectrumView::draw_semilog ( void )
|
|||
void
|
||||
SpectrumView::draw_curve ( void )
|
||||
{
|
||||
if ( !_bands )
|
||||
return;
|
||||
|
||||
int W = w() - padding_right;
|
||||
|
||||
//Build lines
|
||||
|
@ -283,6 +309,16 @@ SpectrumView::draw ( void )
|
|||
|
||||
int W = w() - padding_right;
|
||||
int H = h() - padding_bottom;
|
||||
|
||||
if ( _data_frames != _nframes )
|
||||
{
|
||||
/* invalid data */
|
||||
if ( _data )
|
||||
delete[] _data;
|
||||
_data = 0;
|
||||
|
||||
clear_bands();
|
||||
}
|
||||
|
||||
if ( !_bands ) {
|
||||
analyze_data( W );
|
||||
|
|
|
@ -25,9 +25,10 @@ class SpectrumView : public Fl_Box
|
|||
static unsigned int _sample_rate;
|
||||
static float _fmin;
|
||||
static float _fmax;
|
||||
static unsigned int _nframes;
|
||||
|
||||
float * _data;
|
||||
unsigned int _nframes;
|
||||
unsigned int _data_frames;
|
||||
float * _bands;
|
||||
float _dbmin;
|
||||
float _dbmax;
|
||||
|
@ -37,10 +38,14 @@ class SpectrumView : public Fl_Box
|
|||
void draw_semilog ( void );
|
||||
void analyze_data ( unsigned int plan_size );
|
||||
void clear_bands ( void );
|
||||
static void clear_plans ( void );
|
||||
|
||||
public:
|
||||
|
||||
static void sample_rate ( unsigned int sample_rate );
|
||||
/* all subsequent calls to data() MUST contain this number of
|
||||
* frames. Changing this value will invalidate all cached plans */
|
||||
static void impulse_frames ( unsigned int nframes );
|
||||
|
||||
/* set dB range. If min == max, then auto leveling will be enabled */
|
||||
void db_range ( float min, float max )
|
||||
|
@ -50,8 +55,10 @@ public:
|
|||
_auto_level = min == max;
|
||||
}
|
||||
|
||||
|
||||
/** /data/ must point to allocated memory. It will be freed when new data is set or when the control is destroyed */
|
||||
void data ( float *data, unsigned int nframes );
|
||||
|
||||
void data ( float *data, unsigned int data_frames );
|
||||
|
||||
SpectrumView ( int X, int Y, int W, int H, const char *L=0 );
|
||||
virtual ~SpectrumView ( );
|
||||
|
|
Loading…
Reference in New Issue