// handlers/music/composition/generateMusicLessonHandler.ts import * as vscode from "vscode"; // βœ… UNIFIED ARCHITECTURE IMPORTS import { ensureDirectoryExists, isBrainAvailable, shareAnalysisData, } from "../../../shared/utils"; // 🧠 KEEP FOR All HANDLER FILESβ€” Brain Enhanced import { BrainConnector } from "../../../brain/BrainConnector"; export async function generateMusicLessonHandler(): Promise { try { // Get lesson topic const lessonTopic = await vscode.window.showQuickPick( [ "🎡 Music Theory Basics", "🎸 Chord Progressions", "🎹 Scale Patterns", "🎢 Rhythm & Timing", "🎀 Songwriting Fundamentals", "🎡 Harmony & Voice Leading", "🎸 Guitar Techniques", "🎹 Piano Fundamentals", ], { placeHolder: "Select lesson topic", } ); if (!lessonTopic) return; // Get skill level const skillLevel = await vscode.window.showQuickPick( ["Absolute Beginner", "Beginner", "Intermediate", "Advanced", "Expert"], { placeHolder: "Select skill level", } ); if (!skillLevel) return; // Get lesson duration const duration = await vscode.window.showQuickPick( ["15 minutes", "30 minutes", "45 minutes", "60 minutes"], { placeHolder: "Select lesson duration", } ); if (!duration) return; vscode.window.showInformationMessage("🎼 Generating AI music lesson..."); const lessonContent = await generateMusicLessonContent( lessonTopic, skillLevel, duration ); // Create lesson file using established patterns await createMusicLessonFile(lessonContent, lessonTopic); // Share with brain if (isBrainAvailable()) { await shareAnalysisData("music-theory", { action: "music-lesson-generation", topic: lessonTopic, skillLevel, duration, success: true, timestamp: Date.now(), }); } vscode.window.showInformationMessage("βœ… Music lesson generated! 🎼"); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); console.error("🎼 Music lesson generation error:", error); await shareAnalysisData("music-theory", { action: "music-lesson-generation", success: false, error: errorMessage, timestamp: Date.now(), }); vscode.window.showErrorMessage( `🎼 Music lesson generation failed: ${errorMessage}` ); } } async function generateMusicLessonContent( topic: string, level: string, duration: string ): Promise { const topicName = topic .replace(/[🎡🎸🎹🎢🎀]/g, "") .trim() .replace(/\s+/g, ""); return `# 🎼 ${topic} - ${level} Lesson **Duration:** ${duration} **Generated:** ${new Date().toLocaleDateString()} ## πŸ“š Lesson Overview This AI-generated lesson covers ${topic} at a ${level.toLowerCase()} level. ## 🎯 Learning Objectives By the end of this lesson, you will: - Understand the fundamentals of ${topic} - Apply practical techniques - Practice with guided exercises - Build confidence in your musical skills ## πŸ“– Lesson Content ### Part 1: Introduction (5 minutes) - What is ${topic}? - Why is it important? - Key concepts to understand ### Part 2: Core Concepts (${parseInt(duration) * 0.6} minutes) - Detailed explanation of concepts - Visual examples and diagrams - Audio demonstrations ### Part 3: Practice Exercises (${parseInt(duration) * 0.25} minutes) - Guided practice activities - Progressive difficulty exercises - Real-time feedback ### Part 4: Review & Next Steps (${parseInt(duration) * 0.15} minutes) - Lesson summary - Key takeaways - Recommended next lessons ## 🎡 Interactive Elements - [ ] Audio playback examples - [ ] Visual chord/scale diagrams - [ ] Practice timing exercises - [ ] Progress tracking ## πŸ“ Notes Section *Add your personal notes and observations here* --- *Generated by Cipher AI Music Education System*`; } async function createMusicLessonFile( content: string, topic: string ): Promise { const workspaceFolder = vscode.workspace.workspaceFolders?.[0]; if (!workspaceFolder) { throw new Error("No workspace folder found"); } const fileName = topic .replace(/[🎡🎸🎹🎢🎀]/g, "") .trim() .replace(/\s+/g, "") + "Lesson.md"; const lessonsDir = vscode.Uri.joinPath(workspaceFolder.uri, "music-lessons"); // Use established directory creation utility await ensureDirectoryExists(lessonsDir); const fileUri = vscode.Uri.joinPath(lessonsDir, fileName); await vscode.workspace.fs.writeFile(fileUri, Buffer.from(content)); // Open the created file const doc = await vscode.workspace.openTextDocument(fileUri); await vscode.window.showTextDocument(doc); }