value);
});

document.getElementById('harmony-intensity').addEventListener('input', (e) => {
this.setHarmonyIntensity(parseInt(e.target.value));
});

// 节奏控制
document.getElementById('time-signature').addEventListener('change', (e) => {
this.setTimeSignature(e.target.value);
});

document.getElementById('swing').addEventListener('input', (e) => {
this.setSwing(parseInt(e.target.value));
});

// 预设控制
document.getElementById('preset-select').addEventListener('change', (e) => {
this.loadPreset(e.target.value);
});
}

// 拖放初始化
initializeDragAndDrop() {
// 实现文件拖放功能
const dropZone = document.getElementById('lyrics-editor');

dropZone.addEventListener('dragover', (e) => {
e.preventDefault();
dropZone.style.backgroundColor = 'rgba(102, 126, 234, 0.1)';
});

dropZone.addEventListener('dragleave', () => {
dropZone.style.backgroundColor = '';
});

dropZone.addEventListener('drop', (e) => {
e.preventDefault();
dropZone.style.backgroundColor = '';

const files = e.dataTransfer.files;
if (files.length > 0) {
this.handleFileDrop(files[0]);
}
});
}

// 文件拖放处理
async handleFileDrop(file) {
if (file.type === 'text/plain' || file.name.endsWith('.txt')) {
const text = await file.text();
document.getElementById('lyrics-editor').value = text;
this.showMessage('歌词文件已加载', 'success');
} else {
this.showMessage('不支持的文件格式', 'error');
}
}

// 全局键盘处理
handleGlobalKeydown(event) {
// 防止在输入框中触发
if (event.target.tagName === 'INPUT' || event.target.tagName === 'TEXTAREA') {
return;
}

switch(event.key) {
case ' ': // 空格键播放/暂停
event.preventDefault();
this.togglePlayback();
break;
case 'Escape': // ESC键停止
this.stopPlayback();
break;
case 'r': // R键录制
if (event.ctrlKey) this.toggleRecording();
break;
case 's': // S键保存
if (event.ctrlKey) {
event.preventDefault();
this.savePreset();
}
break;
}
}

// 页面关闭处理
handleBeforeUnload() {
if (this.systemState.isPlaying || this.systemState.isRecording) {
return '音乐正在播放或录制中,确定要离开吗?';
}
}

// 开始系统监控
startSystemMonitoring() {
// 监控音频上下文状态
setInterval(() => {
if (this.systemState.audioContext &&
this.systemState.audioContext.state === 'suspended') {
this.systemState.audioContext.resume();
}
}, 1000);

// 监控内存使用
setInterval(() => {
this.monitorMemoryUsage();
}, 5000);
}

// 监控内存使用
monitorMemoryUsage() {
if (performance.memory) {
this.systemState.performance.memoryUsage =
performance.memory.usedJSHeapSize / 1024 / 1024; // MB
}
}

// 开始自动保存
startAutoSave() {
setInterval(() => {
if (this.hasUnsavedChanges()) {
this.autoSave();
}
}, this.config.ux.autoSaveInterval);
}

// 检查是否有未保存的更改
hasUnsavedChanges() {
// 实现检查逻辑
return true;
}

// 自动保存
autoSave() {
const backup = this.createSystemBackup();
localStorage.setItem('musicSystem_backup', JSON.stringify(backup));
}

// 创建系统备份
createSystemBackup() {
return {
timestamp: Date.now(),
lyrics: document.getElementById('lyrics-editor').value,
config: {
bpm: this.musicSystem.bpm,
voice: this.musicSystem.currentVoice,
instrument: this.musicSystem.currentInstrument,
emotions: this.emotionSystem.profile,
effects: this.effectSystem.profile
}
};
}

// 加载用户配置
loadUserConfiguration() {
try {
const saved = localStorage.getItem('musicSystem_config');
if (saved) {
const config = JSON.parse(saved);
this.applyUserConfiguration(config);
this.showMessage('用户配置已加载', 'success');
}
} catch (error) {
console.warn('加载用户配置失败:', error);
}
}

// 应用用户配置
applyUserConfiguration(config) {
if (config.bpm) this.setBPM(config.bpm);
if (config.voice) this.selectVoice(config.voice);
if (config.instrument) this.selectInstrument(config.instrument);
if (config.emotions) this.emotionSystem.profile = config.emotions;
if (config.effects) this.effectSystem.profile = config.effects;

this.updateUserInterface();
}

// 保存用户配置
saveUserConfiguration() {
const config = {
bpm: this.musicSystem.bpm,
voice: this.musicSystem.currentVoice,
instrument: this.musicSystem.currentInstrument,
emotions: this.emotionSystem.profile,
effects: this.effectSystem.profile,
timestamp: Date.now()
};

localStorage.setItem('musicSystem_config', JSON.stringify(config));
}

// 播放控制方法
async togglePlayback() {
if (this.systemState.isPlaying) {
this.pausePlayback();
} else {
await this.startPlayback();
}
}

async startPlayback() {
if (!this.systemState.isInitialized) {
this.showMessage('系统未初始化', 'error');
return;
}

try {
this.systemState.isPlaying = true;
this.updatePlaybackUI();

Prev | Next
Pg.: 1 ... 24 25 26 27 28 29 30 31 32 33 34 ... 56


Back to home | File page

Subscribe | Register | Login | N