jpfun 0.5.0 → 0.7.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.
Files changed (79) hide show
  1. package/dist/converter/midi/convert.d.ts +3 -1
  2. package/dist/converter/midi/convert.js +78 -66
  3. package/dist/converter/musicxml/features.d.ts +19 -5
  4. package/dist/converter/musicxml/features.js +46 -8
  5. package/dist/converter/musicxml/index.js +142 -23
  6. package/dist/converter/musicxml/model.d.ts +15 -0
  7. package/dist/diagnostic.js +1 -1
  8. package/dist/functions/ASTtypes.d.ts +4 -0
  9. package/dist/functions/ASTtypes.js +25 -14
  10. package/dist/functions/adjust/index.js +6 -2
  11. package/dist/functions/arpeggio/index.js +21 -17
  12. package/dist/functions/arpeggio/shape.d.ts +1 -1
  13. package/dist/functions/arpeggio/shape.js +27 -21
  14. package/dist/functions/bar/index.js +37 -36
  15. package/dist/functions/beam/auto.js +18 -24
  16. package/dist/functions/beam/layout.js +15 -23
  17. package/dist/functions/box/index.js +52 -1
  18. package/dist/functions/br/index.js +3 -4
  19. package/dist/functions/default.js +10 -5
  20. package/dist/functions/div/index.js +2 -3
  21. package/dist/functions/gliss/index.d.ts +2 -0
  22. package/dist/functions/gliss/index.js +180 -0
  23. package/dist/functions/grace/index.d.ts +4 -2
  24. package/dist/functions/grace/index.js +19 -11
  25. package/dist/functions/head/index.js +50 -62
  26. package/dist/functions/meter/index.js +45 -24
  27. package/dist/functions/meter/shape.d.ts +3 -0
  28. package/dist/functions/meter/shape.js +43 -0
  29. package/dist/functions/note/accidentals.js +10 -16
  30. package/dist/functions/note/index.js +38 -48
  31. package/dist/functions/ottava/index.d.ts +2 -0
  32. package/dist/functions/ottava/index.js +217 -0
  33. package/dist/functions/page/index.js +3 -3
  34. package/dist/functions/pagebreak/index.d.ts +2 -0
  35. package/dist/functions/pagebreak/index.js +36 -0
  36. package/dist/functions/rest/index.d.ts +2 -0
  37. package/dist/functions/rest/index.js +231 -0
  38. package/dist/functions/slide/index.d.ts +2 -0
  39. package/dist/functions/slide/index.js +132 -0
  40. package/dist/functions/stack/index.js +8 -15
  41. package/dist/functions/symbol/index.d.ts +9 -0
  42. package/dist/functions/symbol/index.js +41 -12
  43. package/dist/functions/symbol/ornament.js +15 -20
  44. package/dist/functions/symbol/shape.js +4 -1
  45. package/dist/functions/symbol/symbols/fine.js +1 -1
  46. package/dist/functions/symbol/symbols/tr.js +46 -1
  47. package/dist/functions/temporal.d.ts +36 -12
  48. package/dist/functions/temporal.js +29 -9
  49. package/dist/functions/tie/index.js +46 -32
  50. package/dist/functions/tuplet/index.js +1 -1
  51. package/dist/functions/up/index.js +51 -33
  52. package/dist/functions/voice/connections.d.ts +19 -0
  53. package/dist/functions/voice/connections.js +90 -0
  54. package/dist/functions/voice/index.js +245 -99
  55. package/dist/functions/volta/index.js +41 -21
  56. package/dist/jpfun.core.min.js +48 -55
  57. package/dist/jpfun.from-midi.min.js +5 -5
  58. package/dist/jpfun.from-musicxml.min.js +8 -8
  59. package/dist/jpfun.min.js +57 -64
  60. package/dist/layout/engine.d.ts +4 -1
  61. package/dist/layout/engine.js +232 -75
  62. package/dist/layout/model.js +22 -66
  63. package/dist/layout/page.d.ts +3 -2
  64. package/dist/layout/page.js +7 -6
  65. package/dist/layout/types.d.ts +34 -45
  66. package/dist/lowering/loweringContext.d.ts +1 -1
  67. package/dist/lowering/loweringContext.js +41 -171
  68. package/dist/parser/parserContext.d.ts +2 -0
  69. package/dist/parser/parserContext.js +31 -14
  70. package/dist/parser/preprocess.js +4 -6
  71. package/dist/playback/compile.js +12 -3
  72. package/dist/playback/types.d.ts +4 -2
  73. package/dist/render/paint.js +1 -1
  74. package/dist/render/svg.js +1 -0
  75. package/dist/render/text.d.ts +1 -1
  76. package/dist/render/text.js +3 -2
  77. package/dist/render/types.d.ts +1 -0
  78. package/grammar.md +221 -257
  79. package/package.json +1 -1
@@ -18,7 +18,9 @@ export interface MidiToJpFunOptions {
18
18
  title?: string;
19
19
  }
20
20
  export interface MidiLayoutCapability {
21
- compileScore: (source: string) => {
21
+ compileScore: (source: string, options?: {
22
+ horizontalOnly?: boolean;
23
+ }) => {
22
24
  layout: {
23
25
  objects: {
24
26
  T: {
@@ -263,12 +263,12 @@ function automaticLineBreaks(source, bars, scale, capability) {
263
263
  // 超宽页面关闭自动换行,从真实布局对象取得每个小节的自然宽度
264
264
  const naturalWidth = Math.max(1_000_000, source.length * 64);
265
265
  const naturalSource = `@page(width=${naturalWidth}px, height=0px, top=0px, bottom=0px, left=0px, right=0px)\n${source}`;
266
- const layout = capability.compileScore(naturalSource).layout;
267
- const bodyLine = Math.max(...layout.objects.filter(node => !node.T.isZero()).map(node => node.layoutLine));
268
- const bodyObjects = layout.objects.filter(node => node.layoutLine === bodyLine && node.box.w > 0);
266
+ const layout = capability.compileScore(naturalSource, { horizontalOnly: true }).layout;
269
267
  const measureBounds = bars.map(() => ({ left: Infinity, right: -Infinity }));
270
- // 按对象起点归入小节,小节线本身属于左侧刚结束的小节
271
- for (const node of bodyObjects) {
268
+ // 测宽候选不含 head,所有正文可见对象均位于第 0 行;按起点归入小节,小节线归入左侧刚结束的小节
269
+ for (const node of layout.objects) {
270
+ if (node.box.w <= 0)
271
+ continue;
272
272
  const at = Math.round(node.t.toNumber() * scale);
273
273
  let low = 0;
274
274
  let high = bars.length;
@@ -340,20 +340,22 @@ function itemHead(item, pitchMode, suffix = "", labels) {
340
340
  * dash 只允许延续本小节内已经出现的音;跨小节或不足一拍时重写同音,
341
341
  * 每个和弦成员分别收集完整标签链,音结束时一次输出 @tie(x, y, ...)。
342
342
  */
343
- function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMode, bars, lineBreaks, adjustments, programs, nextTieLabel) {
343
+ function renderLane(lane, rangeStart, rangeEnd, lineSpan, rhythmScale, timeFactor, pitchMode, bars, regionBars, lineBreaks, adjustments, programs, nextTieLabel) {
344
344
  // 事件边界与所有控制点共同切分时间线,保证每个片段内语义不变
345
345
  const points = new Set([rangeStart, rangeEnd]);
346
346
  for (const item of lane.items) {
347
347
  points.add(item.start);
348
348
  points.add(item.end);
349
349
  }
350
- for (const at of bars)
351
- if (at > rangeStart && at < rangeEnd)
352
- points.add(at);
353
- for (const at of adjustments?.keys() ?? []) {
354
- if (at >= rangeStart && at < rangeEnd)
355
- points.add(at);
350
+ for (const at of regionBars)
351
+ points.add(at);
352
+ if (adjustments) {
353
+ for (const at of adjustments.keys()) {
354
+ if (at >= rangeStart && at < rangeEnd)
355
+ points.add(at);
356
+ }
356
357
  }
358
+ // 测宽也保留 program 控制点,避免持续音的切分与完整源码不同。
357
359
  for (const at of programs.keys()) {
358
360
  if (at >= rangeStart && at < rangeEnd)
359
361
  points.add(at);
@@ -368,28 +370,33 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
368
370
  return label;
369
371
  });
370
372
  // 预扫描找出不能只用 dash 延续的音符,提前为其建立逐音高标签链
371
- for (const item of lane.items) {
372
- if ("members" in item)
373
- continue;
374
- const startIndex = timelineIndex.get(item.start);
375
- for (let index = startIndex; timeline[index] < item.end; index++) {
376
- const suffixes = rhythmSuffixes((timeline[index + 1] - timeline[index]) / timeFactor, rhythmScale);
377
- if ((timeline[index] > item.start && bars.has(timeline[index]))
378
- || suffixes.some((suffix, suffixIndex) => (timeline[index] > item.start || suffixIndex > 0) && suffix.includes("/"))) {
379
- tieChains.set(item, item.notes.map(() => []));
380
- break;
373
+ if (nextTieLabel) {
374
+ for (const item of lane.items) {
375
+ if ("members" in item)
376
+ continue;
377
+ const startIndex = timelineIndex.get(item.start);
378
+ for (let index = startIndex; timeline[index] < item.end; index++) {
379
+ const suffixes = rhythmSuffixes((timeline[index + 1] - timeline[index]) / timeFactor, rhythmScale);
380
+ if ((timeline[index] > item.start && bars.has(timeline[index]))
381
+ || suffixes.some((suffix, suffixIndex) => (timeline[index] > item.start || suffixIndex > 0) && suffix.includes("/"))) {
382
+ tieChains.set(item, item.notes.map(() => []));
383
+ break;
384
+ }
381
385
  }
382
386
  }
383
387
  }
384
- const outputs = Array.from({ length: lineBreaks.size + 1 }, () => []);
385
- let outputIndex = [...lineBreaks].filter(at => at <= rangeStart).length;
388
+ const outputs = Array.from({ length: lineSpan }, () => []);
389
+ let outputIndex = 0;
386
390
  let itemIndex = 0;
387
- let initialProgram = programs.size ? 0 : undefined;
388
- let programStart = -Infinity;
389
- for (const [at, program] of programs) {
390
- if (at <= rangeStart && at >= programStart) {
391
- initialProgram = program;
392
- programStart = at;
391
+ let initialProgram;
392
+ if (nextTieLabel && programs.size) {
393
+ initialProgram = 0;
394
+ let programStart = -Infinity;
395
+ for (const [at, program] of programs) {
396
+ if (at <= rangeStart && at >= programStart) {
397
+ initialProgram = program;
398
+ programStart = at;
399
+ }
393
400
  }
394
401
  }
395
402
  // 沿时间片单向推进当前事件,依次输出控制项、音符或补齐休止
@@ -404,9 +411,11 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
404
411
  const next = timeline[index + 1];
405
412
  if (next === undefined)
406
413
  continue;
407
- const program = at === rangeStart ? initialProgram : programs.get(at);
408
- if (program !== undefined)
409
- outputs[outputIndex].push(`@program(${program})`);
414
+ if (nextTieLabel) {
415
+ const program = at === rangeStart ? initialProgram : programs.get(at);
416
+ if (program !== undefined)
417
+ outputs[outputIndex].push(`@program(${program})`);
418
+ }
410
419
  const changes = adjustments?.get(at) ?? [];
411
420
  const item = lane.items[itemIndex];
412
421
  if (item && item.start <= at && item.end >= next) {
@@ -426,25 +435,11 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
426
435
  for (let suffixIndex = 0; suffixIndex < suffixes.length; suffixIndex++) {
427
436
  const suffix = suffixes[suffixIndex];
428
437
  const continuation = at > item.start || suffixIndex > 0;
429
- let token;
430
438
  const chains = tieChains.get(item);
431
- if (!continuation) {
432
- if (chains) {
433
- token = itemHead(item, pitchMode, suffix, extendTieChains(chains));
434
- }
435
- else {
436
- token = itemHead(item, pitchMode, suffix);
437
- }
438
- }
439
- else if ((suffixIndex === 0 && bars.has(at)) || suffix.includes("/")) {
440
- token = itemHead(item, pitchMode, suffix, extendTieChains(chains));
441
- }
442
- else {
443
- token = `-${suffix}`;
444
- }
445
- if (suffixIndex === 0)
446
- token = attachAbove(token, changes);
447
- outputs[outputIndex].push(token);
439
+ const token = !continuation || (suffixIndex === 0 && bars.has(at)) || suffix.includes("/")
440
+ ? itemHead(item, pitchMode, suffix, chains && extendTieChains(chains))
441
+ : `-${suffix}`;
442
+ outputs[outputIndex].push(suffixIndex === 0 ? attachAbove(token, changes) : token);
448
443
  if (chains && next === item.end && suffixIndex === suffixes.length - 1) {
449
444
  outputs[outputIndex].push(...chains.map(labels => `@tie(${labels.join(", ")})`));
450
445
  }
@@ -458,7 +453,7 @@ function renderLane(lane, rangeStart, rangeEnd, rhythmScale, timeFactor, pitchMo
458
453
  }
459
454
  return outputs.map(output => output.join(" "));
460
455
  }
461
- function renderTrack(track, scoreEnd, bars, lineBreaks, render, showName) {
456
+ function renderTrack(track, scoreEnd, bars, orderedBars, lineBreaks, render, showName) {
462
457
  const lineCount = lineBreaks.size + 1;
463
458
  const outputs = Array.from({ length: lineCount }, () => []);
464
459
  const segments = [];
@@ -472,21 +467,36 @@ function renderTrack(track, scoreEnd, bars, lineBreaks, render, showName) {
472
467
  }
473
468
  if (cursor < scoreEnd)
474
469
  segments.push({ start: cursor, end: scoreEnd, lanes: [{ items: [] }] });
475
- // 每个重叠区域独立渲染,多 lane 只在该区域局部组成 @stack
470
+ // segments 按时间递增且连续,小节线与行号可沿游标单向推进
471
+ let barCursor = 0;
472
+ let lineCursor = 0;
476
473
  for (const region of segments) {
477
474
  if (region.start > 0 && bars.has(region.start)) {
478
- const lineIndex = [...lineBreaks].filter(at => at < region.start).length;
479
- outputs[lineIndex].push("|");
475
+ outputs[lineCursor].push("|");
476
+ if (lineBreaks.has(region.start))
477
+ lineCursor++;
478
+ }
479
+ while (barCursor < orderedBars.length && orderedBars[barCursor] <= region.start)
480
+ barCursor++;
481
+ const barStart = barCursor;
482
+ let lineEnd = lineCursor;
483
+ while (barCursor < orderedBars.length && orderedBars[barCursor] < region.end) {
484
+ if (lineBreaks.has(orderedBars[barCursor]))
485
+ lineEnd++;
486
+ barCursor++;
480
487
  }
481
- const lanes = region.lanes.map(lane => render(region, lane));
482
- for (let lineIndex = 0; lineIndex < lineCount; lineIndex++) {
483
- if (!lanes.some(lines => lines[lineIndex]))
488
+ const regionBars = orderedBars.slice(barStart, barCursor);
489
+ const lineSpan = lineEnd - lineCursor + 1;
490
+ const lanes = region.lanes.map(lane => render(region, lane, regionBars, lineSpan));
491
+ for (let offset = 0; offset < lineSpan; offset++) {
492
+ if (!lanes.some(lines => lines[offset]))
484
493
  continue;
485
494
  const content = lanes.length === 1
486
- ? lanes[0][lineIndex]
487
- : `@stack(${lanes.map(lines => `{ ${lines[lineIndex]} }`).join(", ")})`;
488
- outputs[lineIndex].push(content);
495
+ ? lanes[0][offset]
496
+ : `@stack(${lanes.map(lines => `{ ${lines[offset]} }`).join(", ")})`;
497
+ outputs[lineCursor + offset].push(content);
489
498
  }
499
+ lineCursor = lineEnd;
490
500
  }
491
501
  if (bars.has(scoreEnd))
492
502
  outputs[lineCount - 1].push("|");
@@ -693,15 +703,17 @@ export function convertMidiJsonToJpFun(input, options = {}, layoutCapability) {
693
703
  });
694
704
  if (convertedTracks.length === 0)
695
705
  return head;
696
- // 第六阶段:先生成单行候选做自然宽度测量,再用选出的断点生成最终源码
706
+ // 第六阶段:先用不含 head/tie/program 的单行候选测自然宽度,再用选出的断点生成完整源码
697
707
  const renderScore = (lineBreaks) => {
698
708
  let tieIndex = 0;
699
- // 每次渲染重新编号 tie,单行测量与最终源码因此保持相同标签结构
700
- const tracks = convertedTracks.map((track, trackIndex) => renderTrack(track, scoreEnd, bars, lineBreaks, (region, lane) => renderLane(lane, region.start, region.end, rhythmScale, timeFactor, pitchMode, bars, lineBreaks, trackIndex === 0 && lane === region.lanes.at(-1) ? scoreAdjustments : undefined, track.programs, () => `mt${tieIndex++}`), convertedTracks.length > 1));
701
- return `${head}\n\n${renderSystems(tracks)}`;
709
+ const nextTieLabel = lineBreaks ? () => `mt${tieIndex++}` : undefined;
710
+ const breaks = lineBreaks ?? new Set();
711
+ const tracks = convertedTracks.map((track, trackIndex) => renderTrack(track, scoreEnd, bars, orderedBars, breaks, (region, lane, regionBars, lineSpan) => renderLane(lane, region.start, region.end, lineSpan, rhythmScale, timeFactor, pitchMode, bars, regionBars, breaks, trackIndex === 0 && lane === region.lanes.at(-1) ? scoreAdjustments : undefined, track.programs, nextTieLabel), convertedTracks.length > 1));
712
+ const body = renderSystems(tracks);
713
+ return lineBreaks ? `${head}\n\n${body}` : body;
702
714
  };
703
715
  const lineBreaks = barsPerLine <= 0
704
- ? automaticLineBreaks(renderScore(new Set()), orderedBars, scale, layoutCapability)
716
+ ? automaticLineBreaks(renderScore(), orderedBars, scale, layoutCapability)
705
717
  : new Set(orderedBars.filter((at, index) => (index + 1) % barsPerLine === 0 && at < scoreEnd));
706
718
  return renderScore(lineBreaks);
707
719
  }
@@ -17,6 +17,7 @@ declare const DIAGNOSTICS: {
17
17
  readonly directionOutput: readonly ["UNATTACHED_CONTENT", "Direction mark has no generated output position and was omitted."];
18
18
  readonly tempoReplaced: readonly ["UNATTACHED_CONTENT", "Tempo {value} was replaced by a different tempo at the same time and was omitted."];
19
19
  readonly arpeggioOutput: readonly ["UNSUPPORTED_ELEMENT", "Arpeggiate mark requires at least two pitches in one event and was omitted."];
20
+ readonly multipleRest: readonly ["APPROXIMATED", "Multiple-rest grouping could not be preserved without discarding musical content; individual rests were retained."];
20
21
  readonly textHost: readonly ["UNATTACHED_CONTENT", "Text {value} has no target event and was omitted."];
21
22
  readonly wedgeStart: readonly ["UNRESOLVED_RELATION", "Wedge stop has no matching start and was omitted."];
22
23
  readonly wedgeReplaced: readonly ["UNRESOLVED_RELATION", "Wedge start was replaced before a matching stop and was omitted."];
@@ -29,6 +30,11 @@ declare const DIAGNOSTICS: {
29
30
  readonly endingEndpoints: readonly ["UNRESOLVED_RELATION", "Ending has no event endpoints in its interval and was omitted."];
30
31
  readonly tieStart: readonly ["UNRESOLVED_RELATION", "Tie stop has no matching start and was omitted."];
31
32
  readonly tieStop: readonly ["UNRESOLVED_RELATION", "Tie start has no matching stop in any ending branch and was omitted."];
33
+ readonly glissStart: readonly ["UNRESOLVED_RELATION", "Glissando stop has no matching start and was omitted."];
34
+ readonly glissStop: readonly ["UNRESOLVED_RELATION", "Glissando start has no matching stop and was omitted."];
35
+ readonly glissReplaced: readonly ["UNRESOLVED_RELATION", "Glissando start was replaced before a matching stop and was omitted."];
36
+ readonly glissEndpoints: readonly ["UNRESOLVED_RELATION", "Glissando endpoints are simultaneous or cross a score line and were omitted."];
37
+ readonly glissStyle: readonly ["APPROXIMATED", "MusicXML <{value}> was converted to a straight glissando arrow."];
32
38
  };
33
39
  export declare function reportDiagnostic(diagnostics: MusicXmlDiagnostic[], issue: keyof typeof DIAGNOSTICS, location: MusicXmlDiagnostic["location"], value?: string | number): void;
34
40
  /** 查询不改变覆盖状态;解析结果写入语义模型后显式确认,未确认项按 XML 顺序报告 */
@@ -55,12 +61,20 @@ export declare function parsePitch(note: MusicXmlElement, location: MusicXmlPitc
55
61
  export declare function transposePitch(pitch: MusicXmlPitch, chromatic: number, diatonic: number | undefined, octaves: number): void;
56
62
  /** 将支持的 fermata articulation 和 ornament 转成 jpFun 修饰符 */
57
63
  export declare function noteModifiers(notations: MusicXmlReader | undefined, diagnostics: MusicXmlDiagnostic[], location: MusicXmlDiagnostic["location"]): {
58
- name: string;
59
- placement: "above" | "below";
60
- }[];
61
- /** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦。 */
64
+ modifiers: {
65
+ name: string;
66
+ placement: "above" | "below";
67
+ }[];
68
+ slides: {
69
+ side: "pre" | "post";
70
+ direction: "up" | "down";
71
+ }[];
72
+ };
73
+ /** 双音 slide 与 glissando 均是标签关系;与 articulations 下的单音滑音区别处理 */
74
+ export declare function noteGlissandi(notations: MusicXmlReader | undefined, pitch: MusicXmlPitch | null, diagnostics: MusicXmlDiagnostic[]): void;
75
+ /** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦 */
62
76
  export declare function mergeArpeggio(current?: MusicXmlArpeggio, next?: MusicXmlArpeggio): MusicXmlArpeggio | undefined;
63
- /** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏。 */
77
+ /** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏 */
64
78
  export declare function noteArpeggio(notations: MusicXmlReader | undefined, location: MusicXmlPitch["location"]): MusicXmlArpeggio | undefined;
65
79
  /** 解析 tuplet 的实际音数与正常音数,并保留显式组边界 */
66
80
  export declare function timeModification(note: MusicXmlElement, tuplets: readonly MusicXmlElement[] | undefined): {
@@ -14,6 +14,7 @@ const DIAGNOSTICS = {
14
14
  directionOutput: ["UNATTACHED_CONTENT", "Direction mark has no generated output position and was omitted."],
15
15
  tempoReplaced: ["UNATTACHED_CONTENT", "Tempo {value} was replaced by a different tempo at the same time and was omitted."],
16
16
  arpeggioOutput: ["UNSUPPORTED_ELEMENT", "Arpeggiate mark requires at least two pitches in one event and was omitted."],
17
+ multipleRest: ["APPROXIMATED", "Multiple-rest grouping could not be preserved without discarding musical content; individual rests were retained."],
17
18
  textHost: ["UNATTACHED_CONTENT", "Text {value} has no target event and was omitted."],
18
19
  wedgeStart: ["UNRESOLVED_RELATION", "Wedge stop has no matching start and was omitted."],
19
20
  wedgeReplaced: ["UNRESOLVED_RELATION", "Wedge start was replaced before a matching stop and was omitted."],
@@ -26,6 +27,11 @@ const DIAGNOSTICS = {
26
27
  endingEndpoints: ["UNRESOLVED_RELATION", "Ending has no event endpoints in its interval and was omitted."],
27
28
  tieStart: ["UNRESOLVED_RELATION", "Tie stop has no matching start and was omitted."],
28
29
  tieStop: ["UNRESOLVED_RELATION", "Tie start has no matching stop in any ending branch and was omitted."],
30
+ glissStart: ["UNRESOLVED_RELATION", "Glissando stop has no matching start and was omitted."],
31
+ glissStop: ["UNRESOLVED_RELATION", "Glissando start has no matching stop and was omitted."],
32
+ glissReplaced: ["UNRESOLVED_RELATION", "Glissando start was replaced before a matching stop and was omitted."],
33
+ glissEndpoints: ["UNRESOLVED_RELATION", "Glissando endpoints are simultaneous or cross a score line and were omitted."],
34
+ glissStyle: ["APPROXIMATED", "MusicXML <{value}> was converted to a straight glissando arrow."],
29
35
  };
30
36
  export function reportDiagnostic(diagnostics, issue, location, value = "") {
31
37
  const [kind, message] = DIAGNOSTICS[issue];
@@ -197,21 +203,35 @@ export function transposePitch(pitch, chromatic, diatonic, octaves) {
197
203
  }
198
204
  /** 将支持的 fermata articulation 和 ornament 转成 jpFun 修饰符 */
199
205
  export function noteModifiers(notations, diagnostics, location) {
200
- const result = [];
206
+ const modifiers = [];
207
+ const slides = [];
201
208
  if (!notations)
202
- return result;
209
+ return { modifiers, slides };
203
210
  const fermata = notations.read("fermata");
204
211
  if (fermata) {
205
- result.push({ name: "fermata", placement: placementOf(fermata, fermata.getAttribute("type") === "inverted" ? "below" : "above") });
212
+ modifiers.push({ name: "fermata", placement: placementOf(fermata, fermata.getAttribute("type") === "inverted" ? "below" : "above") });
206
213
  notations.accept(fermata);
207
214
  }
208
215
  const articulations = notations.read("articulations");
209
216
  if (articulations) {
210
217
  const accent = notations.read("accent", false, articulations);
211
218
  if (accent) {
212
- result.push({ name: "accent", placement: placementOf(accent, "above") });
219
+ modifiers.push({ name: "accent", placement: placementOf(accent, "above") });
213
220
  notations.accept(accent);
214
221
  }
222
+ for (const [tag, side, direction] of [
223
+ ["scoop", "pre", "up"], ["plop", "pre", "down"],
224
+ ["doit", "post", "up"], ["falloff", "post", "down"],
225
+ ]) {
226
+ for (const articulation of children(articulations, tag)) {
227
+ slides.push({ side, direction });
228
+ notations.accept(articulation);
229
+ if (articulation.getAttribute("line-shape") === "curved"
230
+ || articulation.getAttribute("line-type") === "wavy") {
231
+ reportDiagnostic(diagnostics, "glissStyle", { ...location, element: tag }, tag);
232
+ }
233
+ }
234
+ }
215
235
  notations.report(diagnostics, location, articulations);
216
236
  notations.accept(articulations);
217
237
  }
@@ -225,16 +245,34 @@ export function noteModifiers(notations, diagnostics, location) {
225
245
  for (const [tag, name] of names) {
226
246
  const ornament = notations.read(tag, false, ornaments);
227
247
  if (ornament) {
228
- result.push({ name, placement: placementOf(ornament, "above") });
248
+ modifiers.push({ name, placement: placementOf(ornament, "above") });
229
249
  notations.accept(ornament);
230
250
  }
231
251
  }
232
252
  notations.report(diagnostics, location, ornaments);
233
253
  notations.accept(ornaments);
234
254
  }
235
- return result;
255
+ return { modifiers, slides };
256
+ }
257
+ /** 双音 slide 与 glissando 均是标签关系;与 articulations 下的单音滑音区别处理 */
258
+ export function noteGlissandi(notations, pitch, diagnostics) {
259
+ if (!notations || !pitch)
260
+ return;
261
+ for (const kind of ["slide", "glissando"]) {
262
+ for (const element of notations.readAll(kind)) {
263
+ const type = element.getAttribute("type");
264
+ if (type !== "start" && type !== "stop")
265
+ continue;
266
+ (pitch.glissandi ??= []).push({ kind, type, number: element.getAttribute("number") || "1" });
267
+ notations.accept(element);
268
+ if (type === "start" && (kind === "glissando" && element.getAttribute("line-type") !== "solid"
269
+ || element.getAttribute("line-type") === "wavy" || text(element))) {
270
+ reportDiagnostic(diagnostics, "glissStyle", { ...pitch.location, element: kind }, kind);
271
+ }
272
+ }
273
+ }
236
274
  }
237
- /** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦。 */
275
+ /** 无箭头不覆盖显式方向,两个相反的显式方向不能属于同一和弦 */
238
276
  export function mergeArpeggio(current, next) {
239
277
  if (!next || next.direction === "none")
240
278
  return current ?? next;
@@ -243,7 +281,7 @@ export function mergeArpeggio(current, next) {
243
281
  }
244
282
  return next;
245
283
  }
246
- /** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏。 */
284
+ /** 读取和弦成员上的琶音方向;none 表示无箭头但仍按自下而上演奏 */
247
285
  export function noteArpeggio(notations, location) {
248
286
  if (!notations)
249
287
  return undefined;