IMPROVE: hướng dẫn AI tạo nhạc đầy đủ số bars và tracks theo yêu cầu

This commit is contained in:
2026-07-30 16:39:28 +07:00
parent 938c8d7f87
commit a9be38b76f
4 changed files with 24 additions and 23 deletions
+8 -16
View File
@@ -826,21 +826,6 @@ const MasterStripConsole = ({ masterVolume, setMasterVolume, showMasteringModal,
levelR = peakR; levelR = peakR;
} }
if (!isMuted && (isTestPlaying || isPlaying)) {
const db = masterVolume;
const linearGain = db <= -60 ? 0 : Math.pow(10, db / 20);
const baseSignal = 0.5 * linearGain;
if (baseSignal > 0) {
levelL = Math.min(1.0, Math.max(0, baseSignal * (0.9 + Math.random() * 0.18)));
levelR = Math.min(1.0, Math.max(0, baseSignal * (0.88 + Math.random() * 0.22)));
if (isMono) {
const mono = (levelL + levelR) / 2;
levelL = mono;
levelR = mono;
}
}
}
const padding = 4; const padding = 4;
const gap = 4; const gap = 4;
const barW = Math.max(4, (w - padding * 2 - gap) / 2); const barW = Math.max(4, (w - padding * 2 - gap) / 2);
@@ -864,7 +849,7 @@ const MasterStripConsole = ({ masterVolume, setMasterVolume, showMasteringModal,
return () => { return () => {
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current); if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
}; };
}, [isPlaying, masterVolume, isMuted, isMono]); }, [masterVolume, isMuted, isMono]);
return React.createElement("div", { return React.createElement("div", {
className: "flex flex-col items-stretch w-[300px] shrink-0 strip-bg rounded-lg p-2 text-slate-300 select-none shadow-2xl relative overflow-hidden" className: "flex flex-col items-stretch w-[300px] shrink-0 strip-bg rounded-lg p-2 text-slate-300 select-none shadow-2xl relative overflow-hidden"
@@ -16318,6 +16303,13 @@ const App = () => {
}); });
let matchedInstruction = ''; let matchedInstruction = '';
if (aiPromptMgrRef.current) {
const matchResult = aiPromptMgrRef.current.matchPreset(prompt);
if (matchResult && matchResult.preset) {
matchedInstruction = matchResult.preset.system_instruction_template;
setAiActionLog(prev => [...prev, { type: 'info', text: ` Khớp với preset: "${matchResult.preset.name}"`, time: Date.now() }]);
}
}
const result = await window.AIGateway.executeAIPrompt({ const result = await window.AIGateway.executeAIPrompt({
prompt: prompt, prompt: prompt,
File diff suppressed because one or more lines are too long
+11 -2
View File
@@ -54,10 +54,10 @@ const AIGateway = (function() {
properties: { properties: {
composition_title: { type: 'string', description: 'Title of the musical piece (e.g., Epic Orchestra Intro 8-Bars)' }, composition_title: { type: 'string', description: 'Title of the musical piece (e.g., Epic Orchestra Intro 8-Bars)' },
bpm: { type: 'integer' }, bpm: { type: 'integer' },
total_bars: { type: 'integer' }, total_bars: { type: 'integer', description: 'Total length of the composition in bars. You MUST populate all bars with notes.' },
tracks: { tracks: {
type: 'array', type: 'array',
description: 'Array of instrument tracks with MIDI notes and SoundFont instrument selection', description: 'CRITICAL: Array of instrument tracks. You MUST generate exactly the number of tracks requested by the user. Every track in this array MUST contain a full sequence of notes that spans the entire duration of the piece (from start_beat 0.0 to total_bars * 4.0).',
items: { items: {
type: 'object', type: 'object',
properties: { properties: {
@@ -68,6 +68,7 @@ const AIGateway = (function() {
soundfont_program: { type: 'integer', description: 'MIDI Program Number 0-127 matching the instrument name in the SoundFont catalog' }, soundfont_program: { type: 'integer', description: 'MIDI Program Number 0-127 matching the instrument name in the SoundFont catalog' },
notes: { notes: {
type: 'array', type: 'array',
description: 'CRITICAL: Array of MIDI notes. You MUST write notes completely filling all bars from bar 0 (beat 0.0) up to the final bar (beat total_bars * 4.0). Do NOT leave empty bars or stop early. Fill the entire duration of the composition with continuous musical notes.',
items: { items: {
type: 'object', type: 'object',
properties: { properties: {
@@ -342,6 +343,14 @@ ${rules.join('\n')}` },
Nhiệm vụ của bạn là phân tích yêu cầu của người dùng và chuyển đổi thành danh sách các function calls tương ứng. Nhiệm vụ của bạn là phân tích yêu cầu của người dùng và chuyển đổi thành danh sách các function calls tương ứng.
${systemInstruction ? `\nHướng dẫn tạo nhạc đặc biệt từ Preset:\n${systemInstruction}\n` : ''} ${systemInstruction ? `\nHướng dẫn tạo nhạc đặc biệt từ Preset:\n${systemInstruction}\n` : ''}
${catalogSection} ${catalogSection}
=== HƯỚNG DẪN SOẠN NHẠC MIDI / MIDI COMPOSITION RULES ===
KHI NGƯỜI DÙNG YÊU CẦU TẠO NHẠC / COMPOSITION RULES:
1. FULL TRACKS & BARS: If the user requests X tracks and Y bars, you MUST generate exactly X tracks. Each track MUST contain a continuous sequence of MIDI notes starting from beat 0.0 and stretching all the way to beat Y * 4.0 (the end of the composition).
2. NO EARLY STOPPING: Do NOT stop early or leave empty bars at the end or in the middle. Every track must be fully populated with notes throughout the entire duration.
3. EXPRESS MELODY & EMOTION: The generated MIDI notes (pitch, start_beat, duration_beats, velocity) must express the requested musical emotion (e.g., happy, sad, epic, energetic, melancholic). Use rich harmonies/chords for backing tracks (Strings, Pads, Piano) and expressive, rhythmic melodies for Lead/Solo tracks. Do NOT write single repeating notes or overly sparse patterns unless explicitly asked.
4. VIẾT ĐẦY ĐỦ CÁC NOTE: Bạn phải viết đầy đủ các note cho TẤT CẢ các tracks được yêu cầu, và trải dài trong SUỐT chiều dài số bars yêu cầu (ví dụ: yêu cầu 8 bars và 6 tracks thì phải tạo đủ 6 tracks, mỗi track phải có các note MIDI bắt đầu từ beat 0.0 kéo dài liên tục đến beat 32.0 (8 bars * 4 beat/bar)).
QUAN TRỌNG: QUAN TRỌNG:
1. Bạn đang hoạt động ở chế độ một lượt (one-shot). Hãy trả về TẤT CẢ các function calls cần thiết để thực hiện toàn bộ các bước trong yêu cầu của người dùng trong một phản hồi duy nhất. Đừng thực hiện từng bước qua nhiều lượt chat. 1. Bạn đang hoạt động ở chế độ một lượt (one-shot). Hãy trả về TẤT CẢ các function calls cần thiết để thực hiện toàn bộ các bước trong yêu cầu của người dùng trong một phản hồi duy nhất. Đừng thực hiện từng bước qua nhiều lượt chat.
2. Có thể gọi nhiều function cùng một lúc (gọi song song/nối tiếp). Chúng sẽ được thực thi theo thứ tự bạn trả về. 2. Có thể gọi nhiều function cùng một lúc (gọi song song/nối tiếp). Chúng sẽ được thực thi theo thứ tự bạn trả về.
@@ -8,7 +8,7 @@ const PromptTemplateManager = (function() {
default_bars: 8, default_bars: 8,
default_bpm: 130, default_bpm: 130,
default_scale: "C Minor", default_scale: "C Minor",
system_instruction_template: "You are a professional film composer. Create a powerful, dramatic 8-bar orchestral intro. Keep the note density low (e.g. use mostly whole notes, half notes, or quarter notes) and do NOT generate dense 16th notes or complex drum rolls. This is critical to avoid output token limit timeouts. The required structure to return via the `generate_multitrack_midi` tool consists of 3 tracks: 1. Strings: plays smooth legato chord changes (one chord per 1 or 2 bars). 2. Brass Theme: plays a swelling simple melodic line in the C3-C5 range. 3. Epic Percussion: hits heavily on beats 1 and 3. Ensure the duration is precisely 8 bars (32 beats).", system_instruction_template: "You are a professional film composer. Create a powerful, dramatic 8-bar orchestral intro. Write notes continuously across all 8 bars (from beat 0.0 to 32.0) for every track. Use whole notes, half notes, or quarter notes to maintain a clean layout without overloading the sequence. The required structure to return via the `generate_multitrack_midi` tool consists of 3 tracks: 1. Strings: plays smooth legato chord changes (one chord per 1 or 2 bars continuously). 2. Brass Theme: plays a swelling simple melodic line in the C3-C5 range spanning all 8 bars. 3. Epic Percussion: hits heavily on beats 1 and 3 throughout the entire 8 bars.",
is_user_defined: false, is_user_defined: false,
is_favorite: false, is_favorite: false,
created_at: "2026-07-23T16:00:00Z" created_at: "2026-07-23T16:00:00Z"
@@ -21,7 +21,7 @@ const PromptTemplateManager = (function() {
default_bars: 4, default_bars: 4,
default_bpm: 90, default_bpm: 90,
default_scale: "C Major", default_scale: "C Major",
system_instruction_template: "You are a professional Pop Piano player. Generate a beautiful 4-bar piano chord progression (e.g. C - G - Am - F) with pleasant chord voicing and simple accompaniment. Return the MIDI notes via `generate_multitrack_midi` function on a track named 'Pop Piano'. Keep notes simple, using mostly whole/half/quarter notes. Ensure the duration of the track is precisely 4 bars (16 beats).", system_instruction_template: "You are a professional Pop Piano player. Generate a beautiful 4-bar piano chord progression (e.g. C - G - Am - F) with pleasant chord voicing and simple accompaniment. Return the MIDI notes via the `generate_multitrack_midi` function on a track named 'Pop Piano'. Write notes continuously across all 4 bars (from beat 0.0 to 16.0). Use whole/half/quarter notes continuously to ensure every bar has piano chords playing.",
is_user_defined: false, is_user_defined: false,
is_favorite: false, is_favorite: false,
created_at: "2026-07-23T16:00:00Z" created_at: "2026-07-23T16:00:00Z"
@@ -34,7 +34,7 @@ const PromptTemplateManager = (function() {
default_bars: 8, default_bars: 8,
default_bpm: 120, default_bpm: 120,
default_scale: "A Minor", default_scale: "A Minor",
system_instruction_template: "You are a Synthwave producer. Generate a driving 8-bar cyberpunk synth theme. Return MIDI notes via `generate_multitrack_midi` containing: 1. Synth Bass: eighth notes on pitch A1, C2, G1. 2. Synth Lead: simple melodic line in high register C4-E5. Keep notes clean and concise to ensure fast generation.", system_instruction_template: "You are a Synthwave producer. Generate a driving 8-bar cyberpunk synth theme. Return MIDI notes via `generate_multitrack_midi` containing: 1. Synth Bass: plays eighth notes on pitch A1, C2, G1 continuously across all 8 bars (from beat 0.0 to 32.0). 2. Synth Lead: plays a simple, melodic line in the high register (C4-E5) continuously across all 8 bars (from beat 0.0 to 32.0).",
is_user_defined: false, is_user_defined: false,
is_favorite: false, is_favorite: false,
created_at: "2026-07-23T16:00:00Z" created_at: "2026-07-23T16:00:00Z"