完整的 Note、Track、Project 数据模型,支持 JSON/MIDI 序列化与 IndexedDB 存储
XSS 防护、SQL 注入检测、Unicode 规范化、Emoji 过滤等全方位输入安全
// 基于音阶的概率分布生成音符
generateNote(scale, tensionLevel = 'normal') {
const probabilities = this.getTensionProbabilities(tensionLevel);
const scaleDegree = this.weightedRandom(
scale.degrees,
probabilities
);
return {
pitch: scale.notes[scaleDegree],
octave: this.selectOctave(scaleDegree),
duration: this.getRandomDuration(),
velocity: this.calculateVelocity(scaleDegree)
};
}
// I-V-vi-IV 经典进行 + 随机变奏
generateProgression(key, style = 'pop') {
const templates = MusicStyleTemplates[style];
const progression = templates.progressions[
Math.floor(Math.random() * templates.progressions.length)
];
return progression.map(degree => ({
root: key.notes[degree - 1],
quality: this.determineQuality(degree),
inversion: this.randomInversion()
}));
}
// LZ-String 压缩 + JSON 去重
compress(data) {
const jsonString = JSON.stringify(data);
const deduplicated = this.deduplicate(jsonString);
const compressed = LZString.compress(deduplicated);
this.stats.compressionRatio = (
1 - compressed.length / jsonString.length
) * 100;
return compressed;
}
// 动态并发数调整
async uploadWithConcurrency(chunks) {
const concurrency = await this.networkMonitor
.recommendConcurrency();
const queue = new ConcurrencyQueue(concurrency);
for (const chunk of chunks) {
queue.add(() => this.uploadChunk(chunk, {
retry: this.retryStrategy
}));
}
return queue.executeAll();
}