Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 94x 6x 6x 94x 94x 94x 94x 94x 2x 2x 94x 94x 94x 94x 94x 5x 5x 94x 94x 94x 94x 94x 2x 2x 94x 94x 94x 94x 94x 94x 94x 3x 2x 2x 2x 3x 1x 1x 1x 2x 2x 3x 94x 94x 94x 94x 94x 94x 94x 3x 1x 1x 2x 3x 1x 1x 1x 1x 1x 1x 3x 94x 94x 94x 94x 94x 4x 4x 94x 94x 94x 94x 94x 4x 4x 94x 94x 94x 94x 94x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 94x | /**
* @file 音符模型
* @description 表示乐谱中的音符,包含音高、时值、连接等信息
*/
import {
NoteType, StemDirection, BeamType, AccidentalType,
TieSlurType, SyllabicType, ID
} from './types';
import { Pitch, Rest, Unpitched } from './Pitch';
/**
* 连音符(tuplet)信息
*/
export interface TimeModification {
/** 实际演奏的音符数 */
actualNotes: number;
/** 等效的正常音符数 */
normalNotes: number;
/** 基准音符类型 */
normalType?: NoteType;
/** 基准音符的附点数 */
normalDots?: number;
}
/**
* 连音线信息
*/
export interface TieInfo {
type: TieSlurType;
number?: number;
}
/**
* 符杠信息
*/
export interface BeamInfo {
number: number; // 1-8,表示第几层符杠
type: BeamType;
}
/**
* 歌词信息
*/
export interface Lyric {
/** 歌词编号(用于多段歌词) */
number?: string;
/** 音节类型 */
syllabic?: SyllabicType;
/** 歌词文字 */
text: string;
/** 是否延长 */
extend?: boolean;
/** 是否有省略符号 */
elision?: boolean;
}
/**
* 装饰音信息
*/
export interface GraceNote {
/** 是否为倚音(有时值) */
slash?: boolean;
/** 是否从前音偷时值 */
stealTimePrevious?: number;
/** 是否从后音偷时值 */
stealTimeFollowing?: number;
/** 制造时值 */
makeTime?: number;
}
/**
* 音符数据接口
*/
export interface INote {
/** 唯一标识 */
id?: ID;
// === 音高信息(三选一)===
/** 有音高的音符 */
pitch?: Pitch;
/** 休止符 */
rest?: Rest;
/** 无固定音高(打击乐) */
unpitched?: Unpitched;
// === 时值信息 ===
/** 时值(以 divisions 为单位) */
duration: number;
/** 符头类型 */
type?: NoteType;
/** 附点数量 */
dots?: number;
/** 连音符信息 */
timeModification?: TimeModification;
// === 和弦信息 ===
/** 是否为和弦的非第一个音 */
chord?: boolean;
// === 装饰音 ===
/** 装饰音信息 */
grace?: GraceNote;
/** 是否为提示音 */
cue?: boolean;
// === 连接信息 ===
/** 连音线 */
ties?: TieInfo[];
/** 符杠 */
beams?: BeamInfo[];
// === 显示信息 ===
/** 符干方向 */
stem?: StemDirection;
/** 临时记号 */
accidental?: AccidentalType;
/** 是否显示临时记号的括号 */
accidentalBracket?: boolean;
/** 是否为礼貌性临时记号 */
accidentalCourtesy?: boolean;
// === 声部信息 ===
/** 声部号 */
voice?: number;
/** 谱表号(多谱表时) */
staff?: number;
// === 歌词 ===
lyrics?: Lyric[];
// === 乐器 ===
instrumentId?: string;
// === 其他 ===
/** 记号(连线、演奏技法等) */
notations?: NoteNotations;
}
/**
* 音符上的各种记号
*/
export interface NoteNotations {
/** 连音线(视觉) */
tied?: { type: TieSlurType; number?: number }[];
/** 圆滑线 */
slurs?: { type: TieSlurType; number?: number }[];
/** 连音符括号 */
tuplet?: { type: 'start' | 'stop'; number?: number; bracket?: boolean };
/** 延音记号 */
fermata?: { type?: 'upright' | 'inverted'; shape?: string };
/** 演奏技法 */
articulations?: string[];
/** 装饰记号 */
ornaments?: string[];
/** 力度 */
dynamics?: string[];
/** 技术记号(指法等) */
technical?: string[];
/** 琶音 */
arpeggiate?: { direction?: 'up' | 'down' };
/** 滑音 */
glissando?: { type: 'start' | 'stop'; lineType?: string };
/** 滑奏 */
slide?: { type: 'start' | 'stop'; lineType?: string };
}
/**
* 音符类
*/
export class Note implements INote {
id?: ID;
pitch?: Pitch;
rest?: Rest;
unpitched?: Unpitched;
duration: number;
type?: NoteType;
dots: number;
timeModification?: TimeModification;
chord: boolean;
grace?: GraceNote;
cue: boolean;
ties?: TieInfo[];
beams?: BeamInfo[];
stem?: StemDirection;
accidental?: AccidentalType;
accidentalBracket: boolean;
accidentalCourtesy: boolean;
voice: number;
staff: number;
lyrics?: Lyric[];
instrumentId?: string;
notations?: NoteNotations;
constructor(data: INote) {
this.id = data.id;
this.pitch = data.pitch;
this.rest = data.rest;
this.unpitched = data.unpitched;
this.duration = data.duration;
this.type = data.type;
this.dots = data.dots ?? 0;
this.timeModification = data.timeModification;
this.chord = data.chord ?? false;
this.grace = data.grace;
this.cue = data.cue ?? false;
this.ties = data.ties;
this.beams = data.beams;
this.stem = data.stem;
this.accidental = data.accidental;
this.accidentalBracket = data.accidentalBracket ?? false;
this.accidentalCourtesy = data.accidentalCourtesy ?? false;
this.voice = data.voice ?? 1;
this.staff = data.staff ?? 1;
this.lyrics = data.lyrics;
this.instrumentId = data.instrumentId;
this.notations = data.notations;
}
/**
* 是否为休止符
*/
get isRest(): boolean {
return this.rest !== undefined;
}
/**
* 是否为有音高的音符
*/
get isPitched(): boolean {
return this.pitch !== undefined;
}
/**
* 是否为装饰音
*/
get isGrace(): boolean {
return this.grace !== undefined;
}
/**
* 是否为和弦音
*/
get isChordNote(): boolean {
return this.chord;
}
/**
* 获取实际时值(考虑连音符)
* @param divisions 每四分音符的divisions值
* @returns 以四分音符为单位的时值
*/
getActualDuration(divisions: number): number {
if (this.isGrace) return 0;
let baseDuration = this.duration / divisions;
if (this.timeModification) {
// 连音符:实际时值 = 书写时值 × (normalNotes / actualNotes)
baseDuration = baseDuration * this.timeModification.normalNotes / this.timeModification.actualNotes;
}
return baseDuration;
}
/**
* 获取简谱表示
* @param key 调号(五度圈位置)
* @param useMovableDo 是否首调
*/
getJianpuRepresentation(key: number = 0, useMovableDo: boolean = false): string {
if (this.isRest) {
return '0';
}
if (this.pitch) {
return this.pitch.toJianpuString(key, useMovableDo);
}
if (this.unpitched) {
return 'X'; // 打击乐
}
return '?';
}
/**
* 是否有连音线开始
*/
hasTieStart(): boolean {
return this.ties?.some(t => t.type === 'start') ?? false;
}
/**
* 是否有连音线结束
*/
hasTieStop(): boolean {
return this.ties?.some(t => t.type === 'stop') ?? false;
}
/**
* 克隆音符
*/
clone(): Note {
return new Note({
...this,
pitch: this.pitch?.clone(),
rest: this.rest ? new Rest(this.rest) : undefined,
ties: this.ties ? [...this.ties] : undefined,
beams: this.beams ? [...this.beams] : undefined,
lyrics: this.lyrics ? [...this.lyrics] : undefined,
notations: this.notations ? { ...this.notations } : undefined,
});
}
}
|