diff --git a/src/scenes/DaftSynthScene.ts b/src/scenes/DaftSynthScene.ts index ef6d7cf..f190362 100644 --- a/src/scenes/DaftSynthScene.ts +++ b/src/scenes/DaftSynthScene.ts @@ -7,7 +7,10 @@ import {PadsSceneSettings} from './PadsScene.ts'; export class DaftSynthScene extends SimpleSynthScene { constructor() { - super(); + super({ + min: SimpleSynthScene.minNumberOfOctaves, + max: SimpleSynthScene.maxNumberOfOctaves, + }); this.settings.noteDuration = 2; } diff --git a/src/scenes/SimpleSynthScene.ts b/src/scenes/SimpleSynthScene.ts index 88e4ca6..1427501 100644 --- a/src/scenes/SimpleSynthScene.ts +++ b/src/scenes/SimpleSynthScene.ts @@ -4,34 +4,35 @@ import {createAudioContext} from '../samples/sample-utils.ts'; import Phaser from 'phaser'; import {PhaserColors} from '../utils/colors.ts'; -const numberOfNotes = 12; -const maxNumberOfOctaves = 6; -const maxNumberOfPads = numberOfNotes * maxNumberOfOctaves; +export class SimpleSynthScene extends PadsScene { -const getCols = (octaves: Range) => { - return octaves.max + 1 - octaves.min; -} + protected static numberOfNotes = 12; + protected static minNumberOfOctaves = 1; + protected static maxNumberOfOctaves = 6; + protected static maxNumberOfPads = this.numberOfNotes * this.maxNumberOfOctaves; -const getRows = () => { - return numberOfNotes; -} + protected static octaveRange = { + min: 2, + max: this.maxNumberOfOctaves - 2, + }; -const octaveRange = { - min: 2, - max: maxNumberOfOctaves - 2, -}; + protected static getCols(octaves: Range) { + return octaves.max + 1 - octaves.min; + } -export class SimpleSynthScene extends PadsScene { + protected static getRows() { + return this.numberOfNotes; + } - constructor() { - super(getCols(octaveRange), getRows()); + constructor(octaveRange: Range = SimpleSynthScene.octaveRange) { + super(SimpleSynthScene.getCols(octaveRange), SimpleSynthScene.getRows()); this.settings.noteDuration = 1.5; this.settings.octaveRange = octaveRange; } protected getNoteColor(index: number): Phaser.Display.Color { return super.getPadColor( - maxNumberOfPads, + SimpleSynthScene.maxNumberOfPads, index + this.getNoteIndexOffset() ); // const key = allFrequencies[index]?.key; @@ -75,7 +76,7 @@ export class SimpleSynthScene extends PadsScene { * when changing the range of the notes, we need to offset the index to get the correct note */ protected getNoteIndexOffset() { - return this.getLowerRangeIndex() * numberOfNotes; + return this.getLowerRangeIndex() * SimpleSynthScene.numberOfNotes; } protected getLowerRangeIndex() { @@ -95,12 +96,12 @@ export class SimpleSynthScene extends PadsScene { onSettingChange(setting: Setting) { super.onSettingChange(setting); if (setting.octaveRange) { - super.changePadNumber(getCols(setting.octaveRange), numberOfNotes); + super.changePadNumber(SimpleSynthScene.getCols(setting.octaveRange), SimpleSynthScene.numberOfNotes); } } } -const playPianoTone = ({ frequency, volume = 50, noteDuration = 1.5 }: { frequency: number } & PadsSceneSettings) => { +const playPianoTone = ({frequency, volume = 50, noteDuration = 1.5}: { frequency: number } & PadsSceneSettings) => { const audioContext = createAudioContext(); // Create an oscillator for the main tone const oscillator = audioContext.createOscillator();