Skip to content

Commit

Permalink
vumeter[-qt]: Do some cleanup work
Browse files Browse the repository at this point in the history
  • Loading branch information
radioactiveman committed Jan 6, 2025
1 parent ba69553 commit ceaf237
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 43 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ if test "x$USE_GTK" = "xyes" ; then
echo " Search Tool: yes"
echo " Spectrum Analyzer (2D): yes"
echo " Status Icon: yes"
echo " VU Meter: yes"
echo " X11 Global Hotkeys: $have_hotkey"
echo " X11 On-Screen Display (aosd): $have_aosd"
echo
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ if meson.version().version_compare('>= 0.53')
'Search Tool': true,
'Spectrum Analyzer (2D)': true,
'Status Icon': true,
'VU Meter': get_option('vumeter'),
'X11 Global Hotkeys': get_variable('have_hotkey', false),
'X11 On-Screen Display (aosd)': get_variable('have_aosd', false),
}, section: 'GTK Support')
Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ option('speedpitch', type: 'boolean', value: true,
option('gl-spectrum', type: 'boolean', value: true,
description: 'Whether the OpenGL spectrum visualization plugin is enabled')
option('vumeter', type: 'boolean', value: true,
description: 'Whether the VUMeter visualization plugin is enabled')
description: 'Whether the VU Meter visualization plugin is enabled')


# interface plugins
Expand Down
5 changes: 4 additions & 1 deletion src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ if conf.has('USE_GTK')
subdir('search-tool')
subdir('skins')
subdir('statusicon')
subdir('vumeter')

if get_option('aosd')
subdir('aosd')
Expand All @@ -160,6 +159,10 @@ if conf.has('USE_GTK')
if get_option('hotkey')
subdir('hotkey')
endif

if get_option('vumeter')
subdir('vumeter')
endif
endif


Expand Down
44 changes: 6 additions & 38 deletions src/vumeter-qt/vumeter_qt_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,24 @@ float VUMeterQtWidget::get_db_on_range(float db)

float VUMeterQtWidget::get_db_factor(float db)
{
float factor = 0.0f;
float factor;

if (db < -db_range)
{
factor = 0.0f;
}
else if (db < -60.0f)
{
factor = (db + db_range) * 2.5f/(db_range-60);
}
else if (db < -50.0f)
{
factor = (db + 60.0f) * 0.5f + 2.5f;
}
else if (db < -40.0f)
{
factor = (db + 50.0f) * 0.75f + 7.5f;
}
else if (db < -30.0f)
{
factor = (db + 40.0f) * 1.5f + 15.0f;
}
else if (db < -20.0f)
{
factor = (db + 30.0f) * 2.0f + 30.0f;
}
else if (db < 0.0f)
{
factor = (db + 20.0f) * 2.5f + 50.0f;
}
else
{
factor = 100.0f;
}

return factor / 100.0f;
}
Expand All @@ -86,7 +70,7 @@ float VUMeterQtWidget::get_y_from_db(float db)

void VUMeterQtWidget::render_multi_pcm (const float * pcm, int channels)
{
nchannels = aud::clamp(channels, 0, max_channels);
nchannels = aud::clamp(channels, 1, max_channels);

float * peaks = new float[nchannels];
for (int channel = 0; channel < nchannels; channel++)
Expand All @@ -105,9 +89,7 @@ void VUMeterQtWidget::render_multi_pcm (const float * pcm, int channels)
for (int i = 0; i < nchannels; i++)
{
float n = peaks[i];

float db = 20 * log10f(n);
db = get_db_on_range(db);
float db = get_db_on_range(20 * log10f(n));

if (db > channels_db_level[i])
{
Expand Down Expand Up @@ -195,20 +177,12 @@ void VUMeterQtWidget::draw_vu_legend(QPainter & p)
p.setPen(pen);
for (int i = 0; i >= -60; i--)
{
draw_vu_legend_line(p, i);

if (i > -30)
{
draw_vu_legend_line(p, i);
draw_vu_legend_line(p, i - 0.5, 0.5);
}
else if (i > -40)
{
draw_vu_legend_line(p, i);
}
else if (i >= -60)
{
draw_vu_legend_line(p, i);
else if (i <= -40)
i -= 1;
}
}
draw_vu_legend_line(p, -db_range);
}
Expand Down Expand Up @@ -310,17 +284,11 @@ void VUMeterQtWidget::draw_visualizer(QPainter & p)
QString VUMeterQtWidget::format_db(const float val)
{
if (val > -10)
{
return QString::number(val, 'f', 1);
}
else if (val > -db_range)
{
return QString::number(val, 'f', 0);
}
else
{
return QString("-inf");
}
}

float VUMeterQtWidget::get_bar_width(int channels)
Expand Down
4 changes: 1 addition & 3 deletions src/vumeter/vumeter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ static void draw_legend (cairo_t * cr)

if (i > -30)
draw_vu_legend_line (cr, i - 0.5, 0.5);
else if (i > -40) {}
// no-op
else if (i >= -60)
else if (i <= -40)
i -= 1;
}

Expand Down

0 comments on commit ceaf237

Please sign in to comment.