From b3ce29159cdbd1912b19e3610853f93e2a1b926a Mon Sep 17 00:00:00 2001 From: Amaru8 <52407090+Amaru8@users.noreply.github.com> Date: Wed, 18 May 2022 21:45:00 +0200 Subject: [PATCH] Implement wheel support --- .../views/components/audio-playbackrate.ejs | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/renderer/views/components/audio-playbackrate.ejs b/src/renderer/views/components/audio-playbackrate.ejs index 814d57a5..9b40a00d 100644 --- a/src/renderer/views/components/audio-playbackrate.ejs +++ b/src/renderer/views/components/audio-playbackrate.ejs @@ -15,7 +15,7 @@ {{playbackRate}} ×
- +
@@ -29,15 +29,43 @@ data: function () { return { app: this.$root, - playbackRate: this.$root.cfg.audio.playbackRate + playbackRate: this.$root.cfg.audio.playbackRate / 100 } }, watch: { playbackRate: function (newValue, _oldValue) { - this.$root.mk.playbackRate = newValue - this.$root.cfg.audio.playbackRate = newValue - this.playbackRate = newValue + this.saveValue(newValue); } - } + }, + methods: { + playbackRateWheel(event) { + if (app.checkScrollDirectionIsUp(event)) { + this.saveValue(this.$root.cfg.audio.playbackRate + 5); + } else { + this.saveValue(this.$root.cfg.audio.playbackRate - 5); + } + }, + saveValue(newValue) { + newValue = Number(newValue); + if (this.isAllowedRate(newValue)) { + if (newValue > 2) { + newValue = String(newValue).length > 4 ? newValue.toFixed(2) : newValue; + this.$root.mk.playbackRate = newValue / 100; + this.$root.cfg.audio.playbackRate = newValue; + this.playbackRate = newValue / 100; + } else { + newValue = String(newValue).length > 6 ? newValue.toFixed(2) : newValue; + this.$root.mk.playbackRate = newValue; + this.$root.cfg.audio.playbackRate = newValue * 100; + this.playbackRate = newValue; + } + } + }, + isAllowedRate(input) { + if (input >= 25 && input <= 200) { return true } + if (input >= 0.25 && input <= 2) { return true } + return false; + } + } }); \ No newline at end of file