From 90255ea48bd82eb1ab9a88bcd908cda130bd1549 Mon Sep 17 00:00:00 2001 From: Ruth Wong Date: Sun, 8 Sep 2024 19:56:51 +0800 Subject: [PATCH] Support transposition --- src/components/ChordChart.vue | 13 ++++++++++++- src/views/HomeView.vue | 28 ++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/components/ChordChart.vue b/src/components/ChordChart.vue index b59d4cc..fcf14a6 100644 --- a/src/components/ChordChart.vue +++ b/src/components/ChordChart.vue @@ -49,11 +49,15 @@ import { computed, inject, ref, watch } from 'vue'; import { ChordProParser, Song } from 'chordsheetjs'; import ChordChartBodyParagraph from './ChordChartBodyParagraph.vue'; -defineProps({ +const props = defineProps({ columns: { type: Number, default: 1, }, + transposition: { + type: Number, + default: 0, + }, }); @@ -77,6 +81,13 @@ watch(chordProInput, (newValue) => { console.error(err); } }, { immediate: true }); + +watch(() => props.transposition, (newValue, oldValue) => { + if (song.value) { + const difference = newValue - oldValue; + song.value = song.value.transpose(difference); + } +}, { immediate: true });