Skip to content

Commit

Permalink
feat: 调整transPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
liningzhu committed Jan 15, 2024
1 parent f1301cd commit 6edef93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/buitar/src/style/definitions/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $pcLayout: "only screen and (min-width: 499px)";
--btn-margin: 1.6px;

--font-10: 10px;
--font-12: 10px;
--font-12: 11px;
--font-14: 12px;
--font-16: 14px;
--font-18: 16px;
Expand Down
33 changes: 22 additions & 11 deletions packages/to-guitar/src/utils/trans-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,31 @@ const transChordTaps = (
}

/**
* 过滤 和弦指法手指按位超过 fingerSpan(正常指法不超过4根手指)
* 过滤 和弦指法手指按位超过 4(正常指法不超过4根手指,这里4不是fingerSpan「和弦品位跨度」
* & 手指不超过 1
* & 最小品不超过 12 (超过12品重复的八度音高)
* & 非零最小品不超过 12 (超过12品重复的八度音高)
* @param taps
*/
const fingersFilter = (taps: Point[]) => {
// 最小品位(最小品位超过1,则为横按指法)
const minGrade = Math.min(...taps.map((tap) => tap.grade))
let fingerNums = minGrade > 0 ? 1 : 0
// 非零最小品位
let notZeroMinGrade = Infinity
taps.forEach((tap) => {
if (tap.grade > minGrade) {
fingerNums++
}
if (tap.grade > 0 && tap.grade < notZeroMinGrade) {
notZeroMinGrade = tap.grade
}
})
return fingerNums <= fingerSpan && fingerNums >= 1 && minGrade < 12
return fingerNums <= 4 && fingerNums >= 1 && minGrade < 12 && notZeroMinGrade < 12
}

/**
* 过滤 非完整和弦音组成
* @todo 优化 真实的和弦组成音不一定绝对完整,比如七和弦可以不要 5 音
* @param taps
*/
const integrityFilter = (taps: Point[]) => {
Expand All @@ -373,9 +379,9 @@ const transChordTaps = (
* @param tapsA
* @param tapsB
*/
const gradeSorter = (chordA: BoardChord, chordB: BoardChord) => {
const maxGradeA = Math.max(...chordA.chordTaps.map((tap) => tap.grade))
const maxGradeB = Math.max(...chordB.chordTaps.map((tap) => tap.grade))
const gradeSorter = (chordTapsA: Point[], chordTapsB: Point[]) => {
const maxGradeA = Math.max(...chordTapsA.map((tap) => tap.grade))
const maxGradeB = Math.max(...chordTapsB.map((tap) => tap.grade))
return maxGradeA - maxGradeB
}

Expand Down Expand Up @@ -426,6 +432,7 @@ const transChordTaps = (
findNextString(point.string, [point], list)
// 过滤无效和弦
list = list.filter(integrityFilter).filter(fingersFilter).filter(repeatingPitchFilter)
// 增加当前point为根音的和弦
root.chordTapsList.push(...list)
}
})
Expand All @@ -435,16 +442,17 @@ const transChordTaps = (
// 扁平化多转位和弦
overRoots.forEach((item) => {
// 格式化当前转位的所有和弦
let tempList = item.chordTapsList.map(
let tempList = item.chordTapsList.sort(gradeSorter).map(
(taps) => ({ chordType: item.chordType, chordTaps: taps } as BoardChord)
)
// 所有和弦指位去重
tempList = coverTapsReduce(tempList)
tapsList.push(...tempList)

if(tempList){
tapsList.push(...tempList)
}
})

// 根据品位排序
tapsList = tapsList.sort(gradeSorter).filter((item)=>!!item)
return tapsList
}

Expand Down Expand Up @@ -547,7 +555,10 @@ const getTapsFromBoard = (tones: Pitch[], options: TapsRangeProps) => {
return points
}

/**根据指位获取Taps */
/**
* 根据指位获取Taps
* { x弦, y品} => Point
*/
const getTapsOnBoard = (positions: BoardPosition[], keyboard: BoardOption['keyboard']) => {
return positions.map(({ string, grade }) => keyboard[string - 1][grade])
}
Expand Down
2 changes: 1 addition & 1 deletion packages/to-guitar/src/utils/trans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const transChordType = (chords: Tone[], calGrades?: number) => {
}

/**
* 五度圈 数组
* 五度圈 ToneSchema 数组
* @param root 根音 默认「C」
*/
const transFifthsCircle = (root: Tone = 'C') => {
Expand Down

0 comments on commit 6edef93

Please sign in to comment.