Skip to content

Commit

Permalink
Support UltimateGuitar format
Browse files Browse the repository at this point in the history
  • Loading branch information
woshibiantai committed Sep 8, 2024
1 parent 90255ea commit 2c38a2b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { provide, ref } from 'vue';
import { RouterLink, RouterView } from 'vue-router'
const chordProInput = ref('');
const format = ref('chordpro');
provide('chordProInput', chordProInput);
provide('format', format);
import('@/assets/sample-chart.js')
.then(({ sampleChordProChart }) => {
Expand Down
11 changes: 7 additions & 4 deletions src/components/ChordChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<script setup>
import { computed, inject, ref, watch } from 'vue';
import { ChordProParser, Song } from 'chordsheetjs';
import { ChordProParser, Song, UltimateGuitarParser } from 'chordsheetjs';
import ChordChartBodyParagraph from './ChordChartBodyParagraph.vue';
const props = defineProps({
Expand All @@ -62,7 +62,9 @@ const props = defineProps({
const chordProInput = inject('chordProInput');
const parser = new ChordProParser();
const format = inject('format');
const chordProParser = new ChordProParser();
const ultimateGuitarParser = new UltimateGuitarParser();
const song = ref(new Song());
const metadata = computed(() => song.value.metadata);
Expand All @@ -73,10 +75,11 @@ const key = computed(() => metadata.value.get('key'));
const tempo = computed(() => metadata.value.get('tempo'));
const time = computed(() => metadata.value.get('time'));
const title = computed(() => metadata.value.get('title'));
const parser = computed(() => format.value === 'ultimate-guitar' ? ultimateGuitarParser : chordProParser);
watch(chordProInput, (newValue) => {
watch([chordProInput, parser], () => {
try {
song.value = parser.parse(newValue);
song.value = parser.value.parse(chordProInput.value);
} catch(err) {
console.error(err);
}
Expand Down
39 changes: 29 additions & 10 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,36 @@
class="no-print"
@submit.prevent
>
<label for="chordpro-input">Chord chart in ChordPro format:</label>
<label for="chordpro-input">Chord chart in {{ format }} format:</label>
<textarea
ref="textareaRef"
v-model="input"
id="chordpro-input"
rows="10"
/>

<label for="chordpro-transpose">Transpose: </label>
<input
type="number"
id="chordpro-transpose"
v-model="transposition"
max="12"
min="-12"
required
>
<fieldset>
<legend>Settings</legend>
<label for="chordpro-transpose">Transpose: </label>
<input
type="number"
id="chordpro-transpose"
v-model="transposition"
max="12"
min="-12"
required
>

<label for="chordpro-format">Format:</label>
<select
id="chordpro-format"
v-model="format"
required
>
<option value="chordpro" default>ChordPro</option>
<option value="ultimate-guitar">Ultimate Guitar</option>
</select>
</fieldset>
</form>
<ChordChart
:transposition="validatedTransposition"
Expand All @@ -33,6 +46,7 @@
import { computed, inject, defineAsyncComponent, provide, ref, watch } from 'vue';
const ChordChart = defineAsyncComponent(() => import('../components/ChordChart.vue'));
const input = inject('chordProInput');
const format = inject('format');
const textareaRef = ref(null);
const caretPosition = ref(0);
const transposition = ref(0);
Expand Down Expand Up @@ -107,4 +121,9 @@ textarea {
input:invalid {
border-color: red;
}
fieldset {
display: flex;
gap: 8px;
}
</style>

0 comments on commit 2c38a2b

Please sign in to comment.