diff --git a/public/resources/modes/functional_chords.json b/public/resources/modes/functional_chords.json index e0092ca..0324683 100644 --- a/public/resources/modes/functional_chords.json +++ b/public/resources/modes/functional_chords.json @@ -1,5 +1,7 @@ { "ionian": { + "name": "Ionian", + "steps": [2, 2, 1, 2, 2, 2, 1], "T": ["I", "vi", "iii", "I⁶"], "S": ["IV", "ii", "vi", "IV⁶"], "D": ["V", "V7", "vii°", "♭II"], @@ -18,6 +20,8 @@ } }, "aeolian": { + "name": "Aeolian", + "steps": [2, 1, 2, 2, 1, 2, 2], "T": ["i", "VI", "III", "i⁶"], "S": ["iv", "ii°", "VI", "iv⁶"], "D": ["v", "♭VII"], @@ -34,6 +38,8 @@ } }, "harmonic_minor": { + "name": "Harmonic Minor", + "steps": [2, 1, 2, 2, 1, 3, 1], "T": ["i", "VI", "III+", "i⁶"], "S": ["iv", "ii°", "VI", "iv⁶"], "D": ["V", "V7", "vii°", "♭II"], @@ -52,6 +58,8 @@ } }, "melodic_minor": { + "name": "Melodic Minor", + "steps": [2, 1, 2, 2, 2, 2, 1], "T": ["i", "III+", "vi", "i⁶"], "S": ["IV", "ii"], "D": ["V", "vii°"], @@ -67,6 +75,8 @@ } }, "dorian": { + "name": "Dorian", + "steps": [2, 1, 2, 2, 2, 1, 2], "T": ["i", "III", "i⁶"], "S": ["IV", "ii"], "D": ["v", "♭VII"], @@ -81,6 +91,8 @@ } }, "phrygian": { + "name": "Phrygian", + "steps": [1, 2, 2, 2, 1, 2, 2], "T": ["i", "i⁶"], "S": ["♭II", "iv"], "D": [], @@ -92,6 +104,8 @@ } }, "lydian": { + "name": "Lydian", + "steps": [2, 2, 2, 1, 2, 2, 1], "T": ["I", "I⁶"], "S": ["II"], "D": ["V"], @@ -103,6 +117,8 @@ } }, "mixolydian": { + "name": "Mixolydian", + "steps": [2, 2, 1, 2, 2, 1, 2], "T": ["I", "vi"], "S": ["IV", "ii"], "D": ["v", "♭VII"], @@ -116,6 +132,8 @@ } }, "locrian": { + "name": "Locrian", + "steps": [1, 2, 2, 1, 2, 2, 2], "T": ["i°"], "S": ["♭II", "iv"], "D": [], @@ -126,6 +144,8 @@ } }, "phrygian_dominant": { + "name": "Phrygian Dominant", + "steps": [1, 3, 1, 2, 1, 2, 2], "T": ["I", "I⁶"], "S": ["♭II", "iv"], "D": ["v°", "vii"], @@ -139,6 +159,8 @@ } }, "harmonic_major": { + "name": "Harmonic Major", + "steps": [2, 2, 1, 2, 1, 3, 1], "T": ["I", "VI", "iii"], "S": ["IV", "ii"], "D": ["V", "V7", "vii°", "♭II"], diff --git a/public/resources/modes/mode_list.json b/public/resources/modes/mode_list.json deleted file mode 100644 index e255879..0000000 --- a/public/resources/modes/mode_list.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "modes": [ - { - "id": "ionian", - "name": "Ionian", - "steps": [2, 2, 1, 2, 2, 2, 1] - }, - { - "id": "aeolian", - "name": "Aeolian", - "steps": [2, 1, 2, 2, 1, 2, 2] - }, - { - "id": "harmonic_minor", - "name": "Harmonic Minor", - "steps": [2, 1, 2, 2, 1, 3, 1] - }, - { - "id": "melodic_minor", - "name": "Melodic Minor", - "steps": [2, 1, 2, 2, 2, 2, 1] - }, - { - "id": "dorian", - "name": "Dorian", - "steps": [2, 1, 2, 2, 2, 1, 2] - }, - { - "id": "phrygian", - "name": "Phrygian", - "steps": [1, 2, 2, 2, 1, 2, 2] - }, - { - "id": "lydian", - "name": "Lydian", - "steps": [2, 2, 2, 1, 2, 2, 1] - }, - { - "id": "mixolydian", - "name": "Mixolydian", - "steps": [2, 2, 1, 2, 2, 1, 2] - }, - { - "id": "locrian", - "name": "Locrian", - "steps": [1, 2, 2, 1, 2, 2, 2] - }, - { - "id": "phrygian_dominant", - "name": "Phrygian Dominant", - "steps": [1, 3, 1, 2, 1, 2, 2] - }, - { - "id": "harmonic_major", - "name": "Harmonic Major", - "steps": [2, 2, 1, 2, 1, 3, 1] - } - ] -} diff --git a/src/App.tsx b/src/App.tsx index 845296a..9a037a0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -45,28 +45,30 @@ function App() { // Load all mode and chord data files in parallel try { - const [modeListResponse, functionalChordsResponse] = await Promise.all([ - fetch(`${import.meta.env.BASE_URL}resources/modes/mode_list.json`), + const [functionalChordsResponse] = await Promise.all([ fetch(`${import.meta.env.BASE_URL}resources/modes/functional_chords.json`) ]); - const [modeListData, functionalChordsData] = await Promise.all([ - modeListResponse.json(), + const [functionalChordsData] = await Promise.all([ functionalChordsResponse.json() ]); - // Store mode data with id, name, and steps - KGCore.MODE_DATA = modeListData.modes; - console.log(`Loaded ${modeListData.modes.length} modes:`, modeListData.modes.map((m: { name: string }) => m.name)); - - // Store functional chords data (T/S/D by mode, including mode-specific chord notes) + // Store functional chords data (includes name, steps, T/S/D groups, and chord notes for each mode) KGCore.FUNCTIONAL_CHORDS_DATA = functionalChordsData; console.log(`Loaded functional chords for ${Object.keys(functionalChordsData).length} modes`); } catch (error) { console.error('Failed to load mode/chord data:', error); // Fallback to defaults - KGCore.MODE_DATA = [{ id: 'ionian', name: 'Ionian', steps: [2, 2, 1, 2, 2, 2, 1] }]; - KGCore.FUNCTIONAL_CHORDS_DATA = {}; + KGCore.FUNCTIONAL_CHORDS_DATA = { + ionian: { + name: 'Ionian', + steps: [2, 2, 1, 2, 2, 2, 1], + T: [], + S: [], + D: [], + chords: {} + } + }; } // Log maxBars after initialization completes diff --git a/src/components/piano-roll/PianoRollToolbar.tsx b/src/components/piano-roll/PianoRollToolbar.tsx index 02eda12..ed12ea0 100644 --- a/src/components/piano-roll/PianoRollToolbar.tsx +++ b/src/components/piano-roll/PianoRollToolbar.tsx @@ -38,7 +38,7 @@ const PianoRollToolbar: React.FC = ({
{/* Left section with mode and chord guide dropdowns */} ({ label: m.name, value: m.id }))} + options={Object.entries(KGCore.FUNCTIONAL_CHORDS_DATA).map(([id, data]) => ({ label: data.name, value: id }))} value={selectedMode} onChange={(value) => onModeChange(value)} label="Mode" diff --git a/src/core/KGCore.ts b/src/core/KGCore.ts index 5a07788..ddb09e7 100644 --- a/src/core/KGCore.ts +++ b/src/core/KGCore.ts @@ -18,8 +18,7 @@ export class KGCore { private static _instance: KGCore | null = null; // Global music data resources - public static MODE_DATA: Array<{ id: string; name: string; steps: number[] }> = []; // Modes with id, display name, and interval steps - public static FUNCTIONAL_CHORDS_DATA: Record }> = {}; // Functional chords by mode (T/S/D) with mode-specific chord notes + public static FUNCTIONAL_CHORDS_DATA: Record }> = {}; // Functional chords by mode (T/S/D) with mode-specific chord notes, and mode metadata private currentProject: KGProject = new KGProject(); diff --git a/src/util/scaleUtil.test.ts b/src/util/scaleUtil.test.ts index 8dcb2c3..fc089cc 100644 --- a/src/util/scaleUtil.test.ts +++ b/src/util/scaleUtil.test.ts @@ -16,15 +16,7 @@ import functionalChordsData from '../../public/resources/modes/functional_chords describe('scaleUtil', () => { // Setup: Mock KGCore with real chord data beforeEach(() => { - // Mock MODE_DATA with ionian for basic tests - KGCore.MODE_DATA = [ - { id: 'ionian', name: 'Ionian', steps: [2, 2, 1, 2, 2, 2, 1] }, - { id: 'dorian', name: 'Dorian', steps: [2, 1, 2, 2, 2, 1, 2] }, - { id: 'aeolian', name: 'Aeolian', steps: [2, 1, 2, 2, 1, 2, 2] }, - { id: 'mixolydian', name: 'Mixolydian', steps: [2, 2, 1, 2, 2, 1, 2] } - ] - - // Use real functional chords data from JSON file + // Use real functional chords data from JSON file (includes name, steps, and chord data) KGCore.FUNCTIONAL_CHORDS_DATA = functionalChordsData }) diff --git a/src/util/scaleUtil.ts b/src/util/scaleUtil.ts index 5157220..492b275 100644 --- a/src/util/scaleUtil.ts +++ b/src/util/scaleUtil.ts @@ -66,12 +66,12 @@ export const getScalePitchClasses = (rootNote: string, modeSteps: number[]): num * @returns Array of interval steps, or default ionian if not found */ export const getModeSteps = (modeId: string): number[] => { - const modeData = KGCore.MODE_DATA.find(m => m.id === modeId); - if (!modeData) { + const functionalChords = KGCore.FUNCTIONAL_CHORDS_DATA[modeId]; + if (!functionalChords || !functionalChords.steps) { console.warn(`Mode not found: ${modeId}, defaulting to ionian`); return [2, 2, 1, 2, 2, 2, 1]; // Default to ionian (major scale) } - return modeData.steps; + return functionalChords.steps; }; /**