From f2916d10b958a1b58dd6fc07842c65c80654a4d4 Mon Sep 17 00:00:00 2001 From: Alexey Yakovenko Date: Sun, 13 Sep 2009 11:13:01 +0200 Subject: reduced volumebar range to -50..0dB --- callbacks.c | 23 +++++++++++++---------- volume.c | 14 ++++++++++---- volume.h | 3 +++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/callbacks.c b/callbacks.c index e04241e5..3d13b550 100644 --- a/callbacks.c +++ b/callbacks.c @@ -1042,9 +1042,9 @@ volumebar_draw (GtkWidget *widget) { if (!cr) { return; } - + float range = -volume_get_min_db (); int n = widget->allocation.width / 4; - float vol = (60.f + volume_get_db ()) / 60.f * n; + float vol = (range + volume_get_db ()) / range * n; float h = 16; for (int i = 0; i < n; i++) { float iy = (float)i + 3; @@ -1096,12 +1096,13 @@ on_volumebar_motion_notify_event (GtkWidget *widget, gpointer user_data) { if (event->state & GDK_BUTTON1_MASK) { - float volume = event->x / widget->allocation.width * 60.f - 60.f; + float range = -volume_get_min_db (); + float volume = event->x / widget->allocation.width * range - range; if (volume > 0) { volume = 0; } - if (volume < -60) { - volume = -60; + if (volume < -range) { + volume = -range; } volume_set_db (volume); volumebar_draw (widget); @@ -1115,9 +1116,10 @@ on_volumebar_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) { - float volume = event->x / widget->allocation.width * 60.f - 60.f; - if (volume < -60) { - volume = -60; + float range = -volume_get_min_db (); + float volume = event->x / widget->allocation.width * range - range; + if (volume < -range) { + volume = -range; } if (volume > 0) { volume = 0; @@ -1166,6 +1168,7 @@ on_volumebar_scroll_event (GtkWidget *widget, GdkEventScroll *event, gpointer user_data) { + float range = -volume_get_min_db (); float vol = volume_get_db (); if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT) { vol += 1; @@ -1176,8 +1179,8 @@ on_volumebar_scroll_event (GtkWidget *widget, if (vol > 0) { vol = 0; } - else if (vol < -60) { - vol = -60; + else if (vol < -range) { + vol = -range; } volume_set_db (vol); GtkWidget *volumebar = lookup_widget (mainwin, "volumebar"); diff --git a/volume.c b/volume.c index 6726dd9f..7b82623e 100644 --- a/volume.c +++ b/volume.c @@ -21,20 +21,22 @@ #include "volume.h" #include "session.h" +#define VOLUME_MIN (-50.f) + static float volume_db = 0; // in dB static float volume_amp = 1; // amplitude [0..1] void volume_set_db (float dB) { - if (dB < -60) { - dB = -60; + if (dB < VOLUME_MIN) { + dB = VOLUME_MIN; } if (dB > 0) { dB = 0; } session_set_volume (dB); volume_db = dB; - volume_amp = dB > -60 ? db_to_amp (dB) : 0; + volume_amp = dB > VOLUME_MIN ? db_to_amp (dB) : 0; } float @@ -51,7 +53,7 @@ volume_set_amp (float amp) { amp = 1; } volume_amp = amp; - volume_db = amp > 0 ? amp_to_db (amp) : -60.f; + volume_db = amp > 0 ? amp_to_db (amp) : VOLUME_MIN; session_set_volume (volume_db); } @@ -70,3 +72,7 @@ amp_to_db (float amp) { return 20*log10 (amp); } +float +volume_get_min_db (void) { + return VOLUME_MIN; +} diff --git a/volume.h b/volume.h index b6c2868d..a372cc1c 100644 --- a/volume.h +++ b/volume.h @@ -37,4 +37,7 @@ db_to_amp (float dB); float amp_to_db (float amp); +float +volume_get_min_db (void); + #endif // __VOLUME_H -- cgit v1.2.3