jpfun 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -15
- package/dist/diagnostic.d.ts +29 -2
- package/dist/diagnostic.js +5 -4
- package/dist/functions/arpeggio/index.js +2 -3
- package/dist/functions/bar/index.d.ts +3 -0
- package/dist/functions/bar/index.js +18 -3
- package/dist/functions/beam/layout.js +3 -2
- package/dist/functions/box/index.js +1 -0
- package/dist/functions/dash/index.js +5 -2
- package/dist/functions/div/index.d.ts +1 -1
- package/dist/functions/div/index.js +4 -2
- package/dist/functions/dyn/index.js +1 -0
- package/dist/functions/gliss/index.js +4 -2
- package/dist/functions/grace/index.js +3 -5
- package/dist/functions/head/index.js +23 -30
- package/dist/functions/key/index.js +4 -7
- package/dist/functions/meter/index.d.ts +1 -0
- package/dist/functions/meter/index.js +3 -0
- package/dist/functions/meter/shape.d.ts +1 -1
- package/dist/functions/note/accidentals.d.ts +3 -3
- package/dist/functions/note/accidentals.js +29 -16
- package/dist/functions/note/index.js +11 -13
- package/dist/functions/note/source-transform.d.ts +15 -0
- package/dist/functions/note/source-transform.js +74 -67
- package/dist/functions/ottava/index.js +1 -0
- package/dist/functions/page/index.js +4 -3
- package/dist/functions/rest/index.js +8 -6
- package/dist/functions/slide/index.js +1 -0
- package/dist/functions/temporal.d.ts +9 -3
- package/dist/functions/temporal.js +15 -2
- package/dist/functions/tie/index.js +28 -4
- package/dist/functions/tremolo/index.js +1 -0
- package/dist/functions/tuplet/index.js +1 -0
- package/dist/functions/up/index.js +3 -5
- package/dist/functions/voice/connections.d.ts +1 -1
- package/dist/functions/voice/lyrics.d.ts +9 -5
- package/dist/functions/voice/lyrics.js +148 -44
- package/dist/functions/voice/voice.d.ts +6 -2
- package/dist/functions/voice/voice.js +49 -17
- package/dist/functions/voice/voices.js +2 -1
- package/dist/functions/volta/index.js +1 -0
- package/dist/index.d.ts +97 -3
- package/dist/index.js +97 -3
- package/dist/jpfun.min.js +47 -60
- package/dist/layout/engine.d.ts +4 -3
- package/dist/layout/engine.js +160 -6
- package/dist/layout/model.d.ts +12 -3
- package/dist/layout/model.js +15 -7
- package/dist/layout/page.js +2 -2
- package/dist/layout/path.js +1 -1
- package/dist/layout/types.d.ts +10 -2
- package/dist/parser/grammarType.d.ts +3 -3
- package/dist/parser/parse-utils/brace-utils.js +7 -17
- package/dist/parser/parse-utils/call-utils.d.ts +3 -1
- package/dist/parser/parse-utils/call-utils.js +17 -32
- package/dist/parser/parse-utils/note-utils.d.ts +4 -0
- package/dist/parser/parse-utils/note-utils.js +8 -12
- package/dist/parser/parserContext.d.ts +8 -2
- package/dist/parser/parserContext.js +57 -55
- package/dist/parser/preprocess.d.ts +7 -0
- package/dist/parser/preprocess.js +21 -19
- package/dist/pipeline.d.ts +1 -1
- package/dist/playback/compile.js +1 -1
- package/dist/render/canvas.js +50 -35
- package/dist/render/index.d.ts +1 -1
- package/dist/render/index.js +1 -1
- package/dist/render/paint.d.ts +7 -0
- package/dist/render/paint.js +70 -20
- package/dist/render/recording.d.ts +8 -1
- package/dist/render/recording.js +12 -0
- package/dist/render/svg.d.ts +5 -1
- package/dist/render/svg.js +37 -17
- package/dist/render/text.d.ts +2 -2
- package/dist/render/text.js +7 -6
- package/dist/render/translate.d.ts +3 -1
- package/dist/render/translate.js +6 -0
- package/dist/render/types.d.ts +9 -0
- package/grammar.md +6 -5
- package/package.json +8 -18
- package/dist/converter/midi/convert.d.ts +0 -42
- package/dist/converter/midi/convert.js +0 -682
- package/dist/converter/midi/index.d.ts +0 -5
- package/dist/converter/midi/index.js +0 -11
- package/dist/converter/midi/json.d.ts +0 -38
- package/dist/converter/midi/json.js +0 -1
- package/dist/converter/midi/triplet.d.ts +0 -30
- package/dist/converter/midi/triplet.js +0 -75
- package/dist/converter/musicxml/dom.d.ts +0 -25
- package/dist/converter/musicxml/dom.js +0 -65
- package/dist/converter/musicxml/features.d.ts +0 -114
- package/dist/converter/musicxml/features.js +0 -501
- package/dist/converter/musicxml/index.d.ts +0 -14
- package/dist/converter/musicxml/index.js +0 -1285
- package/dist/converter/musicxml/model.d.ts +0 -176
- package/dist/converter/musicxml/model.js +0 -1
- package/dist/converter/musicxml/resolve.d.ts +0 -10
- package/dist/converter/musicxml/resolve.js +0 -152
- package/dist/converter/source.d.ts +0 -19
- package/dist/converter/source.js +0 -53
- package/dist/core.d.ts +0 -24
- package/dist/core.js +0 -24
- package/dist/jpfun.core.min.js +0 -132
- package/dist/jpfun.from-midi.min.js +0 -9
- package/dist/jpfun.from-musicxml.min.js +0 -12
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import type { Fraction } from "../../fraction.js";
|
|
2
|
-
export interface MusicXmlDiagnostic {
|
|
3
|
-
code: "W_MUSICXML_PERCUSSION_SKIPPED" | "W_MUSICXML_APPROXIMATED" | "W_MUSICXML_UNSUPPORTED_ELEMENT" | "W_MUSICXML_UNATTACHED_CONTENT" | "W_MUSICXML_UNRESOLVED_RELATION";
|
|
4
|
-
severity: "warning";
|
|
5
|
-
message: string;
|
|
6
|
-
location: {
|
|
7
|
-
element: string;
|
|
8
|
-
partId?: string;
|
|
9
|
-
measureIndex?: number;
|
|
10
|
-
measureNumber?: string;
|
|
11
|
-
staff?: string;
|
|
12
|
-
voice?: string;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
type MusicXmlPartLocation = MusicXmlDiagnostic["location"] & {
|
|
16
|
-
partId: string;
|
|
17
|
-
measureIndex: number;
|
|
18
|
-
};
|
|
19
|
-
export interface MusicXmlArpeggio {
|
|
20
|
-
direction: "none" | "up" | "down";
|
|
21
|
-
location: MusicXmlPitch["location"];
|
|
22
|
-
}
|
|
23
|
-
/** 单个书面音高,tie 标记保留在音高上以支持和弦成员独立连音 */
|
|
24
|
-
export interface MusicXmlPitch {
|
|
25
|
-
location: MusicXmlPartLocation & {
|
|
26
|
-
staff: string;
|
|
27
|
-
voice: string;
|
|
28
|
-
};
|
|
29
|
-
step: string;
|
|
30
|
-
alter: number;
|
|
31
|
-
octave: number;
|
|
32
|
-
tieStart: boolean;
|
|
33
|
-
tieStop: boolean;
|
|
34
|
-
glissandi?: {
|
|
35
|
-
kind: "slide" | "glissando";
|
|
36
|
-
number: string;
|
|
37
|
-
type: "start" | "stop";
|
|
38
|
-
}[];
|
|
39
|
-
}
|
|
40
|
-
/** 一个 lane 上的原子事件,同起止音高已合并为一个和弦事件 */
|
|
41
|
-
export interface MusicXmlEvent {
|
|
42
|
-
start: Fraction;
|
|
43
|
-
duration: Fraction;
|
|
44
|
-
pitches: MusicXmlPitch[];
|
|
45
|
-
rest: boolean;
|
|
46
|
-
order: number;
|
|
47
|
-
modifiers: {
|
|
48
|
-
name: string;
|
|
49
|
-
placement: "above" | "below";
|
|
50
|
-
}[];
|
|
51
|
-
annotations: {
|
|
52
|
-
text: string;
|
|
53
|
-
placement: "above" | "below";
|
|
54
|
-
boxed?: boolean;
|
|
55
|
-
}[];
|
|
56
|
-
preGraces: MusicXmlPitch[][];
|
|
57
|
-
postGraces: MusicXmlPitch[][];
|
|
58
|
-
lyrics: Map<string, string>;
|
|
59
|
-
arpeggio?: MusicXmlArpeggio;
|
|
60
|
-
slides?: {
|
|
61
|
-
side: "pre" | "post";
|
|
62
|
-
direction: "up" | "down";
|
|
63
|
-
}[];
|
|
64
|
-
program?: number;
|
|
65
|
-
timeModification?: {
|
|
66
|
-
actual: number;
|
|
67
|
-
normal: number;
|
|
68
|
-
start: boolean;
|
|
69
|
-
stop: boolean;
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/** MusicXML 的 part + staff + voice 对应一条 jpFun lane */
|
|
73
|
-
export interface MusicXmlLane {
|
|
74
|
-
partId: string;
|
|
75
|
-
partName: string;
|
|
76
|
-
staff: string;
|
|
77
|
-
voice: string;
|
|
78
|
-
events: MusicXmlEvent[];
|
|
79
|
-
dynamics?: ({
|
|
80
|
-
at: Fraction;
|
|
81
|
-
location: MusicXmlDiagnostic["location"];
|
|
82
|
-
} & MusicXmlEvent["modifiers"][number])[];
|
|
83
|
-
}
|
|
84
|
-
/** 全谱时间流上的拍号状态点 */
|
|
85
|
-
export interface MusicXmlMeterPoint {
|
|
86
|
-
at: Fraction;
|
|
87
|
-
numerator: number;
|
|
88
|
-
denominator: number;
|
|
89
|
-
}
|
|
90
|
-
/** 全谱时间流上的调号状态点 */
|
|
91
|
-
export interface MusicXmlKeyPoint {
|
|
92
|
-
at: Fraction;
|
|
93
|
-
fifths: number;
|
|
94
|
-
mode: string;
|
|
95
|
-
}
|
|
96
|
-
export type MusicXmlRepeatSymbol = "segno" | "coda" | "dc" | "ds" | "fine" | "tocoda";
|
|
97
|
-
/** 全谱时间流上的反复与跳转记号 */
|
|
98
|
-
export interface MusicXmlRepeatPoint {
|
|
99
|
-
at: Fraction;
|
|
100
|
-
symbol: MusicXmlRepeatSymbol;
|
|
101
|
-
placement: "above" | "below";
|
|
102
|
-
location: MusicXmlDiagnostic["location"];
|
|
103
|
-
}
|
|
104
|
-
/** 尚未附着到事件的力度或文字方向 */
|
|
105
|
-
export interface MusicXmlDirectionPoint {
|
|
106
|
-
location: MusicXmlPartLocation & {
|
|
107
|
-
staff: string;
|
|
108
|
-
};
|
|
109
|
-
at: Fraction;
|
|
110
|
-
placement: "above" | "below";
|
|
111
|
-
dynamic?: string;
|
|
112
|
-
texts: {
|
|
113
|
-
text: string;
|
|
114
|
-
boxed: boolean;
|
|
115
|
-
}[];
|
|
116
|
-
}
|
|
117
|
-
/** 参与楔形线配对的原始起止点 */
|
|
118
|
-
export interface MusicXmlWedgePoint {
|
|
119
|
-
location: MusicXmlDirectionPoint["location"];
|
|
120
|
-
at: Fraction;
|
|
121
|
-
number: string;
|
|
122
|
-
type: "crescendo" | "diminuendo" | "stop";
|
|
123
|
-
}
|
|
124
|
-
/** 已配对的渐强或渐弱区间 */
|
|
125
|
-
export interface MusicXmlWedgeSpan {
|
|
126
|
-
from: MusicXmlWedgePoint;
|
|
127
|
-
end: Fraction;
|
|
128
|
-
}
|
|
129
|
-
/** 参与房子配对的原始起止点 */
|
|
130
|
-
export interface MusicXmlEndingPoint {
|
|
131
|
-
location: MusicXmlPartLocation;
|
|
132
|
-
at: Fraction;
|
|
133
|
-
type: "start" | "stop" | "discontinue";
|
|
134
|
-
passes: number[];
|
|
135
|
-
}
|
|
136
|
-
/** 已配对的房子区间,遍数语义由起点持有 */
|
|
137
|
-
export interface MusicXmlEndingSpan {
|
|
138
|
-
from: MusicXmlEndingPoint;
|
|
139
|
-
end: Fraction;
|
|
140
|
-
}
|
|
141
|
-
/** XML 解析完成后的格式无关乐谱模型,渲染阶段不再读取 DOM */
|
|
142
|
-
export interface ParsedMusicXmlScore {
|
|
143
|
-
title: string;
|
|
144
|
-
subtitle: string;
|
|
145
|
-
creator: string;
|
|
146
|
-
page?: {
|
|
147
|
-
width: number;
|
|
148
|
-
height: number;
|
|
149
|
-
top: number;
|
|
150
|
-
bottom: number;
|
|
151
|
-
left: number;
|
|
152
|
-
right: number;
|
|
153
|
-
};
|
|
154
|
-
lanes: MusicXmlLane[];
|
|
155
|
-
meters: MusicXmlMeterPoint[];
|
|
156
|
-
keys: MusicXmlKeyPoint[];
|
|
157
|
-
tempos: {
|
|
158
|
-
at: Fraction;
|
|
159
|
-
bpm: number;
|
|
160
|
-
location?: MusicXmlDiagnostic["location"];
|
|
161
|
-
}[];
|
|
162
|
-
repeats: MusicXmlRepeatPoint[];
|
|
163
|
-
wedges: MusicXmlWedgeSpan[];
|
|
164
|
-
endings: MusicXmlEndingSpan[];
|
|
165
|
-
bars: Map<string, string>;
|
|
166
|
-
measureBoundaries: Set<string>;
|
|
167
|
-
lineBreaks: Set<string>;
|
|
168
|
-
multipleRests: {
|
|
169
|
-
location: MusicXmlPartLocation;
|
|
170
|
-
start: Fraction;
|
|
171
|
-
end?: Fraction;
|
|
172
|
-
count: number;
|
|
173
|
-
}[];
|
|
174
|
-
end: Fraction;
|
|
175
|
-
}
|
|
176
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MusicXmlDiagnostic, MusicXmlDirectionPoint as DirectionPoint, MusicXmlEndingPoint as EndingPoint, MusicXmlEndingSpan as EndingSpan, MusicXmlLane as Lane, MusicXmlWedgePoint as WedgePoint, MusicXmlWedgeSpan as WedgeSpan } from "./model.js";
|
|
2
|
-
/** 省略 voice 才广播到同 staff;显式目标缺失时不得改写其他声部 */
|
|
3
|
-
export declare function matchingLanes(lanes: readonly Lane[], { partId, staff, voice }: DirectionPoint["location"]): Lane[];
|
|
4
|
-
/** 所有 part 扫描结束后配对关系;此阶段只处理语义点,不读取 DOM 或推进游标 */
|
|
5
|
-
export declare function resolveRelations(wedgePoints: WedgePoint[], endingPoints: EndingPoint[], diagnostics: MusicXmlDiagnostic[]): {
|
|
6
|
-
wedges: WedgeSpan[];
|
|
7
|
-
endings: EndingSpan[];
|
|
8
|
-
};
|
|
9
|
-
/** 锚点先于附着,附着先于拆声部,避免重复文字或遗漏派生声部的力度 */
|
|
10
|
-
export declare function resolveVoices(lanes: Lane[], endings: readonly EndingSpan[], directions: readonly DirectionPoint[], nextOrder: number, partNames: ReadonlyMap<string, string>, diagnostics: MusicXmlDiagnostic[]): Lane[];
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { quote } from "../source.js";
|
|
2
|
-
import { reportDiagnostic } from "./features.js";
|
|
3
|
-
function eventEnd(event) {
|
|
4
|
-
return event.start.clone().add(event.duration);
|
|
5
|
-
}
|
|
6
|
-
/** 省略 voice 才广播到同 staff;显式目标缺失时不得改写其他声部 */
|
|
7
|
-
export function matchingLanes(lanes, { partId, staff, voice }) {
|
|
8
|
-
return lanes.filter(lane => lane.partId === partId && lane.staff === staff && (!voice || lane.voice === voice));
|
|
9
|
-
}
|
|
10
|
-
/** 所有 part 扫描结束后配对关系;此阶段只处理语义点,不读取 DOM 或推进游标 */
|
|
11
|
-
export function resolveRelations(wedgePoints, endingPoints, diagnostics) {
|
|
12
|
-
const wedges = [];
|
|
13
|
-
const activeWedges = new Map();
|
|
14
|
-
for (const point of wedgePoints.sort((left, right) => left.at.compare(right.at))) {
|
|
15
|
-
const { partId, staff, voice = "" } = point.location;
|
|
16
|
-
const key = `${partId}\0${staff}\0${voice}\0${point.number}`;
|
|
17
|
-
if (point.type === "stop") {
|
|
18
|
-
const from = activeWedges.get(key);
|
|
19
|
-
if (from)
|
|
20
|
-
wedges.push({ from, end: point.at });
|
|
21
|
-
else
|
|
22
|
-
reportDiagnostic(diagnostics, "wedgeStart", point.location);
|
|
23
|
-
activeWedges.delete(key);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
const previous = activeWedges.get(key);
|
|
27
|
-
if (previous)
|
|
28
|
-
reportDiagnostic(diagnostics, "wedgeReplaced", previous.location);
|
|
29
|
-
activeWedges.set(key, point);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const point of activeWedges.values())
|
|
33
|
-
reportDiagnostic(diagnostics, "wedgeStop", point.location);
|
|
34
|
-
const endings = [];
|
|
35
|
-
let activeEnding;
|
|
36
|
-
for (const point of endingPoints.sort((left, right) => left.at.compare(right.at))) {
|
|
37
|
-
if (point.type === "start") {
|
|
38
|
-
if (activeEnding)
|
|
39
|
-
reportDiagnostic(diagnostics, "endingReplaced", activeEnding.location);
|
|
40
|
-
activeEnding = point;
|
|
41
|
-
}
|
|
42
|
-
else if (activeEnding) {
|
|
43
|
-
endings.push({ from: activeEnding, end: point.at });
|
|
44
|
-
activeEnding = undefined;
|
|
45
|
-
}
|
|
46
|
-
else
|
|
47
|
-
reportDiagnostic(diagnostics, "endingStart", point.location);
|
|
48
|
-
}
|
|
49
|
-
if (activeEnding)
|
|
50
|
-
reportDiagnostic(diagnostics, "endingStop", activeEnding.location);
|
|
51
|
-
return { wedges, endings };
|
|
52
|
-
}
|
|
53
|
-
/** 为无起音的有效房子补休止端点;锚点不得覆盖已有长音,并延续解析阶段的事件次序 */
|
|
54
|
-
function anchorEndings(lanes, endings, directions, order, partNames) {
|
|
55
|
-
const topLane = lanes[0];
|
|
56
|
-
if (!topLane)
|
|
57
|
-
return;
|
|
58
|
-
for (const ending of endings) {
|
|
59
|
-
if (ending.from.at.compare(ending.end) >= 0)
|
|
60
|
-
continue;
|
|
61
|
-
const direction = directions.find(item => item.at.compare(ending.from.at) >= 0 && item.at.compare(ending.end) < 0);
|
|
62
|
-
const hostPartId = direction?.location.partId ?? topLane.partId;
|
|
63
|
-
const hostStaff = direction?.location.staff ?? topLane.staff;
|
|
64
|
-
const hostLanes = lanes.filter(lane => lane.partId === hostPartId && lane.staff === hostStaff);
|
|
65
|
-
if (hostLanes.some(lane => lane.events.some(event => event.start.compare(ending.from.at) >= 0 && event.start.compare(ending.end) < 0)))
|
|
66
|
-
continue;
|
|
67
|
-
let hostLane = hostLanes.find(lane => !lane.events.some(event => event.start.compare(ending.end) < 0 && eventEnd(event).compare(ending.from.at) > 0));
|
|
68
|
-
if (!hostLane) {
|
|
69
|
-
const voices = hostLanes.map(lane => Number(lane.voice)).filter(Number.isFinite);
|
|
70
|
-
hostLane = {
|
|
71
|
-
partId: hostPartId,
|
|
72
|
-
partName: partNames.get(hostPartId) ?? hostPartId,
|
|
73
|
-
staff: hostStaff,
|
|
74
|
-
voice: String(Math.max(0, ...voices) + 1),
|
|
75
|
-
events: [],
|
|
76
|
-
};
|
|
77
|
-
lanes.push(hostLane);
|
|
78
|
-
}
|
|
79
|
-
hostLane.events.push({
|
|
80
|
-
start: ending.from.at.clone(),
|
|
81
|
-
duration: ending.end.clone().sub(ending.from.at),
|
|
82
|
-
pitches: [],
|
|
83
|
-
rest: true,
|
|
84
|
-
order: order++,
|
|
85
|
-
modifiers: [],
|
|
86
|
-
annotations: [],
|
|
87
|
-
preGraces: [],
|
|
88
|
-
postGraces: [],
|
|
89
|
-
lyrics: new Map(),
|
|
90
|
-
});
|
|
91
|
-
hostLane.events.sort((left, right) => left.start.compare(right.start) || left.order - right.order);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/** 无 voice 的力度作用于同 staff 的全部 lane;文字只附着一次,允许使用刚补出的房子锚点 */
|
|
95
|
-
function attachDirections(lanes, directions, diagnostics) {
|
|
96
|
-
for (const direction of directions) {
|
|
97
|
-
const targets = matchingLanes(lanes, direction.location);
|
|
98
|
-
if (direction.dynamic && targets.length === 0) {
|
|
99
|
-
reportDiagnostic(diagnostics, "dynamicHost", { ...direction.location, element: "dynamics" }, direction.dynamic);
|
|
100
|
-
}
|
|
101
|
-
if (direction.dynamic) {
|
|
102
|
-
const dynamic = {
|
|
103
|
-
at: direction.at,
|
|
104
|
-
name: direction.dynamic,
|
|
105
|
-
placement: direction.placement,
|
|
106
|
-
location: { ...direction.location, element: "dynamics" },
|
|
107
|
-
};
|
|
108
|
-
for (const lane of targets)
|
|
109
|
-
(lane.dynamics ??= []).push(dynamic);
|
|
110
|
-
}
|
|
111
|
-
if (direction.texts.length === 0)
|
|
112
|
-
continue;
|
|
113
|
-
let target;
|
|
114
|
-
findTarget: for (const lane of targets)
|
|
115
|
-
for (const event of lane.events) {
|
|
116
|
-
const position = event.start.compare(direction.at);
|
|
117
|
-
if (position < 0 && eventEnd(event).compare(direction.at) > 0) {
|
|
118
|
-
target = event;
|
|
119
|
-
break findTarget;
|
|
120
|
-
}
|
|
121
|
-
if (!target || target.start.compare(direction.at) < 0 || position >= 0
|
|
122
|
-
&& (event.start.compare(target.start) < 0 || event.start.equals(target.start) && event.order < target.order))
|
|
123
|
-
target = event;
|
|
124
|
-
}
|
|
125
|
-
for (const annotation of direction.texts) {
|
|
126
|
-
if (target)
|
|
127
|
-
target.annotations.push({ ...annotation, placement: direction.placement });
|
|
128
|
-
else
|
|
129
|
-
reportDiagnostic(diagnostics, "textHost", { ...direction.location, element: annotation.boxed ? "rehearsal" : "words" }, quote(annotation.text));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/** 附着完成后拆分重叠事件;所有派生 lane 继承原有的声部身份及精确力度控制点 */
|
|
134
|
-
function splitOverlappingLanes(lanes) {
|
|
135
|
-
return lanes.flatMap(lane => {
|
|
136
|
-
const parallel = [];
|
|
137
|
-
for (const event of [...lane.events].sort((left, right) => left.start.compare(right.start) || left.order - right.order)) {
|
|
138
|
-
const target = parallel.find(candidate => eventEnd(candidate.events.at(-1)).compare(event.start) <= 0);
|
|
139
|
-
if (target)
|
|
140
|
-
target.events.push(event);
|
|
141
|
-
else
|
|
142
|
-
parallel.push({ ...lane, events: [event] });
|
|
143
|
-
}
|
|
144
|
-
return parallel.length ? parallel : [lane];
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
/** 锚点先于附着,附着先于拆声部,避免重复文字或遗漏派生声部的力度 */
|
|
148
|
-
export function resolveVoices(lanes, endings, directions, nextOrder, partNames, diagnostics) {
|
|
149
|
-
anchorEndings(lanes, endings, directions, nextOrder, partNames);
|
|
150
|
-
attachDirections(lanes, directions, diagnostics);
|
|
151
|
-
return splitOverlappingLanes(lanes);
|
|
152
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { quote } from "../parser/parse-utils/string-utils.js";
|
|
2
|
-
export type PitchMode = "relative" | "absolute";
|
|
3
|
-
interface HeadOptions {
|
|
4
|
-
title?: string;
|
|
5
|
-
subtitle?: string;
|
|
6
|
-
author?: string;
|
|
7
|
-
key: string;
|
|
8
|
-
meter: readonly [numerator: number, denominator: number];
|
|
9
|
-
tempo: number;
|
|
10
|
-
}
|
|
11
|
-
/** 按书写顺序把多个零时长标记叠到主体上方。 */
|
|
12
|
-
export declare function attachAbove(source: string, additions: readonly string[]): string;
|
|
13
|
-
/** 将相对主音的半音差写成简谱音高 token。 */
|
|
14
|
-
export declare function renderRelativePitch(semitoneOffset: number): string;
|
|
15
|
-
/** 将绝对音名、升降号与八度写成 jpFun 音高 token。 */
|
|
16
|
-
export declare function renderAbsolutePitch(name: string, accidental: string, octave: number): string;
|
|
17
|
-
export declare function renderHead(options: HeadOptions): string;
|
|
18
|
-
/** 把“每个声部的各系统”转置成“每个系统的完整声部组” */
|
|
19
|
-
export declare function renderSystems(groups: readonly (readonly string[])[]): string;
|
package/dist/converter/source.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/** MIDI 与 MusicXML 共享的 jpFun 源码片段生成工具 */
|
|
2
|
-
import { quote } from "../parser/parse-utils/string-utils.js";
|
|
3
|
-
export { quote } from "../parser/parse-utils/string-utils.js";
|
|
4
|
-
const HEAD_TEXT_PRESET = {
|
|
5
|
-
title: "size=2em, align=center",
|
|
6
|
-
subtitle: "size=0.85em, align=center",
|
|
7
|
-
author: "size=0.8em, align=right",
|
|
8
|
-
};
|
|
9
|
-
const RELATIVE_NAMES = ["1", "#1", "2", "#2", "3", "4", "#4", "5", "#5", "6", "#6", "7"];
|
|
10
|
-
/** 按书写顺序把多个零时长标记叠到主体上方。 */
|
|
11
|
-
export function attachAbove(source, additions) {
|
|
12
|
-
for (let index = additions.length - 1; index >= 0; index--) {
|
|
13
|
-
source = `{${source} ^ ${additions[index]}}`;
|
|
14
|
-
}
|
|
15
|
-
return source;
|
|
16
|
-
}
|
|
17
|
-
/** 将相对主音的半音差写成简谱音高 token。 */
|
|
18
|
-
export function renderRelativePitch(semitoneOffset) {
|
|
19
|
-
const pitchClass = ((semitoneOffset % 12) + 12) % 12;
|
|
20
|
-
const octave = Math.floor(semitoneOffset / 12);
|
|
21
|
-
const octaveMarks = octave > 0 ? "'".repeat(octave) : ",".repeat(-octave);
|
|
22
|
-
return `${RELATIVE_NAMES[pitchClass]}${octaveMarks}`;
|
|
23
|
-
}
|
|
24
|
-
/** 将绝对音名、升降号与八度写成 jpFun 音高 token。 */
|
|
25
|
-
export function renderAbsolutePitch(name, accidental, octave) {
|
|
26
|
-
return octave === 0 ? `@note(${name}, ${accidental}, 0)` : `${name}${accidental}${octave}`;
|
|
27
|
-
}
|
|
28
|
-
function renderHeadText(field, value) {
|
|
29
|
-
// 会被注释、续行或 DSL 语法误读的文本改用显式 @text,其余保留简洁的 H.* 裸文本
|
|
30
|
-
const needsExplicitText = value.trim() !== value
|
|
31
|
-
|| /[\r\n%]/.test(value) || /^\s*[@{]/.test(value) || value.endsWith("\\");
|
|
32
|
-
return needsExplicitText
|
|
33
|
-
? `H.${field}: @text(${quote(value)}, ${HEAD_TEXT_PRESET[field]})`
|
|
34
|
-
: `H.${field}: ${value}`;
|
|
35
|
-
}
|
|
36
|
-
export function renderHead(options) {
|
|
37
|
-
const [numerator, denominator] = options.meter;
|
|
38
|
-
const lines = [];
|
|
39
|
-
if (options.title)
|
|
40
|
-
lines.push(renderHeadText("title", options.title));
|
|
41
|
-
if (options.subtitle)
|
|
42
|
-
lines.push(renderHeadText("subtitle", options.subtitle));
|
|
43
|
-
if (options.author)
|
|
44
|
-
lines.push(renderHeadText("author", options.author));
|
|
45
|
-
lines.push(`H.signature: 1=${options.key} ${numerator}/${denominator}`);
|
|
46
|
-
lines.push(`H.tempo: ${options.tempo}`);
|
|
47
|
-
return lines.join("\n");
|
|
48
|
-
}
|
|
49
|
-
/** 把“每个声部的各系统”转置成“每个系统的完整声部组” */
|
|
50
|
-
export function renderSystems(groups) {
|
|
51
|
-
const systemCount = Math.max(0, ...groups.map(lines => lines.length));
|
|
52
|
-
return Array.from({ length: systemCount }, (_, index) => groups.map(lines => lines[index]).filter(Boolean).join("\n")).join("\n\n");
|
|
53
|
-
}
|
package/dist/core.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from "./pipeline.js";
|
|
2
|
-
export * from "./functions/ASTtypes.js";
|
|
3
|
-
export * from "./functions/temporal.js";
|
|
4
|
-
export * from "./functions/default.js";
|
|
5
|
-
export { symbols, type OrnamentPattern, type SymbolDefinition, type SymbolShape, } from "./functions/symbol/index.js";
|
|
6
|
-
export { transformNotes, type NoteTransform, type SourceEdit } from "./functions/note/index.js";
|
|
7
|
-
export * from "./diagnostic.js";
|
|
8
|
-
export * from "./fraction.js";
|
|
9
|
-
export * from "./parser/types.js";
|
|
10
|
-
export * from "./parser/grammarType.js";
|
|
11
|
-
export * from "./parser/parserContext.js";
|
|
12
|
-
export * from "./parser/preprocess.js";
|
|
13
|
-
export * from "./lowering/types.js";
|
|
14
|
-
export * from "./lowering/loweringContext.js";
|
|
15
|
-
export * from "./lowering/track.js";
|
|
16
|
-
export * from "./playback/types.js";
|
|
17
|
-
export * from "./playback/time.js";
|
|
18
|
-
export * from "./playback/compile.js";
|
|
19
|
-
export * from "./layout/types.js";
|
|
20
|
-
export * from "./layout/model.js";
|
|
21
|
-
export * from "./layout/default.js";
|
|
22
|
-
export * from "./layout/page.js";
|
|
23
|
-
export * from "./layout/engine.js";
|
|
24
|
-
export * from "./render/index.js";
|
package/dist/core.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export * from "./pipeline.js";
|
|
2
|
-
export * from "./functions/ASTtypes.js";
|
|
3
|
-
export * from "./functions/temporal.js";
|
|
4
|
-
export * from "./functions/default.js";
|
|
5
|
-
export { symbols, } from "./functions/symbol/index.js";
|
|
6
|
-
export { transformNotes } from "./functions/note/index.js";
|
|
7
|
-
export * from "./diagnostic.js";
|
|
8
|
-
export * from "./fraction.js";
|
|
9
|
-
export * from "./parser/types.js";
|
|
10
|
-
export * from "./parser/grammarType.js";
|
|
11
|
-
export * from "./parser/parserContext.js";
|
|
12
|
-
export * from "./parser/preprocess.js";
|
|
13
|
-
export * from "./lowering/types.js";
|
|
14
|
-
export * from "./lowering/loweringContext.js";
|
|
15
|
-
export * from "./lowering/track.js";
|
|
16
|
-
export * from "./playback/types.js";
|
|
17
|
-
export * from "./playback/time.js";
|
|
18
|
-
export * from "./playback/compile.js";
|
|
19
|
-
export * from "./layout/types.js";
|
|
20
|
-
export * from "./layout/model.js";
|
|
21
|
-
export * from "./layout/default.js";
|
|
22
|
-
export * from "./layout/page.js";
|
|
23
|
-
export * from "./layout/engine.js";
|
|
24
|
-
export * from "./render/index.js";
|