mirror of
https://github.com/9x/sheetmusictrainer.git
synced 2026-11-03 22:03:54 +01:00
Unified target-note controls: key filter + fret window across all modes
- New shared PracticeFilter settings (keyTonic/keyMode/fretWindow), persisted via AppSettings.practice, defaults off (behavior unchanged). - music/targetPool.ts: single source for the effective target pool — base playable range ∩ fret window ∩ key/mode pitch classes (9 modes incl. pentatonic, same scale machinery as Phrase Mode). - useGameLogic now builds validNotes via computeTargetPool. - TargetNoteControls component (key on/off + tonic/mode, fret window on/off + min/max) rendered in Controls for all game modes; key is independent of the displayed key signature. - Phrase Mode binds its key/fret-window setup to the same shared filter (read/write mirror) and drops the duplicate controls in its setup panel. - Tests: targetPool.test.ts (7 cases); suite 156/156 green, build ok.
This commit is contained in:
@@ -8,12 +8,8 @@ import {
|
||||
getRandomNote,
|
||||
getNoteDetails
|
||||
} from '../music/NoteUtils';
|
||||
import {
|
||||
TUNINGS,
|
||||
getOpenStringNotes,
|
||||
getFirstPositionNotes,
|
||||
} from '../music/Tunings';
|
||||
import { INSTRUMENT_DEFINITIONS } from '../music/InstrumentConfigs';
|
||||
import { computeTargetPool } from '../music/targetPool';
|
||||
import { getPracticeFilter } from '../types/SettingsTypes';
|
||||
import {
|
||||
NOTE_MATCH_THRESHOLD_MS,
|
||||
NOTE_MATCH_GRACE_MS,
|
||||
@@ -36,65 +32,25 @@ export const useGameLogic = (
|
||||
const [tracker] = useState(() => new MatchTracker(NOTE_MATCH_THRESHOLD_MS, NOTE_MATCH_GRACE_MS));
|
||||
|
||||
// --- Valid Notes Calculation ---
|
||||
const currentTuning = TUNINGS[settings.tuningId];
|
||||
const currentInstrumentDef = INSTRUMENT_DEFINITIONS[settings.instrument];
|
||||
|
||||
const validNotes = useMemo(() => {
|
||||
const rangeConfig = currentInstrumentDef.ranges.find(r => r.id === settings.difficulty);
|
||||
|
||||
const getNotesFromConfig = (config: typeof rangeConfig) => {
|
||||
if (!config) return [];
|
||||
|
||||
if (config.type === 'open_strings') {
|
||||
if (currentTuning) return getOpenStringNotes(currentTuning);
|
||||
return config.notes || [];
|
||||
}
|
||||
|
||||
if (config.type === 'first_position') {
|
||||
if (currentTuning) return getFirstPositionNotes(currentTuning);
|
||||
return config.notes || [];
|
||||
}
|
||||
|
||||
if (config.type === 'custom_fret') {
|
||||
if (currentTuning) {
|
||||
const minFret = settings.customMinFret ?? config.defaultMinFret ?? 0;
|
||||
const maxFret = settings.customMaxFret ?? config.defaultMaxFret ?? 12;
|
||||
const notes = new Set<number>();
|
||||
currentTuning.strings.forEach(stringMidi => {
|
||||
for (let fret = minFret; fret <= maxFret; fret++) {
|
||||
notes.add(stringMidi + fret);
|
||||
}
|
||||
});
|
||||
return Array.from(notes).sort((a, b) => a - b);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
if (config.type === 'specific_string') {
|
||||
if (currentTuning && config.stringIndex !== undefined) {
|
||||
const openNote = currentTuning.strings[config.stringIndex];
|
||||
if (openNote === undefined) return [];
|
||||
const notes = [];
|
||||
for (let i = 0; i <= 12; i++) {
|
||||
notes.push(openNote + i);
|
||||
}
|
||||
return notes;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
if (config.notes) return config.notes;
|
||||
if (config.min !== undefined && config.max !== undefined) {
|
||||
return Array.from({ length: config.max - config.min + 1 }, (_, i) => config.min! + i);
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
if (rangeConfig) return getNotesFromConfig(rangeConfig);
|
||||
const fallbackRange = currentInstrumentDef.ranges[0];
|
||||
return getNotesFromConfig(fallbackRange);
|
||||
|
||||
}, [settings.difficulty, currentInstrumentDef, currentTuning, settings.customMinFret, settings.customMaxFret]);
|
||||
const pf = getPracticeFilter(settings);
|
||||
return computeTargetPool({
|
||||
instrumentId: settings.instrument,
|
||||
difficulty: settings.difficulty,
|
||||
tuningId: settings.tuningId,
|
||||
customMinFret: settings.customMinFret,
|
||||
customMaxFret: settings.customMaxFret,
|
||||
keyEnabled: pf.keyEnabled,
|
||||
keyTonic: pf.keyTonic,
|
||||
keyMode: pf.keyMode,
|
||||
fretWindowEnabled: pf.fretWindowEnabled,
|
||||
fretMin: pf.fretMin,
|
||||
fretMax: pf.fretMax,
|
||||
});
|
||||
}, [settings.instrument, settings.difficulty, settings.tuningId, settings.customMinFret, settings.customMaxFret,
|
||||
settings.practice?.keyEnabled, settings.practice?.keyTonic, settings.practice?.keyMode,
|
||||
settings.practice?.fretWindowEnabled, settings.practice?.fretMin, settings.practice?.fretMax]);
|
||||
|
||||
// --- Note Generation ---
|
||||
const generateNewNote = useCallback((keepFeedback = false) => {
|
||||
|
||||
Reference in New Issue
Block a user