Add app info and instrument controls

This commit is contained in:
Ninosaurier committed 2026-11-15 13:43:06 +01:00
1 parent e23825cdb1
commit 9d8f277971
38 files changed
+4001 -257

No files matched your search

+31 -39
View File
@@ -1,57 +1,49 @@
import { useState } from 'react';
import { IonApp, IonContent, IonPage } from '@ionic/react';
import { BeatLoopPanel } from './components/BeatLoopPanel';
import { BeatTemplateSelector } from './components/BeatTemplateSelector';
import { AppHeader } from './components/AppHeader';
import { TransportBar } from './components/TransportBar';
import { useBeatStudio } from './hooks/useBeatStudio';
import { AboutView } from './views/AboutView';
import { StudioView } from './views/StudioView';
import type { AppView } from './views/viewTypes';
function App() {
const studio = useBeatStudio();
const [activeView, setActiveView] = useState<AppView>('studio');
const isStudioView = activeView === 'studio';
function navigateTo(view: AppView): void {
if (view === 'about' && studio.sequencer.isPlaying) {
void studio.sequencer.togglePlayback();
}
setActiveView(view);
}
return (
<IonApp>
<IonPage>
<IonContent fullscreen className="app-content">
<div className="app-shell">
<header className="app-header">
<a className="brand" href="#studio" aria-label="BeatHound home">
<img
className="brand-logo"
src="/logo/logo-horizontal-dark-notagline.svg"
alt=""
/>
</a>
<span className="header-tag">Sharpen your sense of rhythm</span>
</header>
<main id="studio" className="studio">
<div className="studio-heading">
<h1>Build a beat.</h1>
<p className="template-prompt">Choose a dance template</p>
<BeatTemplateSelector onSelectTemplate={studio.applyTemplate} />
<p
className={`intro-copy${studio.sequencer.beats.length > 0 ? ' is-hidden' : ''}`}
aria-hidden={studio.sequencer.beats.length > 0}
>
Add a sound, then move it around the loop.
</p>
</div>
<BeatLoopPanel sequencer={studio.sequencer} soundPalette={studio.soundPalette} />
{studio.sequencer.audioError && (
<p className="audio-error" role="alert">{studio.sequencer.audioError}</p>
)}
</main>
<AppHeader activeView={activeView} onNavigate={navigateTo} />
{isStudioView ? (
<StudioView studio={studio} />
) : (
<AboutView onReturnToStudio={() => navigateTo('studio')} />
)}
</div>
</IonContent>
<TransportBar
isPlaying={studio.sequencer.isPlaying}
isStarting={studio.sequencer.isStarting}
hasBeats={studio.sequencer.beats.length > 0}
onTogglePlayback={studio.sequencer.togglePlayback}
onAddSound={studio.addSound}
/>
{isStudioView && (
<TransportBar
isPlaying={studio.sequencer.isPlaying}
isStarting={studio.sequencer.isStarting}
hasBeats={studio.sequencer.beats.length > 0}
selectedBeat={studio.sequencer.selectedBeat}
onTogglePlayback={studio.sequencer.togglePlayback}
onAddInstrument={studio.addSound}
onChangeBeatPitch={studio.sequencer.changeBeatPitch}
/>
)}
</IonPage>
</IonApp>
);
+4 -4
View File
@@ -1,5 +1,5 @@
import type { SoundId } from '../domain/sounds';
import { SOUND_VOICES } from './soundVoices';
import type { InstrumentId } from '../domain/instruments';
import { INSTRUMENT_VOICES } from './soundVoices';
type AudioWindow = Window & typeof globalThis & {
webkitAudioContext?: typeof AudioContext;
@@ -30,9 +30,9 @@ export class AudioEngine {
}
}
play(soundId: SoundId): void {
play(instrumentId: InstrumentId, pitchSemitones: number): void {
if (this.context?.state !== 'running') return;
SOUND_VOICES[soundId](this.context);
INSTRUMENT_VOICES[instrumentId](this.context, pitchSemitones);
}
async dispose(): Promise<void> {
+246 -25
View File
@@ -1,4 +1,95 @@
export function playKick(context: AudioContext): void {
interface ToneOptions {
frequency: number;
duration: number;
peakGain: number;
waveform?: OscillatorType;
attack?: number;
endFrequency?: number;
filterFrequency?: number;
}
interface NoiseOptions {
duration: number;
peakGain: number;
filterType: BiquadFilterType;
filterFrequency: number;
bursts?: readonly number[];
}
function getPitchedFrequency(baseFrequency: number, pitchSemitones: number): number {
return baseFrequency * (2 ** (pitchSemitones / 12));
}
function playTone(context: AudioContext, options: ToneOptions): void {
const now = context.currentTime;
const oscillator = context.createOscillator();
const envelope = context.createGain();
const attack = Math.min(options.attack ?? 0.008, options.duration / 2);
oscillator.type = options.waveform ?? 'sine';
oscillator.frequency.setValueAtTime(options.frequency, now);
if (options.endFrequency) {
oscillator.frequency.exponentialRampToValueAtTime(options.endFrequency, now + options.duration);
}
envelope.gain.setValueAtTime(0.0001, now);
envelope.gain.exponentialRampToValueAtTime(options.peakGain, now + attack);
envelope.gain.exponentialRampToValueAtTime(0.0001, now + options.duration);
if (options.filterFrequency) {
const filter = context.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.setValueAtTime(options.filterFrequency, now);
oscillator.connect(filter);
filter.connect(envelope);
} else {
oscillator.connect(envelope);
}
envelope.connect(context.destination);
oscillator.start(now);
oscillator.stop(now + options.duration + 0.01);
}
function playNoise(context: AudioContext, options: NoiseOptions): void {
const now = context.currentTime;
const buffer = context.createBuffer(
1,
Math.ceil(context.sampleRate * options.duration),
context.sampleRate,
);
const channel = buffer.getChannelData(0);
for (let index = 0; index < channel.length; index += 1) {
channel[index] = Math.random() * 2 - 1;
}
const source = context.createBufferSource();
const filter = context.createBiquadFilter();
const envelope = context.createGain();
source.buffer = buffer;
filter.type = options.filterType;
filter.frequency.setValueAtTime(options.filterFrequency, now);
envelope.gain.setValueAtTime(0.0001, now);
if (options.bursts) {
options.bursts.forEach((burstTime) => {
envelope.gain.setValueAtTime(0.0001, now + burstTime);
envelope.gain.exponentialRampToValueAtTime(options.peakGain, now + burstTime + 0.003);
envelope.gain.exponentialRampToValueAtTime(0.0001, now + burstTime + 0.025);
});
} else {
envelope.gain.exponentialRampToValueAtTime(options.peakGain, now + 0.004);
envelope.gain.exponentialRampToValueAtTime(0.0001, now + options.duration);
}
source.connect(filter);
filter.connect(envelope);
envelope.connect(context.destination);
source.start(now);
source.stop(now + options.duration);
}
export function playKick(context: AudioContext, pitchSemitones: number): void {
const ratio = 2 ** (pitchSemitones / 12);
const now = context.currentTime;
const oscillator = context.createOscillator();
const transient = context.createOscillator();
@@ -6,8 +97,8 @@ export function playKick(context: AudioContext): void {
const transientGain = context.createGain();
oscillator.type = 'sine';
oscillator.frequency.setValueAtTime(175, now);
oscillator.frequency.exponentialRampToValueAtTime(62, now + 0.16);
oscillator.frequency.setValueAtTime(175 * ratio, now);
oscillator.frequency.exponentialRampToValueAtTime(62 * ratio, now + 0.16);
gain.gain.setValueAtTime(0.0001, now);
gain.gain.exponentialRampToValueAtTime(0.95, now + 0.008);
gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.32);
@@ -27,27 +118,157 @@ export function playKick(context: AudioContext): void {
transient.stop(now + 0.035);
}
export function playSnare(context: AudioContext): void {
playNoise(context, {
duration: 0.2,
peakGain: 0.55,
filterType: 'highpass',
filterFrequency: 1200,
});
playTone(context, { frequency: 185, duration: 0.13, peakGain: 0.3 });
}
export function playHiHat(context: AudioContext): void {
const now = context.currentTime;
const duration = 0.075;
const buffer = context.createBuffer(1, Math.ceil(context.sampleRate * duration), context.sampleRate);
const channel = buffer.getChannelData(0);
for (let index = 0; index < channel.length; index += 1) {
channel[index] = Math.random() * 2 - 1;
}
const source = context.createBufferSource();
const filter = context.createBiquadFilter();
const gain = context.createGain();
source.buffer = buffer;
filter.type = 'highpass';
filter.frequency.setValueAtTime(5500, now);
gain.gain.setValueAtTime(0.0001, now);
gain.gain.exponentialRampToValueAtTime(0.38, now + 0.004);
gain.gain.exponentialRampToValueAtTime(0.0001, now + duration);
source.connect(filter);
filter.connect(gain);
gain.connect(context.destination);
source.start(now);
source.stop(now + duration);
playNoise(context, {
duration: 0.075,
peakGain: 0.38,
filterType: 'highpass',
filterFrequency: 5500,
});
}
export function playToms(context: AudioContext, pitchSemitones: number): void {
const frequency = getPitchedFrequency(155, pitchSemitones);
playTone(context, {
frequency,
endFrequency: frequency * 0.48,
duration: 0.32,
peakGain: 0.72,
});
}
export function playCymbals(context: AudioContext): void {
playNoise(context, {
duration: 0.48,
peakGain: 0.3,
filterType: 'highpass',
filterFrequency: 6500,
});
}
export function playClap(context: AudioContext): void {
playNoise(context, {
duration: 0.16,
peakGain: 0.52,
filterType: 'bandpass',
filterFrequency: 1500,
bursts: [0, 0.025, 0.05, 0.075],
});
}
export function playShaker(context: AudioContext): void {
playNoise(context, {
duration: 0.12,
peakGain: 0.24,
filterType: 'highpass',
filterFrequency: 3600,
});
}
export function playCowbell(context: AudioContext): void {
playTone(context, { frequency: 560, duration: 0.18, peakGain: 0.24, waveform: 'square' });
playTone(context, { frequency: 845, duration: 0.16, peakGain: 0.19, waveform: 'square' });
}
export function playWoodblock(context: AudioContext): void {
playTone(context, {
frequency: 920,
endFrequency: 620,
duration: 0.075,
peakGain: 0.48,
});
}
export function playBongos(context: AudioContext, pitchSemitones: number): void {
const frequency = getPitchedFrequency(245, pitchSemitones);
playTone(context, {
frequency,
endFrequency: frequency * 0.78,
duration: 0.17,
peakGain: 0.62,
});
}
export function playBass(context: AudioContext, pitchSemitones: number): void {
playTone(context, {
frequency: getPitchedFrequency(65.41, pitchSemitones),
duration: 0.36,
peakGain: 0.42,
waveform: 'sawtooth',
filterFrequency: 320,
});
}
export function playPiano(context: AudioContext, pitchSemitones: number): void {
const frequency = getPitchedFrequency(261.63, pitchSemitones);
playTone(context, { frequency, duration: 0.42, peakGain: 0.32, waveform: 'triangle' });
playTone(context, { frequency: frequency * 2, duration: 0.28, peakGain: 0.1 });
playTone(context, { frequency: frequency * 3, duration: 0.18, peakGain: 0.04 });
}
export function playOrgan(context: AudioContext, pitchSemitones: number): void {
const frequency = getPitchedFrequency(261.63, pitchSemitones);
playTone(context, {
frequency,
duration: 0.42,
peakGain: 0.22,
waveform: 'sine',
attack: 0.025,
});
playTone(context, {
frequency: frequency * 2,
duration: 0.42,
peakGain: 0.09,
waveform: 'sine',
attack: 0.025,
});
playTone(context, {
frequency: frequency * 3,
duration: 0.42,
peakGain: 0.035,
waveform: 'sine',
attack: 0.025,
});
}
export function playStrings(context: AudioContext, pitchSemitones: number): void {
playTone(context, {
frequency: getPitchedFrequency(261.63, pitchSemitones),
duration: 0.48,
peakGain: 0.2,
waveform: 'sawtooth',
attack: 0.09,
filterFrequency: 1400,
});
}
export function playWinds(context: AudioContext, pitchSemitones: number): void {
playTone(context, {
frequency: getPitchedFrequency(261.63, pitchSemitones),
duration: 0.4,
peakGain: 0.24,
waveform: 'triangle',
attack: 0.035,
filterFrequency: 1800,
});
}
export function playSynth(context: AudioContext, pitchSemitones: number): void {
playTone(context, {
frequency: getPitchedFrequency(261.63, pitchSemitones),
duration: 0.34,
peakGain: 0.22,
waveform: 'sawtooth',
filterFrequency: 2200,
});
}
+38 -4
View File
@@ -1,9 +1,43 @@
import type { SoundId } from '../domain/sounds';
import { playHiHat, playKick } from './instruments';
import type { InstrumentId } from '../domain/instruments';
import {
playBass,
playBongos,
playClap,
playCowbell,
playCymbals,
playHiHat,
playKick,
playOrgan,
playPiano,
playShaker,
playSnare,
playStrings,
playSynth,
playToms,
playWinds,
playWoodblock,
} from './instruments';
export type SoundVoice = (context: AudioContext) => void;
export type InstrumentVoice = (context: AudioContext, pitchSemitones: number) => void;
export const SOUND_VOICES: Record<SoundId, SoundVoice> = {
export const INSTRUMENT_VOICES: Record<InstrumentId, InstrumentVoice> = {
bass: playBass,
bongos: playBongos,
clap: playClap,
cowbell: playCowbell,
cymbals: playCymbals,
'hi-hat': playHiHat,
kick: playKick,
organ: playOrgan,
piano: playPiano,
shaker: playShaker,
snare: playSnare,
strings: playStrings,
synth: playSynth,
toms: playToms,
winds: playWinds,
woodblock: playWoodblock,
};
export type SoundVoice = InstrumentVoice;
export const SOUND_VOICES = INSTRUMENT_VOICES;
+84
View File
@@ -0,0 +1,84 @@
import { useRef } from 'react';
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
import { ellipsisVertical } from 'ionicons/icons';
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
import type { AppView } from '../views/viewTypes';
interface AppHeaderProps {
activeView: AppView;
onNavigate: (view: AppView) => void;
}
export function AppHeader({ activeView, onNavigate }: AppHeaderProps) {
const popoverRef = useRef<HTMLIonPopoverElement>(null);
const popover = usePopoverDisclosure();
function selectView(view: AppView): void {
void popoverRef.current?.dismiss();
onNavigate(view);
}
return (
<header className="app-header">
<a
className="brand"
href="#studio"
aria-label="BeatHound home"
onClick={(event) => {
event.preventDefault();
onNavigate('studio');
}}
>
<img
className="brand-logo"
src="/logo/logo-horizontal-dark-notagline.svg"
alt=""
/>
</a>
<div className="app-header-actions">
<span className="header-tag">Sharpen your sense of rhythm</span>
<IonButton
id="app-menu-trigger"
className="app-menu-trigger"
fill="clear"
aria-label="Open app menu"
aria-haspopup="dialog"
aria-expanded={popover.isOpen}
>
<IonIcon icon={ellipsisVertical} />
</IonButton>
</div>
<IonPopover
className="app-menu-popover"
ref={popoverRef}
trigger="app-menu-trigger"
triggerAction="click"
side="bottom"
alignment="end"
onDidPresent={popover.onDidPresent}
onDidDismiss={popover.onDidDismiss}
>
<nav className="app-menu-options" aria-label="App navigation">
<IonButton
className="app-menu-option"
fill={activeView === 'studio' ? 'solid' : 'clear'}
aria-current={activeView === 'studio' ? 'page' : undefined}
onClick={() => selectView('studio')}
>
Beat studio
</IonButton>
<IonButton
className="app-menu-option"
fill={activeView === 'about' ? 'solid' : 'clear'}
aria-current={activeView === 'about' ? 'page' : undefined}
onClick={() => selectView('about')}
>
About BeatHound
</IonButton>
</nav>
</IonPopover>
</header>
);
}
+5 -5
View File
@@ -6,7 +6,7 @@ import { CircularTimeline } from './CircularTimeline';
import { SoundRingSelector } from './SoundRingSelector';
import { TempoControl } from './TempoControl';
import { TimeSignatureSelector } from './TimeSignatureSelector';
import { SOUND_BY_ID, SOUND_CATALOG } from '../domain/sounds';
import { INSTRUMENT_BY_ID, INSTRUMENT_CATALOG } from '../domain/instruments';
import type { BeatSequencer } from '../hooks/useBeatSequencer';
import type { SoundPalette } from '../hooks/useSoundPalette';
@@ -18,7 +18,7 @@ interface BeatLoopPanelProps {
export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
const soundIdsInLoop = useMemo(() => {
const soundsInLoop = new Set(sequencer.beats.map((beat) => beat.soundId));
return SOUND_CATALOG
return INSTRUMENT_CATALOG
.filter((sound) => soundsInLoop.has(sound.id))
.map((sound) => sound.id);
}, [sequencer.beats]);
@@ -32,9 +32,9 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
: null;
const hasDeleteTarget = Boolean(sequencer.selectedBeat || focusedRingSoundId);
const deleteLabel = sequencer.selectedBeat
? `Remove ${SOUND_BY_ID[sequencer.selectedBeat.soundId].label}`
? `Remove ${INSTRUMENT_BY_ID[sequencer.selectedBeat.soundId].label}`
: focusedRingSoundId
? `Remove ${SOUND_BY_ID[focusedRingSoundId].label} ring`
? `Remove ${INSTRUMENT_BY_ID[focusedRingSoundId].label} ring`
: 'Remove sound';
return (
@@ -105,7 +105,7 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
legendSounds.map((activeSound) => (
<span className="legend-sound" key={activeSound.id}>
<span className="legend-swatch" style={{ backgroundColor: activeSound.color }} />
{SOUND_BY_ID[activeSound.id].label}
{INSTRUMENT_BY_ID[activeSound.id].label}
</span>
))
) : (
+5 -5
View File
@@ -1,13 +1,13 @@
import { memo } from 'react';
import { getLoopPositionPercent } from '../domain/timeline';
import { SOUND_BY_ID } from '../domain/sounds';
import { INSTRUMENT_BY_ID } from '../domain/instruments';
import type { BeatPoint } from '../domain/sequencer';
import type { SoundId } from '../domain/sounds';
import type { InstrumentId } from '../domain/instruments';
interface BeatSelectionHintProps {
selectedBeat: BeatPoint | undefined;
focusedSoundId: SoundId | null;
colorBySoundId: Partial<Record<SoundId, string>>;
focusedSoundId: InstrumentId | null;
colorBySoundId: Partial<Record<InstrumentId, string>>;
totalSteps: number;
}
@@ -26,7 +26,7 @@ export const BeatSelectionHint = memo(function BeatSelectionHint({
className="hint-swatch"
style={{ backgroundColor: colorBySoundId[soundId] }}
/>
{SOUND_BY_ID[soundId].label}
{INSTRUMENT_BY_ID[soundId].label}
{selectedBeat && (
<>
<span className="hint-separator">·</span>
+12 -9
View File
@@ -16,20 +16,20 @@ import {
getStackedPosition,
wrapStepPosition,
} from '../domain/timeline';
import { SOUND_BY_ID } from '../domain/sounds';
import type { SoundId } from '../domain/sounds';
import { INSTRUMENT_BY_ID } from '../domain/instruments';
import type { InstrumentId } from '../domain/instruments';
interface CircularTimelineProps {
beats: BeatPoint[];
soundIds: readonly SoundId[];
colorBySoundId: Partial<Record<SoundId, string>>;
soundIds: readonly InstrumentId[];
colorBySoundId: Partial<Record<InstrumentId, string>>;
currentStep: number;
totalSteps: number;
focusedSoundId: SoundId | null;
focusedSoundId: InstrumentId | null;
selectedBeatId: string | null;
onMoveBeat: (beatId: string, step: number) => void;
onSelectBeat: (beatId: string) => void;
onSelectSound: (soundId: SoundId) => void;
onSelectSound: (soundId: InstrumentId) => void;
}
function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
@@ -94,7 +94,10 @@ export function CircularTimeline({
onMoveBeat(beat.id, nextStep);
}
function handleOrbitKeyDown(event: ReactKeyboardEvent<SVGCircleElement>, soundId: SoundId): void {
function handleOrbitKeyDown(
event: ReactKeyboardEvent<SVGCircleElement>,
soundId: InstrumentId,
): void {
if (event.key !== 'Enter' && event.key !== ' ') return;
event.preventDefault();
onSelectSound(soundId);
@@ -165,7 +168,7 @@ export function CircularTimeline({
pointerEvents="stroke"
role="button"
tabIndex={0}
aria-label={`Select ${SOUND_BY_ID[soundId].label} ring`}
aria-label={`Select ${INSTRUMENT_BY_ID[soundId].label} ring`}
aria-pressed={soundId === activeSoundId}
onClick={() => onSelectSound(soundId)}
onKeyDown={(event) => handleOrbitKeyDown(event, soundId)}
@@ -184,7 +187,7 @@ export function CircularTimeline({
})()}
{beats.map((beat) => {
const sound = SOUND_BY_ID[beat.soundId];
const sound = INSTRUMENT_BY_ID[beat.soundId];
const soundIndex = orderedSoundIds.indexOf(beat.soundId);
const point = getStackedPosition(
beat,
+97
View File
@@ -0,0 +1,97 @@
import { useRef, useState } from 'react';
import { IonButton, IonIcon, IonPopover, IonSelect, IonSelectOption } from '@ionic/react';
import { add } from 'ionicons/icons';
import {
INSTRUMENT_BY_ID,
INSTRUMENT_CATEGORIES,
isInstrumentId,
} from '../domain/instruments';
import type { InstrumentId } from '../domain/instruments';
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
interface InstrumentSelectorProps {
onSelectInstrument: (instrumentId: InstrumentId) => void;
}
export function InstrumentSelector({ onSelectInstrument }: InstrumentSelectorProps) {
const [selectedCategoryId, setSelectedCategoryId] = useState('drums');
const popoverRef = useRef<HTMLIonPopoverElement>(null);
const popover = usePopoverDisclosure();
const selectedCategory = INSTRUMENT_CATEGORIES.find(
(category) => category.id === selectedCategoryId,
) ?? INSTRUMENT_CATEGORIES[0];
function handleCategoryChange(value: unknown): void {
if (typeof value !== 'string') return;
const category = INSTRUMENT_CATEGORIES.find((candidate) => candidate.id === value);
if (category) setSelectedCategoryId(category.id);
}
function addInstrument(value: unknown): void {
if (!isInstrumentId(value)) return;
void popoverRef.current?.dismiss();
onSelectInstrument(value);
}
return (
<div className="instrument-selector-group">
<IonSelect
className="instrument-selector"
fill="solid"
interface="popover"
aria-label="Choose an instrument category"
value={selectedCategoryId}
onIonChange={(event) => handleCategoryChange(event.detail.value)}
>
{INSTRUMENT_CATEGORIES.map((category) => (
<IonSelectOption key={category.id} value={category.id}>
{category.label}
</IonSelectOption>
))}
</IonSelect>
<IonButton
id="instrument-add-trigger"
className="instrument-add-button"
fill="solid"
aria-label={`Show ${selectedCategory.label} instruments`}
aria-haspopup="dialog"
aria-expanded={popover.isOpen}
>
<IonIcon icon={add} />
</IonButton>
<IonPopover
ref={popoverRef}
className="instrument-picker-popover"
trigger="instrument-add-trigger"
triggerAction="click"
side="top"
alignment="start"
onDidPresent={popover.onDidPresent}
onDidDismiss={popover.onDidDismiss}
>
<div className="instrument-picker-menu" role="group" aria-label={`${selectedCategory.label} instruments`}>
{selectedCategory.instrumentIds.map((instrumentId) => {
const instrument = INSTRUMENT_BY_ID[instrumentId];
return (
<IonButton
className="instrument-picker-option"
fill="clear"
key={instrumentId}
aria-label={`Add ${instrument.label}`}
onClick={() => addInstrument(instrumentId)}
>
<span className="instrument-picker-option-copy">
<span>{instrument.label}</span>
<span>{instrument.description}</span>
</span>
</IonButton>
);
})}
</div>
</IonPopover>
</div>
);
}
+44
View File
@@ -0,0 +1,44 @@
import { IonRange } from '@ionic/react';
import {
getPitchLabel,
INSTRUMENT_BY_ID,
MAX_PITCH_SEMITONES,
MIN_PITCH_SEMITONES,
} from '../domain/instruments';
import type { BeatPoint } from '../domain/sequencer';
interface PitchControlProps {
selectedBeat: BeatPoint | undefined;
onChangePitch: (beatId: string, pitchSemitones: number) => void;
}
export function PitchControl({ selectedBeat, onChangePitch }: PitchControlProps) {
if (!selectedBeat || !INSTRUMENT_BY_ID[selectedBeat.soundId].supportsPitch) return null;
const pitchSemitones = selectedBeat.pitchSemitones ?? 0;
const instrument = INSTRUMENT_BY_ID[selectedBeat.soundId];
return (
<div className="pitch-control">
<div className="pitch-control-heading">
<span>Pitch</span>
<output aria-live="polite">
{getPitchLabel(pitchSemitones, instrument.pitchBaseMidi)}
</output>
</div>
<IonRange
className="pitch-range"
aria-label={`${instrument.label} pitch`}
min={MIN_PITCH_SEMITONES}
max={MAX_PITCH_SEMITONES}
step={1}
value={pitchSemitones}
onIonInput={(event) => {
if (typeof event.detail.value === 'number') {
onChangePitch(selectedBeat.id, event.detail.value);
}
}}
/>
</div>
);
}
+8 -8
View File
@@ -1,15 +1,15 @@
import { memo } from 'react';
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
import { chevronDown } from 'ionicons/icons';
import { SOUND_BY_ID } from '../domain/sounds';
import type { SoundId } from '../domain/sounds';
import { INSTRUMENT_BY_ID } from '../domain/instruments';
import type { InstrumentId } from '../domain/instruments';
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
interface SoundRingSelectorProps {
soundIds: SoundId[];
focusedSoundId: SoundId | null;
colorBySoundId: Partial<Record<SoundId, string>>;
onSelectSound: (soundId: SoundId) => void;
soundIds: InstrumentId[];
focusedSoundId: InstrumentId | null;
colorBySoundId: Partial<Record<InstrumentId, string>>;
onSelectSound: (soundId: InstrumentId) => void;
}
export const SoundRingSelector = memo(function SoundRingSelector({
@@ -19,7 +19,7 @@ export const SoundRingSelector = memo(function SoundRingSelector({
onSelectSound,
}: SoundRingSelectorProps) {
const popover = usePopoverDisclosure();
const focusedSound = focusedSoundId ? SOUND_BY_ID[focusedSoundId] : undefined;
const focusedSound = focusedSoundId ? INSTRUMENT_BY_ID[focusedSoundId] : undefined;
return (
<>
@@ -70,7 +70,7 @@ export const SoundRingSelector = memo(function SoundRingSelector({
className="ring-selector-swatch"
style={{ backgroundColor: colorBySoundId[soundId] ?? '#b8b4e0' }}
/>
<span>{SOUND_BY_ID[soundId].label} ring</span>
<span>{INSTRUMENT_BY_ID[soundId].label} ring</span>
</span>
</IonButton>
);
+14 -35
View File
@@ -1,31 +1,29 @@
import { memo } from 'react';
import {
IonFab,
IonButton,
IonFabButton,
IonFabList,
IonFooter,
IonIcon,
IonToolbar,
} from '@ionic/react';
import { add, musicalNotes, pause, play } from 'ionicons/icons';
import type { SoundId } from '../domain/sounds';
import { SOUND_CATALOG } from '../domain/sounds';
import { IonButton, IonFooter, IonIcon, IonToolbar } from '@ionic/react';
import { pause, play } from 'ionicons/icons';
import type { InstrumentId } from '../domain/instruments';
import type { BeatPoint } from '../domain/sequencer';
import { InstrumentSelector } from './InstrumentSelector';
import { PitchControl } from './PitchControl';
interface TransportBarProps {
isPlaying: boolean;
isStarting: boolean;
hasBeats: boolean;
selectedBeat: BeatPoint | undefined;
onTogglePlayback: () => Promise<void>;
onAddSound: (soundId: SoundId) => void;
onAddInstrument: (instrumentId: InstrumentId) => void;
onChangeBeatPitch: (beatId: string, pitchSemitones: number) => void;
}
export const TransportBar = memo(function TransportBar({
isPlaying,
isStarting,
hasBeats,
selectedBeat,
onTogglePlayback,
onAddSound,
onAddInstrument,
onChangeBeatPitch,
}: TransportBarProps) {
return (
<IonFooter className="transport-footer">
@@ -39,29 +37,10 @@ export const TransportBar = memo(function TransportBar({
<IonIcon slot="start" icon={isPlaying ? pause : play} />
{isStarting ? 'Starting' : isPlaying ? 'Pause' : 'Play'}
</IonButton>
<InstrumentSelector onSelectInstrument={onAddInstrument} />
<PitchControl selectedBeat={selectedBeat} onChangePitch={onChangeBeatPitch} />
</div>
</IonToolbar>
<IonFab className="transport-fab">
<IonFabButton className="add-sound-fab" aria-label="Add a sound">
<IonIcon icon={add} />
</IonFabButton>
<IonFabList className="sound-fab-list" side="top">
{SOUND_CATALOG.map((sound) => (
<IonFabButton
className="sound-fab-option"
key={sound.id}
aria-label={`Add ${sound.label}`}
onClick={() => onAddSound(sound.id)}
>
<span className="sound-fab-option-content">
<IonIcon icon={musicalNotes} />
<span>{sound.label}</span>
</span>
</IonFabButton>
))}
</IonFabList>
</IonFab>
</IonFooter>
);
});
+9
View File
@@ -0,0 +1,9 @@
import packageMetadata from '../../package.json';
export const PROJECT_INFO = {
version: packageMetadata.version,
copyright: '© 2026 Ninosaurier',
licenseUrl: 'https://www.gnu.org/licenses/gpl-3.0.html',
repositoryUrl: 'https://git.byting-pandas.ninja/Ninosaurier/beat-hound',
issuesUrl: 'https://git.byting-pandas.ninja/Ninosaurier/beat-hound/issues/new',
} as const;
+3 -2
View File
@@ -1,10 +1,11 @@
import { DEFAULT_BEATS_PER_BAR, TEMPO_BPM } from './sequencer';
import type { BeatsPerBar } from './sequencer';
import type { SoundId } from './sounds';
import type { InstrumentId } from './instruments';
export interface TemplateBeat {
soundId: SoundId;
soundId: InstrumentId;
step: number;
pitchSemitones?: number;
}
export type BeatTemplateId = 'empty' | 'bachata' | 'salsa' | 'lindy-hop';
+187
View File
@@ -0,0 +1,187 @@
const INSTRUMENT_DEFINITIONS = {
kick: {
id: 'kick',
label: 'Kick',
description: 'Low drum pulse',
categoryId: 'drums',
supportsPitch: true,
pitchBaseMidi: 53,
},
snare: {
id: 'snare',
label: 'Snare',
description: 'Sharp drum hit',
categoryId: 'drums',
supportsPitch: false,
pitchBaseMidi: 60,
},
'hi-hat': {
id: 'hi-hat',
label: 'Hi-hat',
description: 'Bright tick',
categoryId: 'drums',
supportsPitch: false,
pitchBaseMidi: 60,
},
toms: {
id: 'toms',
label: 'Toms',
description: 'Tuned drum tones',
categoryId: 'drums',
supportsPitch: true,
pitchBaseMidi: 51,
},
cymbals: {
id: 'cymbals',
label: 'Cymbals',
description: 'Bright metallic wash',
categoryId: 'drums',
supportsPitch: false,
pitchBaseMidi: 60,
},
clap: {
id: 'clap',
label: 'Clap',
description: 'Short handclap',
categoryId: 'percussion',
supportsPitch: false,
pitchBaseMidi: 60,
},
shaker: {
id: 'shaker',
label: 'Shaker',
description: 'Soft rhythmic rattle',
categoryId: 'percussion',
supportsPitch: false,
pitchBaseMidi: 60,
},
cowbell: {
id: 'cowbell',
label: 'Cowbell',
description: 'Metallic bell tone',
categoryId: 'percussion',
supportsPitch: false,
pitchBaseMidi: 60,
},
woodblock: {
id: 'woodblock',
label: 'Woodblock',
description: 'Short wooden click',
categoryId: 'percussion',
supportsPitch: false,
pitchBaseMidi: 60,
},
bongos: {
id: 'bongos',
label: 'Bongos',
description: 'Tuned hand drums',
categoryId: 'percussion',
supportsPitch: true,
pitchBaseMidi: 59,
},
bass: {
id: 'bass',
label: 'Bass',
description: 'Low pitched tone',
categoryId: 'bass',
supportsPitch: true,
pitchBaseMidi: 36,
},
piano: {
id: 'piano',
label: 'Piano',
description: 'Short keyed tone',
categoryId: 'keys',
supportsPitch: true,
pitchBaseMidi: 60,
},
organ: {
id: 'organ',
label: 'Organ',
description: 'Sustained keyed tone',
categoryId: 'keys',
supportsPitch: true,
pitchBaseMidi: 60,
},
strings: {
id: 'strings',
label: 'Strings',
description: 'Warm sustained tone',
categoryId: 'strings',
supportsPitch: true,
pitchBaseMidi: 60,
},
winds: {
id: 'winds',
label: 'Winds',
description: 'Soft breath-like tone',
categoryId: 'winds',
supportsPitch: true,
pitchBaseMidi: 60,
},
synth: {
id: 'synth',
label: 'Synth',
description: 'Bright electronic tone',
categoryId: 'synth',
supportsPitch: true,
pitchBaseMidi: 60,
},
} as const;
export type InstrumentId = keyof typeof INSTRUMENT_DEFINITIONS;
export type InstrumentDefinition = (typeof INSTRUMENT_DEFINITIONS)[InstrumentId];
export type InstrumentCategoryId = InstrumentDefinition['categoryId'];
export interface InstrumentCategory {
id: InstrumentCategoryId;
label: string;
instrumentIds: readonly InstrumentId[];
}
export const INSTRUMENT_BY_ID: Record<InstrumentId, InstrumentDefinition> = INSTRUMENT_DEFINITIONS;
export const INSTRUMENT_CATALOG: readonly InstrumentDefinition[] = Object.values(INSTRUMENT_DEFINITIONS);
const INSTRUMENT_ID_SET = new Set<string>(INSTRUMENT_CATALOG.map((instrument) => instrument.id));
export function isInstrumentId(value: unknown): value is InstrumentId {
return typeof value === 'string' && INSTRUMENT_ID_SET.has(value);
}
export const INSTRUMENT_CATEGORIES = [
{ id: 'drums', label: 'Drums', instrumentIds: ['kick', 'snare', 'hi-hat', 'toms', 'cymbals'] },
{
id: 'percussion',
label: 'Percussion',
instrumentIds: ['clap', 'shaker', 'cowbell', 'woodblock', 'bongos'],
},
{ id: 'bass', label: 'Bass', instrumentIds: ['bass'] },
{ id: 'keys', label: 'Keys', instrumentIds: ['piano', 'organ'] },
{ id: 'strings', label: 'Strings', instrumentIds: ['strings'] },
{ id: 'winds', label: 'Winds', instrumentIds: ['winds'] },
{ id: 'synth', label: 'Synth', instrumentIds: ['synth'] },
] as const satisfies readonly InstrumentCategory[];
export const DEFAULT_PITCH_SEMITONES = 0;
export const MIN_PITCH_SEMITONES = -24;
export const MAX_PITCH_SEMITONES = 24;
export function clampPitchSemitones(pitchSemitones: number): number {
return Math.min(
MAX_PITCH_SEMITONES,
Math.max(MIN_PITCH_SEMITONES, Math.round(pitchSemitones)),
);
}
export function getPitchLabel(pitchSemitones: number, baseMidiNote = 60): string {
const noteNames = ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B'];
const midiNote = baseMidiNote + clampPitchSemitones(pitchSemitones);
const noteName = noteNames[midiNote % 12];
const octave = Math.floor(midiNote / 12) - 1;
return `${noteName}${octave}`;
}
// Keep the original names available for existing sequencer data and saved templates.
export type SoundId = InstrumentId;
export type SoundDefinition = InstrumentDefinition;
export const SOUND_BY_ID = INSTRUMENT_BY_ID;
export const SOUND_CATALOG = INSTRUMENT_CATALOG;
+4 -2
View File
@@ -1,4 +1,4 @@
import type { SoundId } from './sounds';
import type { InstrumentId } from './instruments';
export const STEPS_PER_BEAT = 4;
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
@@ -24,9 +24,11 @@ export function getPlaybackTickDurationMs(tempoBpm: number): number {
export interface BeatPoint {
id: string;
soundId: SoundId;
soundId: InstrumentId;
/** Position in sixteenth-note steps; fractional values represent microtiming. */
step: number;
/** Pitch offset from the instrument's base note in semitones. */
pitchSemitones?: number;
}
export function getNextAvailableStep(
+20 -4
View File
@@ -1,11 +1,17 @@
import { clampTempoBpm, DEFAULT_BEATS_PER_BAR, getTotalSteps, TEMPO_BPM } from './sequencer';
import {
clampTempoBpm,
DEFAULT_BEATS_PER_BAR,
getTotalSteps,
TEMPO_BPM,
} from './sequencer';
import type { BeatsPerBar, BeatPoint } from './sequencer';
import type { SoundId } from './sounds';
import { clampPitchSemitones } from './instruments';
import type { InstrumentId } from './instruments';
export interface SequencerState {
beats: BeatPoint[];
selectedBeatId: string | null;
focusedSoundId: SoundId | null;
focusedSoundId: InstrumentId | null;
tempoBpm: number;
beatsPerBar: BeatsPerBar;
}
@@ -13,8 +19,9 @@ export interface SequencerState {
export type SequencerAction =
| { type: 'beat-added'; beat: BeatPoint }
| { type: 'beat-moved'; beatId: string; step: number }
| { type: 'beat-pitch-changed'; beatId: string; pitchSemitones: number }
| { type: 'beat-selected'; beatId: string }
| { type: 'sound-selected'; soundId: SoundId }
| { type: 'sound-selected'; soundId: InstrumentId }
| { type: 'selected-beat-removed' }
| { type: 'focused-sound-removed' }
| { type: 'tempo-changed'; tempoBpm: number }
@@ -51,6 +58,15 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
beat.id === action.beatId ? { ...beat, step: action.step } : beat
)),
};
case 'beat-pitch-changed':
return {
...state,
beats: state.beats.map((beat) => (
beat.id === action.beatId
? { ...beat, pitchSemitones: clampPitchSemitones(action.pitchSemitones) }
: beat
)),
};
case 'beat-selected': {
const beat = state.beats.find((candidate) => candidate.id === action.beatId);
if (!beat) return state;
+1 -10
View File
@@ -1,10 +1 @@
const SOUND_DEFINITIONS = {
'hi-hat': { id: 'hi-hat', label: 'Hi-hat', description: 'Bright tick' },
kick: { id: 'kick', label: 'Kick', description: 'Low pulse' },
} as const;
export type SoundId = keyof typeof SOUND_DEFINITIONS;
export type SoundDefinition = (typeof SOUND_DEFINITIONS)[SoundId];
export const SOUND_BY_ID: Record<SoundId, SoundDefinition> = SOUND_DEFINITIONS;
export const SOUND_CATALOG: readonly SoundDefinition[] = Object.values(SOUND_DEFINITIONS);
export * from './instruments';
+3 -1
View File
@@ -49,7 +49,9 @@ export function useBeatPlayback({
beatsRef.current.forEach((beat) => {
if (beat.step >= totalStepsRef.current) return;
const beatTick = Math.round(beat.step * PLAYBACK_SUBSTEPS_PER_STEP) % totalPlaybackTicks;
if (beatTick === playbackTick) audioEngineRef.current?.play(beat.soundId);
if (beatTick === playbackTick) {
audioEngineRef.current?.play(beat.soundId, beat.pitchSemitones ?? 0);
}
});
nextPlaybackTickRef.current = (playbackTick + 1) % totalPlaybackTicks;
+15 -6
View File
@@ -6,7 +6,8 @@ import {
} from '../domain/sequencer';
import type { BeatsPerBar } from '../domain/sequencer';
import type { BeatPoint } from '../domain/sequencer';
import type { SoundId } from '../domain/sounds';
import { DEFAULT_PITCH_SEMITONES } from '../domain/instruments';
import type { InstrumentId } from '../domain/instruments';
import { createInitialSequencerState, sequencerReducer } from '../domain/sequencerReducer';
import { useBeatPlayback } from './useBeatPlayback';
@@ -19,12 +20,13 @@ export interface BeatSequencer {
tempoBpm: number;
beatsPerBar: BeatsPerBar;
totalSteps: number;
focusedSoundId: SoundId | null;
focusedSoundId: InstrumentId | null;
selectedBeat: BeatPoint | undefined;
addBeat: (soundId: SoundId) => void;
addBeat: (soundId: InstrumentId) => void;
moveBeat: (beatId: string, step: number) => void;
changeBeatPitch: (beatId: string, pitchSemitones: number) => void;
selectBeat: (beatId: string) => void;
selectSound: (soundId: SoundId) => void;
selectSound: (soundId: InstrumentId) => void;
removeSelectedBeat: () => void;
removeFocusedSound: () => void;
setTempoBpm: (tempoBpm: number) => void;
@@ -55,11 +57,12 @@ export function useBeatSequencer(): BeatSequencer {
const playback = useBeatPlayback({ beats: visibleBeats, tempoBpm, totalSteps });
const resetPlayback = playback.resetPlayback;
const addBeat = useCallback((soundId: SoundId): void => {
const addBeat = useCallback((soundId: InstrumentId): void => {
const beat: BeatPoint = {
id: `beat-${nextBeatIdRef.current}`,
soundId,
step: getNextAvailableStep(beats, totalSteps),
pitchSemitones: DEFAULT_PITCH_SEMITONES,
};
nextBeatIdRef.current += 1;
dispatch({ type: 'beat-added', beat });
@@ -69,11 +72,15 @@ export function useBeatSequencer(): BeatSequencer {
dispatch({ type: 'beat-moved', beatId, step });
}, []);
const changeBeatPitch = useCallback((beatId: string, pitchSemitones: number): void => {
dispatch({ type: 'beat-pitch-changed', beatId, pitchSemitones });
}, []);
const selectBeat = useCallback((beatId: string): void => {
dispatch({ type: 'beat-selected', beatId });
}, []);
const selectSound = useCallback((soundId: SoundId): void => {
const selectSound = useCallback((soundId: InstrumentId): void => {
dispatch({ type: 'sound-selected', soundId });
}, []);
@@ -98,6 +105,7 @@ export function useBeatSequencer(): BeatSequencer {
const beat: BeatPoint = {
id: `beat-${nextBeatIdRef.current}`,
...templateBeat,
pitchSemitones: templateBeat.pitchSemitones ?? DEFAULT_PITCH_SEMITONES,
};
nextBeatIdRef.current += 1;
return beat;
@@ -125,6 +133,7 @@ export function useBeatSequencer(): BeatSequencer {
selectedBeat,
addBeat,
moveBeat,
changeBeatPitch,
selectBeat,
selectSound,
removeSelectedBeat,
+3 -3
View File
@@ -1,6 +1,6 @@
import { useCallback } from 'react';
import type { BeatTemplate } from '../domain/beatTemplates';
import type { SoundId } from '../domain/sounds';
import type { InstrumentId } from '../domain/instruments';
import type { BeatSequencer } from './useBeatSequencer';
import { useBeatSequencer } from './useBeatSequencer';
import type { SoundPalette } from './useSoundPalette';
@@ -9,7 +9,7 @@ import { useSoundPalette } from './useSoundPalette';
export interface BeatStudio {
sequencer: BeatSequencer;
soundPalette: SoundPalette;
addSound: (soundId: SoundId) => void;
addSound: (soundId: InstrumentId) => void;
applyTemplate: (template: BeatTemplate) => void;
}
@@ -19,7 +19,7 @@ export function useBeatStudio(): BeatStudio {
const { addBeat, loadTemplate } = sequencer;
const { activateSounds } = soundPalette;
const addSound = useCallback((soundId: SoundId): void => {
const addSound = useCallback((soundId: InstrumentId): void => {
activateSounds([soundId]);
addBeat(soundId);
}, [activateSounds, addBeat]);
+6 -6
View File
@@ -1,22 +1,22 @@
import { useCallback, useMemo, useState } from 'react';
import type { SoundId } from '../domain/sounds';
import type { InstrumentId } from '../domain/instruments';
import { generateUniqueSoundColor } from '../domain/soundColors';
export interface PaletteSound {
id: SoundId;
id: InstrumentId;
color: string;
}
export interface SoundPalette {
activeSounds: PaletteSound[];
colorBySoundId: Partial<Record<SoundId, string>>;
activateSounds: (soundIds: readonly SoundId[]) => void;
colorBySoundId: Partial<Record<InstrumentId, string>>;
activateSounds: (soundIds: readonly InstrumentId[]) => void;
}
export function useSoundPalette(): SoundPalette {
const [activeSounds, setActiveSounds] = useState<PaletteSound[]>([]);
const activateSounds = useCallback((soundIds: readonly SoundId[]): void => {
const activateSounds = useCallback((soundIds: readonly InstrumentId[]): void => {
setActiveSounds((currentSounds) => {
const nextSounds = [...currentSounds];
const currentCount = nextSounds.length;
@@ -33,7 +33,7 @@ export function useSoundPalette(): SoundPalette {
}, []);
const colorBySoundId = useMemo(() => {
const colors: Partial<Record<SoundId, string>> = {};
const colors: Partial<Record<InstrumentId, string>> = {};
activeSounds.forEach((sound) => {
colors[sound.id] = sound.color;
});
+1
View File
@@ -1,6 +1,7 @@
declare module 'ionicons/icons' {
export const add: string;
export const chevronDown: string;
export const ellipsisVertical: string;
export const musicalNotes: string;
export const pause: string;
export const play: string;
+55
View File
@@ -5,6 +5,16 @@ import {
sequencerReducer,
} from './domain/sequencerReducer';
import { generateUniqueSoundColor } from './domain/soundColors';
import {
clampPitchSemitones,
getPitchLabel,
INSTRUMENT_CATEGORIES,
INSTRUMENT_CATALOG,
INSTRUMENT_BY_ID,
MAX_PITCH_SEMITONES,
MIN_PITCH_SEMITONES,
} from './domain/instruments';
import { INSTRUMENT_VOICES } from './audio/soundVoices';
import {
getNextAvailableStep,
getPlaybackTickDurationMs,
@@ -108,6 +118,30 @@ describe('sound colors', () => {
});
});
describe('instrument catalog and pitch', () => {
it('places every instrument in exactly one category and has a sound voice', () => {
const categorizedInstruments = INSTRUMENT_CATEGORIES.flatMap(
(category) => category.instrumentIds,
);
expect(new Set(categorizedInstruments).size).toBe(INSTRUMENT_CATALOG.length);
INSTRUMENT_CATALOG.forEach((instrument) => {
expect(categorizedInstruments).toContain(instrument.id);
expect(typeof INSTRUMENT_VOICES[instrument.id]).toBe('function');
});
});
it('keeps pitch within two octaves and names notes from C2 through C6', () => {
expect(clampPitchSemitones(MIN_PITCH_SEMITONES - 1)).toBe(MIN_PITCH_SEMITONES);
expect(clampPitchSemitones(MAX_PITCH_SEMITONES + 1)).toBe(MAX_PITCH_SEMITONES);
expect(clampPitchSemitones(3.7)).toBe(4);
expect(getPitchLabel(MIN_PITCH_SEMITONES)).toBe('C2');
expect(getPitchLabel(0)).toBe('C4');
expect(getPitchLabel(MAX_PITCH_SEMITONES)).toBe('C6');
expect(getPitchLabel(0, INSTRUMENT_BY_ID.kick.pitchBaseMidi)).toBe('F3');
});
});
describe('sequencer state transitions', () => {
it('loads a template with a focused first beat and removes a focused sound ring', () => {
const templateBeats: BeatPoint[] = [
@@ -180,6 +214,27 @@ describe('sequencer state transitions', () => {
expect(tooSlow.tempoBpm).toBe(MIN_TEMPO_BPM);
expect(tooFast.tempoBpm).toBe(MAX_TEMPO_BPM);
});
it('changes pitch on one selected beat and clamps it to the supported range', () => {
const beats: BeatPoint[] = [
{ id: 'bass-1', soundId: 'bass', step: 0, pitchSemitones: 0 },
{ id: 'piano-1', soundId: 'piano', step: 4, pitchSemitones: 0 },
];
const loaded = sequencerReducer(createInitialSequencerState(), {
type: 'template-loaded',
beats,
tempoBpm: TEMPO_BPM,
beatsPerBar: 4,
});
const changed = sequencerReducer(loaded, {
type: 'beat-pitch-changed',
beatId: 'bass-1',
pitchSemitones: MAX_PITCH_SEMITONES + 12,
});
expect(changed.beats[0].pitchSemitones).toBe(MAX_PITCH_SEMITONES);
expect(changed.beats[1].pitchSemitones).toBe(0);
});
});
describe('dance templates', () => {
+1
View File
@@ -1,3 +1,4 @@
export * from './domain/beatTemplates';
export * from './domain/instruments';
export * from './domain/sequencer';
export * from './domain/timeline';
+420 -76
View File
@@ -83,6 +83,7 @@ ion-content.app-content {
height: 76px;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 0 auto;
border-bottom: 1px solid rgba(var(--primary-rgb), 0.1);
}
@@ -115,12 +116,210 @@ ion-content.app-content {
letter-spacing: 0.1px;
}
.app-header-actions {
display: flex;
min-width: 0;
align-items: center;
gap: 8px;
}
.app-menu-trigger {
width: 40px;
height: 40px;
flex: 0 0 40px;
margin: 0;
--color: var(--muted);
--padding-start: 0;
--padding-end: 0;
}
.app-menu-trigger::part(native) {
width: 40px;
height: 40px;
}
.app-menu-trigger ion-icon {
font-size: 20px;
}
.app-menu-popover {
--width: 190px;
--background: var(--surface);
--backdrop-opacity: 0;
--box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.app-menu-options {
display: flex;
flex-direction: column;
gap: 4px;
padding: 8px;
}
.app-menu-option {
width: 100%;
height: 40px;
margin: 0;
--color: var(--ink);
--background: var(--surface-raised);
--background-hover: #33323b;
--background-activated: #3b3944;
--border-radius: 8px;
font-size: 12px;
text-transform: none;
}
.app-menu-option::part(native) {
justify-content: flex-start;
}
.studio {
width: min(100%, 660px);
margin: 0 auto;
padding-bottom: 24px;
}
.about-view {
width: min(100%, 660px);
margin: 0 auto;
padding: 44px 0 32px;
}
.about-heading {
padding: 0 12px;
text-align: center;
}
.about-eyebrow {
margin: 0 0 12px;
color: var(--accent);
font-family: var(--mono);
font-size: 10px;
letter-spacing: 1.2px;
text-transform: uppercase;
}
.about-heading h1 {
margin: 0;
color: var(--ink);
font: 500 clamp(34px, 7vw, 44px)/1.1 var(--display);
letter-spacing: -1.8px;
}
.about-intro {
max-width: 520px;
margin: 17px auto 0;
color: var(--muted);
font-size: 14px;
line-height: 1.7;
}
.about-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 13px;
margin-top: 30px;
}
.about-card {
padding: 20px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--surface);
}
.about-card-wide {
grid-column: 1 / -1;
}
.about-card h2 {
margin: 0;
color: var(--ink);
font: 500 17px/1.3 var(--display);
}
.about-card p {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.7;
}
.project-metadata {
display: grid;
gap: 11px;
margin: 15px 0 0;
}
.project-metadata > div {
display: grid;
grid-template-columns: minmax(72px, 0.7fr) minmax(0, 1.3fr);
gap: 8px;
align-items: baseline;
}
.project-metadata dt {
color: var(--soft);
font-size: 11px;
}
.project-metadata dd {
margin: 0;
color: var(--ink);
font-size: 11px;
line-height: 1.55;
}
.about-actions {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.about-link-button {
min-height: 36px;
margin: 0;
--background: var(--accent);
--background-hover: var(--accent-hover);
--background-activated: var(--accent-pressed);
--color: #111116;
--border-radius: 8px;
font-size: 10px;
font-weight: 600;
text-transform: none;
}
.about-link-button-secondary {
--background: transparent;
--color: var(--ink);
--border-color: var(--border);
--border-width: 1px;
}
.about-return-row {
margin-top: 24px;
text-align: center;
}
.about-return-button {
--background: var(--accent);
--background-hover: var(--accent-hover);
--background-activated: var(--accent-pressed);
--color: #111116;
--border-radius: 9px;
margin: 0;
font-size: 12px;
font-weight: 600;
text-transform: none;
}
.about-return-row p {
margin: 12px 0 0;
color: var(--soft);
font-size: 10px;
}
.studio-heading {
padding: 37px 0 10px;
text-align: center;
@@ -593,10 +792,10 @@ ion-content.app-content {
width: min(100%, 660px);
min-height: 84px;
align-items: center;
justify-content: flex-start;
gap: 17px;
flex-wrap: wrap;
gap: 10px;
margin: 0 auto;
padding: 12px 86px max(12px, env(safe-area-inset-bottom)) 20px;
padding: 12px 20px max(12px, env(safe-area-inset-bottom));
}
.transport-play-button {
@@ -618,6 +817,155 @@ ion-content.app-content {
font-size: 17px;
}
.instrument-selector {
width: 170px;
min-width: 140px;
height: 44px;
flex: 1 1 150px;
margin: 0;
--background: var(--surface-raised);
--border-radius: 9px;
--color: var(--ink);
--padding-start: 11px;
--padding-end: 9px;
--placeholder-color: var(--ink);
--placeholder-opacity: 1;
font-size: 11px;
font-weight: 600;
}
.instrument-selector::part(icon) {
color: var(--muted);
opacity: 1;
}
.instrument-selector-group {
display: flex;
min-width: 0;
flex: 0 1 auto;
align-items: center;
gap: 6px;
}
.instrument-add-button {
width: 44px;
height: 44px;
flex: 0 0 44px;
margin: 0;
--background: var(--surface-raised);
--background-hover: #33323b;
--background-activated: #3b3944;
--border-radius: 9px;
--color: var(--ink);
--padding-start: 0;
--padding-end: 0;
}
.instrument-add-button::part(native) {
width: 44px;
height: 44px;
}
.instrument-add-button ion-icon {
font-size: 19px;
}
ion-popover.instrument-picker-popover {
--width: min(250px, calc(100vw - 24px));
--background: var(--surface);
--backdrop-opacity: 0;
--box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
.instrument-picker-menu {
display: flex;
max-height: min(60vh, 420px);
flex-direction: column;
gap: 4px;
overflow-y: auto;
overscroll-behavior: contain;
padding: 8px;
}
.instrument-picker-option {
width: 100%;
height: 48px;
flex: 0 0 48px;
margin: 0;
--background: var(--surface-raised);
--background-hover: #33323b;
--background-activated: #3b3944;
--border-radius: 8px;
--color: var(--ink);
font-size: 11px;
text-transform: none;
}
.instrument-picker-option::part(native) {
justify-content: flex-start;
text-align: left;
}
.instrument-picker-option-copy {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
}
.instrument-picker-option-copy > span:first-child {
color: var(--ink);
font-size: 11px;
font-weight: 600;
}
.instrument-picker-option-copy > span:last-child {
color: var(--soft);
font-size: 9px;
}
.pitch-control {
display: flex;
min-width: 145px;
max-width: 230px;
flex: 1 1 160px;
flex-direction: column;
gap: 1px;
margin-left: auto;
}
.pitch-control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
color: var(--muted);
font-family: var(--mono);
font-size: 9px;
letter-spacing: 0.5px;
text-transform: uppercase;
}
.pitch-control-heading output {
color: var(--ink);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.pitch-range {
height: 28px;
margin: 0;
--bar-background: #58537d;
--bar-background-active: var(--accent);
--bar-height: 3px;
--height: 28px;
--knob-background: var(--accent);
--knob-size: 12px;
--padding-top: 2px;
--padding-bottom: 2px;
--padding-start: 2px;
--padding-end: 2px;
}
.tempo-trigger {
--color: var(--ink);
--background: var(--surface-raised);
@@ -773,73 +1121,6 @@ ion-content.app-content {
text-align: center;
}
.transport-fab {
position: absolute;
top: 15px;
right: max(14px, calc((100vw - 660px) / 2 + 20px));
bottom: auto;
left: auto;
z-index: 1001;
display: block;
width: 54px;
height: 54px;
flex: 0 0 54px;
}
.add-sound-fab {
--background: var(--surface-raised);
--background-activated: #33323b;
--color: var(--ink);
--box-shadow: none;
width: 54px;
height: 54px;
margin: 0;
border: 1px solid var(--border);
border-radius: 50%;
font-size: 22px;
}
.sound-fab-list {
right: 0;
left: auto;
z-index: 3;
}
.sound-fab-option {
--background: var(--surface);
--background-activated: var(--surface-raised);
--color: var(--ink);
--box-shadow: 0 5px 16px rgba(var(--primary-rgb), 0.16);
--border-radius: 12px;
width: 112px;
height: 42px;
margin: 5px 0;
font-size: 11px;
font-weight: 600;
white-space: nowrap;
}
.sound-fab-option::part(native) {
padding: 0 10px;
}
.sound-fab-option-content {
display: flex;
width: 100%;
min-width: 0;
align-items: center;
justify-content: center;
gap: 7px;
}
.sound-fab-option-content > span {
text-align: center;
}
.sound-fab-option ion-icon {
font-size: 15px;
}
@media (max-width: 600px) {
/* Compact layout */
.app-shell {
@@ -851,13 +1132,62 @@ ion-content.app-content {
}
.brand-logo {
width: min(142px, 42vw);
width: min(132px, 38vw);
max-height: 38px;
}
.app-header-actions {
gap: 4px;
}
.app-menu-trigger,
.app-menu-trigger::part(native) {
width: 36px;
height: 36px;
}
.app-menu-trigger {
flex-basis: 36px;
}
.header-tag {
font-size: 9px;
letter-spacing: 0;
max-width: 115px;
}
.about-view {
padding: 31px 0 24px;
}
.about-heading h1 {
font-size: 36px;
}
.about-intro {
font-size: 13px;
}
.about-grid {
grid-template-columns: minmax(0, 1fr);
gap: 10px;
margin-top: 23px;
}
.about-card-wide {
grid-column: auto;
}
.about-card {
padding: 17px;
}
.about-actions {
flex-direction: column;
}
.about-link-button {
width: 100%;
}
.studio-heading {
@@ -894,8 +1224,8 @@ ion-content.app-content {
}
.transport-inner {
gap: 4px;
padding-right: 80px;
gap: 7px;
padding-right: 14px;
padding-left: 14px;
}
@@ -903,6 +1233,20 @@ ion-content.app-content {
min-width: 98px;
}
.instrument-selector {
min-width: 130px;
font-size: 10px;
}
.instrument-selector-group {
min-width: 182px;
flex: 1 1 182px;
}
.pitch-control {
max-width: none;
}
.tempo-trigger,
.meter-trigger {
font-size: 10px;
@@ -916,14 +1260,14 @@ ion-content.app-content {
@media (max-width: 360px) {
.header-tag {
max-width: 145px;
max-width: 90px;
font-size: 8px;
text-align: right;
}
.transport-inner {
gap: 3px;
padding-right: 80px;
gap: 5px;
padding-right: 10px;
padding-left: 10px;
}
+112
View File
@@ -0,0 +1,112 @@
import { IonButton } from '@ionic/react';
import { PROJECT_INFO } from '../config/projectInfo';
interface AboutViewProps {
onReturnToStudio: () => void;
}
export function AboutView({ onReturnToStudio }: AboutViewProps) {
return (
<main className="about-view">
<header className="about-heading">
<p className="about-eyebrow">Project details</p>
<h1>About BeatHound</h1>
<p className="about-intro">
Technical information, source code, license, and ways to report a problem.
</p>
</header>
<div className="about-grid">
<section className="about-card" aria-labelledby="about-project-title">
<h2 id="about-project-title">Project</h2>
<dl className="project-metadata">
<div>
<dt>Version</dt>
<dd>{PROJECT_INFO.version}</dd>
</div>
<div>
<dt>Maintainer</dt>
<dd>Ninosaurier</dd>
</div>
<div>
<dt>Copyright</dt>
<dd>{PROJECT_INFO.copyright}</dd>
</div>
</dl>
</section>
<section className="about-card" aria-labelledby="about-license-title">
<h2 id="about-license-title">License</h2>
<p>
BeatHound is released under the GNU General Public License, version 3
or any later version (GPL-3.0-or-later).
</p>
<IonButton
className="about-link-button about-link-button-secondary"
fill="outline"
href={PROJECT_INFO.licenseUrl}
target="_blank"
rel="noreferrer"
>
Read the GPL license
</IonButton>
</section>
<section className="about-card" aria-labelledby="about-tech-title">
<h2 id="about-tech-title">Built with</h2>
<dl className="project-metadata">
<div>
<dt>Interface</dt>
<dd>React 19 and Ionic React 8</dd>
</div>
<div>
<dt>Language</dt>
<dd>TypeScript 5</dd>
</div>
<div>
<dt>Build tools</dt>
<dd>Vite 7 and Vitest 3</dd>
</div>
<div>
<dt>Audio</dt>
<dd>Browser Web Audio API</dd>
</div>
</dl>
</section>
<section className="about-card" aria-labelledby="about-support-title">
<h2 id="about-support-title">Source and support</h2>
<p>
Browse the source code or open the issue tracker to report a bug or
request an improvement.
</p>
<div className="about-actions">
<IonButton
className="about-link-button"
href={PROJECT_INFO.repositoryUrl}
target="_blank"
rel="noreferrer"
>
Source repository
</IonButton>
<IonButton
className="about-link-button about-link-button-secondary"
fill="outline"
href={PROJECT_INFO.issuesUrl}
target="_blank"
rel="noreferrer"
>
Report an issue
</IonButton>
</div>
</section>
</div>
<div className="about-return-row">
<IonButton className="about-return-button" onClick={onReturnToStudio}>
Back to the beat studio
</IonButton>
</div>
</main>
);
}
+31
View File
@@ -0,0 +1,31 @@
import { BeatLoopPanel } from '../components/BeatLoopPanel';
import { BeatTemplateSelector } from '../components/BeatTemplateSelector';
import type { BeatStudio } from '../hooks/useBeatStudio';
interface StudioViewProps {
studio: BeatStudio;
}
export function StudioView({ studio }: StudioViewProps) {
return (
<main id="studio" className="studio">
<div className="studio-heading">
<h1>Build a beat.</h1>
<p className="template-prompt">Choose a dance template</p>
<BeatTemplateSelector onSelectTemplate={studio.applyTemplate} />
<p
className={`intro-copy${studio.sequencer.beats.length > 0 ? ' is-hidden' : ''}`}
aria-hidden={studio.sequencer.beats.length > 0}
>
Add a sound, then move it around the loop.
</p>
</div>
<BeatLoopPanel sequencer={studio.sequencer} soundPalette={studio.soundPalette} />
{studio.sequencer.audioError && (
<p className="audio-error" role="alert">{studio.sequencer.audioError}</p>
)}
</main>
);
}
+1
View File
@@ -0,0 +1 @@
export type AppView = 'studio' | 'about';