|
| 1 | +/** |
| 2 | + * 装饰符(Decoration/Ornament)类型定义 |
| 3 | + * |
| 4 | + * 根据 ABC 标准 v2.1/v2.2 |
| 5 | + * @see https://abcnotation.com/wiki/abc:standard:v2.1#decorations |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * 装饰符类型 |
| 10 | + * |
| 11 | + * ABC 支持两种表示方式: |
| 12 | + * 1. 符号形式:. ~ H L M O P S T u v 等 |
| 13 | + * 2. 长格式:!trill!, !fermata!, !marcato! 等 |
| 14 | + */ |
| 15 | +export enum SNDecorationType { |
| 16 | + // 基本装饰符 |
| 17 | + STACCATO = 'staccato', // . 断奏 |
| 18 | + TENUTO = 'tenuto', // - 保持音 |
| 19 | + ACCENT = 'accent', // > < 重音 |
| 20 | + MARCATO = 'marcato', // ^ 强音 |
| 21 | + |
| 22 | + // 颤音和回音 |
| 23 | + TRILL = 'trill', // T !trill! 颤音 |
| 24 | + MORDENT = 'mordent', // M !mordent! 波音 |
| 25 | + LOWER_MORDENT = 'lower-mordent', // !lowermordent! 下波音 |
| 26 | + UPPER_MORDENT = 'upper-mordent', // !uppermordent! 上波音 |
| 27 | + PRALLTRILLER = 'pralltriller', // P !pralltriller! 回音 |
| 28 | + TURN = 'turn', // !turn! 回音 |
| 29 | + |
| 30 | + // 滑音和装饰音 |
| 31 | + SLIDE = 'slide', // !slide! 滑音 |
| 32 | + ROLL = 'roll', // R !roll! 滚奏 |
| 33 | + |
| 34 | + // 延音和休止 |
| 35 | + FERMATA = 'fermata', // H !fermata! 延音 |
| 36 | + FERMATA_BELOW = 'fermata-below', // !fermata-below! 下延音 |
| 37 | + FERMATA_ABOVE = 'fermata-above', // !fermata-above! 上延音 |
| 38 | + BREATH = 'breath', // !breath! 换气记号 |
| 39 | + |
| 40 | + // 琶音和和弦装饰 |
| 41 | + ARPEGGIO = 'arpeggio', // !arpeggio! 琶音 |
| 42 | + |
| 43 | + // 弓法(弦乐器) |
| 44 | + UPBOW = 'upbow', // u !upbow! 上弓 |
| 45 | + DOWNBOW = 'downbow', // v !downbow! 下弓 |
| 46 | + |
| 47 | + // 力度记号 |
| 48 | + CRESCENDO = 'crescendo', // !crescendo(! 渐强开始 |
| 49 | + CRESCENDO_END = 'crescendo-end', // !crescendo)! 渐强结束 |
| 50 | + DIMINUENDO = 'diminuendo', // !diminuendo(! 渐弱开始 |
| 51 | + DIMINUENDO_END = 'diminuendo-end', // !diminuendo)! 渐弱结束 |
| 52 | + |
| 53 | + // 踏板记号(钢琴) |
| 54 | + PEDAL_DOWN = 'pedal-down', // !ped! 踏板按下 |
| 55 | + PEDAL_UP = 'pedal-up', // !ped-up! 踏板抬起 |
| 56 | + |
| 57 | + // 特殊记号 |
| 58 | + SEGNO = 'segno', // !segno! 反复记号 |
| 59 | + CODA = 'coda', // !coda! 尾声记号 |
| 60 | + D_C = 'd.c.', // !D.C.! 从头反复 |
| 61 | + D_S = 'd.s.', // !D.S.! 从记号反复 |
| 62 | + FINE = 'fine', // !fine! 终止 |
| 63 | + |
| 64 | + // 编辑性记号 |
| 65 | + EDITORIAL = 'editorial', // !editorial! 编辑性记号 |
| 66 | + COURTESY = 'courtesy', // !courtesy! 提示性记号 |
| 67 | + |
| 68 | + // 其他 |
| 69 | + PLUS = 'plus', // + !plus! 加号 |
| 70 | + EMPHASIS = 'emphasis', // !emphasis! 强调 |
| 71 | + FINGERING = 'fingering', // 指法记号 |
| 72 | + |
| 73 | + // 自定义 |
| 74 | + CUSTOM = 'custom', // 自定义装饰符 |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * 装饰符对象 |
| 79 | + */ |
| 80 | +export interface SNDecoration { |
| 81 | + /** 装饰符类型 */ |
| 82 | + type: SNDecorationType; |
| 83 | + /** 原始文本(如 "!trill!", "T", "." 等) */ |
| 84 | + text: string; |
| 85 | + /** 位置(above 或 below,某些装饰符支持) */ |
| 86 | + position?: 'above' | 'below'; |
| 87 | + /** 参数(如指法数字、自定义内容) */ |
| 88 | + parameter?: string; |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * 装饰符符号到类型的映射 |
| 93 | + * |
| 94 | + * 根据 ABC 标准定义 |
| 95 | + */ |
| 96 | +export const DECORATION_SYMBOL_MAP: Record<string, SNDecorationType> = { |
| 97 | + // 基本符号形式 |
| 98 | + '.': SNDecorationType.STACCATO, |
| 99 | + '~': SNDecorationType.ROLL, |
| 100 | + H: SNDecorationType.FERMATA, |
| 101 | + L: SNDecorationType.ACCENT, |
| 102 | + M: SNDecorationType.MORDENT, |
| 103 | + O: SNDecorationType.CODA, |
| 104 | + P: SNDecorationType.PRALLTRILLER, |
| 105 | + S: SNDecorationType.SEGNO, |
| 106 | + T: SNDecorationType.TRILL, |
| 107 | + u: SNDecorationType.UPBOW, |
| 108 | + v: SNDecorationType.DOWNBOW, |
| 109 | +}; |
| 110 | + |
| 111 | +/** |
| 112 | + * 装饰符长格式到类型的映射 |
| 113 | + * |
| 114 | + * 支持 !decoration! 格式 |
| 115 | + */ |
| 116 | +export const DECORATION_LONG_MAP: Record<string, SNDecorationType> = { |
| 117 | + // 颤音和回音 |
| 118 | + trill: SNDecorationType.TRILL, |
| 119 | + mordent: SNDecorationType.MORDENT, |
| 120 | + lowermordent: SNDecorationType.LOWER_MORDENT, |
| 121 | + uppermordent: SNDecorationType.UPPER_MORDENT, |
| 122 | + pralltriller: SNDecorationType.PRALLTRILLER, |
| 123 | + turn: SNDecorationType.TURN, |
| 124 | + |
| 125 | + // 滑音和装饰音 |
| 126 | + slide: SNDecorationType.SLIDE, |
| 127 | + roll: SNDecorationType.ROLL, |
| 128 | + |
| 129 | + // 延音 |
| 130 | + fermata: SNDecorationType.FERMATA, |
| 131 | + 'fermata-above': SNDecorationType.FERMATA_ABOVE, |
| 132 | + 'fermata-below': SNDecorationType.FERMATA_BELOW, |
| 133 | + breath: SNDecorationType.BREATH, |
| 134 | + |
| 135 | + // 琶音 |
| 136 | + arpeggio: SNDecorationType.ARPEGGIO, |
| 137 | + |
| 138 | + // 弓法 |
| 139 | + upbow: SNDecorationType.UPBOW, |
| 140 | + downbow: SNDecorationType.DOWNBOW, |
| 141 | + |
| 142 | + // 力度 |
| 143 | + 'crescendo(': SNDecorationType.CRESCENDO, |
| 144 | + 'crescendo)': SNDecorationType.CRESCENDO_END, |
| 145 | + 'diminuendo(': SNDecorationType.DIMINUENDO, |
| 146 | + 'diminuendo)': SNDecorationType.DIMINUENDO_END, |
| 147 | + '<(': SNDecorationType.CRESCENDO, |
| 148 | + '<)': SNDecorationType.CRESCENDO_END, |
| 149 | + '>(': SNDecorationType.DIMINUENDO, |
| 150 | + '>)': SNDecorationType.DIMINUENDO_END, |
| 151 | + |
| 152 | + // 踏板 |
| 153 | + ped: SNDecorationType.PEDAL_DOWN, |
| 154 | + 'ped-up': SNDecorationType.PEDAL_UP, |
| 155 | + |
| 156 | + // 特殊记号 |
| 157 | + segno: SNDecorationType.SEGNO, |
| 158 | + coda: SNDecorationType.CODA, |
| 159 | + 'D.C.': SNDecorationType.D_C, |
| 160 | + 'D.S.': SNDecorationType.D_S, |
| 161 | + fine: SNDecorationType.FINE, |
| 162 | + |
| 163 | + // 编辑性记号 |
| 164 | + editorial: SNDecorationType.EDITORIAL, |
| 165 | + courtesy: SNDecorationType.COURTESY, |
| 166 | + |
| 167 | + // 基本装饰 |
| 168 | + staccato: SNDecorationType.STACCATO, |
| 169 | + tenuto: SNDecorationType.TENUTO, |
| 170 | + accent: SNDecorationType.ACCENT, |
| 171 | + marcato: SNDecorationType.MARCATO, |
| 172 | + emphasis: SNDecorationType.EMPHASIS, |
| 173 | + |
| 174 | + // 其他 |
| 175 | + '+': SNDecorationType.PLUS, |
| 176 | + plus: SNDecorationType.PLUS, |
| 177 | +}; |
0 commit comments