Skip to content

Commit d03fd36

Browse files
committed
feat(dependencies): 更新依赖项和修复代码逻辑
- 在 package.json 中新增 @fontsource/bravura 依赖,并将 typescript 版本从 ^5.5.3 降级至 ^5.4.2。 - 更新 yarn.lock 文件以反映依赖项的变化。 - 修改多个组件和工具类,优化吉他和钢琴和弦处理逻辑,使用 ChordTool 替代原有的和弦位置映射,提升代码整洁性和可维护性。 - 增强代码注释,符合jsdoc规范,提升可读性和维护性。
1 parent 9c2136f commit d03fd36

File tree

14 files changed

+359
-411
lines changed

14 files changed

+359
-411
lines changed

examples/index.html

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<link rel="icon" type="ico" href="/favicon.ico" />
6-
<meta
7-
name="viewport"
8-
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
9-
/>
10-
<title>Simple Notation - 简谱展示工具</title>
11-
<style>
12-
html {
13-
margin: 0;
14-
padding: 0;
15-
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC',
16-
'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial,
17-
'Hiragino Sans GB', 'Heiti SC', 'WenQuanYi Micro Hei', sans-serif;
18-
background-color: #f5f5f5;
19-
position: relative;
20-
overflow: auto;
21-
}
22-
body {
23-
display: flex;
24-
flex-direction: column;
25-
box-sizing: border-box;
26-
}
27-
</style>
28-
</head>
29-
<body
30-
class="bg-gradient-to-br from-gray-100 to-gray-300 min-h-screen px-4 pt-40 pb-40"
31-
>
32-
<div id="app"></div>
33-
<script type="module" src="/src/main.ts"></script>
34-
</body>
35-
</html>
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="ico" href="/favicon.ico" />
7+
<meta name="viewport"
8+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
9+
<title>Simple Notation - 简谱展示工具</title>
10+
<style>
11+
html {
12+
margin: 0;
13+
padding: 0;
14+
font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC',
15+
'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial,
16+
'Hiragino Sans GB', 'Heiti SC', 'WenQuanYi Micro Hei', sans-serif;
17+
background-color: #f5f5f5;
18+
position: relative;
19+
overflow: auto;
20+
}
21+
22+
body {
23+
display: flex;
24+
flex-direction: column;
25+
box-sizing: border-box;
26+
}
27+
</style>
28+
</head>
29+
30+
<body class="bg-gradient-to-br from-gray-100 to-gray-300 min-h-screen px-4 pt-40 pb-40">
31+
<div id="app"></div>
32+
<script type="module" src="/src/main.ts"></script>
33+
</body>
34+
35+
</html>

examples/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function convertMidiToSnTemplate(midiData: Midi): SNTemplate {
368368
let measureCount = 0;
369369
track.notes.forEach((note, index) => {
370370
const noteIndex = index + 1;
371-
const noteData = SNTransition.General.MidiToSimpleNote(note.midi);
371+
const noteData = SNTransition.General.midiToSimpleNote(note.midi);
372372
if (noteIndex % 4 === 0) {
373373
score += noteData + '|';
374374
measureCount++;

examples/src/components/instrument/PanelGuitar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ import { computed, ref, onMounted, onUnmounted, type CSSProperties } from 'vue';
108108
import { useTone } from '../../use/useTone';
109109
import { useGuitarStore } from '../../stores';
110110
import { GuitarPosition } from '../../model';
111-
import { guitarTuning } from '@types';
111+
import { SNTransition } from '@utils';
112112
113113
const guitarStore = useGuitarStore();
114114
const guitarFretboard = ref<HTMLElement | null>(null);
@@ -257,7 +257,7 @@ function getStringSegmentStyle(stringIndex: number): CSSProperties {
257257
* @returns {string | null} - 音名,如果无效则返回 null
258258
*/
259259
function getStringFretNote(stringIndex: number, fret: number): string | null {
260-
const openNote = guitarTuning[stringIndex];
260+
const openNote = SNTransition.guitarTuningNoteNameMap[stringIndex];
261261
if (!openNote) return null;
262262
const openMidi = noteNameToMidi(openNote);
263263
const playedMidi = openMidi + fret;

examples/src/stores/instrument/guitar.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed, ref } from 'vue';
33
import type { GuitarPosition } from '../../model';
44
import { useTone } from '../../use/useTone';
55
import { SNTransition } from '@utils';
6-
import { getGuitarPositionsForChord, getMidiForGuitarPosition } from '@utils';
6+
import { ChordTool } from '@utils';
77

88
export const useGuitarStore = defineStore('guitar', () => {
99
// 使用 ref 来存储高亮显示的品位/弦组合
@@ -30,12 +30,12 @@ export const useGuitarStore = defineStore('guitar', () => {
3030
const chordNotes: string[] = [];
3131

3232
chordSymbols.forEach((symbol) => {
33-
const fretPositions = getGuitarPositionsForChord(symbol);
33+
const fretPositions = ChordTool.getGuitarPositionsForChord(symbol);
3434
if (fretPositions.length > 0) {
3535
fretPositions.forEach((fret: number | null, stringIndex: number) => {
3636
const stringNumber = 6 - stringIndex; // Convert 0-5 index to 6-1 string number
3737
if (fret !== null) {
38-
const playedMidi = getMidiForGuitarPosition(
38+
const playedMidi = ChordTool.getMidiForGuitarPosition(
3939
stringNumber,
4040
fret + transpose.value,
4141
);

examples/src/stores/instrument/piano.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
22
import { computed, ref } from 'vue';
33
import { PianoKey } from '../../model';
44
import { useTone } from '../../use/useTone';
5-
import { getPianoNotesForChord } from '@utils';
5+
import { ChordTool } from '@utils';
66

77
export const usePianoStore = defineStore('piano', () => {
88
const keys = ref<PianoKey[]>([]);
@@ -28,7 +28,7 @@ export const usePianoStore = defineStore('piano', () => {
2828
const midisToHighlight: number[] = [];
2929

3030
chordSymbols.forEach((symbol) => {
31-
const notes = getPianoNotesForChord(symbol);
31+
const notes = ChordTool.getPianoNotesForChord(symbol);
3232
if (notes.length > 0) {
3333
notesToPlay.push(...notes);
3434
// Explicitly type the result of map to number[]

lib/src/components/note.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { SNConfig, SNRuntime } from '@config';
1313
import { SNTieLineLayer } from '@layers';
1414
import { SNChordLayer } from '@layers';
1515
import { SNPointerLayer } from '@layers';
16-
import { getPianoNotesForChord } from '@utils';
16+
import { ChordTool } from '@utils';
1717

1818
/**
1919
* SNNote 类 - 简谱音符渲染组件
@@ -533,7 +533,7 @@ export class SNNote extends SNBox {
533533
SNConfig.score.chordLineHeight;
534534

535535
if (this.chord && this.chord.length > 0) {
536-
const parsedNotes = getPianoNotesForChord(this.chord[0]).map(
536+
const parsedNotes = ChordTool.getPianoNotesForChord(this.chord[0]).map(
537537
(noteName) => SNTransition.General.noteNameToParsedNote(noteName),
538538
);
539539

lib/src/core/parser/abc-parser.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
SNAbcKey,
44
SNData,
55
SNDataInfo,
6+
SNGraceNoteOptions,
7+
SNMultiNoteOptions,
68
SNNoteOptions,
7-
SNNoteParserOptions,
89
SNStaveOptions,
910
} from '@types';
1011
import { SNConfig } from '@config';
@@ -135,15 +136,17 @@ export class AbcParser extends BaseParser {
135136
* @param noteData - 音符的原始字符串数据
136137
* @returns 解析后的音符信息对象
137138
*/
138-
parseNote(noteData: string): SNNoteParserOptions {
139+
parseNote(noteData: string): SNNoteOptions {
139140
const weight = 10;
140141
let nodeTime = 0;
141142
let upDownCount = 0;
142143
let octaveCount = 0;
143144
let underlineCount = 0;
145+
let isDelay = false;
144146
let isTieStart = false;
145147
let isTieEnd = false;
146-
let graceNotes: SNNoteParserOptions['graceNotes'] = [];
148+
let graceNotes: SNGraceNoteOptions[] = [];
149+
const multiNotes: SNMultiNoteOptions[] = [];
147150
let chord: string[] = [];
148151
let durationNum = 4; // 默认四分音符
149152

@@ -285,6 +288,7 @@ export class AbcParser extends BaseParser {
285288
}
286289
if (dot) {
287290
nodeTime *= 1.5;
291+
isDelay = true;
288292
}
289293
// underlineCount根据nodetime与一拍(四分音符=1)关系判断
290294
const timeDenominator =
@@ -298,14 +302,17 @@ export class AbcParser extends BaseParser {
298302
else underlineCount = 0;
299303
return {
300304
weight,
305+
noteData,
301306
nodeTime,
302307
note: jianpu,
303308
underlineCount,
304309
upDownCount,
305310
octaveCount,
311+
isDelay,
306312
isTieStart,
307313
isTieEnd,
308314
graceNotes,
315+
multiNotes,
309316
isError: false,
310317
chord,
311318
duration: durationNum,
@@ -314,13 +321,16 @@ export class AbcParser extends BaseParser {
314321
return {
315322
weight,
316323
nodeTime,
324+
noteData,
317325
note: noteData,
318326
underlineCount,
319327
upDownCount: 0,
320328
octaveCount: 0,
329+
isDelay,
321330
isTieStart,
322331
isTieEnd,
323332
graceNotes,
333+
multiNotes,
324334
isError: false,
325335
chord,
326336
duration: durationNum,
@@ -372,9 +382,11 @@ export class AbcParser extends BaseParser {
372382
underlineCount,
373383
upDownCount,
374384
octaveCount,
385+
isDelay,
375386
isTieStart,
376387
isTieEnd,
377388
graceNotes,
389+
multiNotes,
378390
chord,
379391
duration,
380392
} = this.parseNote(noteData);
@@ -393,9 +405,11 @@ export class AbcParser extends BaseParser {
393405
underlineCount,
394406
upDownCount,
395407
octaveCount,
408+
isDelay,
396409
isTieStart,
397410
isTieEnd,
398411
graceNotes,
412+
multiNotes,
399413
isError,
400414
chord,
401415
x: 0,

lib/src/core/parser/base-parser.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
SNData,
3-
SNDataInfo,
4-
SNNoteOptions,
5-
SNNoteParserOptions,
6-
SNStaveOptions,
7-
} from '@types';
1+
import { SNData, SNDataInfo, SNNoteOptions, SNStaveOptions } from '@types';
82

93
/**
104
* 抽象解析器基类,定义乐谱解析的核心方法接口
@@ -28,7 +22,7 @@ export abstract class BaseParser {
2822
* @param noteData - 音符的原始字符串数据
2923
* @returns 解析后的音符信息对象
3024
*/
31-
abstract parseNote(noteData: string): SNNoteParserOptions;
25+
abstract parseNote(noteData: string): SNNoteOptions;
3226

3327
/**
3428
* 解析单个小节的数据

lib/src/layers/chord.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SNNote, SNStave } from '@components';
2-
import { guitarChordPositionsMap, Logger, SvgUtils } from '@utils';
2+
import { ChordTool, Logger, SvgUtils } from '@utils';
33
import { SNConfig } from '@config';
44
import { SNChordType } from '@types';
55

@@ -108,7 +108,7 @@ export class SNChordLayer {
108108
sectionRepeatGroup.appendChild(lPath);
109109

110110
elementToDraw = sectionRepeatGroup;
111-
} else if (guitarChordPositionsMap[symbol]) {
111+
} else if (ChordTool.guitarChordPositionsMap[symbol]) {
112112
// 绘制和弦符号
113113
// 和弦符号位置相对于当前音符中心
114114
const chordX = baseX;
@@ -117,7 +117,7 @@ export class SNChordLayer {
117117
if (chordType === 'guitar') {
118118
// 查找和弦指位(吉他指位图)
119119
const positions =
120-
guitarChordPositionsMap[symbol] ??
120+
ChordTool.guitarChordPositionsMap[symbol] ??
121121
SNChordLayer.defaultChordPositions;
122122
elementToDraw = SvgUtils.createGuitarChordDiagram(
123123
symbol,

0 commit comments

Comments
 (0)