Skip to content

Commit 0a74d12

Browse files
committed
improve console.warn for probably invalid positions
1 parent 0d36160 commit 0a74d12

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

app.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function expandChord(beatPosition: BeatPosition) {
192192
} else {
193193
const chordData = { chord: getChord(beatPosition), ...beatPosition }
194194
targetedChordId.value = `${chordData.measure}-${chordData.beat}`
195-
console.log(targetedChordId.value)
195+
196196
expandedChords.value.push(chordData)
197197
198198
let direction: 'previous' | 'next' = 'next'

assets/chords/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Chord from '@/models/chord'
22

33
const chords: { [key: string]: Chord } = {
4+
// [string, fret, finger]
45
F: new Chord('F', [
56
[1, 1, 1],
67
[2, 3, 4],

models/chord.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ export default class Chord {
1414
this.generateGrip()
1515
}
1616

17-
private sameStringOrFingerIsUsedTwice = () => {
17+
private warnIfSameStringOrFingerIsUsedTwice = () => {
1818
const strings = this.fingerPositions?.map(p => p[0])
19-
const fingers = this.fingerPositions?.map(p => p[2])
20-
const isUniqueSet = (arr = []) => new Set(arr).size == arr.length
2119

22-
return (!isUniqueSet(strings) || !isUniqueSet(fingers))
20+
if (new Set(strings).size !== strings.length) {
21+
console.warn(`Same string is used twice in ${this.label}`)
22+
}
23+
24+
if (this.fingerPositions.some((p1) => !!this.fingerPositions.find((p2) => {
25+
const [fret, finger] = [1, 2]
26+
27+
return p1[finger] == p2[finger] && p1[fret] !== p2[fret]
28+
}))) {
29+
console.warn(`Same finger is used on different frets in ${this.label}`)
30+
}
2331
}
2432

2533
private generateFingerData = (string) => {
@@ -38,9 +46,7 @@ export default class Chord {
3846
}
3947

4048
private generateGrip = () => {
41-
if (this.sameStringOrFingerIsUsedTwice()) {
42-
console.warn(`Same finger or string is used twice in ${this.label}`)
43-
}
49+
this.warnIfSameStringOrFingerIsUsedTwice()
4450

4551
this.grip = Object.assign({}, ...this.availableStrings.map(this.generateFingerData))
4652
}

0 commit comments

Comments
 (0)