Skip to content

Commit

Permalink
播放速率设置面板新增是否音调补偿设置
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed May 31, 2023
1 parent 0adb4f5 commit 677c3f1
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions publish/changeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 新增

- 新增音效设置(实验性功能),支持10段均衡器设置、内置的一些环境混响音效、3D立体环绕音效
- 播放速率设置面板新增是否音调补偿设置,在调整播放速率后,可以选择是否启用音调补偿,默认启用

### 修复

Expand Down
1 change: 1 addition & 0 deletions src/common/defaultSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const defaultSetting: LX.AppSetting = {
'player.volume': 1,
'player.isMute': false,
'player.playbackRate': 1,
'player.preservesPitch': true,
'player.mediaDeviceId': 'default',
'player.isMediaDeviceRemovedStopPlay': false,
'player.isShowLyricTranslation': false,
Expand Down
5 changes: 5 additions & 0 deletions src/common/types/app_setting.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ declare global {
*/
'player.playbackRate': number

/**
* 是否自动调整音频的音高以补偿对播放速率设置所做的更改
*/
'player.preservesPitch': boolean

/**
* 音频输出设备id
*/
Expand Down
1 change: 1 addition & 0 deletions src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"player__play_toggle_mode_off": "Disable",
"player__play_toggle_mode_random": "List Random",
"player__play_toggle_mode_single_loop": "Single Loop",
"player__playback_preserves_pitch": "Pitch compensation",
"player__playback_rate": "Current playback rate:",
"player__playback_rate_reset_btn": "Reset",
"player__playing": "Now playing...",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"player__play_toggle_mode_off": "禁用",
"player__play_toggle_mode_random": "列表随机",
"player__play_toggle_mode_single_loop": "单曲循环",
"player__playback_preserves_pitch": "音调补偿",
"player__playback_rate": "当前播放速率:",
"player__playback_rate_reset_btn": "重置",
"player__playing": "播放中...",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
"player__play_toggle_mode_off": "禁用",
"player__play_toggle_mode_random": "列表隨機",
"player__play_toggle_mode_single_loop": "單曲循環",
"player__playback_preserves_pitch": "音調補償",
"player__playback_rate": "當前播放速率:",
"player__playback_rate_reset_btn": "重置",
"player__playing": "播放中...",
Expand Down
23 changes: 21 additions & 2 deletions src/renderer/components/common/PlaybackRateBtn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
<div :class="$style.setting">
<div :class="$style.info">
<span>{{ playbackRate.toFixed(2) }}x</span>
<base-btn min @click="handleUpdatePlaybackRate(100)">{{ $t('player__playback_rate_reset_btn') }}</base-btn>
<div :class="$style.control">
<base-checkbox
id="player__playback_preserves_pitch"
:model-value="appSetting['player.preservesPitch']"
:label="$t('player__playback_preserves_pitch')"
@update:model-value="updatePreservesPitch"
/>
<base-btn min @click="handleUpdatePlaybackRate(100)">{{ $t('player__playback_rate_reset_btn') }}</base-btn>
</div>
</div>
<base-slider-bar :class="$style.slider" :value="playbackRate * 100" :min="60" :max="200" @change="handleUpdatePlaybackRate" />
<base-slider-bar :class="$style.slider" :value="playbackRate * 100" :min="50" :max="200" @change="handleUpdatePlaybackRate" />
</div>
</template>
</material-popup-btn>
Expand All @@ -20,11 +28,17 @@
<script setup>
// import { computed } from '@common/utils/vueTools'
import { playbackRate } from '@renderer/store/player/playbackRate'
import { appSetting, updateSetting } from '@renderer/store/setting'
const handleUpdatePlaybackRate = (val) => {
window.app_event.setPlaybackRate(Math.round(val) / 100)
}
const updatePreservesPitch = (enabled) => {
updateSetting({ 'player.preservesPitch': enabled })
}
// const icon = computed(() => {
// return playbackRate.value == 0
// ? '#icon-volume-off-outline'
Expand Down Expand Up @@ -100,6 +114,11 @@ const handleUpdatePlaybackRate = (val) => {
line-height: 1;
}
}
.control {
align-items: center;
display: flex;
gap: 10px;
}
.slider {
width: 100%;
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/core/useApp/usePlayer/usePlaybackRate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { onBeforeUnmount, watch } from '@common/utils/vueTools'
import { setPlaybackRate as setPlayerPlaybackRate } from '@renderer/plugins/player'
import { setPlaybackRate as setPlayerPlaybackRate, setPreservesPitch } from '@renderer/plugins/player'

import { debounce } from '@common/utils'
// import { HOTKEY_PLAYER } from '@common/hotKey'
Expand All @@ -11,6 +11,7 @@ export default () => {

setPlaybackRate(appSetting['player.playbackRate'])
setPlayerPlaybackRate(appSetting['player.playbackRate'])
setPreservesPitch(appSetting['player.preservesPitch'])


const handleSetPlaybackRate = (num: number) => {
Expand Down Expand Up @@ -41,6 +42,11 @@ export default () => {
})


watch(() => appSetting['player.preservesPitch'], preservesPitch => {
setPreservesPitch(preservesPitch)
})


// window.key_event.on(HOTKEY_PLAYER.volume_up.action, hotkeyVolumeUp)
// window.key_event.on(HOTKEY_PLAYER.volume_down.action, hotkeyVolumeDown)
window.app_event.on('setPlaybackRate', handleSetPlaybackRate)
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/plugins/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ export const setPlaybackRate = (rate: number) => {
audio.playbackRate = rate
}

export const setPreservesPitch = (preservesPitch: boolean) => {
if (!audio) return
audio.preservesPitch = preservesPitch
}

export const getMute = (): boolean => {
return audio?.muted ?? false
}
Expand Down

0 comments on commit 677c3f1

Please sign in to comment.