2) * 0.4;
adjusted.volume += (happiness - 0.3) * 0.2;

// 限制范围
adjusted.pitch = Math.max(0.5, Math.min(2.0, adjusted.pitch));
adjusted.rate = Math.max(0.3, Math.min(2.0, adjusted.rate));
adjusted.volume = Math.max(0.3, Math.min(1.0, adjusted.volume));

return adjusted;
}

// 智能伴奏
async addIntelligentAccompaniment(text, sectionType) {
const duration = this.calculateLineDuration(text);
const style = this.getMusicStyleForSection(sectionType);

await this.generateIntelligentMusic(this.musicSystem.currentInstrument, duration, style);

if (this.musicSystem.harmonyType !== 'none') {
await this.generateIntelligentHarmony(text, duration, style);
}
}

// 生成智能音乐
async generateIntelligentMusic(instrument, duration, style) {
const chords = this.generateIntelligentChords(style, duration);
const melody = this.generateIntelligentMelody(style, duration);

// 并行播放和弦和旋律
await Promise.all([
this.playChordProgression(chords, instrument),
this.playMelody(melody, instrument)
]);
}

// 生成智能和声
async generateIntelligentHarmony(text, duration, style) {
const harmonyNotes = this.generateHarmonyNotes(text, duration, style);

for (const note of harmonyNotes) {
this.playNoteWithEffects(
note.frequency,
note.duration,
note.volume,
this.musicSystem.currentInstrument
);
}

await this.delay(duration * 1000);
}

// 录音控制
toggleRecording() {
this.systemState.isRecording = !this.systemState.isRecording;

if (this.systemState.isRecording) {
this.startRecording();
} else {
this.stopRecording();
}

this.updateRecordingUI();
}

startRecording() {
this.systemState.recordingData = [];
this.showMessage('开始录制...', 'info');

// 这里可以实现实际的音频录制逻辑
// 使用 MediaRecorder API 或 Web Audio API 的 ScriptProcessorNode
}

stopRecording() {
this.showMessage(`录制完成,共 ${this.systemState.recordingData.length} 个片段`, 'success');
this.saveRecording();
}

// 循环控制
toggleLooping() {
this.systemState.isLooping = !this.systemState.isLooping;
this.updateLoopingUI();

this.showMessage(
this.systemState.isLooping ? '循环播放已启用' : '循环播放已禁用',
'info'
);
}

// 系统配置方法
setBPM(bpm) {
this.musicSystem.bpm = Math.max(60, Math.min(240, bpm));
this.updateBPMUI();
this.showMessage(`BPM设置为: ${this.musicSystem.bpm}`, 'info');
}

setPitch(pitch) {
this.musicSystem.pitch = pitch;
// 应用音调调整到所有音频
}

setVolume(volume) {
this.musicSystem.volume = volume;
// 应用音量调整
}

setEmotion(emotion, value) {
this.emotionSystem.profile[emotion] = value;
this.updateEmotionUI(emotion, value);
this.showMessage(`${emotion}情感设置为: ${value}%`, 'info');
}

setEffect(effect, value) {
this.effectSystem.profile[effect] = value;
this.updateEffectUI(effect, value);
this.applyEffect(effect, value);
}

setHarmonyType(type) {
this.musicSystem.harmonyType = type;
this.showMessage(`和声类型设置为: ${type}`, 'info');
}

setHarmonyIntensity(intensity) {
this.musicSystem.harmonyIntensity = intensity;
this.updateHarmonyIntensityUI(intensity);
}

setTimeSignature(signature) {
this.musicSystem.timeSignature = signature;
this.showMessage(`拍号设置为: ${signature}`, 'info');
}

setSwing(swing) {
this.musicSystem.swing = swing;
this.updateSwingUI(swing);
}

selectVoice(voice) {
this.musicSystem.currentVoice = voice;
this.updateVoiceSelectionUI(voice);
this.showMessage(`发音人切换为: ${this.getVoiceDisplayName(voice)}`, 'success');
}

selectInstrument(instrument) {
this.musicSystem.currentInstrument = instrument;
this.updateInstrumentSelectionUI(instrument);
this.showMessage(`乐器切换为: ${this.getInstrumentDisplayName(instrument)}`, 'success');
}

// 用户界面更新方法
updateUserInterface() {
this.updatePlaybackUI();
this.updateRecordingUI();
this.updateLoopingUI();
this.updateBPMUI();
this.updateVoiceSelectionUI(this.musicSystem.currentVoice);
this.updateInstrumentSelectionUI(this.musicSystem.currentInstrument);
this.updateEmotionUI();
this.updateEffectUI();
this.updateHarmonyIntensityUI(this.musicSystem.harmonyIntensity);
this.updateSwingUI(this.musicSystem.swing);
this.updateProgressUI();
}

updatePlaybackUI() {
const playBtn = document.getElementById('play-btn');
if (this.systemState.isPlaying) {
playBtn.innerHTML = '<span>⏸️</span><span>暂停</span>';
} else {
playBtn.innerHTML = '<span>▶️</span><span>播放</span>';
}
}

updateRecordingUI() {
const recordBtn = document.getElementById('record-btn');
if (this.systemState.isRecording) {
recordBtn.style.background = 'var(--color-danger)';
} else {
recordBtn.style.background = '';
}
}

updateLoopingUI() {
const loopBtn = document.getElementById('loop-btn');
if (this.systemState.isLooping) {
loopBtn.style.background = 'var(--color-success)';
} else {
loopBtn.style.background = '';
}
}

updateBPMUI() {
document.getElementById('bpm').value = this.musicSystem.bpm;
document.getElementById('current-bpm').textContent = `BPM: ${this.musicSystem.bpm}`;
}

updateVoiceSelectionUI(voice) {
document.querySelectorAll('[data-voice]').forEach(card => {

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


Back to home | File page

Subscribe | Register | Login | N