feat: use a function to convert volume set by the user to a scale of -60~0 dB. Then convert dB to a factor from 0 to 1 used as the real volume factor.

This commit is contained in:
Terry Geng
2020-06-08 17:30:37 +08:00
parent 32e32774eb
commit 5f67517dc3
3 changed files with 64 additions and 42 deletions

View File

@ -319,7 +319,7 @@ def status():
'empty': False,
'play': not var.bot.is_pause,
'mode': var.playlist.mode,
'volume': var.bot.volume_set,
'volume': var.bot.get_displayed_volume(),
'playhead': var.bot.playhead
})
@ -329,7 +329,7 @@ def status():
'empty': True,
'play': not var.bot.is_pause,
'mode': var.playlist.mode,
'volume': var.bot.volume_set,
'volume': var.bot.get_displayed_volume(),
'playhead': 0
})
@ -486,31 +486,31 @@ def post():
elif action == "clear":
var.bot.clear()
elif action == "volume_up":
if var.bot.volume_set + 0.03 < 1.0:
var.bot.volume_set = var.bot.volume_set + 0.03
if var.bot.get_displayed_volume() + 0.03 < 1.0:
var.bot.convert_set_volume(var.bot.unconverted_volume + 0.03)
else:
var.bot.volume_set = 1.0
var.db.set('bot', 'volume', str(var.bot.volume_set))
log.info("web: volume up to %d" % (var.bot.volume_set * 100))
var.bot.convert_set_volume(1.0)
var.db.set('bot', 'volume', str(var.bot.get_displayed_volume()))
log.info("web: volume up to %d" % (var.bot.get_displayed_volume() * 100))
elif action == "volume_down":
if var.bot.volume_set - 0.03 > 0:
var.bot.volume_set = var.bot.volume_set - 0.03
if var.bot.get_displayed_volume() - 0.03 > 0:
var.bot.convert_set_volume(var.bot.unconverted_volume - 0.03)
else:
var.bot.volume_set = 0
var.db.set('bot', 'volume', str(var.bot.volume_set))
log.info("web: volume up to %d" % (var.bot.volume_set * 100))
var.bot.convert_set_volume(1.0)
var.db.set('bot', 'volume', str(var.bot.get_displayed_volume()))
log.info("web: volume down to %d" % (var.bot.get_displayed_volume() * 100))
elif action == "volume_set_value":
if 'new_volume' in request.form:
if float(request.form['new_volume']) > 1:
var.bot.volume_set = 1
var.bot.convert_set_volume(1.0)
elif float(request.form['new_volume']) < 0:
var.bot.volume_set = 0
var.bot.convert_set_volume(0)
else:
# value for new volume is between 0 and 1, round to two decimal digits
var.bot.volume_set = round(float(request.form['new_volume']), 2)
var.bot.convert_set_volume(round(float(request.form['new_volume']), 2))
var.db.set('bot', 'volume', str(var.bot.volume_set))
log.info("web: volume set to %d" % (var.bot.volume_set * 100))
var.db.set('bot', 'volume', str(var.bot.get_displayed_volume()))
log.info("web: volume set to %d" % (var.bot.get_displayed_volume() * 100))
return status()