Skip to content

Commit

Permalink
feat(drums): add mid tom
Browse files Browse the repository at this point in the history
  • Loading branch information
domi7777 committed Dec 20, 2024
1 parent 9a948c0 commit 8895898
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
10 changes: 0 additions & 10 deletions src/samples/drums/tom-high.ts

This file was deleted.

22 changes: 20 additions & 2 deletions src/samples/drums/tom-low.ts → src/samples/drums/toms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,29 @@ export function triggerTom(volume = 50, settings = defaults) {
osc.stop(time + settings.decayTime + 0.02);
}

export function playTom1Low(volume = 100) {
export function playLowTom(volume = 100) {
triggerTom(volume, {
frequency: 180, // Higher than kick but lower than high tom
frequency: 160, // Lower than mid tom
decayTime: 0.45, // Longer decay
pitchDecay: 0.25, // More pitch decay
frequencyDrop: 0.6 // More pronounced drop than mid tom
});
}

export function playMidTom(volume = 100) {
triggerTom(volume, {
frequency: 220, // Between low and high tom
decayTime: 0.35, // Medium decay
pitchDecay: 0.15, // Medium pitch decay
frequencyDrop: 0.4 // More pronounced drop than high tom
});
}

export function playHighTom(volume = 100) {
triggerTom(volume, {
frequency: 280, // Higher than low tom
decayTime: 0.3, // Shorter decay
pitchDecay: 0.1, // Less pitch decay
frequencyDrop: 0.3 // Less pronounced drop than low tom
});
}
10 changes: 5 additions & 5 deletions src/samples/play-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {playSnare} from './drums/snare.ts';
import {playCrashCymbal} from './drums/crash.ts';
import {playOpenHiHat} from './drums/hihat-open.ts';
import {playRide} from './drums/ride.ts';
import {playTom1Low} from './drums/tom-low.ts';
import {playTom2High} from './drums/tom-high.ts';
import {resetAudioContext} from './sample-utils.ts';
import {logger} from '../utils/logger.ts';
import {playHighTom, playLowTom, playMidTom} from './drums/toms.ts';

const sampleToAudioFn: Record<Sample, (volume: number) => void> = {
hihat: playHiHat,
Expand All @@ -16,8 +15,9 @@ const sampleToAudioFn: Record<Sample, (volume: number) => void> = {
crash: playCrashCymbal,
'hihat-open': playOpenHiHat,
ride: playRide,
'tom-low': playTom1Low,
'tom-high': playTom2High,
'tom-low': playLowTom,
'tom-high': playHighTom,
'tom-mid': playMidTom,
}

export const playSample = (sample: Sample, volume: number) => {
Expand All @@ -34,4 +34,4 @@ export const playSample = (sample: Sample, volume: number) => {
}

export type Sample = 'hihat' | 'hihat-open' | 'ride' | 'crash'
| 'snare' | 'kick' | 'tom-low' | 'tom-high';
| 'snare' | 'kick' | 'tom-low' | 'tom-high' | 'tom-mid';
9 changes: 7 additions & 2 deletions src/scenes/DrumsScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ const padColors: Record<Sample, HexaColor> = {
ride: Colors.yellow2,
'tom-low': Colors.orange2,
'tom-high': Colors.purple,
'tom-mid': Colors.pink,
};

// create same object but instead of instrument, name colors

export class DrumsScene extends PadsScene {

private instruments: Sample[] = [
// cymbals
'crash',
'crash',
'ride',
'hihat-open',
'hihat',
// drums
'snare',
'tom-low',
'tom-high',
'tom-mid',
'tom-low',
'kick',
]

constructor() {
super(2, 4);
super(2, 5);
}

protected getPadColor(_numberOfPads: number, _index: number) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Colors = {
yellow2: '#F5C542',
orange2: '#FF7F50',
purple: '#9B59B6',
pink: '#FFC0CB',
} as const;

export type PhaserColor = Phaser.Display.Color;
Expand Down Expand Up @@ -59,6 +60,9 @@ export const PhaserColors = {
get purple() {
return hexToColor(Colors.purple);
},
get pink() {
return hexToColor(Colors.pink);
},
} as const satisfies Record<keyof typeof Colors, PhaserColor>;

// @Deprecated
Expand Down

0 comments on commit 8895898

Please sign in to comment.