Skip to content

Commit

Permalink
feat(electro): widest range of octaves by default
Browse files Browse the repository at this point in the history
  • Loading branch information
domi7777 committed Dec 28, 2024
1 parent 1ccd91a commit 72488f1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/scenes/DaftSynthScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
41 changes: 21 additions & 20 deletions src/scenes/SimpleSynthScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit 72488f1

Please sign in to comment.